Skip to content

fix(spawn): hide the remaining Windows console windows on git child launches - #687

Merged
jeff-r2026 merged 2 commits into
Tencent:mainfrom
CarlosWonMore:fix/windowshide-git-provider-spawns
Sep 21, 2026
Merged

jeff-r2026 merged 2 commits into
Tencent:mainfrom
CarlosWonMore:fix/windowshide-git-provider-spawns

Conversation

@CarlosWonMore

@CarlosWonMore CarlosWonMore commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #686.

What

#679 hid the console window on the child launches it could reach. A run-time audit of the released
0.24.0 build — every child_process launch instrumented, 101 launches across init /
import --from-repo / doctor / packages — found three more git launches on a code path #679
did not touch. This PR fixes those three plus the siblings that reading the same two files turns up.

file function before
src/providers/git/index.ts:28 gitIdentity() spawnSync('git', ['config','--get','user.name'], …) — no windowsHide
src/providers/git/index.ts:72 ensureInstalled() spawnSync('git', ['--version'], …) — no windowsHide
src/providers/git/index.ts:85 cloneRepo() spawnSync('git', ['clone','--',…], …) — no windowsHide
src/wiki-engine/code-knowledge/code-collector.ts:146 gitCommit() execFileAsync('git', ['-C', root, 'rev-parse','HEAD']) — no options object at all
src/wiki-engine/code-knowledge/code-collector.ts:162 isWorkingTreeClean() execFileAsync(…) — no options object
src/wiki-engine/code-knowledge/code-collector.ts:183 gitDiffNameStatus() execFileAsync(…) — no options object

The first two are GenericGitProvider, which is selected only when the repository host is not one
we recognise — so #679's provider / gitHub / gitLab branches never reached them. The
code-collector three run on every teamai import --from-repo / wiki scan.

The code-collector change hoists one module-level constant so the three call sites stay in sync:

const GIT_EXEC_OPTIONS = { windowsHide: true } as const;

cloneRepo() is not in the audit table (the git provider never reached a clone in that run) but
shares its second-argument shape with ensureInstalled() and flashes once per clone, so it is
fixed here too.

Why it matters

A parent with no console of its own — a GUI host or a hook host — makes Windows give the child a
new one, which flashes a visible window. Before this change a single teamai init <git-url> plus a
single teamai import --from-repo starts four such children: the audit recorded 4 launches with
windowsHide=None out of 101, three of them on these branches.

Tests

  • src/__tests__/generic-git-provider.test.ts — new GenericGitProvider — windowsHide block drives
    ensureInstalled() → authenticate() → cloneRepo() and asserts all three spawnSync calls
    carry windowsHide: true.
  • src/__tests__/code-collector-windowshide.test.ts (new) — mocks node:child_process, drives the
    three helpers, asserts the same on the options object handed to execFile.

Both assert on the options object on purpose: CI has no Windows runner
(os: [ubuntu-latest, macos-latest]), so nothing else can catch a missing windowsHide.

Verified locally on Windows 11 25H2 / Node 22.22.2:

step result
tsc --noEmit clean (0 lines)
those two files, patch applied Test Files 2 passed (2) / Tests 19 passed (19)
those two files, patch reverted Test Files 2 failed (2) / Tests 2 failed | 17 passed

The revert run fails on exactly the two new assertions, i.e. the tests do guard the change:

expected { encoding: 'utf-8', …(2) } to deeply equal ObjectContaining {"windowsHide": true}
expected 'function' to be 'object' // Object.is equality

Real-CLI end-to-end verification on this build

The 101-launch audit above was measured against released 0.24.0. It documents what those branches
did before this PR; it is not evidence about this build. Here is the same instrument re-run on the
built output of the branch head.

Build. npm run build → dist/index.js 1,804,627 B (head 3cb1b28, Windows 11 25H2,
Node 22.22.2, tsup 8.5.1).

Harness. The git provider channel from the #679 audit: a bare fixture repo exported by
git daemon on 127.0.0.1:9418, reached as https://127.0.0.1:9418/group/fixture.git so the host
is unknown and resolveHostProvider selects GenericGitProvider. USERPROFILE / HOME and
GIT_CONFIG_GLOBAL are redirected into a scratch directory, and the credential guards are the same
(GIT_TERMINAL_PROMPT=0, GCM_INTERACTIVE=never, GCM_GUI_PROMPT=0, GIT_ASKPASS=,
SSH_ASKPASS=). Every child_process entry point is wrapped by a CJS --require shim.

