The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): re-check the replay barrier after a cold re-resume REST read
teknium14d58c3a84bd5
diff --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 f43d4248791..e67942d39d6 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@@ -1805,6 +1805,15 @@ export function useSessionActions({// Non-fatal: gateway resume below can still hydrate the session.}+ // The socket can drop and redial while REST is in flight. Painting now+ // would let the new socket's replay append the same turn again; a lost+ // socket (false) drops this read and the resume below binds without it.+ const viewReplayAtReturn = viewRuntimeId ? pendingSessionReplay(viewRuntimeId) : undefined++ if (prefetchedResult && viewReplayAtReturn && !(await viewReplayAtReturn)) {+ prefetchedResult = null+ }+// A completed read still warms its exact durable scope after navigation.// It must not adopt a runtime or touch the foreground on that path.if (diff --git a/apps/desktop/src/app/session/hooks/warm-resume-replay-barrier.test.tsx b/apps/desktop/src/app/session/hooks/warm-resume-replay-barrier.test.tsxindex c54fd479a75..db3e3c56d40 100644--- a/apps/desktop/src/app/session/hooks/warm-resume-replay-barrier.test.tsx+++ b/apps/desktop/src/app/session/hooks/warm-resume-replay-barrier.test.tsx@@ -162,7 +162,7 @@ async function mountWithPendingReplay() {const request = second.sent.find(item => item.method === 'session.events.since')!expect(request.params).toMatchObject({ session_id: runtimeId, last_seen: 1 })- return { ...hook, client, requestGateway, second, request }+ return { ...hook, client, connect, requestGateway, second, request }}beforeEach(() => {@@ -316,3 +316,48 @@ it('holds a reconnect re-resume of the selected session behind its replay (coldclient.close()}})++it('does not paint a cold re-resume read ahead of a replay redialed while REST was in flight', async () => {+ const { result, client, connect } = await mountWithPendingReplay()+ const { activeSessionIdRef, runtimeIdByStoredSessionIdRef, selectedStoredSessionIdRef } = result.current.cache+ let releaseRest!: () => void+ const restGate = new Promise<void>(resolve => (releaseRest = resolve))+ const latest = vi.mocked(getLatestSessionMessages).getMockImplementation()!+ vi.mocked(getLatestSessionMessages).mockImplementation(async (...args) => restGate.then(() => latest(...args)))+ selectedStoredSessionIdRef.current = storedId+ activeSessionIdRef.current = runtimeId+ runtimeIdByStoredSessionIdRef.current.delete(storedId)++ try {+ let pending!: Promise<void>+ await act(async () => {+ pending = result.current.actions.resumeSession(storedId, true)+ })+ // The replay socket drops (barrier false: cold resume starts its REST read)+ // and redials before that read returns, owning a fresh replay of the turn.+ let third!: Awaited<ReturnType<typeof connect>>+ await act(async () => {+ client.invalidate()+ third = await connect()+ })+ expect(getLatestSessionMessages).toHaveBeenCalledTimes(1)+ const request = third.sent.find(item => item.method === 'session.events.since')!++ await act(async () => {+ releaseRest()+ await new Promise(resolve => setTimeout(resolve, 0))+ third.frame({ id: request.id, jsonrpc: '2.0', result: { events: replay } })+ await pending+ })++ expect(+ $messages+ .get()+ .map(chatMessageText)+ .join('\n')+ .match(/Finished result\./g)+ ).toHaveLength(1)+ } finally {+ client.close()+ }+})