Skip to content

fix: retain timed-out bash commands and clean up shells on runtime exit - #317

Merged
frostming merged 2 commits into
mainfrom
fix/bash-timeout-background
Sep 21, 2026
Merged

frostming merged 2 commits into
mainfrom
fix/bash-timeout-background

Conversation

@frostming

@frostming frostming commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Foreground bash commands that exceed timeout_seconds now continue in the background and return a shell_id, instead of being terminated. Output remains available through bash.output, and bash.kill can stop the command. Explicit background responses also include the shell ID and follow-up actions.

Shell ownership now follows the runtime lifecycle:

  • A new provide_lifespan hook enters plugin resource generators within framework.running(). The builtin implementation owns shells across turns and cleans them up on normal exit, exceptions, cancellation, and startup failure.
  • Separate runtime scopes remain independent, including when they use the same session ID. Shutdown waits for in-flight process creation, and tasks cannot create shells after their owning scope closes.
  • On POSIX, foreground completion cleans up remaining process-group members even if the shell leader has exited and its children redirected their output.
  • Termination finishes before cancellation propagates, including repeated cancellation. Cleanup continues for other shells if one reader fails. Timeout during cleanup does not return a released shell ID.

Tests cover continued output after timeout, explicit termination, session and runtime cleanup, scope isolation, spawn/shutdown races, repeated cancellation, and descendant termination. English and Chinese hook documentation describe the lifecycle and its limits.

Limits: cleanup covers the POSIX process group. Descendants that deliberately leave it and abrupt SIGKILL of Bub require OS-level supervision. Windows currently terminates only the direct shell process. SDK callers need to run the builtin lifecycle within framework.running() (or explicitly manage their ShellManager lifespan).

Validation:

  • Full pytest suite with doctests: 485 passed, 1 skipped.
  • Ruff checks and formatting passed.
  • mypy passed for all 51 source files.
  • Website/docs production build passed.
  • git diff --check passed.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

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
bub 2f6f19a Commit Preview URL

Branch Preview URL
Sep 21 2026, 01:58 AM

@frostming frostming changed the title fix: keep timed-out bash commands running in background fix: retain timed-out bash commands and clean up shells on runtime exit Sep 21, 2026
@frostming
frostming merged commit ee4c060 into main Sep 21, 2026
6 checks passed
@frostming
frostming deleted the fix/bash-timeout-background branch September 21, 2026 02:11
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.

1 participant