Skip to content

fix(server): close a streamed file before ending the response; read win32 hook args in claude.test - #89

Open
zereight wants to merge 2 commits into
mainfrom
fix/windows-test-failures
Open

zereight wants to merge 2 commits into
mainfrom
fix/windows-test-failures

Conversation

@zereight

@zereight zereight commented Dec 2, 2026

Copy link
Copy Markdown
Owner

What changed

Two failures that happen only on windows-latest in main CI (run 46698074578 on 5ac219492, vitest windows shards 8/8 and 5/8).

  • server/harness/http.ts — streamFileHandle now closes the file handle before it ends the response: pipeline(stream, res, { end: false }) → await handle.close() → res.end(). HEAD and empty ranges close and end without a stream. The error path is unchanged, and the callers' own finally close is kept (a second close resolves as a no-op).
  • server/drivers/claude.test.ts — the browser-guard and tool-guard assertions read the hook's command and args, and the tool-guard pattern accepts the args form (no shell quotes).

Why

page-files EPERM. #50 (a454ea105) switched video streaming to createReadStream({ autoClose: false }) + pipeline(stream, res) and left closing the handle to the caller's finally. pipeline ends res first, so a client that sees the response finish can act while the file is still open. On Windows an open file cannot be replaced, which is what server/page-files.test.ts:195 does next:

FAIL  server/page-files.test.ts > a folder page's video > refuses a file deleted, replaced or edited since the page was shown
Error: EPERM: operation not permitted, rename '…\omb-page-video-X0ZAiY\new.mp4' -> '…\omb-page-video-X0ZAiY\clip.mp4'
 ❯ server/page-files.test.ts:195:5

The fix closes the handle at the point the bytes are done, so the order is fixed by the code, not by timing. #50's reason for owning the handle (no FileHandle left for GC on aborted requests, no ERR_STREAM_UNABLE_TO_PIPE) is kept: autoClose stays off and aborted requests still go through the same catch + caller finally.

claude.test on win32. On Windows the hook runs node directly with the helper path in args (87cc269bc, "Start Claude's hook helper without a shell on Windows"; covered by claude.test.ts:115). That product shape is intended. The settings-file tests from #28 / guardrails only read .command, which on win32 is the Node path:

FAIL  server/drivers/claude.test.ts > … > guards every non-guest turn against a shell command that opens a browser window, …
AssertionError: expected 'C:\hostedtoolcache\windows\node\24.22…' to contain 'omb-browser-guard'
 ❯ server/drivers/claude.test.ts:1888:38

The same check at :1901 fails the second test, and :1903 (tool guard toMatch) would fail next; CI never reached it.

How it was verified

All on macOS, Node v24.22.1 (CI's version), same commands on main (8c67e9dd6) and this branch (a49086f1a).

Check Before (main) After (this branch)
Is clip.mp4 still open when the response has finished? (lsof on the server process, GET bytes=0-9 / GET whole file / HEAD) 1 / 1 / 0 0 / 0 / 0
#50 scenario: 15 early aborts + 15 mid-stream aborts + whole/range/HEAD under --expose-gc problems: [], 0 open after settle problems: [], 0 open after settle
Test assertions applied to browserGuardHookSettings / toolGuardHookSettings output for win32 browser false, tool false browser true, tool true
Same assertions for darwin and linux true, true true, true
vitest run claude.test, page-files, harness/http, message-file, routes/threads-* (10 files) 10 passed, 363 passed / 1 skipped 10 passed, 363 passed / 1 skipped
pnpm typecheck — exit 0
oxlint server/harness/http.ts server/drivers/claude.test.ts — exit 0
pre-push — 2 changed file(s) checked in 6.7 s

The macOS vitest run passes on both sides: the two failures only show on Windows. The handle probe is what shows the order change on this machine.

No screenshots: nothing in the UI changed.

Not covered

  • The EPERM itself and the win32 hook run were not reproduced locally (no Windows machine). This PR's CI runs the windows-latest vitest shards: scripts/ci-scope.mjs picks Windows for this diff (windowsReason → the changed line naming Windows in http.ts). Those shards are the proof.
  • The Windows shards also carry failures from other groups (stale tests, removed features), so they will not be fully green from this PR alone; what to look for is that page-files.test.ts and claude.test.ts no longer appear.

Checklist

  • Root cause fixed in the product code (http.ts), no retry or wait added to the test
  • Product hook shape on win32 kept; only the test's reading of it changed
  • No new tests
  • Before/After from the same commands on main and this branch

Windows cannot rename or delete a file that is still open. Since #50 the stream ran with autoClose off and the caller closed the handle after the response had already ended, so a client that saw the response finish could still hit EPERM (page-files test on windows-latest). Close the handle first, then end the response; aborted requests keep #50's path.
On win32 the hook runs node directly with the helper path in args (87cc269), so the browser and tool guard checks that read only .command failed on windows-latest.
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.

1 participant