Repository navigation
fix(process-daemon): spawn Windows pipe processes suspended before joining their job - #64901
Conversation
There was a problem hiding this comment.
Looks sound. I couldn't verify it: it needs Windows with PowerShell 7 from the Microsoft Store, and this sandbox is Linux with no Rust toolchain, so I reviewed the diff by hand.
The new order (create suspended, put the child in the job, then resume) keeps the whole process tree inside the job, because the child can't start anything before it is in. The fallback when the job refuses the child still works. If resuming fails, the child is killed before it ever ran. One behaviour change: the old jobless retry only fired on error 5, and now any refusal from the job falls back to running without it. That is what also covers the 0xC0070005 case.
The new test is small, skips itself where Store PowerShell isn't installed, and kills its 30-second command explicitly. No concerns there.
Public API: unchanged (internal change to the daemon's Windows spawn path).
Fixes #63892
There was a problem hiding this comment.
The new commit looks sound. As before, I reviewed it by reading the code: it needs Windows with Store PowerShell 7, and this sandbox has neither Windows nor a Rust toolchain.
The suspended child is now killed whenever spawning fails before it is resumed, including when the resume itself fails. The extended test now also checks that killing one Store PowerShell command doesn't kill another one running at the same time, and it cleans up its processes if an assertion fails. The SPEC.md wording matches the new, broader fallback.
Public API: unchanged.
There was a problem hiding this comment.
The new commit looks sound. As before, I reviewed it by reading the code: it needs Windows with Store PowerShell 7, and this sandbox has neither Windows nor a Rust toolchain.
Taking the two handles straight from a successful CreateProcessW is fine, since both are valid at that point. A child that is never resumed is still killed on drop. The test now passes the full environment to the shells, as OpenCode does.
Public API: unchanged.
Issue for this PR
Closes #64803
Closes #63892
Type of change
What does this PR do?
On Windows with PowerShell 7 from the Microsoft Store, running two shell commands at once makes one of them fail with
failed to spawn ...\WindowsApps\pwsh.exe: (os error 5).The daemon put each pipe child in its kill-on-close job with
PROC_THREAD_ATTRIBUTE_JOB_LIST. With that attribute the new process is in our job before Windows adds it to the Store package's own container job, and Windows refuses that second step while another process of the same package is still running (AppModel events 212/208,0x80070005). So the first command works and every command started while it runs is refused. The jobless retry then either fails too (the report) or runs the command outside the job, so cancelling it can't reach its children.There is a second bug on
dev: when the first command's job-list spawn succeeds, the package's container job ends up inside that command's job. Killing that command then kills every other Storepwshcommand running at the same time (they exit with 1).The child is now created with
CREATE_SUSPENDED, assigned withAssignProcessToJobObject, then resumed. It can't run or start anything before it is in the job, so the tree is still fully contained. Our job now sits inside the package's job instead of the other way round, so killing one command only kills that command. Removing the job list also covers the real packaged path (C:\Program Files\WindowsApps\...\pwsh.exe), which #63892 reports failing with0xC0070005.Other changes:
AssignProcessToJobObjectfailure now falls back to running without the job, not only error 5. Errors from creating the process itself still fail the spawn as before.SPEC.mdis updated to match.How did you verify your code works?
On Windows 11 with Store PowerShell 7.7.0:
devthroughspawn: with one Storepwshrunning, every further spawn was refused the job (cannot join the job object ... os error 5). In 6 rounds of 2 simultaneous spawns, each round had exactly one refusal, as in the report.store_powershell_joins_its_job_while_another_instance_runs. It starts two Storepwshcommands with the full environment, kills the first while the second is still running, then checks that the second still exits with its own code. It fails ondevand passed 10 runs out of 10 with the fix. It returns early where Store PowerShell isn't installed, as on CI.ResumeThreadreports a suspend count of 1 for bothcmd.exeand Storepwsh, so Store app activation doesn't start the process early.cmd.exe, batch files, Windows PowerShell 5.1 and Git Bash still join their job and report their exit code.pwshitself starts (e.g.[Diagnostics.Process]::Start('ping.exe')) are in no job at all, ondevand with this PR, so killing the command doesn't reach them. Windows starts them outside every job, including the daemon's own. Fixed separately in the stacked fix(process-daemon): keep children of Store apps in the Windows pipe job #64902.cargo fmt --check,cargo clippy --all-targets --all-features -- -D warningsandcargo test --all-targets --all-featuresinpackages/process-daemonall pass, including the Windows pipe tests that kill grandchildren through the job.No flag: this is a fix in the daemon's spawn path.
Screenshots / recordings
Not a UI change.
Checklist
Added by the opencode bot (AI-generated).
Fixes #63892