Commands and results.

# command exit launches missing windowsHide
1 init <url> --scope user --agent codebuddy --force 0 31 0
2 import --from-repo <url> --skip-enrich --all --output <out> 0 14 0
3 import --from-repo <url> --incremental --skip-enrich --all --output <out> 0 18 0
total 63 0

All six call sites this PR touches were reached on the real paths:

call site launch shape reached by launches
providers/git/index.ts ensureInstalled() spawnSync('git', ['--version'], …) init 1
providers/git/index.ts gitIdentity() spawnSync('git', ['config','--get','user.name'], …) init 1
providers/git/index.ts cloneRepo() spawnSync('git', ['clone','--',…], …) init 1
code-collector.ts gitCommit() execFile('git', ['-C',<cache>,'rev-parse','HEAD'], …) import 3
code-collector.ts isWorkingTreeClean() execFile('git', ['-C',<cache>,'status','--porcelain'], …) import --incremental 1
code-collector.ts gitDiffNameStatus() execFile('git', ['-C',<cache>,'-c','core.quotePath=false','diff','--name-status','-M','-C',<old>,<new>], …) import --incremental 1

Raw records, showing the options object arrived at the three execFile shapes:

{"fn":"execFile","cmd":"git","args":["-C","…\\cache\\repos\\git\\group\\fixture","rev-parse","HEAD"],"hasOptions":true,"windowsHide":true,"stdio":null,"shell":null}
{"fn":"execFile","cmd":"git","args":["-C","…\\cache\\repos\\git\\group\\fixture","status","--porcelain"],"hasOptions":true,"windowsHide":true,"stdio":null,"shell":null}
{"fn":"execFile","cmd":"git","args":["-C","…\\cache\\repos\\git\\group\\fixture","-c","core.quotePath=false","diff","--name-status","-M","-C","0b3a193cde29fb05acc38eff2ce90103ae0e9986","0cfb450976422a9a03591a81eaf2003b875342ee"],"hasOptions":true,"windowsHide":true,"stdio":null,"shell":null}

The incremental run fetched a real new fixture commit and acted on the diff, so the code-collector
paths were live rather than skipped:

ℹ [incremental] cache hit …\cache\repos\git\group\fixture, syncing from 0b3a193c
ℹ [incremental] Fetch complete: SHA=0cfb4509
[extract] incremental: 1 files changed, 0 deleted

For comparison, the #679 run recorded windowsHide=None on 4 of 101 launches under these same
commands — three of them on the branches this PR fixes. On this build: 0 of 63.

The instrument had to be fixed before it could be trusted. The first shim replaced the six
child_process entries with a plain function (...args) { record(...); return original.apply(this, args); },
which drops util.promisify.custom. promisify(execFile) then degrades from { stdout, stderr } to
a bare string, so code-collector's const { stdout } = … received undefined, stdout.trim()
threw, and each function's own catch swallowed it — the shim was manufacturing a silent failure
and hiding the very incremental path it was meant to observe. spawn-audit.cjs now re-attaches the
symbol after wrapping, and the unfixed original is kept next to it so the #679 numbers stay
reproducible.

What this does not cover. The five clone functions added in 3cb1b28 (ghRepoClone,
gitlabRepoClone, gitcodeRepoClone, cnbRepoClone, gfRepoClone) run only when the host matches
github / gitlab / gitcode / cnb / tgit, which needs a live instance and a token per
provider, so the git channel cannot reach them. They are covered by
src/__tests__/provider-clone-windowshide.test.ts instead: every git launch is asserted to carry
windowsHide: true, and the CNB no-token path launches twice so the credential-helper write is
covered too. With the patch the three related files give Test Files 3 passed (3) /
Tests 24 passed (24); with the five provider files restored to HEAD and only the test file kept,
Tests 5 failed (5), each on
expected { encoding: 'utf-8', …(2) } to deeply equal ObjectContaining {"windowsHide": true}.
Since CI runs only ubuntu-latest / macos-latest, that assertion is the only guard this Windows
behaviour has.

One incidental finding, out of scope here: isWorkingTreeClean() is unreachable in practice. The
product writes its own cache artefacts (LAST_SYNC, teamwiki/) into the same tree it then asks
git status --porcelain about, so the tree is never clean and gitDiffNameStatus() only runs when
those are excluded. The run above adds them to the cache clone's .git/info/exclude, which touches
the scratch clone and not the repo under test; worth a separate issue.

