learn-claude-code icon indicating copy to clipboard operation
learn-claude-code copied to clipboard

Background task results may be lost when agent loop exits early

Open kevinforge opened this issue 9 months ago • 0 comments

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

  1. Ask the agent to run a long-running command in background: User: "Run npm test in the background"
  2. Agent calls background_run("npm test") and receives a task_id
  3. Agent responds with something like "OK, the test is running in the background"
  4. LLM returns with stop_reason = "end_turn" (no tool calls)
  5. Agent loop exits
  6. Background task completes and enqueues result to _notification_queue
  7. Result is never delivered since the loop has already exited

kevinforge avatar Mar 02 '26 06:03 kevinforge