fix(desktop): coalesce tail spellings against backends without the profile field

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'.
This commit is contained in:
kshitijk4poor
2026-09-11 11:49:46 +05:30
committed by kshitij
parent 1affcb9386
commit a0977b0a3c
2 changed files with 23 additions and 1 deletions
@@ -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'
+6 -1
View File
@@ -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) {