learn-claude-code
learn-claude-code copied to clipboard
Background task results may be lost when agent loop exits early
In s08_background_tasks.py, background task results are delivered via a pull-based notification queue that is only drained before each LLM call. However, if the LLM decides it has no more work to do (i.e., stop_reason != "tool_use"), the agent loop exits immediately, and any pending background task results remain in the queue and are never delivered.
Steps to Reproduce
- Ask the agent to run a long-running command in background: User: "Run npm test in the background"
- Agent calls background_run("npm test") and receives a task_id
- Agent responds with something like "OK, the test is running in the background"
- LLM returns with stop_reason = "end_turn" (no tool calls)
- Agent loop exits
- Background task completes and enqueues result to _notification_queue
- Result is never delivered since the loop has already exited