Skip to content

fix(streaming): clear output callback on cancellation#1839

Open
chaliy wants to merge 1 commit into
mainfrom
2026-06-02-fix-output-leak-in-python-streaming-execution
Open

fix(streaming): clear output callback on cancellation#1839
chaliy wants to merge 1 commit into
mainfrom
2026-06-02-fix-output-leak-in-python-streaming-execution

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Jun 2, 2026

Motivation

  • Prevent stale interpreter output callbacks from surviving if a streaming execution future is cancelled or dropped, which can leak stdout/stderr into later executions and cross-request contexts.

Description

  • Introduce an RAII guard OutputCallbackGuard that installs the callback via install and clears it in Drop to make cleanup cancellation-safe and robust across await points. (crates/bashkit/src/lib.rs)
  • Mark the guard Send with a safety comment so it can travel across executor boundaries while still ensuring unique access to the interpreter. (crates/bashkit/src/lib.rs)
  • Use the guard in exec_streaming_with_extensions so callbacks are cleared even if the streaming future is cancelled. (crates/bashkit/src/lib.rs)
  • Add a Rust regression test test_exec_streaming_cancel_clears_callback proving a timed-out/cancelled streaming run does not receive later output. (crates/bashkit/src/lib.rs)
  • Add a Python async regression test_execute_on_output_cancel_does_not_poison_future_calls covering asyncio.wait_for cancellation for both Bash and BashTool. (crates/bashkit-python/tests/test_streaming_output.py)

Testing

  • cargo test -p bashkit test_exec_streaming_cancel_clears_callback --lib — passed.
  • VIRTUAL_ENV=$PWD/.uv-venv-bashkit PATH=$PWD/.uv-venv-bashkit/bin:$PATH uvx maturin develop --manifest-path crates/bashkit-python/Cargo.toml and python -m pytest crates/bashkit-python/tests/test_streaming_output.py -q — Python tests passed (26 passed).
  • cargo clippy -p bashkit --lib -- -D warnings — passed.
  • cargo fmt --check and ruff check / ruff format --check on the modified Python test file — passed.

Codex Task

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Jun 2, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 2f2d295 Commit Preview URL Jun 02 2026, 09:36 AM

@chaliy chaliy force-pushed the 2026-06-02-fix-output-leak-in-python-streaming-execution branch from d9799ec to 2f2d295 Compare June 2, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant