Skip to content

The agent that grows with you

fix(desktop): reconcile workspace tiles when the window is viewed again

liuhao102426439fe1ea88
diff --git a/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts b/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
index c47e851560f..87043479d09 100644
--- a/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.test.ts
@@ -772,6 +772,29 @@ describe('active transcript refresh', () => {
expect(refresh).toHaveBeenCalledTimes(1)
})
+ it('reconciles workspace tiles on return, not just the main pane (#125532 review)', async () => {
+ // A zombie socket that survives sleep replays no sessions.changed tick, so
+ // the tile reconcile driven by run() never fires; bot canonical chats never
+ // resolve through the main-pane path, and the tile stays pre-sleep forever.
+ const tileRuntimeId = 'runtime-wake-tile'
+ const tileStoredId = 'stored-wake-tile'
+ $sessionTiles.set([{ runtimeId: tileRuntimeId, storedSessionId: tileStoredId }])
+ publishSessionState(tileRuntimeId, createClientSessionState(tileStoredId))
+ vi.mocked(getLatestSessionMessages).mockResolvedValue(transcript('wake tile answer', tileStoredId) as never)
+
+ const refresh = vi.fn(async () => undefined)
+ renderSync(refresh)
+ refresh.mockClear() // drop the connect-time pull; this test is about returns
+ vi.mocked(getLatestSessionMessages).mockClear()
+
+ await act(async () => {
+ document.dispatchEvent(new Event('visibilitychange'))
+ })
+
+ expect(refresh).toHaveBeenCalledTimes(1) // main pane still covered
+ await waitFor(() => expect(getLatestSessionMessages).toHaveBeenCalledWith(tileStoredId, undefined, { passive: true }))
+ })
+
it('does not refresh on a visibilitychange to hidden (#125532 review)', () => {
vi.spyOn(document, 'visibilityState', 'get').mockReturnValue('hidden')
$changeEventsAvailable.set(true)
diff --git a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts b/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
index c87784d1f38..9313f1b32a5 100644
--- a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
+++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.ts
@@ -1193,6 +1193,15 @@ export function useBackgroundSync({
lastRefreshAt = now
requestActiveTranscriptRefresh(true)
+ // Workspace tiles share the zombie-socket blind spot: the sessions.changed
+ // tick that would have reconciled them does not replay on wake, and bot
+ // canonical chats never resolve through the main-pane path. The shared
+ // signature gate keeps a no-change pass free (#125532).
+ void reconcileTileTranscripts({
+ requestSequenceRef: tileRequestSequenceRef,
+ signatureRef: tileSignatureRef,
+ updateSessionState
+ })
}
document.addEventListener('visibilitychange', refreshOnReturn)
@@ -1202,7 +1211,7 @@ export function useBackgroundSync({
document.removeEventListener('visibilitychange', refreshOnReturn)
window.removeEventListener('focus', refreshOnReturn)
}
- }, [activeIsMessaging, activeSessionId, activeStoredSessionId, gatewayState, requestActiveTranscriptRefresh])
+ }, [activeIsMessaging, activeSessionId, activeStoredSessionId, gatewayState, requestActiveTranscriptRefresh, updateSessionState])
// A reconnect loses renderer-only working/attention atoms while the backend
// keeps the actual turns alive. Re-seed from the gateway's in-memory session