Repository navigation
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
Open
fix(server): close a streamed file before ending the response; read win32 hook args in claude.test#89zereight wants to merge 2 commits into
zereight wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Two failures that happen only on
windows-latestin main CI (run 46698074578 on5ac219492, vitest windows shards 8/8 and 5/8).server/harness/http.ts—streamFileHandlenow 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' ownfinallyclose 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'scommandandargs, and the tool-guard pattern accepts the args form (no shell quotes).Why
page-files EPERM. #50 (
a454ea105) switched video streaming tocreateReadStream({ autoClose: false })+pipeline(stream, res)and left closing the handle to the caller'sfinally.pipelineendsresfirst, 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 whatserver/page-files.test.ts:195does next: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
FileHandleleft for GC on aborted requests, noERR_STREAM_UNABLE_TO_PIPE) is kept:autoClosestays off and aborted requests still go through the same catch + callerfinally.claude.test on win32. On Windows the hook runs
nodedirectly with the helper path inargs(87cc269bc, "Start Claude's hook helper without a shell on Windows"; covered byclaude.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:The same check at
:1901fails the second test, and:1903(tool guardtoMatch) 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).main)clip.mp4still open when the response has finished? (lsofon the server process, GETbytes=0-9/ GET whole file / HEAD)--expose-gcproblems: [], 0 open after settleproblems: [], 0 open after settlebrowserGuardHookSettings/toolGuardHookSettingsoutput forwin32darwinandlinuxvitest runclaude.test, page-files, harness/http, message-file, routes/threads-* (10 files)pnpm typecheckoxlint server/harness/http.ts server/drivers/claude.test.ts2 changed file(s) checked in 6.7 sThe 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
windows-latestvitest shards:scripts/ci-scope.mjspicks Windows for this diff (windowsReason→ the changed line naming Windows inhttp.ts). Those shards are the proof.page-files.test.tsandclaude.test.tsno longer appear.Checklist
http.ts), no retry or wait added to the testmainand this branch