Skip to content

[PIR #1919] Windows: hide child-process console windows; throttle Team view refresh - #1932

Merged
amrmelsayed merged 22 commits into
mainfrom
builder/pir-1919
Nov 18, 2026
Merged

amrmelsayed merged 22 commits into
mainfrom
builder/pir-1919

Conversation

@amrmelsayed

@amrmelsayed amrmelsayed commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

PIR Review: Windows console window flashes while an agent works

Fixes #1919

Summary

On native Windows a console window flashed about twice a second while an agent worked in a VS Code Codev terminal. Tower, started detached, has no console, so every console program it spawned without windowsHide got a visible window of its own. The VS Code Team view refreshed on every Tower SSE event (about one per agent tool call), and each refresh made Tower run an unhidden git remote get-url origin. This PR hides every spawn reachable from Tower, afx spawn / afx tower and the extension host, makes the Team view fetch on SSE only while visible and at most every 30 s, caches the origin lookup, and adds a guard test that fails CI on any new unhidden spawn in those import graphs.

Files Changed

  • apps/vscode/src/__tests__/cli-process.test.ts (+32 / -3)
  • apps/vscode/src/__tests__/team-view-refresh.test.ts (+161 / -0)
  • apps/vscode/src/activity-hooks.ts (+1 / -0)
  • apps/vscode/src/cli-process.ts (+29 / -1)
  • apps/vscode/src/clipboard-image.ts (+3 / -1)
  • apps/vscode/src/commands/approve.ts (+2 / -5)
  • apps/vscode/src/commands/cleanup.ts (+2 / -5)
  • apps/vscode/src/commands/press-cursor-ref.ts (+1 / -1)
  • apps/vscode/src/commands/view-diff.ts (+7 / -7)
  • apps/vscode/src/extension.ts (+6 / -1)
  • apps/vscode/src/review-queue/store.ts (+1 / -1)
  • apps/vscode/src/views/team.ts (+100 / -3)
  • codev/plans/1919-windows-console-window-flashes.md (+216 / -0)
  • codev/projects/1919-windows-console-window-flashes/status.yaml (porch state)
  • codev/resources/arch.md (Platform Layer: console windows)
  • codev/resources/lessons-learned.md (Debugging: reproduce through the user's launch path)
  • codev/reviews/1919-windows-console-window-flashes.md (this file)
  • codev/state/pir-1919_thread.md (+15 / -0)
  • packages/codev/src/__tests__/issue-1919-hidden-spawns.test.ts (+98 / -0)
  • packages/codev/src/__tests__/windows-console-spawn-guard.test.ts (+264 / -0)
  • packages/codev/src/agent-farm/__tests__/tower-cron.test.ts (+3 / -1)
  • packages/codev/src/agent-farm/commands/spawn-worktree.ts (+1 / -0)
  • packages/codev/src/agent-farm/commands/tower.ts (+3 / -0)
  • packages/codev/src/agent-farm/servers/architect-session-holder.ts (+1 / -0)
  • packages/codev/src/agent-farm/servers/ide-server.ts (+1 / -0)
  • packages/codev/src/agent-farm/servers/tower-cron.ts (+3 / -0)
  • packages/codev/src/agent-farm/servers/tower-instances.ts (+1 / -0)
  • packages/codev/src/agent-farm/servers/tower-routes.ts (+2 / -0)
  • packages/codev/src/agent-farm/servers/tower-utils.ts (+9 / -0)
  • packages/codev/src/agent-farm/utils/config.ts (+1 / -0)
  • packages/codev/src/agent-farm/utils/shell.ts (+3 / -0)
  • packages/codev/src/commands/porch/artifacts.ts (+6 / -2)
  • packages/codev/src/lib/github.ts (+1 / -1)
  • packages/codev/src/lib/platform/posix/command-launch.ts (+6 / -0)
  • packages/codev/src/lib/platform/posix/processes.ts (+3 / -0)
  • packages/codev/src/lib/team-github.ts (+31 / -3)
  • packages/codev/src/terminal/session-manager.ts (+1 / -0)

Commits

Test Results

Architecture Updates

COLD codev/resources/arch.md, Platform Layer: new Console windows bullet. A detached Tower has no console; every spawn reachable from Tower, afx spawn / afx tower and the extension host passes windowsHide or carries a // windows-console: <reason> comment, enforced by the guard test; the extension spawns CLIs through cli-process.ts. Not HOT: it governs spawn sites, not every change.

Lessons Learned Updates

COLD codev/resources/lessons-learned.md, Debugging: reproduce through the user's launch path. Spec 1658's check passed because a Tower started from inside a codev session inherits a hidden console through the CIM launch path; a user's Tower has none. How a process was launched decides what its children inherit, and a static guard beats a manual check that depends on it.

Things to Look At During PR Review

  • sessionHasLiveHolder on Windows skips the ps probe and returns false when no detector is injected (tower-utils.ts). The architect asked to prefer the process census; I did not, because the census is async and the function sits under the synchronous resolveArchitectLaunch. What returning false changes for architect launch: nothing in production. Every production caller passes its own detector: both tower-instances.ts call sites pass the census-backed reconcileArchitectSessionHolder, and resolveArchitectRestart passes () => false. Only tests reached the default ps path, and on Windows it ran a ps that does not exist there.
  • Team view refresh policy (apps/vscode/src/views/team.ts). It fetches immediately when it becomes visible, on connect while visible, and on manual refresh. SSE-driven fetches happen only while visible, throttled to one per 30 s with a trailing fetch, and never two at once. The Team view now uses createTreeView (so it can see visibility) instead of registerTreeDataProvider.
  • getRepoInfo caches the origin for 5 minutes per cwd; a missing origin (or a transient git failure) only for 45 s, so a workspace that gains origin shows Team data soon. Expired entries are deleted. The cache registers a reset (registerTestReset in lib/test-env.ts) that the shared vitest-setup.ts runs before every test, so cached origins cannot leak between tests.
  • The guard test (windows-console-spawn-guard.test.ts) uses the TypeScript compiler API. It walks relative imports from tower-server.ts, commands/spawn.ts, commands/tower.ts and apps/vscode/src/extension.ts, and checks every child_process call (named imports, dynamic-import destructuring, promisify aliases, same-file object literals) for windowsHide or a // windows-console: comment. It cannot see spawns through an injected function (for example clipboard-image.ts's deps.spawn), so those carry the comment by hand.
  • Adjacent fix: VS Code's approve and cleanup commands called bare execFile('porch'|'afx'), which cannot run npm .cmd shims on Windows. They now use the new execCodevCli, which resolves the shim and hides the window.
  • Comment-only edits in POSIX-only files (lib/platform/posix/*, the ps/pgrep/tail sites, activity-hooks.ts): those calls never run on Windows and carry a // windows-console: comment for the guard. No behaviour change.
  • Hidden git fetch in GitRefResolver (artifacts.ts). Hiding it meant a Git Credential Manager prompt could no longer be seen or answered, and the fetch had no timeout, so it could hang porch. It now runs with GIT_TERMINAL_PROMPT=0, GCM_INTERACTIVE=never and a 60 s timeout; a failed or timed-out fetch falls into the existing warning and the locally cached ref is read. Raised by the Claude consultation; regression test in issue-1919-hidden-spawns.test.ts.
  • Architect review fixes (all in this PR):
    • porch and afx cleanup now run hidden from the extension (execCodevCli), so their graphs (commands/porch/index.ts, agent-farm/commands/cleanup.ts) are guard entry points. That surfaced porch's notify.ts (afx send after porch approve), checks.ts (git branch), state.ts (git add/commit/push of status.yaml) and cleanup.ts's POSIX ps; all now hidden or annotated. The status push also sets GIT_TERMINAL_PROMPT=0, so it fails instead of waiting on a prompt no one can see.
    • The guard accepts only the literal windowsHide: true (not false, a variable or a shorthand).
    • GIT_FETCH_TIMEOUT_MS moved above GitRefResolver's doc comment.
    • arch.md: a hidden child can never prompt, so anything that might must be non-interactive.
    • Follow-up filed: Spawn guard: detect new console-less entry points instead of a hand-maintained list #1933 (detect new console-less entry points instead of a hand-maintained list).
  • Consultation (single pass): Claude APPROVE; Codex COMMENT (its sandbox could not read the files, no issues raised); Gemini COMMENT (lane skipped, agy not installed). Claude's other non-blocking notes: the guard's limits are now stated in its header; spawnDetached's windowsHide is a no-op next to detached and now says so; getRepoInfo has no in-flight dedupe and caches a missing origin for 5 minutes (accepted); TeamProvider.dispose() is untested (accepted); a Windows cron command that deliberately opens a window now runs hidden (intended: cron runs unattended).

How to Test Locally

  • View diff: VSCode sidebar → right-click builder pir-1919 → View Diff
  • Run dev: VSCode sidebar → Run Dev, or afx dev pir-1919
  • What to verify (native Windows):
    • Restart Tower from a non-codev shell (afx tower start), so it has no console.
    • Run an agent turn with the Team view expanded, then collapsed: no console window.
    • Watch a cron run: no window.
    • Keep a dashboard file tree open for at least 30 s: no window.
    • In VS Code: spawn a builder, view a diff, approve a gate, paste a clipboard image: no window, and each works.
    • On macOS/Linux: behaviour unchanged, the Team view still updates while visible.

Flaky Tests

None seen on the final runs. An earlier porch done tests check failed while it overlapped another builder's full-suite run; porch truncated the output, so the failing tests are unknown. The solo re-run passed in full. Known load-dependent Windows failures are tracked in #1923.

  • packages/codev/src/__tests__/tower-lifecycle.windows.test.ts, scenario 5 ("a row whose shellper pid was reused is refused and removed"): read ECONNRESET on the Windows workflow, Node 24, run 44258108002; passed on Node 22 and on the re-run.

Tower runs detached with no console, so every unhidden console child
(git, gh, cmd.exe for cron, codev init/adopt) opened a visible window.
Add windowsHide to each site reachable from Tower and from the
console-less afx spawn. Cache getRepoInfo per workspace for 5 minutes;
it ran git on every Team view refresh. sessionHasLiveHolder no longer
runs ps on Windows when no detector is given (no production caller
relies on that default).
The extension host has no console. Hide its git and powershell spawns.
porch approve and afx cleanup now go through execCodevCli, the shim
resolver spawnCodevCli already uses: bare execFile cannot run an npm
.cmd shim on Windows.
… 30s

Tower broadcasts an SSE event for nearly every agent tool call; the Team
view fetched /api/team on each one. Fetch immediately on reveal, connect
and manual refresh; never overlap fetches.
…be hidden

Walks the import graph from Tower, afx spawn, afx tower start and the
extension host; every child_process use must pass windowsHide or carry
a windows-console: annotation (POSIX-only branches are annotated).
@amrmelsayed

Copy link
Copy Markdown
Collaborator Author

Architect integration review

Verdict: changes requested, all small; fix in this PR. The shape is right (per-site windowsHide, annotated exceptions, static guard, arch note) and I confirmed sessionHasLiveHolder's Windows skip is safe because every production caller injects its own detector.

Review coverage, stated plainly: one working model lane (Claude, integration review, HIGH confidence) plus my own read of team.ts, tower-utils.ts and team-github.ts. The Codex lane could not read the workspace on this Windows host (twice) and the Gemini lane is not installed.

Fix before merge

  1. Residual flash on the path this PR creates. execCodevCli now launches porch/afx hidden from the extension host, so those CLIs run console-less. packages/codev/src/commands/porch/notify.ts:49 spawns node <afx> send … without windowsHide, and porch approve calls it (commands/porch/index.ts:842). Add windowsHide there and add the porch CLI graph (commands/porch/index.ts) and agent-farm/commands/cleanup.ts to CONSOLE_LESS_ENTRY_POINTS, then fix whatever else the guard then reports.
  2. getRepoInfo caches a null for 5 minutes. A workspace created through the dashboard, a repo that gets origin added later, or one transient git failure leaves Team/overview GitHub data blank for 5 minutes, and manual refresh cannot clear it. Use a short negative TTL (30-60 s) and delete expired keys.
  3. Cross-test state from the module-level cache. Clear repoInfoCache in shared test setup so one test's cached origin cannot leak into another.
  4. Guard accepts windowsHide: false. Require the literal true (or an annotation).
  5. artifacts.ts: GIT_FETCH_TIMEOUT_MS sits between GitRefResolver's JSDoc and the class, so the class doc now documents the constant. Move the const above the doc block.
  6. Arch note: add one sentence: a hidden child has no console and can never prompt, so anything that might prompt must be made non-interactive (as GitRefResolver now is).

Follow-up issue (not this PR)

  • The guard's entry-point list is hand-maintained and cannot notice a new console-less entry point (a new detached: true launch or a newly hidden CLI). A second assertion that enumerates detached: true spawn sites against an explicit allowlist would close that. Please file it and link it here.

Noted, no change needed

…ve origin cache, literal windowsHide: true
@amrmelsayed

Copy link
Copy Markdown
Collaborator Author

Follow-up filed: #1933 (guard: detect new console-less entry points instead of a hand-maintained list).

@amrmelsayed
amrmelsayed merged commit c6c5340 into main Nov 18, 2026
8 checks passed
amrmelsayed added a commit that referenced this pull request Nov 18, 2026
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: console window flashes while an agent works in a VS Code terminal (unhidden child-process spawns)

1 participant