Repository navigation
test(core): fix the stopped-command race and report stalled PowerShell calls - #491
Merged
Merged
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
…alled permission test Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Nov 14, 2026
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.
Summary
This PR fixes two timing-sensitive cases in
packages/core/test/tool-shell.test.tsthat have each failed the unit gate on a GitHub runner.ShellTool stopped > stops a command the user stopped, keeps its file…(failed on chore(ci): run the full suite on sync and release PRs #490, unit attempt 1, with the killed command's output missing its second line). This is a test race, and it's fixed.stopCallcancelled as soon as any output existed. bash makes stdout line-buffered, soprintf 'first\nsecond\n'reaches the pipe as twowritecalls (strace:write(1, "first\n", 6), thenwrite(1, "second\n", 7)). A cancel that landed between them killed the command beforesecondwas written.stopCallnow takes the number of bytes to wait for, and this test waits for all 13 before cancelling. The other callers keep their behavior: 1 byte, or 0 for the commands that print nothing.ShellTool ordinary shell syntax > PowerShell: ordinary syntax reuses approvals: Write-Output "$(Write-Output hello)"(failed in the2.3.0-shuv.1publish, run 43492639481). This is a pwsh call that sometimes stalls for more than 15s on the runner. It is not a regression and not cold-start latency. The cause is not yet identified, so the hang detector now reports what the call was waiting on.Stopped-command race
To make the race deterministic, I temporarily put a 100ms gap between the two
printfs. With the old wait (cancel after 1 byte), both variants of the test (spawned and daemon) fail exactly as on #490:Expected - 1 / Received + 0, with the second line missing. With the new wait, both pass. On the real command,bun run test test/tool-shell.test.ts -t "ShellTool stopped" --rerun-each 30passed 570 of 570.PowerShell stall
runPermissionCommand, the permission and shell services,ShellSelect, the scanner andpackages/utilare identical between the last passing publish (ac4077949d) and37f5865e0c.Write-Output "$(Write-Output hello)". That is the file's first PowerShell test, and so the first pwsh launch of the core test process. That report showed no pending permission, a pwsh process spawned at once (15,020ms elapsed), and zero bytes of output. On the same image it has passed in 8 other full unit runs: 43497096412, 43498490451, 43501674041, 43505609084 (which also ran 660 in-situ PowerShell reruns, with no failures and a slowest run of 4.25s), 43510855667, 43513808639, 43513820154 and 43513831524. That makes 2 failures in 10 runs.check-testunit (linux) passed at v2.3.0 (43397035564).The first commit's report used
kill(pid, 0), which also succeeds for a zombie. So it could not tell "pwsh hung before writing" apart from "pwsh exited but Bun never observed the exit or output". The report on this head distinguishes them:pending: permission requests still waiting.shells: the shellcreatedand exit events seen during the call, with elapsed milliseconds.commands: for each created command, its shell and job status, its pid, the process state fromps -o stat=,wchan=, and the last 500 bytes of its output file.running, processS/Rwchannames where)running, processZorgonerunningI checked the report by injecting a stall of each kind. An unapproved command gave
{"pending":[["Get-Date","Write-Output hello"]],"shells":[],"commands":[]}. A 20s pwsh sleep gavecreatedat 22ms,statusandjobbothrunning,processSsl futex_wait, and tail"starting\n".No feature flag: this changes tests only.
Tests
bun run test test/tool-shell.test.tsinpackages/corepasses 110 of 110, andShellTool stoppedwith--rerun-each 30passes 570 of 570.bun typecheck, Prettier andgit diff --checkpass. The pre-push hook ran the fullbun run check: 40 of 40 typecheck tasks, 0 lint errors.test.ymlruns only for releases), so I dispatched the unit workflow by hand:d9947b5f03(PowerShell report only): 4 of 4 passed (43510855667, 43513808639, 43513820154, 43513831524).1c54d5e955(both fixes): 43516779134, 43516789288 and 43516800261, still running at the time of writing.--continuepassed 30 of 32 tasks. The two failures exist only on this machine (GitLab OAuth tests need port 8080, and an sdk Workerd timing test); CI passes both.psprocess state, shell and job state, logging the report, the real output tail, a shared timeout constant, and a wider comment.