fix(acp): Preserve wake evidence across an app-owned wake

This PR introduces the only wakeBuffer clear at the ACP startTurn site, and it
also clears midTurnUnreportedCompletedTaskIds there, both on the reasoning that
a user turn owns the conversation.

An orchestrator-injected wake is not a user turn. #4499
fix/delegated-task-parent-wake dispatches app-owned delegated-child wakes as
creationSource "server", which is non-continuation, so once both land such a
wake would discard this session's pending native wake frames and its kept
mid-turn completion marks, losing agent output and a continuation offer that
nothing else can recover.

acpIsAppOwnedWakeTurn exempts orchestrator-injected wakes from both clears,
matching what ClaudeAdapterV2 already does with its own buffer. Inert without
#4499, since nothing else dispatches creationSource "server". Kept as its own
commit because the concern originates in a different PR.
This commit is contained in:
Mike Olson authored and Julius Marminge committed 2026-08-07 13:25:16 +02:00
1 parent cb3f1939c1
commit 5f8f68c586
2 files changed
+40 -2

No files matched your search

@@ -69,6 +69,7 @@ import {
acpClaimNativeTransportRequest,
acpNativeUserInputRequestMatches,
acpPostSettleContinuationOfferEvidence,
acpIsAppOwnedWakeTurn,
acpPostSettleMonitorPromptShouldSuppress,
acpPostSettleWakeEvidence,
acpPostSettleWakeShouldBuffer,
@@ -14209,6 +14210,20 @@ describe("acpPostSettleWakeShouldBuffer", () => {
});
});
describe("acpIsAppOwnedWakeTurn", () => {
it("recognizes only the orchestrator-injected app-owned wake", () => {
// Delegated-child wake: must preserve this session's own wake frames.
assert.isTrue(acpIsAppOwnedWakeTurn({ createdBy: "agent", creationSource: "server" }));
// Provider-native continuation: handled by the continuation branch instead.
assert.isFalse(acpIsAppOwnedWakeTurn({ createdBy: "agent", creationSource: "provider" }));
// Real user turns still clear stale wake residue.
assert.isFalse(acpIsAppOwnedWakeTurn({ createdBy: "user", creationSource: "web" }));
assert.isFalse(acpIsAppOwnedWakeTurn({ createdBy: "user", creationSource: "mcp" }));
// A user-authored message never counts, whatever its surface.
assert.isFalse(acpIsAppOwnedWakeTurn({ createdBy: "user", creationSource: "server" }));
});
});
describe("acpPostSettleMonitorPromptShouldSuppress", () => {
it("suppresses running monitor prompts but not terminal notices", () => {
assert.isTrue(
@@ -1065,6 +1065,20 @@ export function acpPostSettleWakeShouldBuffer(
);
}
/**
* An app-owned wake (a delegated child finishing) is injected by the
* orchestrator, not typed by the user. It reports on a sibling child and says
* nothing about this session's own pending wake frames, so it must not discard
* them the way a real user turn does. ClaudeAdapterV2 already leaves its buffer
* alone on non-continuation turns; this keeps ACP consistent.
*/
export function acpIsAppOwnedWakeTurn(message: {
readonly createdBy: string;
readonly creationSource: string;
}): boolean {
return message.createdBy === "agent" && message.creationSource === "server";
}
export function acpPostSettleMonitorPromptShouldSuppress(
mutation:
| {
@@ -4455,13 +4469,22 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
});
yield* Ref.set(suppressPostSettleMonitorPrompt, false);
yield* Ref.set(handledBackgroundTaskIdsInActiveTurn, new Set());
yield* Ref.set(midTurnUnreportedCompletedTaskIds, new Set());
// Continuation turns attach to wake traffic the agent already produced
// after the prior root turn settled; do not re-prompt the ACP session.
const isContinuationTurn =
postSettleContinuationEnabled &&
turnInput.message.createdBy === "agent" &&
turnInput.message.creationSource === "provider";
const isAppOwnedWakeTurn = acpIsAppOwnedWakeTurn(turnInput.message);
// An app-owned wake reports on a sibling delegated child and owns
// none of this session's background work, so it must not discard
// pending wake evidence: neither the mid-turn completion marks kept
// across a settle with work still running, nor the wake buffer
// below. Dropping the marks here would lose the offer for a task
// that completed unreported before the settle.
if (!isAppOwnedWakeTurn) {
yield* Ref.set(midTurnUnreportedCompletedTaskIds, new Set());
}
// User turns must not inherit prior-turn wake residue. Stale injected-
// turn ack chatter buffered for in-turn-handled work can otherwise
// arm a mid-turn offer when a later monitor completes (multiturn
@@ -4470,7 +4493,7 @@ export function makeAcpAdapterV2(options: AcpAdapterV2Options): ProviderAdapterV
// and re-buffer evidence when they complete; a user message means
// this turn owns the conversation, so prior wake frames cannot be
// legitimate for a synthetic continuation of the previous turn.
if (!isContinuationTurn) {
if (!isContinuationTurn && !isAppOwnedWakeTurn) {
yield* Ref.set(wakeBuffer, []);
}
// Drop a sticky continuation offer when any new turn starts so idle