The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): only park a PRIMARY reconcile's unread dot; confirm parked completions from any fresh snapshot
teknium1cc0c97833c8f
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 74d9b47d18c..153d483fd34 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@@ -8,7 +8,8 @@ import {$sessionStates,$workingSessionIds,clearAllSessionStates,- publishSessionState+ publishSessionState,+ reconcileBusyStatesOnReconnect} from '@/store/session-states'import { rehydrateLiveSessionStatuses } from './use-background-sync'@@ -59,6 +60,20 @@ describe('rehydrateLiveSessionStatuses — reaping vanished runtimes', () => {expect($unreadFinishedSessionIds.get()).toEqual(['stored-b'])})+ // A turn that started just before the socket dropped was never polled, so+ // "seen live last poll" cannot gate its confirmation: the reconcile parked it,+ // and the first fresh snapshot that does not report it working is the+ // terminal fact that lights the dot.+ it('confirms a parked reconnect completion the poll never saw live', () => {+ publishSessionState('runtime-p', { ...createClientSessionState('stored-p'), busy: true, storedSessionId: 'stored-p' })+ reconcileBusyStatesOnReconnect()+ expect($unreadFinishedSessionIds.get()).toEqual([])++ rehydrateLiveSessionStatuses({ sessions: [] })++ expect($unreadFinishedSessionIds.get()).toEqual(['stored-p'])+ })+it('clears a blocked session that disappears from the live snapshot', () => {rehydrateLiveSessionStatuses({sessions: [{ id: 'runtime-c', session_key: 'stored-c', status: 'waiting' }]diff --git a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts b/apps/desktop/src/app/contrib/hooks/use-background-sync.tsindex e457cc663c3..6ff53e0a34b 100644--- a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts+++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.ts@@ -25,7 +25,7 @@ import type { SessionOwnerRoute } from '@/store/session-request-router'import {$sessionStates,$sessionTiles,- confirmReconnectSettle,+ confirmReconnectSettlesExcept,publishSessionState,SESSION_WATCHDOG_TIMEOUT_MS,setSessionStalled@@ -404,6 +404,7 @@ export function rehydrateLiveSessionStatuses(stateAtRequest = $sessionStates.get()): void {const seen = new Set<string>()+ const workingStoredIds = new Set<string>()for (const session of response.sessions ?? []) {const runtimeSessionId = session.id?.trim()@@ -417,6 +418,10 @@ export function rehydrateLiveSessionStatuses(seen.add(runtimeSessionId)+ if (working) {+ workingStoredIds.add(storedSessionId)+ }+const existing = $sessionStates.get()[runtimeSessionId]// The active-list response is an async snapshot. Stream events can start@@ -454,8 +459,6 @@ export function rehydrateLiveSessionStatuses(if (!working) {setSessionStalled(storedSessionId, false)- // Authoritative: the turn a reconnect reconcile downgraded blind is over.- confirmReconnectSettle(storedSessionId)continue}@@ -508,15 +511,17 @@ export function rehydrateLiveSessionStatuses(// does, so the transcript matches the state.messages: sealOpenToolParts(existing.messages)})- } else {- // Already downgraded by the reconnect reconcile: its absence here is- // the terminal fact that reconcile lacked, so the dot lights now.- confirmReconnectSettle(existing?.storedSessionId)}}}liveRuntimeIdsByProfile.set(profileKey, seen)++ // Completions the reconnect reconcile downgraded blind: this snapshot is the+ // terminal fact it lacked. Every parked session not reported working is+ // over, whether or not an earlier poll ever saw its runtime (a turn that+ // started just before the drop was never polled).+ confirmReconnectSettlesExcept(workingStoredIds)}/** Forget every profile's live-runtime bookkeeping. A gateway wipe already@@ -748,7 +753,13 @@ export function useBackgroundSync({}} catch {// Older gateways may not expose session.active_list. Live stream events- // still work as before; leave the current sidebar state untouched.+ // still work as before; leave the current sidebar state untouched —+ // except completions the reconnect reconcile parked awaiting this+ // snapshot: with no snapshot to confirm them they light now (the+ // pre-#113029 behaviour) rather than never.+ if (!cancelled) {+ confirmReconnectSettlesExcept(new Set())+ }} finally {inFlight = falsediff --git a/apps/desktop/src/store/session-states-reconnect.test.ts b/apps/desktop/src/store/session-states-reconnect.test.tsindex 80c3a1ce187..5b13b0ae6d7 100644--- a/apps/desktop/src/store/session-states-reconnect.test.ts+++ b/apps/desktop/src/store/session-states-reconnect.test.ts@@ -225,4 +225,18 @@ describe('reconcileBusyStatesOnReconnect', () => {publishSessionState('rt1', { ...$sessionStates.get().rt1, busy: false })expect($unreadFinishedSessionIds.get()).toContain('s1')})++ // The only confirm producer for a parked completion is the ACTIVE profile's+ // session.active_list poll, which never lists a background socket's+ // runtimes. Parking a scoped downgrade would therefore lose the dot for a+ // turn that ended while that socket was down; it lights at once instead.+ it('a scoped reconcile lights the unread dot immediately — no poll can confirm it', () => {+ publishSessionState('rtA', state({ busy: true, sawAssistantPayload: true, storedSessionId: 'sA' }))+ recordSessionEventScope({ connectionId: 'connA', profile: 'default', session_id: 'rtA' })++ reconcileBusyStatesOnReconnect(registryBackendScopeKey('connA', 'default'))++ expect($workingSessionIds.get()).not.toContain('sA')+ expect($unreadFinishedSessionIds.get()).toEqual(['sA'])+ })})diff --git a/apps/desktop/src/store/session-states.ts b/apps/desktop/src/store/session-states.tsindex f83f8534cca..3320ca3be95 100644--- a/apps/desktop/src/store/session-states.ts+++ b/apps/desktop/src/store/session-states.ts@@ -456,12 +456,16 @@ function handleTransition(previous: ClientSessionState | null, next: ClientSessi} else if (!next.busy && wasWorking) {markSettled(storedId)- // A reconnect reconcile is not a terminal event: it downgrades EVERY busy- // claim on the socket, live turns included, so lighting the dot here is- // the false green of #113029. Park the completion until the post-reconnect- // `session.active_list` snapshot confirms the turn is gone (or a re-assert- // proves it alive).- if (reconcilingBusyClaims) {+ // A PRIMARY reconnect reconcile is not a terminal event: it downgrades+ // EVERY busy claim on the socket, live turns included, so lighting the dot+ // here is the false green of #113029. Park the completion until the+ // post-reconnect `session.active_list` snapshot confirms the turn is gone+ // (or a re-assert proves it alive). A SCOPED (secondary/background-profile)+ // reconcile lights immediately: the active profile's poll never lists that+ // socket's runtimes, so a parked completion there would have no confirm+ // producer and a turn that ended while the socket was down would never+ // earn its dot.+ if (deferringReconcileUnread) {unconfirmedReconnectSettles.add(storedId)return@@ -492,19 +496,27 @@ function lightUnreadCompletion(storedId: string) {}}-/** Stored ids whose busy claim a reconnect reconcile retired without any proof- * the turn ended. The authoritative post-reconnect snapshot settles each one:- * `confirmReconnectSettle` when the runtime is idle or gone, a busy re-assert- * (stream event or `working` row) when the turn is still live. */+/** Stored ids whose busy claim a PRIMARY reconnect reconcile retired without+ * any proof the turn ended. The authoritative post-reconnect snapshot settles+ * each one: `confirmReconnectSettlesExcept` when the runtime is idle or gone,+ * a busy re-assert (stream event or `working` row) when the turn is still+ * live. */const unconfirmedReconnectSettles = new Set<string>()-let reconcilingBusyClaims = false--/** The authoritative snapshot reports this session's turn over: a completion- * the reconnect reconcile downgraded blind now earns its unread dot. No-op- * for sessions the reconcile never touched. */-export function confirmReconnectSettle(storedSessionId: null | string | undefined) {- if (storedSessionId && unconfirmedReconnectSettles.delete(storedSessionId)) {- lightUnreadCompletion(storedSessionId)+let deferringReconcileUnread = false++/** A fresh authoritative snapshot arrived: every parked completion whose+ * session it does not report as still working is over and earns its unread+ * dot. The parked set itself is the eligibility list — a turn that started+ * just before the drop was never polled, so "seen live last poll" cannot be+ * the gate. Pass an empty set when no snapshot can be had (old gateway): a+ * parked completion with no confirm producer must fall back to lighting+ * rather than never lighting. No-op when nothing is parked. */+export function confirmReconnectSettlesExcept(workingStoredIds: ReadonlySet<string>) {+ for (const storedId of unconfirmedReconnectSettles) {+ if (!workingStoredIds.has(storedId)) {+ unconfirmedReconnectSettles.delete(storedId)+ lightUnreadCompletion(storedId)+ }}}@@ -659,9 +671,10 @@ export function clearAllSessionStates() {* answer, and post-reconnect refresh re-asserts or retires it via its own* path. Transition side-effects run through publishSessionState, so* watchdogs disarm and stall hints drop — but the unread dot is deferred:- * this downgrade is blind, so the completion is parked until the+ * a PRIMARY downgrade is blind, so the completion is parked until the* post-reconnect `session.active_list` snapshot confirms the turn is gone- * (`confirmReconnectSettle`) or a busy re-assert proves it alive (#113029).+ * (`confirmReconnectSettlesExcept`) or a busy re-assert proves it alive+ * (#113029). A SCOPED downgrade lights it at once: no poll covers that socket.** The downgrade goes through the delegate's `retireBusyClaim` (the wiring* cache's updateSessionState), not straight into this mirror: the claim has@@ -675,7 +688,10 @@ export function clearAllSessionStates() {export function reconcileBusyStatesOnReconnect(scope?: string) {const states = $sessionStates.get()- reconcilingBusyClaims = true+ // Only the primary socket has a confirm producer for a parked completion+ // (the active profile's `session.active_list` poll); a scoped reconcile+ // lights the dot immediately — see handleTransition.+ deferringReconcileUnread = scope === undefinedtry {for (const [runtimeId, state] of Object.entries(states)) {@@ -699,7 +715,7 @@ export function reconcileBusyStatesOnReconnect(scope?: string) {}}} finally {- reconcilingBusyClaims = false+ deferringReconcileUnread = false}if (scope === undefined) {