Skip to content

fix(tools): bound the output drain after ExecuteBashTool timeouts - #8453

Open
sumedh-aerram wants to merge 1 commit into
google:mainfrom
sumedh-aerram:fix/bash-tool-timeout-drain
Open

sumedh-aerram wants to merge 1 commit into
google:mainfrom
sumedh-aerram:fix/bash-tool-timeout-drain

Conversation

@sumedh-aerram

Copy link
Copy Markdown

Link to Issue or Description of Change

Fixes #8452

Problem: After killing a timed-out command, an escaped descendant holding stdout or stderr could keep ExecuteBashTool waiting indefinitely. Cancelling the original communicate call also discarded already-read output.

Solution: Preserve the original communicate task, bound the process-exit check to one second and the output drain to one second, then close the subprocess transport if inherited pipes remain open. Allow one final bounded second for reader cleanup. Keep the result schema, timeout message, and normal command behavior unchanged.

Testing Plan

Unit Tests:

  • Added real-process POSIX regressions covering ordinary and escaped children, stdout/stderr preservation, and return within six seconds.
  • Both bash-tool test files: 30 passed in 3.77s with asyncio debug enabled and ResourceWarning treated as an error.
  • Upstream reproduction: both new cases failed in 7.61s; escaped child hit the six-second guard, ordinary timeout lost printed output.
  • All applicable pre-commit hooks passed.
  • Targeted mypy check passed with no issues.

Manual End-to-End (E2E) Tests:

The regression tests execute real subprocesses. Run the bash-tool test files with PYTHONASYNCIODEBUG=1 and resource warnings promoted to errors. No separate agent/model E2E run was performed.

Checklist

  • Read CONTRIBUTING.md.
  • Performed self-review.
  • Commented transport cleanup and process-exit behavior.
  • Added regression coverage.
  • Relevant new and existing unit tests pass.
  • Separate manual agent E2E test.
  • No dependent downstream changes required.

Additional context

No new public options. Closing asyncio's subprocess transport requires its private transport attribute because Process exposes no public close API.

Preserve captured output and bound cleanup when escaped descendants retain subprocess pipes.

Fixes google#8452
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.

ExecuteBashTool timeout is not enforced when the command leaves a process in its own session

1 participant