Skip to content

fix(process-daemon): keep children of Store apps in the Windows pipe job - #64902

Open
neriousy wants to merge 2 commits into
devfrom
store-pwsh-children
Open

neriousy wants to merge 2 commits into
devfrom
store-pwsh-children

Conversation

@neriousy

@neriousy neriousy commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Issue for this PR

Follow-up to #64803 and #64901 (merged).

Type of change

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

What does this PR do?

With Store PowerShell 7 as the shell, every program a command starts (git, bun test, a dev server, a plain ping) is in no job at all. So cancelling or timing out a shell command kills only pwsh, and the programs it started keep running. A daemon crash leaves them behind too.

The cause is how Windows handles packaged desktop apps. By default a Store app's children "break away" from the app's package environment, and with it from every job, including the daemon's. The children keep pwsh as their parent but have no package identity and no job. This happens on dev and with #64901.

Windows has a process attribute for exactly this, PROC_THREAD_ATTRIBUTE_DESKTOP_APP_POLICY (Windows 10 1703+). With PROCESS_CREATION_DESKTOP_APP_BREAKAWAY_DISABLE_PROCESS_TREE (0x02, not defined in windows-sys), the children stay inside the package's environment, and so in our kill-on-close job. This covers how OpenCode runs commands, since the shell tool passes Store pwsh to the daemon as the program. For programs that aren't packaged it has no effect.

Tradeoff: children of Store pwsh now run with the PowerShell package's identity. The PowerShell package turns off file-system and registry write virtualization in its manifest, so their writes still go to the real locations (checked below).

How did you verify your code works?

On Windows 11 with Store PowerShell 7.7.0:

  • Added signal_reaches_a_grandchild_of_store_powershell to tests/pipe_windows.rs. It goes through TerminalService: Store pwsh starts ping.exe, the command is killed, and ping must die. It fails without this change (process ... is still running) and passes with it. It returns early where Store PowerShell isn't installed, as on CI.
  • With a probe run through the daemon, the child of Store pwsh is now in a job. Inside such a command:
    • winget, git, node and bun all work.
    • A child's writes to %LOCALAPPDATA%, %TEMP% and HKCU\Software landed in the real locations, seen from outside.
  • Also checked through the daemon:
    • A background child left by a command that exits 0 keeps running, as the SPEC allows.
    • With two Store pwsh commands running, killing one kills only its own child.
  • cargo fmt --check, cargo clippy --all-targets --all-features -- -D warnings and cargo test in packages/process-daemon all pass.

Not covered here, fixed in #65141 (stacked on this PR): a Store app started further down the tree, e.g. cmd.exe or Windows PowerShell running Store pwsh. Store pwsh then breaks away itself, along with its children. Checked through the daemon: this is the same on dev and with this change.

The PTY (interactive terminal) path doesn't set this attribute, and doesn't need to. A Store pwsh terminal behaves like one running regular pwsh: closing it kills everything attached to the console.

No flag: this is a fix in the daemon's spawn path.

Screenshots / recordings

Not a UI change.

Checklist

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

Added by the opencode bot (AI-generated).

Related: #57813

@neriousy
neriousy force-pushed the store-pwsh-children branch from f38eb17 to 4a5d009 Compare November 19, 2026 16:39
Base automatically changed from store-pwsh-spawn to dev November 19, 2026 16:53

@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. The change only affects Windows and needs Store PowerShell 7, and the review sandbox is Linux with no Rust toolchain, so I reviewed it by reading the code only.

The approach looks right to me. Setting PROC_THREAD_ATTRIBUTE_DESKTOP_APP_POLICY with the disable-breakaway bit on the pipe spawn is the documented way to keep children of packaged apps inside the job. It sits next to the existing handle-list attribute, and the list is sized from the number of entries. The 1703+ requirement is within the daemon's existing Windows 10 1709+ minimum (README), so older systems don't lose anything. The new test returns early where Store PowerShell is missing, and it is a small, direct check of the fix.

Public API: unchanged. This is internal to the daemon's Windows spawn path.

No blocking concerns.

Related: #57813

@neriousy
neriousy force-pushed the store-pwsh-children branch from 4a5d009 to 1ab808e Compare November 19, 2026 19:41

@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.

Rebased onto dev only. The PR's commit is identical to what I reviewed before, so I have no new concerns. I still couldn't run it: it only affects Windows (Store PowerShell), and this sandbox is Linux with no Rust toolchain. Public API: unchanged.

@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 updates the docs: SPEC.md and the comment on the policy constant now say that a Store app started by another process in the job (e.g. cmd.exe running pwsh) still breaks away. That matches the description's "Not covered" section. The code is unchanged, and I have no new concerns. I still couldn't run this: it needs Windows with Store PowerShell. Public API: unchanged.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant