Skip to content

The agent that grows with you

fix(desktop): report failed primary session reads instead of empty slices

brooklyn!2054ab9cbcee
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 815971187e3..ed9512ddbf6 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -372,6 +372,7 @@ import {
import { migrateActiveProfileIfMissing as migrateActiveProfileIfMissingPure } from './profile-migration'
import { prepareProfileRenameLifecycle, profileRenameFromRequest } from './profile-rename-routing'
import {
+ assembleSidebarSessionSlices,
buildSidebarSessionSliceParams,
fetchPrimaryProfileSessions,
fetchRegistrySessionRows,
@@ -17019,19 +17020,7 @@ async function interceptSessionRequestForRemote(request) {
fetchProfilesSessionSlice(messagingSp, remoteProfiles)
])
- return {
- recents: {
- sessions: rowsOf(recents),
- total: Number(recents?.total) || 0,
- profile_totals: recents?.profile_totals || {}
- },
- cron: { sessions: rowsOf(cron) },
- messaging: {
- sessions: rowsOf(messaging),
- total: Number(messaging?.total) || rowsOf(messaging).length
- },
- errors: []
- }
+ return assembleSidebarSessionSlices(recents, cron, messaging)
}
// Per-session read/mutation. Owner is in ?profile= (reads) or request.profile
diff --git a/apps/desktop/electron/profile-session-routing.test.ts b/apps/desktop/electron/profile-session-routing.test.ts
index 06ec8f158f1..a436c33c729 100644
--- a/apps/desktop/electron/profile-session-routing.test.ts
+++ b/apps/desktop/electron/profile-session-routing.test.ts
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict'
import { test } from 'vitest'
import {
+ assembleSidebarSessionSlices,
buildSidebarSessionSliceParams,
fetchPrimaryProfileSessions,
fetchRegistrySessionRows,
@@ -70,12 +71,44 @@ test('primary session reads use the profile-aware request path', async () => {
assert.equal(result, expected)
})
-test('primary session reads preserve the empty-list fallback', async () => {
- const result = await fetchPrimaryProfileSessions(new URLSearchParams({ profile: 'all' }), async () => {
+// A failed primary read is an empty page the renderer must NOT treat as the
+// profile's truth: without errors[] it replaced the sidebar with "No sessions"
+// and nothing said why (#67600). Report the failed scope the same way the
+// backend reports a failed profile scan.
+test('primary session reads report a failed read in errors', async () => {
+ const result = await fetchPrimaryProfileSessions(new URLSearchParams({ profile: 'default' }), async () => {
throw new Error('remote unavailable')
})
- assert.deepEqual(result, { sessions: [], total: 0, profile_totals: {} })
+ assert.deepEqual(result, {
+ sessions: [],
+ total: 0,
+ profile_totals: {},
+ errors: [{ profile: 'default', error: 'remote unavailable' }]
+ })
+})
+
+test('a failed unified primary read names the whole aggregate', async () => {
+ const result = await fetchPrimaryProfileSessions(new URLSearchParams({ limit: '20' }), async () => {
+ throw new Error('timed out')
+ })
+
+ assert.deepEqual(result.errors, [{ profile: 'all', error: 'timed out' }])
+})
+
+test('reassembled sidebar slices keep each slice errors', () => {
+ const failed = [{ profile: 'default', error: 'timed out' }]
+
+ const result = assembleSidebarSessionSlices(
+ { sessions: [], total: 0, profile_totals: {}, errors: failed },
+ { sessions: [{ id: 'cron-1' }], total: 1 },
+ { sessions: [], total: 0, errors: failed }
+ )
+
+ assert.deepEqual(result.recents.errors, failed)
+ assert.equal(result.cron.errors, undefined)
+ assert.deepEqual(result.messaging.errors, failed)
+ assert.deepEqual(result.cron.sessions, [{ id: 'cron-1' }])
})
test('remote session reads split oversized sidebar windows into API-safe pages', async () => {
diff --git a/apps/desktop/electron/profile-session-routing.ts b/apps/desktop/electron/profile-session-routing.ts
index 52677ba60c4..83d083601d8 100644
--- a/apps/desktop/electron/profile-session-routing.ts
+++ b/apps/desktop/electron/profile-session-routing.ts
@@ -164,15 +164,63 @@ export function buildSidebarSessionSliceParams(searchParams: URLSearchParams): S
}
}
-/** Fetch the primary backend's profile-aware session slice, falling back to an empty result when unavailable. */
+interface SessionScanError {
+ profile: string
+ error: string
+}
+
+function errorsOf(data: unknown): SessionScanError[] | undefined {
+ const errors = data && typeof data === 'object' ? (data as { errors?: unknown }).errors : undefined
+
+ return Array.isArray(errors) && errors.length ? (errors as SessionScanError[]) : undefined
+}
+
+/** Fetch the primary backend's profile-aware session slice. A failed read is
+ * still an empty page, but it carries `errors` naming the requested scope
+ * (`all` for the unified list), like the backend's failed profile scan, so the
+ * renderer keeps the rows it could not re-read instead of clearing them. */
export async function fetchPrimaryProfileSessions(
searchParams: URLSearchParams,
fetchJsonForProfile: FetchJsonForProfile
): Promise<ProfileSessionsResponse> {
try {
return (await fetchJsonForProfile(null, `/api/profiles/sessions?${searchParams}`)) as ProfileSessionsResponse
- } catch {
- return { sessions: [], total: 0, profile_totals: {} }
+ } catch (error) {
+ const profile = (searchParams.get('profile') || '').trim() || 'all'
+
+ return {
+ sessions: [],
+ total: 0,
+ profile_totals: {},
+ errors: [{ profile, error: error instanceof Error ? error.message : String(error) }]
+ }
+ }
+}
+
+/** Reassemble the batched sidebar response from its three per-slice reads,
+ * keeping each slice's `errors` so a failed scan is never read as an
+ * authoritative empty slice. */
+export function assembleSidebarSessionSlices(recents: unknown, cron: unknown, messaging: unknown) {
+ const slice = (data: unknown) => {
+ const errors = errorsOf(data)
+
+ return { sessions: rowsOf(data), ...(errors ? { errors } : {}) }
+ }
+
+ const recentsSlice = recents as Partial<ProfileSessionsResponse> | undefined
+
+ return {
+ recents: {
+ ...slice(recents),
+ total: Number(recentsSlice?.total) || 0,
+ profile_totals: recentsSlice?.profile_totals || {}
+ },
+ cron: slice(cron),
+ messaging: {
+ ...slice(messaging),
+ total: Number((messaging as Partial<SessionListResponse> | undefined)?.total) || rowsOf(messaging).length
+ },
+ errors: []
}
}
diff --git a/apps/desktop/src/store/session.test.ts b/apps/desktop/src/store/session.test.ts
index d6341c0dd56..5d76e6ff7c6 100644
--- a/apps/desktop/src/store/session.test.ts
+++ b/apps/desktop/src/store/session.test.ts
@@ -777,6 +777,14 @@ describe('carryForwardFailedProfileSessions', () => {
expect(carried.map(s => s.id)).toEqual(['idle'])
})
+
+ it('keeps every profile when the unified (all) read failed', () => {
+ const previous = [session({ id: 'home', profile: 'default' }), session({ id: 'job', profile: 'work' })]
+
+ expect(
+ carryForwardFailedProfileSessions(previous, [], [{ profile: 'all', error: 'timed out' }]).map(s => s.id)
+ ).toEqual(['home', 'job'])
+ })
})
describe('keepFailedProfileMeta', () => {
@@ -795,6 +803,12 @@ describe('keepFailedProfileMeta', () => {
work: { cost_usd: 2, tokens: 20 }
})
})
+
+ it('keeps all previous meta when the unified (all) read failed', () => {
+ const previous = { default: true, work: false }
+
+ expect(keepFailedProfileMeta(previous, {}, [{ profile: 'all' }])).toBe(previous)
+ })
})
describe('touchSessionActivity', () => {
diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.ts
index f066d514064..de6b5ab27ba 100644
--- a/apps/desktop/src/store/session.ts
+++ b/apps/desktop/src/store/session.ts
@@ -701,6 +701,10 @@ export function mergeSessionPage(
return interleaved
}
+// Error scope for a failed unified read (Electron's primary fan-out): every
+// profile in the aggregate went unread, not a profile literally named `all`.
+const ALL_PROFILES_SCAN = 'all'
+
function sidebarProfileKey(session: Pick<SessionInfo, 'profile'>): string {
return (session.profile ?? '').trim() || 'default'
}
@@ -735,7 +739,11 @@ export function carryForwardFailedProfileSessions(
for (const session of previous) {
// A hidden row (canonical Bot Chat) is LISTED-NEVER by design: the
// failed-slice carry must not ride it back into the sidebar (#113273).
- if (session.hidden || !failed.has(sidebarProfileKey(session)) || incomingIds.has(sessionListIdentity(session))) {
+ if (
+ session.hidden ||
+ !(failed.has(ALL_PROFILES_SCAN) || failed.has(sidebarProfileKey(session))) ||
+ incomingIds.has(sessionListIdentity(session))
+ ) {
continue
}
@@ -767,6 +775,10 @@ export function keepFailedProfileMeta<T>(
return incoming
}
+ if (errors.some(error => error.profile?.trim() === ALL_PROFILES_SCAN)) {
+ return previous
+ }
+
const next = { ...incoming }
for (const error of errors) {