diff --git a/packages/coding-agent/src/session/agent-session.ts b/packages/coding-agent/src/session/agent-session.ts index c53d6cc16..8148a7cfc 100644 --- a/packages/coding-agent/src/session/agent-session.ts +++ b/packages/coding-agent/src/session/agent-session.ts @@ -2120,8 +2120,13 @@ export class AgentSession { * and fire-and-forget `agent.continue()` may still be streaming after * the TTSR resume gate resolves. */ - async #waitForPostPromptRecovery(): Promise { + async #waitForPostPromptRecovery(generation?: number): Promise { while (true) { + // An abort bumps #promptGeneration. When this wait runs on behalf of a + // specific prompt turn, stop as soon as that turn has been superseded: + // its promise must resolve on the abort, not block on a queued + // steer/follow-up that the post-abort drain starts as a fresh turn. + if (generation !== undefined && this.#promptGeneration !== generation) return; if (this.#retryPromise) { await this.#retryPromise; continue; @@ -4871,7 +4876,7 @@ export class AgentSession { const agentPromptOptions = options?.toolChoice ? { toolChoice: options.toolChoice } : undefined; await this.#promptAgentWithIdleRetry(messages, agentPromptOptions); if (!options?.skipPostPromptRecoveryWait) { - await this.#waitForPostPromptRecovery(); + await this.#waitForPostPromptRecovery(generation); } } finally { this.#endInFlight();