Skip to content

Background task results may be lost when agent loop exits early #46

@QianzhenSun

Description

@QianzhenSun

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions