diff --git a/apps/desktop/src/api/session-transcript-paging.test.ts b/apps/desktop/src/api/session-transcript-paging.test.ts index e3bbbf2c30..2de1e9ed2c 100644 --- a/apps/desktop/src/api/session-transcript-paging.test.ts +++ b/apps/desktop/src/api/session-transcript-paging.test.ts @@ -82,6 +82,23 @@ describe('session transcript pagination ownership', () => { } ) + it('coalesces spellings against a backend that predates the profile field', async () => { + setApiRequestConnection(null) + const owner = { connectionId: 'local', profile: 'default' } + const tail = Array.from({ length: LATEST_SESSION_MESSAGES_LIMIT }, (_, index) => row(index + 1)) + const { profile: _omitted, ...legacyPage } = page(tail) + api.mockResolvedValue(legacyPage) + + for (const scope of [owner, 'default', undefined]) { + await getLatestSessionMessages('stored-session', scope) + } + + // The legacy response cannot name its profile; the ambient profile stands in. + expect(Object.keys($transcriptTailBySessionId.get())).toHaveLength(1) + expect(transcriptBackfillAvailable('stored-session', owner)).toBe(true) + expect(transcriptBackfillAvailable('stored-session')).toBe(true) + }) + it('preserves legacy named-profile routing while the foreground is local', async () => { setApiRequestConnection(null) const profile = 'remote-alias' diff --git a/apps/desktop/src/api/sessions.ts b/apps/desktop/src/api/sessions.ts index 7387bb2734..339449db11 100644 --- a/apps/desktop/src/api/sessions.ts +++ b/apps/desktop/src/api/sessions.ts @@ -15,6 +15,7 @@ import { capabilityScoped, connectionScoped, getApiRequestConnection, + getApiRequestProfile, hermesApi, type ProfileScope, profileScoped @@ -479,7 +480,11 @@ export function getLatestSessionMessages( // the next older page starts, so "Show earlier" can backfill over REST // (app/chat/transcript-backfill). Keyed under both the requested id and // the resolved id — callers hold either. - const resolvedOwnerScope = { ...ownerScope, profile: ownerScope.profile || page.profile || undefined } + // A backend that predates the `profile` field cannot name itself; an + // untagged read there lands on the ambient profile (`'default'` when + // none is active). `null` is a custom HERMES_HOME and stays distinct. + const servedProfile = page.profile === undefined ? getApiRequestProfile() || 'default' : page.profile + const resolvedOwnerScope = { ...ownerScope, profile: ownerScope.profile || servedProfile } recordTranscriptTail(id, page, tailScope, resolvedOwnerScope) if (page.session_id && page.session_id !== id) {