From a0977b0a3c25af15e158cb5401cd36063009fc29 Mon Sep 17 00:00:00 2001 From: kshitijk4poor <82637225+kshitijk4poor@users.noreply.github.com> Date: Fri, 11 Sep 2026 11:49:46 +0530 Subject: [PATCH] fix(desktop): coalesce tail spellings against backends without the profile field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A backend that predates the `profile` response field left the owner key's profile empty, while the resume path records the same session under {connectionId, profile: 'default'}. Two entries per backend meant the owner-hint lookup only ever saw the resume entry and the no-hint fallback returned nothing — "Show earlier" stayed hidden for exactly the mixed Desktop/backend versions the PR body says remain readable. An absent field now falls back to the ambient request profile ('default' when none is active): that IS the profile an untagged read lands on. A `null` field (custom HERMES_HOME) still stays distinct from 'default'. --- .../src/api/session-transcript-paging.test.ts | 17 +++++++++++++++++ apps/desktop/src/api/sessions.ts | 7 ++++++- 2 files changed, 23 insertions(+), 1 deletion(-) 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) {