Skip to content

fix: prevent background shell output deadlocks - #86

Open
Princess0407 wants to merge 1 commit into
CopperPilot:mainfrom
Princess0407:fix/background-output-deadlock
Open

Princess0407 wants to merge 1 commit into
CopperPilot:mainfrom
Princess0407:fix/background-output-deadlock

Conversation

@Princess0407

Copy link
Copy Markdown

What changed and why

Fixes a deadlock in background shell execution when a subprocess exceeds the configured output limit after being handed over to BackgroundProcessManager. Previously, drain() stopped reading from the subprocess stream as soon as OutputBuffer.append() returned False.
Although the output buffer correctly stopped retaining additional output, abandoning the reader left the subprocess pipe undrained. Once the OS pipe filled, the child process blocked on its next write. BackgroundProcessManager._watch() consequently remained blocked in process.wait(), preventing the task completion event from being set and causing wait_all() to hang indefinitely.

Fixes

Changes

  • Updated drain() to continue consuming the subprocess stream until EOF, regardless of whether the output buffer has reached its limit.
  • Preserved the existing bounded-buffer and truncation behaviour. Excess output is discarded rather than retained.
  • Added test_background_output_overflow_does_not_stall_wait_all to reproduce the deadlock and verify that the background process completes normally after output truncation.

Test plan

  • make lint
  • make test
  • Targeted durability tests: python -m pytest -vv tests/test_durability.py 67 passed
  • ruff check src/copper_pilot_cli/copper_background.py tests/test_durability.py - passed
  • ruff format --check src/copper_pilot_cli/copper_background.py tests/test_durability.py - passed
  • Live test not applicable: this change does not touch auth, the TUI, or the hosted stream.

Checklist

  • Tests added or updated
  • Docs update not required; this is an internal subprocess-output handling fix with no change to the public CLI interface.
  • No new server, model-picker, computer-use, MCP, sandbox, or LangSmith surface.

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.

[Bug]: background shell processes can hang indefinitely after exceeding the output limit

1 participant