Not cited: the whole-suite run

I am not presenting a green whole-suite run, because on this Windows host the signal is
swamped. A full run reports 52 failed | 213 passed files and 180 failed | 3415 passed tests,
but the two files this PR touches are not in the failing set, and 149 of the 180 failures are
temp-directory artefacts:

count error
86 Test timed out in 5000ms
46 EBUSY: resource busy or locked, rmdir 'C:\Users\…\AppData\Local\Temp\…'
9 Hook timed out in 15000ms
8 [vitest-worker]: Timeout calling "onTaskUpdate"
~25 genuine Windows platform mismatches (0o600 vs 0o666, alpha\real.md vs alpha/real.md, …)

So: not a regression claim, and not a pass claim — the suite simply is not a usable gate here.

To put numbers behind that, I re-ran those 52 files serially with --testTimeout=30000 --hookTimeout=60000. I stopped the sweep after 6 files (19 minutes; the full sweep would have run
for hours), and 4 of the 6 that had failed in the parallel run passed outright:

file parallel run serial re-run
contribute-self-learnings.test.ts 3 failed ✅ 3 passed
local-agent-mcp.test.ts failed ✅ 17 passed
migrate.test.ts failed ✅ 32 passed
pull-submodule-skip-sync.test.ts failed ✅ 2 passed
git-kind-reports.test.ts failed ❌ 10 of 16 still fail
local-agent.test.ts failed ❌ 2 of 70 still fail

The last two do not import either module this PR touches — git-kind-reports.test.ts drives
simple-git and utils/reports-branch.js, local-agent.test.ts drives hooks.js — and their
detailed failure output is only printed at the end of a run, which I stopped before it got there,
so I am deliberately not characterising them. 4 of 6 flipping to green purely by removing
parallelism is the shape of the noise, not of a regression.

…aunches

#679 hid the console window on the child launches it could reach, but a
run-time audit of an installed 0.24.0 build (101 child processes observed,
report at teamai-e2e/E2E-REPORT.md §4) found three more git spawns that still
run without `windowsHide`:

  src/providers/git/index.ts
    - gitIdentity()        spawnSync('git', ['config', '--get', 'user.name'])
    - ensureInstalled()    spawnSync('git', ['--version'])
  src/wiki-engine/code-knowledge/code-collector.ts
    - gitCommit()          execFileAsync('git', ['-C', root, 'rev-parse', 'HEAD'])
                           (no options object was passed at all)

Those three sat outside #679's scope. The first two are GenericGitProvider,
which only runs for a repository whose host we do not recognise, so #679's
`provider` / `gitHub` / `gitLab` paths never touched them; the third runs on
every `teamai import --from-repo` scan. `gitCommit()`'s two neighbours in the
same module — `isWorkingTreeClean()` (`git status --porcelain`) and
`gitDiffNameStatus()` (`git diff --name-status`) — launch the same kind of
child with the same missing option and are fixed alongside it.

`cloneRepo()` in the same file is not in the audit table (the `git` provider
never reached a clone in that run) but shares its second argument shape with
`ensureInstalled()` and flashes once per clone, so it is fixed here too.

When the parent has no console of its own — a GUI host or a hook host —
Windows gives the child a new one, which flashes a visible window.

Tests
  - `generic-git-provider.test.ts`: new `GenericGitProvider — windowsHide`
    block drives `ensureInstalled()` -> `authenticate()` -> `cloneRepo()` and
    asserts all three `spawnSync` calls carry `windowsHide: true`.
  - `code-collector-windowshide.test.ts` (new): mocks `node:child_process`,
    drives the three helpers and asserts the same on the options object passed
    to `execFile`.

CI has no Windows runner (`os: [ubuntu-latest, macos-latest]`), so these
assertions on the options object are the only guard available.
@github-actions

Copy link
Copy Markdown
  • [P1 blocking] Incomplete fix leaves reachable Git clone launches visible on Windows. Adding windowsHide only to GenericGitProvider.cloneRepo() at src/providers/git/index.ts:97 misses the equivalent production paths used by recognized providers: src/providers/github/gh-cli.ts:259, src/providers/gitlab/gitlab-api.ts:190, src/providers/gitcode/gitcode-api.ts:180, src/providers/cnb/cnb-cli.ts:238, and src/providers/tgit/gf-cli.ts:354. These are called through each provider’s cloneRepo() during teamai init, so console flashes remain despite the PR’s stated “remaining Windows console windows” goal.

  • [P1 blocking] PR description lacks the required post-change real-CLI/e2e verification. It records tsc, targeted mocked unit tests, and an audit of the already-released 0.24.0 build, but does not show npm run build followed by an actual patched teamai CLI workflow. The trusted review rules explicitly require a real-CLI end-to-end verification record before merge.

