From a0e4ce252c9055b42633fa4e3bacafeb74c03495 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 04:11:46 -0700 Subject: [PATCH] fix(desktop): open cron-run transcripts stay live MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reimplements PR #89728 on top of the ownerRoute rework. The active transcript resolver only looked in $sessions and $messagingSessions, so an open cron-run transcript resolved to nothing and every sessions.changed tick was dropped — the pane froze until the user reopened it. Resolve through ownerLookupSessionRows() (recents + cron + messaging) instead. Co-authored-by: fangliquanflq --- .../app/contrib/hooks/use-background-sync.test.ts | 15 +++++++++++++++ .../src/app/contrib/hooks/use-background-sync.ts | 7 ++----- 2 files changed, 17 insertions(+), 5 deletions(-) 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 7d1bd2cc64..30f1e4f8d3 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 @@ -8,6 +8,7 @@ import { $activeSessionId, $selectedStoredSessionId, setBusy, + setCronSessions, setMessagingSessions, setSessionOwnerHint, setSessions @@ -155,6 +156,7 @@ afterEach(() => { $activeSessionId.set(null) $selectedStoredSessionId.set(null) setSessions([]) + setCronSessions([]) setMessagingSessions([]) setBusy(false) vi.clearAllMocks() @@ -555,6 +557,19 @@ describe('reconcileActiveTranscript', () => { }) }) + it('resolves and hydrates a cron session from the cron sessions store', async () => { + setCronSessions([{ id: ACTIVE_STORED_ID, profile: 'cron-profile', source: 'cron' } as never]) + const fixture = makeRefresh(resolveActiveTranscriptSession) + vi.mocked(getLatestSessionMessages).mockResolvedValue(transcript('cron progress') as never) + + await fixture.refresh() + + expect(getLatestSessionMessages).toHaveBeenCalledWith(ACTIVE_STORED_ID, 'cron-profile') + expect(fixture.states.get(ACTIVE_RUNTIME_ID)?.messages.at(-1)?.parts[0]).toMatchObject({ + text: 'cron progress' + }) + }) + it('fails closed when a hidden session id has multiple owner hints', async () => { const ambiguousStoredSessionId = 'ambiguous-hidden-chat' setSessionOwnerHint(ambiguousStoredSessionId, { 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 663f190a51..ee803cfa3b 100644 --- a/apps/desktop/src/app/contrib/hooks/use-background-sync.ts +++ b/apps/desktop/src/app/contrib/hooks/use-background-sync.ts @@ -13,10 +13,9 @@ import { $activeSessionId, $busy, $currentCwd, - $messagingSessions, $selectedStoredSessionId, - $sessions, getSessionOwnerHint, + ownerLookupSessionRows, sessionMatchesStoredId, setCurrentCwd } from '@/store/session' @@ -39,9 +38,7 @@ interface ActiveTranscriptSession { /** Resolve an active transcript from visible rows or its unique hidden owner. */ export function resolveActiveTranscriptSession(storedSessionId: string): ActiveTranscriptSession | undefined { - const visible = - $sessions.get().find(session => sessionMatchesStoredId(session, storedSessionId)) ?? - $messagingSessions.get().find(session => sessionMatchesStoredId(session, storedSessionId)) + const visible = ownerLookupSessionRows().find(session => sessionMatchesStoredId(session, storedSessionId)) if (visible) { return { profile: visible.profile }