mirror of
https://github.com/agentclientprotocol/claude-agent-acp.git
synced 2026-10-27 04:30:59 +00:00
fix: publish turns that Claude Code starts after end_turn as an async task in v1 (#1390)
## Motivation
Claude Code can start a turn of its own after a prompt has ended, for
example to answer the notification of a finished background task. ACP v1
has no session state, and the client already got `end_turn` for its last
prompt. The output of that turn just keeps arriving as session updates,
and the client has no signal that the agent is working again, or when it
stops.
## Change
The adapter now publishes such a turn as an async task (AIR async tasks
extension) with the id `autonomous-turn-<uuid>`, the name `Claude is
working`, `taskType: "turn"` and `showInTranscript: false`. Its
description is the summary of the last task notification, when there is
one.
- **Start:** the SDK moves to `running` while no prompt is active or
queued. From CLI 2.1.270 the state stays `running` while background
agents run, so the task also starts at the first root output with no
prompt open.
- **End:** the task ends `completed` at the turn's result or at `idle`,
and `failed` at an error result. A coalesced placeholder result
(`num_turns: 0`) does not end it.
- **Folded prompt:** a prompt that the turn takes in ends the task,
because that prompt owns the turn now.
- **Stop:** `_session/async_task/stop` on this task interrupts the turn,
since the SDK has no task to stop. It returns `{ "stopped": false }`
while a prompt waits for its turn, because the interrupt would drop that
prompt.
- **Lifecycle:** the SDK task list does not end the task, because the
SDK does not know about it. Shutdown fails it like other open tasks.
Clients without the async tasks capability get nothing new. The behavior
is documented in `docs/air-extensions.md` under "Autonomous turn".
## Tests
`acp-agent.test.ts` covers the start at `running` and at the first
output, the end at the result, the folded prompt, stop as an interrupt,
and a client without async tasks. `async-tasks.test.ts` covers the SDK
task list reconciliation and shutdown.
This commit is contained in:
@@ -994,6 +994,20 @@ When an announced task leaves that list, the adapter reports `stopped`.
|
||||
A later terminal event can correct that state to `completed` or `failed`.
|
||||
At shutdown, the adapter finishes each open task as `failed` or `stopped`.
|
||||
|
||||
### Autonomous turn
|
||||
|
||||
Claude Code can start a turn of its own after the prompt ended, for example to answer the notification of a finished background task.
|
||||
ACP v1 has no session state, so the adapter publishes such a turn as an async task.
|
||||
The task has the id `autonomous-turn-<uuid>`, the name `Claude is working`, `taskType: "turn"`, and `showInTranscript: false`.
|
||||
Its description is the summary of the last task notification, when there is one.
|
||||
The task starts at the SDK `running` state while no prompt is active or queued.
|
||||
When the state stays `running`, as it does while background agents run, it starts at the first root output with no prompt open.
|
||||
It ends `completed` at the result of the turn or at the SDK `idle` state, and `failed` at an error result.
|
||||
A coalesced placeholder result (`num_turns: 0`) does not end it.
|
||||
A prompt that the turn takes in ends the task, because that prompt owns the turn now.
|
||||
A stop request interrupts the turn instead of stopping an SDK task.
|
||||
It returns `{ "stopped": false }` while a prompt waits for its turn, because the interrupt would drop that prompt.
|
||||
|
||||
### Stop request
|
||||
|
||||
The client sends `_session/async_task/stop`:
|
||||
|
||||
Reference in New Issue
Block a user