Skip to content

fix(windows): hide console window for git child processes#505

Closed
yushengruohui wants to merge 2 commits into
colbymchenry:mainfrom
yushengruohui:fix/windows-hide-git-spawn
Closed

fix(windows): hide console window for git child processes#505
yushengruohui wants to merge 2 commits into
colbymchenry:mainfrom
yushengruohui:fix/windows-hide-git-spawn

Conversation

@yushengruohui
Copy link
Copy Markdown

Fixes #485.

Summary

On Windows, the daemon flashes a black git.exe console window on every auto-sync. The cause is execFileSync('git', …) call sites in the daemon's code paths missing windowsHide: true. This PR adds the option to all 7 sites; the change is a one-liner per call site and a no-op on macOS/Linux.

Root cause

The daemon is launched with detached: true (mcp/index.ts, the existing spawn(process.execPath, …) call), which deliberately leaves it without a parent console. On Windows, when a Console-subsystem child (git.exe) is started from a console-less parent, Windows allocates a fresh console window for it unless CREATE_NO_WINDOW is set. Node maps windowsHide: true to CREATE_NO_WINDOW. Without it, every short-lived git invocation flashes its own window. The daemon launcher itself already passes windowsHide: true — it's the git call sites that were missed.

Call sites changed (7 total)

File Function / line git command
src/extraction/index.ts collectGitFiles shared gitOpts ls-files -c --recurse-submodules, ls-files -o --exclude-standard
src/extraction/index.ts getGitVisibleFiles rev-parse --show-toplevel
src/extraction/index.ts getGitVisibleFiles check-ignore -q
src/extraction/index.ts getGitChangedFiles status --porcelain --no-renames
src/sync/worktree.ts gitWorktreeRoot rev-parse --show-toplevel
src/sync/git-hooks.ts isGitRepo rev-parse --is-inside-work-tree
src/sync/git-hooks.ts gitHooksDir rev-parse --git-path hooks

The fix is the same one-line addition (windowsHide: true) on each options object.

Verification

  1. Apply the patch and rebuild (npm run build).
  2. Restart the daemon: kill the PID in .codegraph/daemon.pid, then trigger any CodeGraph CLI/MCP call so it respawns.
  3. Edit files in an indexed repo at >1 write/sec. The git.exe console window should no longer flash. .codegraph/daemon.log still shows the [CodeGraph MCP] Auto-synced N file(s) in <ms>ms lines — i.e. the sync still runs, just hidden.
  4. macOS/Linux: windowsHide is ignored, behavior unchanged.

Notes for reviewers

  • extraction/wasm-runtime-flags.ts uses spawnSync(process.execPath, …, { stdio: 'inherit' }) — the relaunch shim spawns Node from a Node parent that already owns a console, so no new window is allocated and no change is needed.
  • Optional follow-up (not in this PR to keep the diff minimal): extract a runGit(args, opts) helper that injects windowsHide: true so this can't regress.

yushengruohui and others added 2 commits May 27, 2026 23:28
The codegraph daemon shells out to git via execFileSync without
windowsHide:true. Because the daemon is launched with detached:true
(no parent console), Windows allocates a fresh console window for
every git child. Each short-lived git invocation makes that window
flash on screen — very visible during auto-sync, where many file
writes can trigger several git calls per second.

This sets windowsHide:true on all 7 git call sites:

  - src/extraction/index.ts: shared gitOpts (covers ls-files
    --cached and -o), plus 3 inline opts for rev-parse,
    check-ignore, and status --porcelain
  - src/sync/worktree.ts:    rev-parse --show-toplevel
  - src/sync/git-hooks.ts:   rev-parse --is-inside-work-tree,
                             rev-parse --git-path hooks

mcp/index.ts already passes windowsHide:true when spawning the
detached daemon — these git call sites were missed.

windowsHide:true is a no-op on macOS and Linux.

Fixes colbymchenry#485
Add windowsHide:true to the 4 execFileSync call sites in
src/extraction/index.ts (1 shared gitOpts plus 3 inline option
objects for rev-parse --show-toplevel, check-ignore -q, and
status --porcelain --no-renames).

Companion to the previous commit on this branch which covered the
sync/ module. See colbymchenry#485 for context.
ZyphrZero added a commit to ZyphrZero/codegraph that referenced this pull request May 28, 2026
…de-git-spawn

fix(windows): hide console window for git child processes
ZyphrZero added a commit to ZyphrZero/codegraph that referenced this pull request May 28, 2026
fix(windows): suppress console popup on child_process calls

Resolves overlap with PR colbymchenry#505 (which already added windowsHide to
the 7 git child-process call sites). Keeps PR colbymchenry#498's additional
coverage:
  - WASM relaunch in extraction/wasm-runtime-flags.ts
  - npm install -g in installer/index.ts (preserving the fork's
    @changqiu/codegraph package name)
  - Antigravity codegraph-path resolution
  - mcp/engine.ts comment cleanup

Verified:
  - tsc --noEmit clean
  - sync, git-hooks, installer-targets, wasm-runtime-flags tests:
    160 passed, 0 failed
ZyphrZero added a commit to ZyphrZero/codegraph that referenced this pull request May 28, 2026
Includes Windows console-popup fixes from PR colbymchenry#498 on top of the
existing 0.9.6 fork (PR colbymchenry#415 drive-root path, PR colbymchenry#505 git
windowsHide). Republished under @changqiu/codegraph.
colbymchenry pushed a commit that referenced this pull request May 28, 2026
On Windows, v0.9.5's detached shared daemon (#411) has no inherited console,
so any console-subsystem child it spawns gets a fresh visible console window
unless the spawn passes `windowsHide: true`. The fix adds the flag to all
ten `spawnSync` / `execFileSync` / `execSync` call sites across extraction,
sync, installer, and the WASM-flags relaunch. macOS/Linux ignore the option,
so this is a no-op elsewhere.

Fixes #485, #510, #530.

Co-authored work:
- #498 (csw-chen) — full sweep across extraction, sync, installer, and wasm-runtime. **This is the change being merged.**
- #505 (yushengruohui) — independently identified and fixed the 7 git execFileSync sites. Superseded by #498's broader sweep; same diagnosis.
- #521 (JirA44) — independently identified and fixed the WASM-runtime spawnSync re-exec. Superseded by #498's broader sweep; same diagnosis.

Validated on Windows 11 ARM64 (Parallels): a detached parent's 15 git spawns produce 15 visible black flash-windows without the fix and 0 with it.
@colbymchenry
Copy link
Copy Markdown
Owner

Thanks for the precise diagnosis and the careful per-call-site breakdown — your investigation matched the root cause exactly.

Closing as superseded by #498, which lands the same windowsHide: true change at the 7 git execFileSync sites you identified plus the 3 other call sites (WASM spawnSync relaunch, installer execSync, antigravity target) that were missing the flag for the same reason. Merged in cea78ce.

Validated on Windows 11 ARM64 (Parallels): a detached parent's 15 git spawns produce 15 visible black flash-windows without the fix and 0 with it. Fixes #485, #510, #530.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: Daemon process creates flashing black console windows

2 participants