diff --git a/packages/coding-agent/changelog.d/fix-acp-retry-terminal-correlation.md b/packages/coding-agent/changelog.d/fix-acp-retry-terminal-correlation.md new file mode 100644 index 00000000000..748de0564e7 --- /dev/null +++ b/packages/coding-agent/changelog.d/fix-acp-retry-terminal-correlation.md @@ -0,0 +1,3 @@ +### Fixed + +- Preserve ACP prompt correlation across provider-error retry terminals so completed turns settle instead of being abandoned by the watchdog. diff --git a/packages/coding-agent/src/session/agent-session.ts b/packages/coding-agent/src/session/agent-session.ts index 75fb0717a02..474b4aba1af 100644 --- a/packages/coding-agent/src/session/agent-session.ts +++ b/packages/coding-agent/src/session/agent-session.ts @@ -24346,6 +24346,11 @@ export class AgentSession { scope?: AttemptScope, scopeWasClean = this.#isRetryScopeClean(scope), ): Promise { + // Capture the SDK owner before the failed attempt retires its active scope. + // Retry/continuation terminals must remain attributed to the prompt that + // admitted the provider call, even when the retry starts after agent_end. + const retrySdkRunToken = + (scope ? this.#sdkRunTokensByAttemptScope.get(scope) : undefined) ?? this.#activeSdkRunToken; const retryAbortEpoch = this.#abortAdmissionEpoch; const retryCancelled = () => this.#isDisposed || this.#sessionAdmissionClosing || this.#abortAdmissionEpoch !== retryAbortEpoch; @@ -24959,7 +24964,7 @@ export class AgentSession { await this.agent.continue({ ...this.#managedFallbackPromptOptions(), onRunAccepted: (handle: AttemptRunHandle) => { - this.#acceptSdkAttemptRun(handle, this.#activeSdkRunToken); + this.#acceptSdkAttemptRun(handle, retrySdkRunToken); }, }); return; @@ -24987,6 +24992,7 @@ export class AgentSession { allowDuringCancelAndSubmit: true, suppressPredecessorAgentEnd: resourceRunId !== undefined, resourceRunId, + sdkRunToken: retrySdkRunToken, onError: () => this.#failRetryRecovery("Retry continuation failed to start"), onSkip: () => this.#failRetryRecovery("Retry continuation was superseded"), });