The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): a reply that finishes during a reconnect's resume renders in full
Teknium95ea5013663a
diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/message-stream.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/message-stream.tsindex a80cee99c02..b4c1f6b1424 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/message-stream.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/message-stream.ts@@ -409,7 +409,8 @@ export function handleMessageStreamEvent(ctx: GatewayEventContext): boolean {const finalText = coerceGatewayText(payload?.text) || coerceGatewayText(payload?.rendered)- noteTurnSettled(sessionId)+ // The view mirrors this runtime only while bound to it (settled-turns.ts).+ noteTurnSettled(sessionId, deps.activeSessionIdRef.current === sessionId)completeAssistantMessage(sessionId,finalText,diff --git a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/settled-during-resume.test.ts b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/settled-during-resume.test.tsindex 9cdae25eac4..d9c21b8d3c6 100644--- a/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/settled-during-resume.test.ts+++ b/apps/desktop/src/app/session/hooks/use-message-stream/gateway-event/settled-during-resume.test.ts@@ -59,6 +59,19 @@ describe('a reply settled while a resume is in flight', () => {expect(liveTurnSettledDuringResume({ session_id: 'runtime-a' }, resumeStartedAtS, true)).toBe(true)})+ // A cold resume unbinds the view until it answers. A complete landing then+ // settles only the runtime's state; the view still shows the first chunk, so+ // the resume must reconcile its post-barrier page instead of keeping it.+ it('does not count a settle that landed while the view was unbound from that runtime', () => {+ const resumeStartedAtS = Date.now() / 1000 - 1+ const settledOffScreen = complete('runtime-c')+ settledOffScreen.deps.activeSessionIdRef.current = null++ handleMessageStreamEvent(settledOffScreen)++ expect(liveTurnSettledDuringResume({ session_id: 'runtime-c' }, resumeStartedAtS, true)).toBe(false)+ })+it('does not outrank a resume that started after it, another session, or a cold open', () => {handleMessageStreamEvent(complete('runtime-b'))const laterResumeS = Date.now() / 1000 + 1diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/resume-reconcile.ts b/apps/desktop/src/app/session/hooks/use-session-actions/resume-reconcile.tsindex c5c694524ed..8f0b93fe96e 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/resume-reconcile.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/resume-reconcile.ts@@ -21,8 +21,9 @@ import { appendLiveSessionProjection, reconcileDurableHistory } from './utils'/*** Whether a re-resume of the chat on screen must keep the live transcript: a- * turn of the resumed runtime settled after the resume started (`startedAtS`,- * seconds). A cold open has no live transcript of its own to keep.+ * turn of the resumed runtime settled on screen after the resume started+ * (`startedAtS`, seconds). A cold open has no live transcript of its own to+ * keep, and a settle the unbound view never painted leaves it nothing newer.*/export function liveTurnSettledDuringResume(resumed: Pick<SessionResumeResult, 'session_id'>,diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/settled-turns.ts b/apps/desktop/src/app/session/hooks/use-session-actions/settled-turns.tsindex 3dd675b9bfe..a3ccb3c17a5 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/settled-turns.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/settled-turns.ts@@ -1,15 +1,26 @@/**- * When this renderer last settled a turn of each runtime session (message.complete),- * so a resume that was in flight meanwhile can tell its snapshot is older than the- * reply on screen (resume-reconcile.ts). Bounded: a resume only asks about the- * seconds its own RPC was in flight.+ * When this renderer last settled a turn of each runtime session on screen+ * (message.complete), so a resume that was in flight meanwhile can tell its+ * snapshot is older than the reply on screen (resume-reconcile.ts). Bounded: a+ * resume only asks about the seconds its own RPC was in flight.+ *+ * A settle counts only when the view was bound to that runtime as it landed. A+ * cold resume unbinds the view until its RPC answers, so a `message.complete`+ * arriving in that window settles the runtime's state but never reaches the+ * screen. The view still holds the partial reply then, and keeping it would+ * freeze the reply at its first chunk.*/const settledAt = new Map<string, number>()const MAX_TRACKED_SESSIONS = 64-export function noteTurnSettled(runtimeSessionId: string, at = Date.now()): void {+export function noteTurnSettled(runtimeSessionId: string, onView: boolean, at = Date.now()): void {settledAt.delete(runtimeSessionId)++ if (!onView) {+ return+ }+settledAt.set(runtimeSessionId, at)if (settledAt.size > MAX_TRACKED_SESSIONS) {@@ -17,7 +28,7 @@ export function noteTurnSettled(runtimeSessionId: string, at = Date.now()): void}}-/** Whether a turn of this runtime session settled at or after `sinceMs`. */+/** Whether a turn of this runtime session settled on screen at or after `sinceMs`. */export function turnSettledSince(runtimeSessionId: string, sinceMs: number): boolean {return (settledAt.get(runtimeSessionId) ?? -Infinity) >= sinceMs}