Skip to content

fix(service): retry Windows pipe spawn on packaged access denied - #64137

Open
mvanhorn wants to merge 4 commits into
anomalyco:devfrom
mvanhorn:fix/63892-windows-packaged-job-retry
Open

mvanhorn wants to merge 4 commits into
anomalyco:devfrom
mvanhorn:fix/63892-windows-packaged-job-retry

Conversation

@mvanhorn

Copy link
Copy Markdown

Issue for this PR

Closes #63892

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

On Windows, a shell command that uses Microsoft Store PowerShell 7 stops before it can run. Process creation fails with OS error -1073283067 (0xC0070005), so the caller gets no command output, in a project directory and in a temporary directory. The same commands still run under Windows PowerShell 5.1. Pipe-mode creation passes PROC_THREAD_ATTRIBUTE_JOB_LIST to CreateProcessW and retries without a job when that attribute is refused. The retry matches only Win32 error 5. A packaged executable reports the same refusal as 0xC0070005, so the original spawn failure is returned unchanged.

create_process_refused_job treats both 5 and 0xC0070005 as a job-list refusal, and the Windows spawn path uses it to choose the jobless retry. When either code comes back from a job-backed attempt, the process is created again with no job attribute. A unit test covers both codes, the signed value -1073283067, that same code read from an io::Error, and non-matches for Some(2) and None.

How did you verify your code works?

cargo test -q --manifest-path packages/process-daemon/Cargo.toml -p opencode-pty reported a passing result of 83 passed and 0 failed.

Screenshots / recordings

No user-visible surface changes in this PR, so there is nothing to show.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

AI was used for assistance.

create_process_refused_job treats both 5 and 0xC0070005 as a job-list
refusal, and the Windows spawn path uses it to choose the jobless retry.
When either code comes back from a job-backed attempt, the process is
created again with no job attribute. A unit test covers both codes, the
signed value -1073283067, that same code read from an io::Error, and
non-matches for Some(2) and None.

Fixes anomalyco#63892
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Nov 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

Please edit this PR description to address the above within 72 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't verify this: it needs Windows with PowerShell 7 from the Microsoft Store, and this sandbox is Linux (it has no cargo either, so I couldn't run the tests). From reading the code, the fix does what it says. A job-backed attempt that fails with 0xC0070005 now goes through the existing jobless retry, so the spawn error in the linked issue should go away.

The public API is unchanged: this is internal to the process daemon.

Main concern: with this change, every command run through Store PowerShell 7 starts without a job object, so stopping or timing out a command kills only pwsh itself. Anything it started, like a dev server or watcher, keeps running. That fallback was meant for the rare case of an outer job that refuses new members. Here it becomes the normal path for a common shell. The issue's own test results show that creating the process normally and then calling AssignProcessToJobObject works for Store pwsh 7.7. A fallback that does that (for example, create suspended, assign the process to the job, then resume) would fix the error and keep killing the whole process tree. Details are inline.

The unit test mostly checks constants, and it is the only reason the helper needs a #[cfg(any(windows, test))] home in pipe.rs. It can be dropped and the check inlined in windows.rs, so the fix stays a couple of lines.

When CreateProcessW refuses the job attribute, create the process
suspended, assign it to the job with AssignProcessToJobObject, then
resume it. Store PowerShell rejects the attribute but accepts the
assignment, so cancel and timeout still kill its whole tree. The job is
dropped only when the assignment fails too, as under an outer job with
UI restrictions, and only that case logs that the job cannot be joined.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My earlier concern is resolved. When the job attribute is refused, the process is now created suspended, assigned to the job, then resumed, so Store PowerShell keeps its whole process tree in the job. The jobless fallback is used only when the assignment also fails, which keeps the old behaviour for a restricted outer job. I checked the paths by reading the code: a suspended process is either resumed or killed, and the job is dropped only when the process isn't in it. I couldn't run it: this needs Windows with Store PowerShell 7, and the sandbox is Linux without a Rust toolchain. Someone on that setup should confirm that Write-Output 'probe' through the shell tool works and that cancelling a long-running command also stops its child processes.

The public API is unchanged: this is internal to the process daemon.

No blocking concerns. The constant-only unit test in pipe.rs could still be dropped, as noted before, but that doesn't block anything.

Drop the create_process_refused_job helper and its constants test from
pipe.rs and check both refusal codes next to the spawn retry in
windows.rs.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit only moves the error-code check inline into pipe/windows.rs and removes the helper and its constant-only test from pipe.rs. That addresses my earlier note about the test, and the behaviour is unchanged: both 5 and 0xC0070005 still go through the suspended create, job assignment and resume fallback. I checked it by reading the code; I couldn't run it here, since it needs Windows with Store PowerShell 7.

The public API is unchanged: this is internal to the process daemon.

No new concerns.

Resolve the conflict with anomalyco#64266 in pipe/windows.rs by keeping both
Job::assign and the new Job::finish.
@mvanhorn

Copy link
Copy Markdown
Author

Merged dev into this branch to clear a conflict in pipe/windows.rs, where dev had also changed the job code. I kept both sides: Job::finish from dev and the Job::assign this PR uses for the suspended create fallback. Nothing else in the fix changed. I haven't built this one locally, so CI is the check here.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only new commit merges dev. Compared with the updated base, the PR is still the same change in pipe/windows.rs, and the merge resolution fits dev's refactor: spawn now passes on the job it got back from the assignment step, and the new job clean-up on dev treats it like any other job. My earlier points were addressed in previous rounds; there is nothing new to raise.

I checked this by reading the code. I couldn't run it, since it needs Windows with Store PowerShell 7.

The public API is unchanged: this is internal to the process daemon.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shell: Store PowerShell fails with 0xC0070005 in Windows pipe mode

1 participant