From cd000038294a77e9cf098fc3815aa2b027a284f5 Mon Sep 17 00:00:00 2001 From: can1357 Date: Sun, 14 Jun 2026 07:29:23 +0200 Subject: [PATCH] fix(coding-agent/session): stopped post-prompt recovery waits after aborted generations - Added a generation-aware early-exit check in `#waitForPostPromptRecovery` to return when the prompt turn is superseded. - Passed the current prompt generation into the post-prompt recovery wait after prompting. - Ensured aborted prompts no longer block while later queued retry/follow-up turns drain. --- packages/coding-agent/src/session/agent-session.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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();