The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): don't let a stale resume snapshot mark an open chat idle
Teknium662a77f31e77
diff --git a/apps/desktop/src/app/contrib/hooks/live-status-reap.test.ts b/apps/desktop/src/app/contrib/hooks/live-status-reap.test.tsindex b5d92aa13ae..cca8adf1545 100644--- a/apps/desktop/src/app/contrib/hooks/live-status-reap.test.ts+++ b/apps/desktop/src/app/contrib/hooks/live-status-reap.test.ts@@ -98,9 +98,7 @@ describe('rehydrateLiveSessionStatuses — reaping vanished runtimes', () => {...createClientSessionState('stored-tools'),busy: true,awaitingResponse: true,- messages: [- { id: 'a1', role: 'assistant', parts: [openTool], pending: false } as never- ]+ messages: [{ id: 'a1', role: 'assistant', parts: [openTool], pending: false } as never]})// Keep the runtime referenced so the settled state stays in the storediff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.tsindex e11adefdba9..88deda8dcb3 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts@@ -86,6 +86,7 @@ import {patchSessionWorkspace,preserveLocalPendingTurnMessages,reconcileResumeMessages,+ resolveResumedBusy,resolveSessionProfile,resolveStoredSession,sessionMatchesStoredId,@@ -830,7 +831,13 @@ export function useSessionActions({? reconcileAuthoritativeMessages(activated.messages, cachedViewState.messages, activated): cachedViewState.messages- const running = Boolean(activated.running ?? cachedViewState.busy)+ // #70449: never let the activate snapshot's stale running:false+ // rewind a turn that started while the RPC was in flight — read+ // the freshest cache entry, not the pre-await cachedViewState.+ const running = resolveResumedBusy(+ activated.running ?? cachedViewState.busy,+ Boolean(sessionStateByRuntimeIdRef.current.get(cachedRuntimeId)?.busy)+ )// While idle, the persisted REST transcript is the display// authority: session.activate returns the runtime's compressed@@ -1051,7 +1058,14 @@ export function useSessionActions({return chatMessageArraysEquivalent(currentMessages, resumedMessages) ? currentMessages : resumedMessages})()- resumedRunning = Boolean((resumed as { running?: boolean }).running)+ // #70449: same stale-snapshot guard as the warm path — a turn that+ // started while the resume RPC was in flight has already marked the+ // rebound runtime busy via gateway events; the snapshot must not+ // rewind it to idle just because the user opened the chat.+ resumedRunning = resolveResumedBusy(+ (resumed as { running?: boolean }).running,+ Boolean(sessionStateByRuntimeIdRef.current.get(resumed.session_id)?.busy)+ )// Crash-survivable turn progress: fold a journaled in-flight tail// (persisted by use-session-state-cache while the turn streamed;diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.tsindex 27bff4795e0..1e2667e9372 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.test.ts@@ -25,6 +25,7 @@ import {isSessionGoneError,preserveLocalPendingTurnMessages,reconcileResumeMessages,+ resolveResumedBusy,sessionMatchesStoredId,sessionShouldHaveTranscript,toBranchMessages@@ -1428,3 +1429,21 @@ describe('appendLiveSessionProjection', () => {})})})++describe('resolveResumedBusy', () => {+ it('keeps a live busy turn when the resume snapshot stalely reports idle (#70449)', () => {+ expect(resolveResumedBusy(false, true)).toBe(true)+ expect(resolveResumedBusy(undefined, true)).toBe(true)+ expect(resolveResumedBusy(null, true)).toBe(true)+ })++ it('clears busy when both the snapshot and the live cache agree the turn ended', () => {+ expect(resolveResumedBusy(false, false)).toBe(false)+ expect(resolveResumedBusy(undefined, false)).toBe(false)+ })++ it('adopts a running turn reported by the snapshot even without live state', () => {+ expect(resolveResumedBusy(true, false)).toBe(true)+ expect(resolveResumedBusy(true, true)).toBe(true)+ })+})diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.tsindex db6132c556f..cfa9477f9ba 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts@@ -1255,3 +1255,23 @@ export function isSessionGoneError(err: unknown): boolean {return message.includes('404') || /session not found/i.test(message)}++/**+ * The busy value a resume/activate response should land with (#70449).+ *+ * `running` in a `session.activate` / `session.resume` payload is a snapshot+ * taken when the RPC was issued. A turn that started — or streamed — after+ * that snapshot has already marked the runtime busy in the live cache, so a+ * stale `running: false` must never rewind it: that is exactly how opening an+ * in-progress chat cleared its working indicator while the agent was still+ * going. Preserving the newer live busy is safe, because the turn's own+ * terminal signal (running:false via session.info / the settle path) remains+ * the only authority that ends it, and the background-sync reaper clears+ * truly lost turns.+ *+ * A snapshot that says `running: true` always wins — adopting a live turn is+ * never stale.+ */+export function resolveResumedBusy(snapshotRunning: boolean | null | undefined, liveBusy: boolean): boolean {+ return Boolean(snapshotRunning) || liveBusy+}