codegraph icon indicating copy to clipboard operation
codegraph copied to clipboard

Windows: daemon's file watcher flashes console windows (two git calls missing windowsHide)

Open HarryMuc opened this issue 2 months ago • 3 comments

Title: Windows: daemon's file watcher flashes console windows (two git calls missing windowsHide)

Version: 1.6.1 (win32-x64), Windows 11

On Windows, a console window titled …\Git\cmd\git.exe briefly flashes every few seconds while codegraph serve --mcp is running.

Cause: The MCP daemon is spawned detached, so it has no console. Any child process it starts without windowsHide: true gets its own visible console window. Nearly all git calls already pass windowsHide: true, but two in lib/dist/extraction/index.js don't:

  • git -C <root> config --get core.excludesFile (~line 345)
  • git -C <root> ls-files -z -o -i --exclude-standard --directory in listGitIgnoredDirectories (~line 368)

The watcher calls both repeatedly, which causes the flashing.

Fix: Add windowsHide: true to the execFileSync options of both calls. After patching locally and restarting the daemon, no more windows appear. ui-server/api/trails.js (~line 346, git config user.name) is missing it too, for consistency.

HarryMuc avatar Sep 29 '26 13:09 HarryMuc

Confirmed on 1.6.1 / Windows 11. In 1.6.0 every git call in extraction/index.js passes windowsHide: true, so this is a 1.6.1 regression (see #2094).

Setup: ~10 Claude Code sessions, each in its own git worktree with its own .codegraph index, each running codegraph serve --mcp. While tests in those worktrees were writing files, git.exe console windows (parent: the codegraph node process) flashed almost continuously. The rate grew with the number of worktrees and with file churn.

nirecom avatar Sep 29 '26 14:09 nirecom

Confirming this on the same setup: codegraph 1.6.1 (win32-x64), Windows 11 Pro 10.0.26200, Node 24.21.0, Git for Windows 2.54.0, with the daemon launched by Claude Code as an MCP server.

A few data points that may help:

A dev server makes it continuous. With next dev running, every interaction with the app writes files. Each write triggers the watcher and produces another burst of flashes. The flashes also appeared with the MCP client closed, as long as a daemon was still alive (see the last point).

One file change spawns a burst of git processes. I polled Win32_Process for children of the serve --mcp --path <repo> daemon and touched the mtime of a single source file. Within about 1 s the daemon spawned:

git rev-parse HEAD
git -C <repo> config --get core.excludesFile          (x4)
git -C <repo> ls-files -z -o -i --exclude-standard --directory
git status --porcelain --no-renames -z -uall

core.excludesFile alone ran four times for one change. Caching the ignore rules between events (or debouncing their recomputation) would reduce the process churn even after the windowsHide fix.

Side note for anyone else debugging this: the calls that already pass windowsHide: true also get a conhost.exe, just hidden. So seeing conhost.exe in the process list does not tell you which call is visible.

The proposed fix works. I added windowsHide: true to both calls (readGitExcludeExtraPatterns around line 345, listGitIgnoredDirectories around line 368), then restarted the MCP client so the front process reloaded the module. Restarting only the daemon was not enough. The flashes stopped completely, including with the dev server running.

Possibly related: an orphaned daemon. In one earlier session, the serve --mcp --path <repo> daemon kept running after the MCP client had exited. Its parent PID no longer existed, so it kept watching and kept flashing windows with nothing attached. The client starts the server as cmd.exe /d /s /c codegraph serve --mcp → npm-shim.js → node. I could not reproduce this after a clean client exit, so it may have been a one-off. If it happens again, I can open a separate issue.

Paul-DanielPop avatar Sep 30 '26 13:09 Paul-DanielPop

Additional confirmed reproduction using Codex CLI 0.159.2 and the Windows desktop app 26.928.2636.0, with CodeGraph 1.6.1 win32-x64, bundled Node v24.16.0, Git for Windows 2.54.0, and Windows 11 Pro 26H1 (28000.1719).

This initially looked like the Codex daemon console regression, but recording actual window-show events and ancestry identified the remaining flashes as:

git.exe
  <- CodeGraph per-project node.exe
  <- CodeGraph MCP frontend node.exe
  <- npm-shim.js node.exe
  <- cmd.exe /c codegraph serve --mcp
  <- codex.exe app-server

The desktop app-server was not the shared --managed-daemon. The foreground CLI and the desktop app were both affected while CodeGraph was enabled. Seeing a conhost.exe alone was insufficient; the offending Git windows were confirmed visible.

Reproduction and regression check

  1. Use CodeGraph 1.6.1 on Windows with an indexed Git repository and run codegraph serve --mcp under a GUI/background MCP client such as Codex.
  2. Cause ignore-scope/freshness evaluation (or change a watched source file).
  3. Observe visible Git console windows. Their frequency depends on watcher/freshness activity.
  4. For a deterministic code-path check, wrap child_process.execFileSync to record the Git verb and whether options.windowsHide === true, then invoke the real exported buildScopeIgnore(root) in lib/dist/extraction/index.js against a tiny independent indexed Git fixture.

Before the patch, one buildScopeIgnore() invocation issued six Git calls: three had windowsHide: true, and three did not (the core.excludesFile lookup was called twice, plus the ignored-directory lookup). An assertion requiring the option for every Git invocation failed. After adding the missing options, all six calls passed; five repeated runs passed.

Local fix and verification

Added windowsHide: true at the two reported call sites in lib/dist/extraction/index.js, and at the git config user.name call in lib/dist/ui-server/api/trails.js. Arguments, stdio, timeouts, and return handling were unchanged. Both modified JavaScript files passed the bundled Node's --check.

Already-running CodeGraph Node processes retained the old module in memory. For this diagnostic session, the equivalent Git-only execFileSync option was also applied to the verified existing CodeGraph processes through the local Node Inspector, then the Inspector listeners were closed. New processes use the patched package files. This avoided interrupting active Codex sessions; a normal restart of the MCP clients is the simpler way to reload the package patch.

Crucially, verification was done after stopping the temporary window-hiding utility and restoring the original Windows Terminal delegation setting. An EVENT_OBJECT_SHOW observer plus 25 ms polling of both ConsoleWindowClass and CASCADIA_HOSTING_WINDOW_CLASS saw zero new visible terminal windows over 45 seconds, while the existing manual terminals remained visible. CodeGraph CLI explore and the actual desktop MCP codegraph_explore query both returned the fixture's function successfully. The original Codex CLI and desktop app-server processes continued running.

This confirms that the residual flashes in this environment come from the missing child-process options here, even with the Codex 0.159.2 main background-spawn paths already using CREATE_NO_WINDOW. A post-creation hider only reduced the flashes and was not the fix.

No private project paths, account identifiers, full configuration files, or raw process command lines are included in this report.

Final shared-daemon verification

A separate old shared Codex daemon package (0.157.1) was also present on this machine. It was replaced with the verified official 0.159.2 CLI package, and normal CLI daemon auto-start was restored. The running managed app-server now reports 0.159.2. The daemon's startup produced zero new visible terminal windows in another 45-second observation.

Over the actual managed daemon's Unix-socket WebSocket command/exec API, four read-only probes (PowerShell date, Node print, CMD echo, Git version) all returned exit code 0. A separate 20-second native window observation covering those commands also saw zero new visible terminal windows, with no window-hiding utility running. These probes used an explicit per-request dangerFullAccess policy to isolate process spawning; the global sandbox configuration was not changed. Default Windows sandbox access to the NVM Node path was not part of the passing matrix.

Chasen-Liao avatar Sep 30 '26 16:09 Chasen-Liao