Skip to content

fix(job_output): add timeout to prevent indefinite blocking on wait=true - #3411

Open
kkmkoi wants to merge 1 commit into
charmbracelet:mainfrom
kkmkoi:main
Open

fix(job_output): add timeout to prevent indefinite blocking on wait=true#3411
kkmkoi wants to merge 1 commit into
charmbracelet:mainfrom
kkmkoi:main

Conversation

@kkmkoi

@kkmkoi kkmkoi commented Jul 24, 2026

Copy link
Copy Markdown

Problem

job_output(shell_id="X", wait=true) blocks forever when used on a long-running process (e.g. a web server, dev server, or any process that never exits).

This is a particularly nasty bug because:

  • Short commands (build, test, git) complete instantly → never trigger it
  • Long-running processes (start server, run watcher) → exactly the scenario where users ask an AI coding assistant to "run my project" → deadlock

The root cause: WaitContext only returns when:

  1. The process exits — server never exits → never fires
  2. The context is cancelled — no timeout is set → never fires

Fix

Added a timeout_seconds parameter to JobOutputParams (default: 60, max: 600). When wait=true, the WaitContext call is now wrapped with context.WithTimeout, so the tool always returns within the configured timeout.

Changes

File Change
job_output.go Added TimeoutSeconds field + context.WithTimeout wrapper
job_output.md Updated description to mention timeout
bash.go Added MaxAutoBackgroundSeconds to template data
bash.md.tpl Added warning: NEVER use wait=true on server processes

Example

# Before: blocks forever on a running server
job_output(shell_id="022", wait=true)  → never returns

# After: returns within timeout
job_output(shell_id="022", wait=true)                → returns after 60s
job_output(shell_id="022", wait=true, timeout_seconds=300) → 5min

Signed-off-by: kkmkoi <zhengxy225@mail2.sysu.edu.cn>
@charmcli

charmcli commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@kkmkoi

kkmkoi commented Jul 24, 2026

Copy link
Copy Markdown
Author

recheck

@kkmkoi

kkmkoi commented Jul 24, 2026

Copy link
Copy Markdown
Author

I have read the Contributor License Agreement (CLA) and hereby sign the CLA.

@kkmkoi

kkmkoi commented Jul 24, 2026

Copy link
Copy Markdown
Author

recheck

@kkmkoi

kkmkoi commented Jul 24, 2026

Copy link
Copy Markdown
Author

I encountered this bug while working on a real project — a customer service AI assistant for a beauty e-commerce competition (欧莱雅 Beauty Techathon).

The workflow was:

  1. I asked Crush to build and run my Go backend server
  2. The build completed quickly ✅
  3. The server started and was moved to background (shell_id="022") ✅
  4. Crush called job_output(shell_id="022", wait=true) to check if it started successfully
  5. The server was running fine — but job_output never returned because a server process never exits
  6. I waited 10+ minutes before realizing it was deadlocked 😅

The fix with timeout_seconds would have saved me those 10 minutes — the tool would have returned with the server's startup logs after 60 seconds, and Crush could have confirmed it was running from the output.

This is a great project for learning and contributing to open source. Thanks for maintaining Crush! 🙏

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.

2 participants