shareAI-lab / shareAI-lab/learn-claude-code

Background task results may be lost when agent loop exits early

Open
#46 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
77.2k
Forks
12.4k
Avg merge
2d 5h
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read s08_background_tasks.py first, focusing on the pull-based _notification_queue and the agent loop's stop_reason handling. Reproduce the background npm test sequence and trace when results are enqueued versus drained; done means the early-exit case has a verified path for delivering pending task results.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
ai
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.