anthropics / anthropics/claude-code

Background task notifications stay queued until the next user message in SDK streaming mode

Aperta
#88,378 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area:agent-sdk bug platform:linux
Lingua principale
Python
Stelle
145k
Fork
23.1k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

### What happened

With `@anthropic-ai/claude-agent-sdk` 0.3.220 driven in streaming input mode (the consumer here is VS Code's agent host), background `Task` subagents finish and their notifications are enqueued promptly, but the queue is not drained until the user happens to send an unrelated message. The main agent is never re-prompted, so it keeps believing the work is still running and never reports the results.

Three background subagents were spawned. From the session transcript, all times UTC:

| Time | Entry |
|---|---|
| 19:25:34 | subagent 1 transcript ends |
| 19:25:35 | `{"type":"queue-operation","operation":"enqueue"}` carrying its `` |
| 19:27:03 | subagent 2 transcript ends |
| 19:27:05 | enqueued |
| 19:28:53 | subagent 3 transcript ends |
| 19:28:55 | enqueued |
| 19:32:16 | user sends an unrelated message |
| 19:32:34 | notification 1 finally appears as a `"type":"user"` entry |
| 19:32:40 | notifications 2 and 3 `"operation":"remove"` after being folded in as attachments |

So the notifications sat queued for between 3.5 and 7 minutes. In the meantime the assistant stated that the agents were still running, which was true when written and then stayed stale. The parent turn remained open for the whole period and only ended at 19:32:16, at the instant the user's message arrived.

### What I expected

The session to wake when the background work settled. The SDK's own types describe this: `HookInput.background_tasks` is documented as letting hooks distinguish "session is done" from "session is paused waiting for background work to wake it", `SDKControlInterruptRequest.still_queued` refers to "the drain loop, which starts the next queued turn immediately", and the prompt-source field lists task notifications among machine-injected `system` turns. All of that reads as though the CLI injects the notification as a turn on its own.

For contrast, in interactive Claude Code the same notifications go from queued to delivered in roughly half a second without any user message.

### Notes

I could not narrow this further because the CLI ships as a compiled binary, so I cannot see what gates the drain. I also could not find a consumer-facing option that controls it. If the intent is that an SDK consumer must submit something to drain the queue, that would be worth documenting on `SDKTaskNotificationMessage`, since a consumer that treats the notification as a UI-only signal (which is what VS Code does today) produces exactly this stall.

### Environment

- `@anthropic-ai/claude-agent-sdk` 0.3.220, `linux-arm64`
- Consumer: VS Code agent host, streaming input mode
- Dev container on Windows 11 ARM64

*AI disclosure: this issue and the related investigation were written with the assistance of AI.*

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Start by reproducing streaming input mode with background Task subagents and inspect the notification queue and drain-loop behavior described in the issue. Verify that a settled background task wakes the parent without a user message, and add or run a regression test covering queued task notifications and their delivery.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python, vscode
Ambito
api, backend-api-design
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Attiva
Chiarezza
Da chiarire
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.