Skip to content

Fix #1922: full suite on native Windows no longer stops the live Tower; fix EPERM at its cause - #1926

Merged
amrmelsayed merged 17 commits into
mainfrom
builder/bugfix-1922
Nov 18, 2026
Merged

amrmelsayed merged 17 commits into
mainfrom
builder/bugfix-1922

Conversation

@amrmelsayed

@amrmelsayed amrmelsayed commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Running the packages/codev suite on a native Windows developer machine could stop the developer's live Tower, and it failed on main with EPERM temp-dir cleanups. The launchers test can no longer touch a Tower it didn't start. The EPERM is fixed at its cause in codev update, and the other Windows-only failures listed in the issue are either fixed or filed.

Fixes #1922

Root Cause

  1. The live Tower was stopped. launchers.windows.test.ts starts its Tower on the default port 4100, because workspace start, shell, spawn and dev can't be pointed at another port. With a live Tower already on 4100, afx tower start reported "already running", and afterAll then ran afx tower stop whenever its isolated state dir held a local-key. That stopped the developer's Tower.
  2. EPERM in cold-tier / hot-tier / update tests. The fixtures write user content into CLAUDE.md/AGENTS.md, so update() sees root conflicts and launches the merge session. It did that with a bare spawn('claude', …, { cwd: targetDir }), not awaited. That skipped the harness's CODEV_CLAUDE_BIN fake (consult: run the claude review lane through the installed claude CLI instead of the Agent SDK, on the user's subscription #1912), so the developer's real Claude Code started inside the temp project and was still holding it when afterEach deleted it. CI has no claude on PATH, which is why the GitHub Windows workflow stayed green. Proof: with ~/.local/bin removed from PATH, all 47 tests in those files passed.
  3. bugfix-1691 failure. Run from inside a builder session, the suite inherited CODEV_SHELLPER_SESSION. On Windows that sends towerStart down the CIM branch, which the test's spawn mock doesn't intercept, so the test created a real tower-server process.
  4. vscode tests. diff-nav compared against POSIX path literals, while the code uses path.resolve, which adds a drive letter on Windows. preflight-version-timeout launched #!/bin/sh scripts, which Windows can't start.

Fix

  • launchers.windows.test.ts: before running, it checks whether anything is on 4100 (listener query plus a TCP connect). If so, it skips the file and names the listener (… port 4100 is already in use by PID 29272 …). It re-checks right before tower start and records the PIDs of the Tower it started. afterAll stops a Tower only while 4100 is still held by exactly those PIDs.
  • update.ts: the merge session gets the same injectable seam codev adopt has. It resolves its binary through resolveClaudeBin(), so CODEV_CLAUDE_BIN and the consult: run the claude review lane through the installed claude CLI instead of the Agent SDK, on the user's subscription #1912 test guard apply, and it runs and awaits the session through spawnAgentProcess. The un-awaited launch was not an intended production behaviour. Nothing depended on it, and since the child inherited stdio the CLI process stayed alive until it exited anyway. The only change for users is that update() now returns after the session ends, as adopt does. Adjacent fix: on Windows the launch now goes through commandLaunch, so an npm-installed claude.cmd starts too. The bare spawn could only find claude.exe.
  • codev adopt had the same bare 'claude' merge launch (found in CMAP). update and adopt now share runClaudeSession in lib/agent-process.ts. A failure to resolve or start claude comes back as AgentExit.error, which both callers already report with the manual-merge fallback; it is never thrown.
  • vitest-setup.ts: the fake claude exits immediately (logging to $CODEV_TEST_CLAUDE_LOG) for an interactive, non--p launch. The harness now strips CODEV_SHELLPER_SESSION and CODEV_TOWER_PORT alongside the existing CODEV_BUILDER_WORKTREE scrub.
  • vscode diff-nav / preflight-version-timeout: expected paths go through path.resolve; on Windows the probe fixtures are .cmd files.
  • agy-auth-cache / fake-cli-temp-dir:

agy-auth-cache: cause inferred, not proven

