Skip to content

Fix Windows PTY teardown by preserving ConPTY ownership#20685

Merged
iceweasel-oai merged 3 commits into
mainfrom
codex/windows-conpty-owner-teardown-fix
May 4, 2026
Merged

Fix Windows PTY teardown by preserving ConPTY ownership#20685
iceweasel-oai merged 3 commits into
mainfrom
codex/windows-conpty-owner-teardown-fix

Conversation

@iceweasel-oai

@iceweasel-oai iceweasel-oai commented May 1, 2026

Copy link
Copy Markdown
Collaborator

Why

On Windows, background terminals could stay visible after their shell process had already exited. The elevated runner waits for the PTY output reader to reach EOF before it sends the final exit message, but the ConPTY helper was reducing ownership down to raw handles too early. That left the pseudoconsole's borrowed pipe handles alive past teardown, so EOF never propagated and the session stayed running.

What changed

  • change utils/pty/src/win/conpty.rs to hand off owned ConPTY resources instead of leaking only raw handles
  • make windows-sandbox-rs/src/conpty/mod.rs keep the pseudoconsole owner and the backing pipe handles together until teardown
  • update the elevated runner and the legacy unified-exec backend to keep that ConptyInstance alive, take only the specific pipe handles they need, and drop the owner at teardown instead of trying to close a detached pseudoconsole handle later

Testing

  • desktop app in Auto-review: 11 x cmd /c "ping -n 3 google.com" all exited cleanly and did not accumulate in the UI
  • desktop app in Auto-review: 5 x cmd /c "ping -n 30 google.com" appeared in the UI and drained back out on their own

@iceweasel-oai iceweasel-oai changed the title Fix Windows ConPTY teardown ownership Fix Windows PTY teardown by preserving ConPTY ownership May 1, 2026
@iceweasel-oai

Copy link
Copy Markdown
Collaborator Author

@codex review

@iceweasel-oai iceweasel-oai marked this pull request as ready for review May 1, 2026 22:15
@iceweasel-oai

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

Codex Review: Didn't find any major issues. Swish!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@iceweasel-oai iceweasel-oai enabled auto-merge (squash) May 4, 2026 18:19
@iceweasel-oai iceweasel-oai merged commit 5d55006 into main May 4, 2026
26 checks passed
@iceweasel-oai iceweasel-oai deleted the codex/windows-conpty-owner-teardown-fix branch May 4, 2026 18:40
@github-actions github-actions Bot locked and limited conversation to collaborators May 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants