Skip to content

fix(shell): bound post-exit pipe draining on all platforms - #46085

Merged
Hona merged 8 commits into
anomalyco:v2from
Hona:windows-shell-drain
Aug 31, 2026
Merged

Hona merged 8 commits into
anomalyco:v2from
Hona:windows-shell-drain

Conversation

@Hona

@Hona Hona commented Aug 29, 2026

Copy link
Copy Markdown
Member

Issue for this PR

A command can exit while a background child still has its output pipes open. We keep waiting for EOF, so the shell tool never finishes.

Related issue reports

This fixes the V2 implementation of the post-exit hangs reported below.

Earlier reports, already closed: #19252, #22012, #22154, #24731, #24784, #24926, #25938, #29294, #29822, #33363.

Previous fix attempts: #20901, #28336, #29831, #42756, #43511, #44601.

Type of change

  • Bug fix

What does this PR do?

Give stdout and stderr one shared second to drain after the parent exits. Then finish capture and let the shell return instead of waiting on the background child.

The important part is keeping that separate from process cleanup. Shell timeouts still escalate to SIGKILL, and closing an MCP server still cleans up its descendants. No public API changes.

The tradeoff is that we can lose trailing output. Later bytes are discarded, and writers can get EPIPE/SIGPIPE once their readers close.

How did you verify your code works?

Added four real-process regression cases: held pipes after exit, SIGKILL completion, MCP descendant cleanup, and shell timeout escalation. Each test also fails when its corresponding fix is disabled.

Validation and remaining limits
  • Typechecks pass. Linux MCP, spawner, and available shell-tool tests pass.
  • Windows checks pass apart from the existing echo quoting failure; Unix-only cases are skipped.
  • Native macOS and the reported browser/.NET workloads have not been tested directly.
  • Parallel scope cleanup can still fall back to the old EOF wait. No affected production caller was established.
  • Normal Windows MCP shutdown now makes an extra taskkill attempt, taking roughly 0.35-0.73 seconds in our checks.

Checklist

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

@christianhola

Copy link
Copy Markdown

1

@Hona Hona changed the title fix(shell): bound Windows post-exit pipe draining fix(shell): bound post-exit pipe draining on all platforms Aug 31, 2026
@Hona
Hona marked this pull request as ready for review August 31, 2026 05:00
Copilot AI lite review requested due to automatic review settings August 31, 2026 05:00

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Hona
Hona merged commit 90fb656 into anomalyco:v2 Aug 31, 2026
12 of 14 checks passed
@gterminator

Copy link
Copy Markdown

the problem still exists on 1.18.27

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.

4 participants