The review on #687 pointed out that the fix only covered
`GenericGitProvider.cloneRepo()`. The identified-provider production paths
launch `git clone` the same way, and `teamai init` reaches them whenever the
remote host is known:

  - providers/github/gh-cli.ts     ghRepoClone()
  - providers/gitlab/gitlab-api.ts gitlabRepoClone()
  - providers/gitcode/gitcode-api.ts gitcodeRepoClone()
  - providers/cnb/cnb-cli.ts       cnbRepoClone() (clone + credential-helper write)
  - providers/tgit/gf-cli.ts       gfRepoClone()

All six spawn sites now pass `windowsHide: true`, matching the existing style
in clone.ts / builtin-hooks.ts / hook-dispatch-cli.ts.

provider-clone-windowshide.test.ts drives each clone function with a mocked
`node:child_process` and asserts the option is present on every `git` launch
(the CNB no-token path launches twice, so it covers the credential-helper
write too). CI runs on ubuntu/macos only, so these assertions are the only
guard against this regressing on Windows.

Internal-path `spawnSync('bash', ...)` calls in tgit/gf-cli.ts are deliberately
left alone: they are not git launders and are tracked separately in #686.
@CarlosWonMore

Copy link
Copy Markdown
Contributor Author

Both P1s addressed. 3cb1b28 covers the missing spawn sites; 885a539 now has a real build + real-CLI record.

1. Incomplete fix — the identified-provider clone paths

You are right, and my "listed in #686 for the maintainers to decide" framing was the wrong call for a PR that claims to fix the Windows flash. All six sites now pass windowsHide: true:

file function launch
providers/github/gh-cli.ts:259 ghRepoClone() spawnSync('git', ['clone', …])
providers/gitlab/gitlab-api.ts:190 gitlabRepoClone() spawnSync('git', args, …)
providers/gitcode/gitcode-api.ts:180 gitcodeRepoClone() spawnSync('git', ['clone', …])
providers/cnb/cnb-cli.ts:238 cnbRepoClone() spawnSync('git', args, …)
providers/cnb/cnb-cli.ts:252 cnbRepoClone() spawnSync('git', ['config','--local','credential.helper', …])
providers/tgit/gf-cli.ts:354 gfRepoClone() spawnSync('git', ['clone', …])

Style matches what is already in clone.ts:93 / builtin-hooks.ts:175 / hook-dispatch-cli.ts:277 — the option only, no comment.

provider-clone-windowshide.test.ts drives each clone function with a mocked node:child_process and asserts the option on every git launch. The CNB case deliberately unsets CNB_TOKEN so the no-token branch runs and the credential-helper write is covered too:

✓ provider-clone-windowshide.test.ts (5 tests)
Test Files  3 passed (3)      Tests  24 passed (24)

Reverting the five provider files to HEAD while keeping the tests:

Tests  5 failed (5)
AssertionError: expected { encoding: 'utf-8', …(2) } to deeply equal ObjectContaining {"windowsHide": true}

Being straight about the coverage limit: these six paths cannot be reached by the real-CLI harness I have. They are only selected when the host resolves to github/gitlab/gitcode/cnb/tgit, which needs each vendor's live instance plus a token. The git-provider channel never enters them. So the real-CLI record below covers 885a539; this batch is guarded by unit assertions only — which is also the only guard CI can run, since it has no Windows job.

tgit/gf-cli.ts:51,59 (spawnSync('bash', …)) is left alone: same class of defect, but not a git launch, and it is tracked in #686.

2. The build + real-CLI record

npm run build → dist/index.js 1,804,489 B. Harness is the git provider over a local git daemon fixture, same construction as the #679 report, driven through the CJS --require spawn auditor.

command exit child launches missing windowsHide
init <url> --scope user --agent codebuddy 0 36 0
import --from-repo <url> --skip-enrich --all 0 14 0
import --from-repo <url> --incremental … 0 18 0
total 68 0

All six call sites of this PR were hit on the real path:

call site launch seen
providers/git/index.ts ensureInstalled() spawnSync git --version 1
providers/git/index.ts gitIdentity() spawnSync git config --get user.name 1
providers/git/index.ts cloneRepo() spawnSync git clone -- 1
code-collector.ts gitCommit() execFile git -C <cache> rev-parse HEAD 4
code-collector.ts isWorkingTreeClean() execFile git -C <cache> status --porcelain 1
code-collector.ts gitDiffNameStatus() execFile git -C <cache> -c core.quotePath=false diff --name-status -M -C <old> <new> 1

For contrast, the #679 run recorded 4 launches with windowsHide: None on these same commands.

3. Two things I found while producing that record

(a) The audit harness itself was producing a false failure mode. The original spawn-audit.cjs replaced each child_process entry with a plain function (...args), which loses util.promisify.custom. promisify(execFile) then resolved to a bare stdout string instead of { stdout, stderr }, so const { stdout } = await execFileAsync(...) in code-collector.ts yielded undefined, stdout.trim() threw, and the catch in gitCommit / isWorkingTreeClean / gitDiffNameStatus swallowed it. Symptom: gitCommit() always undefined, so source-manifest.json never got its headSha. Reproduced directly:

untouched  -> typeof=object value={"stdout":"8825d434…\n","stderr":""}
naive wrap -> typeof=string value="8825d434…\n"
naive wrap -> const { stdout } = ...; stdout.trim() => THREW TypeError

Fixed by re-attaching the custom promisify on the wrapper; the original is kept as spawn-audit.orig.cjs. The hasOptions=False observation in the #679 report still stands (it reads the call arguments, not the promise), but any inference there about which code path code-collector took should be read against this report instead.

(b) gitDiffNameStatus() looks unreachable in production, for an unrelated reason. code-incremental.ts:34 gates on isWorkingTreeClean(root), but import-repo.ts:312-330 writes LAST_SYNC and teamwiki/ into that same cache dir before extraction. Both are untracked, so git status --porcelain is never empty and the git diff path always falls through to the sha256 scan. To exercise the sixth row above I added those two names to the cache repo's .git/info/exclude — a fixture-only change, no product code touched. Happy to open a separate issue if you want it tracked; I did not fold it into this PR.

Full report, raw .jsonl audits and the repro script: E2E-REPORT-687.md (2026-09-21).

4. Local checks

npx tsc --noEmit → exit 0. npx vitest run over the three touched test files → 3 passed / 24 tests.

@github-actions

Copy link
Copy Markdown
  • [P1 blocking] The PR description lacks the required post-change real-CLI end-to-end verification. It reports tsc --noEmit and mocked unit tests; the 101-launch audit was performed against released 0.24.0, not this patched build. Per AGENTS.md, run npm run build, exercise the built CLI end-to-end, and record the actual commands and results in the Test Plan before merge.

@CarlosWonMore

Copy link
Copy Markdown
Contributor Author

Addressed in the PR description — ## Real-CLI end-to-end verification on this build now sits above
## Not cited: the whole-suite run.

You were right that the 101-launch audit was not evidence about this build: it was measured on
released 0.24.0. I re-ran the same instrument on the built output of the branch head (3cb1b28,
npm run build → dist/index.js 1,804,627 B):

command launches missing windowsHide
init <url> --scope user --agent codebuddy --force 31 0
import --from-repo <url> --skip-enrich --all 14 0
import --from-repo <url> --incremental --skip-enrich --all 18 0
total 63 0

All six call sites are listed in the description with the path that reaches each one and the observed
launch count, plus the raw audit JSON for the three execFile shapes. The incremental run fetched a
real new fixture commit (0b3a193c → 0cfb4509, 1 files changed), so isWorkingTreeClean() and
gitDiffNameStatus() were live rather than skipped off the end of a guard.

The five provider clone functions added in 3cb1b28 still cannot be reached from this channel — they
need a live instance and a token per provider — so they stay guarded by
provider-clone-windowshide.test.ts: Test Files 3 passed (3) / Tests 24 passed (24) with the
patch, Tests 5 failed (5) when the five provider files are restored to HEAD.

One correction to the instrument itself, also written up in the description: the first version of the
shim dropped util.promisify.custom when it wrapped child_process, which silently degraded
promisify(execFile) to a bare string and made code-collector fail in a way the audit could not
see. That was fixed before any of the numbers above were taken.

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.

[bug] #679 之后仍有 3 处 git 子进程缺少 windowsHide(GenericGitProvider + code-collector)

2 participants