An in-run probe caught one EPERM. At that moment the worker's cwd was not the dir, but the worker still held an un-reaped ChildProcess for one fake agy, and that PID had been clobbered in the shared log. After the test-side changes, 3 consecutive full runs and porch's tests check were green, and the corrected survivor check never fired. The likely cause is a synchronous cleanup retry that blocked the event loop before the lane's killed children were reaped, but that is inferred, not proven. The consult agy lane still resolves right after proc.kill without awaiting the child's close. This PR leaves that alone; it is the open follow-up in #1925 (moved there from #1923).

Test Plan

The launchers guard has no unit regression test. It is a guard inside a test file, so the evidence is the PID before/after across every run above.

Flaky Tests

Load-only failures seen on the owner's Windows machine across 14 full runs I could attribute. All pass when run alone, and none is caused by this branch.

Test Failure Runs Tracked
agy-auth-cache (various tests) EPERM deleting its temp dir 7 of 10 before the test-side changes, 0 of 4 after #1925 (skipped on Windows)
Worker exited unexpectedly (file unidentified) vitest fork crash 2/14 (first two runs only) #1923
metrics-model-id concurrent first-open barrier not reached within 20s 1/14 #1923
windows-job.windows cmd start /b orphan census still lists the leaf's parent 1/14 #1923
bugfix-1137-gitea-tea-api page ceiling 155 of 500 items 1/14 #1923
tower-lifecycle.windows bridge mode bridge Tower not answering on LAN address (throwaway port) 1/14 #1923
porch bugfix-1814-check-timeout killed at 2607 ms vs < 2500 1/14 #1923
tripwire-wiring lane COMMITS stub's git commit failed, then EPERM 1/14 #1923

Also filed: #1924, where the vscode preflight version probe's timeout leaves a .cmd probe's child running on Windows. The test now uses a 5s-bounded fixture.

CMAP

…rt; update merge launch resolves claude

launchers.windows.test.ts skips (naming the listening PID) when anything holds
port 4100, and its teardown stops a Tower only while 4100 is still held by the
PID the file started. codev update's conflict-merge launch now resolves its
binary through resolveClaudeBin() (so CODEV_CLAUDE_BIN and the #1912 test guard
apply) and awaits the session via spawnAgentProcess, as codev adopt does. The
harness fake claude exits at once for an interactive (non -p) launch.
… marker and Tower port

Run from inside a codev session on Windows, towerStart took the CIM branch,
which the #1691 tests' spawn mock does not intercept, so they created a real
tower-server process and failed. Same class as the CODEV_BUILDER_WORKTREE scrub.
…e Windows

diff-nav's expected paths go through path.resolve like the code under test;
preflight's probe fixtures are .cmd scripts on Windows, which cannot start #!/bin/sh.
…val; survivor check survives a failed cleanup

The EPERM holder is unconfirmed and tracked in #1923.
…leanup no longer blocks the event loop

Each fake agy records its PID as its own file: concurrent appends to a shared
log clobbered one PID to 8 on Windows, hiding that process from the survivor
check. afterEach waits for the lane's child handles to be reaped and removes the
temp dir with async rm, replacing the synchronous 50x200ms retry.
…failures are reported, not thrown

CMAP (claude) follow-ups: update and adopt share runClaudeSession (resolveClaudeBin
+ spawnAgentProcess, errors returned as AgentExit.error). adopt spawned a bare
'claude', the same bypass of CODEV_CLAUDE_BIN and the #1912 guard. The
agy-auth-cache child-reaping wait counts only handles opened during the test.
…the started Tower with a bounded retry

CMAP (claude) round 2: the stop decision is holdsOnlyOwnTower(), with the four
cases tested. Listener PIDs after tower start are retried up to 15s, so the
file's own Tower is never left unrecorded. The POSIX fake claude matches -p by
argument, and the claude not-found message names update/adopt too.
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.

tests: full suite on native Windows stops the live Tower and fails on main (launchers.windows port 4100, EPERM temp cleanup)

1 participant