Repository navigation
Description
Summary
When a background task (such as a detached bash command) finishes mid-turn while the main agent is still executing a client-driven session/prompt, the engine steers the active turn and ends it with turn.ended { reason: "completed", continuation: "turn" } so it can immediately start turn N + 1 to process the <notification category="task"> message.
Even after #5447 (merged to main), AcpSession.onTurnEnded in packages/acp-server/src/session.ts still resolves the active session/prompt immediately with { stopReason: "end_turn" } without checking event.continuation === "turn".
Reproduction
- Connect any ACP client to
kimi acp(observed on@moonshot-ai/[email protected], and the sameonTurnEndedbehavior remains onmainafter fix(acp): stream background task turns to editors #5447). - Send a
session/promptwhere the agent starts a short background shell task (e.g., a command that completes or fails within ~1–15s) and continues doing another tool call (e.g.,ReadorGrep) in the same turn. - Wait for the background task to terminate while that next step is in flight (
task.terminated→prompt.steered). - As soon as the
tool_usestep finishes (before any final assistant answer is generated), the engine emits:turn.endedwithreason: "completed",continuation: "turn"(for turnN)turn.promptwith<notification category="task" ...>(for turnN + 1)
Observed Behavior
AcpSession.onTurnEndedseesevent.turnId === driver.turnIdand immediately settles the activesession/promptwith{ stopReason: "end_turn" }, even though turnNended right after atool_usestep withcontinuation: "turn"and the agent has not finished the user's request.- Standard ACP clients mark the turn complete and return the UI to idle mid-task.
- On
2.8.1, all output from turnN + 1is dropped bydriverFor(event.turnId), and any follow-upsession/promptsent while turnN + 1is still running receives an immediate emptyend_turn. - On
main(after fix(acp): stream background task turns to editors #5447), turnN + 1streamssession/updatenotifications aftersession/prompthas already settled, which standard request/response ACP clients do not expect while idle — and if the user sees the idle state and sends a follow-up message, it is rejected withturn.agent_busy.
Expected Behavior
- When
turn.endedhasreason: "completed"andcontinuation: "turn", the in-flightsession/promptshould stay open and follow the immediate continuation turn (N + 1), streaming its updates under the same prompt request. session/promptshould only resolve with{ stopReason: "end_turn" }when the turn actually settles withcontinuation !== "turn"(i.e."none"or"background"), or on error/cancellation.- The post-settle
taskNotificationTurnIdpath added in fix(acp): stream background task turns to editors #5447 remains useful for truly asynchronous wakes (after a turn has already settled withcontinuation: "background"and a long-running task finishes later).
Root Cause & Suggested Direction
In packages/acp-server/src/session.ts, onTurnEnded does not inspect event.continuation:
private onTurnEnded(event: AgentEventPayloads['turn.ended']): void {
if (event.turnId === this.taskNotificationTurnId) {
this.taskNotificationTurnId = undefined;
void this.emitUsageUpdate();
return;
}
const driver = this.driverFor(event.turnId);
if (driver === undefined) return;
...
this.settleDriver(driver, () => {
...
driver.resolve({ stopReason: turnEndReasonToStopReason(event.reason, error) });
});
}If event.reason === 'completed' && event.continuation === 'turn' (and the driver has not been cancelled), keeping this.driver active and binding it to the immediately following turn.started (with a fallback if cancellation or failure occurs) would keep the ACP session/prompt lifecycle aligned with the agent's real turn boundary across all ACP clients.
Happy to open a focused PR with regression tests if a maintainer /approves this approach.
Activity
mw1986518-dot commentedon Nov 30, 2026
Confirming this reproduces in real-world usage with T3 Code
0.1.13(acpRegistry_kimi_code, modelkimi-code/k3.1-pro) on macOS (darwin/arm64).Observed timeline
Read/ shell checks in parallel.session/promptresolved ascompleted(~73s into the run) right after aReadtool call, with no final assistant summary.git commits and a full remote production deployment with zero output streamed to the ACP client."continue"message while the hidden continuation turn was still finishing — that prompt returned emptycompletedin 2.1s with zero assistant/tool items.This is particularly risky for side-effecting workflows (git commits, deployments) because the user sees the run as finished and may re-trigger the workflow while the unattached continuation turn is still mutating files or deploying. Keeping the in-flight
session/promptopen whenevent.continuation === "turn"would directly prevent this.