From d2546e599d67788ac418ecb7ea2f0608470ecc6b Mon Sep 17 00:00:00 2001 From: Merge Sim Date: Wed, 2 Sep 2026 01:58:57 -0700 Subject: [PATCH] fix(native-chat): suppress cancellation toast during retry --- .../structured-agent-session-launch.test.ts | 29 +++++++++++++++++++ .../lib/structured-agent-session-launch.ts | 3 ++ 2 files changed, 32 insertions(+) diff --git a/src/renderer/src/lib/structured-agent-session-launch.test.ts b/src/renderer/src/lib/structured-agent-session-launch.test.ts index 4a60e525da8..93507fad6d0 100644 --- a/src/renderer/src/lib/structured-agent-session-launch.test.ts +++ b/src/renderer/src/lib/structured-agent-session-launch.test.ts @@ -196,6 +196,35 @@ describe('startStructuredCodexLaunch', () => { expect(toast.error).not.toHaveBeenCalled() }) + it('does not toast when cancelled during retry reconciliation', async () => { + const worktreeId = 'wt-retry-close-race' + const intent = launchIntent(worktreeId, 'session-retry-close-race') + let resolveRetryRefresh!: (snapshots: RuntimeMobileSessionTabsResult[]) => void + mocks.createIntent.mockReturnValueOnce(intent) + mocks.launch + .mockRejectedValueOnce(new Error('first response lost')) + .mockRejectedValueOnce(new Error('retry response lost')) + vi.mocked(refreshLocalStructuredSessionTabs) + .mockResolvedValueOnce([]) + .mockImplementationOnce( + () => + new Promise((resolve) => { + resolveRetryRefresh = resolve + }) + ) + + startStructuredCodexLaunch(worktreeId) + await vi.waitFor(() => expect(refreshLocalStructuredSessionTabs).toHaveBeenCalledTimes(2)) + + expect(cancelStructuredCodexLaunch(worktreeId, intent.sessionId)).toBe(true) + resolveRetryRefresh([]) + await flushLaunchSettlement() + + expect(mocks.launch).toHaveBeenCalledTimes(2) + expect(toast.error).not.toHaveBeenCalled() + expect(mocks.abandonIntent).toHaveBeenCalledWith(intent) + }) + it('keeps an unresolved identity reserved until inventory reconciles it', async () => { const worktreeId = 'wt-still-unknown' const intent = launchIntent(worktreeId) diff --git a/src/renderer/src/lib/structured-agent-session-launch.ts b/src/renderer/src/lib/structured-agent-session-launch.ts index 5d638940ea4..411ad30badc 100644 --- a/src/renderer/src/lib/structured-agent-session-launch.ts +++ b/src/renderer/src/lib/structured-agent-session-launch.ts @@ -88,6 +88,9 @@ async function retrySameIntent(state: StructuredLaunchState, priorError: unknown try { return await verifyPublishedSession(state.intent) } catch { + if (state.cancelled) { + throw new StructuredAgentSessionLaunchCancelledError() + } state.visibilityUnknown = true throw error ?? priorError }