The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): keep delegate children out of sessions
worlldzb9cb5a10bcaf
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/resolve-stored-session.test.ts b/apps/desktop/src/app/session/hooks/use-session-actions/resolve-stored-session.test.tsindex 0ad61c36569..250ab7a5665 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/resolve-stored-session.test.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/resolve-stored-session.test.ts@@ -147,6 +147,15 @@ describe('resolveStoredSession profile ownership', () => {expect($unlistedSessionOwnerRows.get().find(s => s.id === 's1')?.hidden).toBe(true)})+ it('returns an internal delegate child without promoting it into regular sessions', async () => {+ mockGetSession.mockResolvedValueOnce(session({ id: 'child', is_internal_child: true }))++ const resolved = await resolveStoredSession('child')++ expect(resolved).toMatchObject({ id: 'child', is_internal_child: true, profile: 'meta' })+ expect($sessions.get()).toEqual([])+ })+it('probed desktop profile overrides a remote backend answering as its own "default"', async () => {// Per-profile remote override: Electron strips the desktop alias before// forwarding, so the standalone backend stamps its backend-local root.diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts b/apps/desktop/src/app/session/hooks/use-session-actions/utils.tsindex 9b2c58a17bf..a3785ca62b5 100644--- a/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts+++ b/apps/desktop/src/app/session/hooks/use-session-actions/utils.ts@@ -1973,6 +1973,14 @@ function upsertResolvedSession(storedSessionId: string,tombstoneGenerationsAtRequestStart: SessionTombstoneGenerationSnapshot) {+ // Exact-id lookup intentionally resolves internal delegate children so a+ // watch tile can open them. They are not ordinary user conversations,+ // though, and the authoritative list endpoints omit them; caching one here+ // would bypass that boundary and leak it into the Sessions sidebar.+ if (session.is_internal_child) {+ return+ }+const removed = $removedSessionIds.get()const identities = [storedSessionId, session.id, session._lineage_root_id]diff --git a/apps/desktop/src/store/session.test.ts b/apps/desktop/src/store/session.test.tsindex 4ff61f34649..6e20ec8e30e 100644--- a/apps/desktop/src/store/session.test.ts+++ b/apps/desktop/src/store/session.test.ts@@ -537,6 +537,17 @@ describe('mergeSessionPage', () => {expect(merged.find(s => s.id === 'a')?.message_count).toBe(2)})+ it('does not preserve an omitted internal delegate child even when selected or working', () => {+ const previous = [+ session({ id: 'delegate-child', is_internal_child: true, parent_session_id: 'parent' }),+ session({ id: 'visible-branch', parent_session_id: 'parent' })+ ]++ const merged = mergeSessionPage(previous, [], ['delegate-child', 'visible-branch'])++ expect(merged.map(s => s.id)).toEqual(['visible-branch'])+ })+it('does not duplicate a working session the server already returned', () => {const previous = [session({ id: 'b' }), session({ id: 'a' })]const incoming = [session({ id: 'b', message_count: 4 }), session({ id: 'a' })]diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.tsindex 9291146d194..2fc134d60fd 100644--- a/apps/desktop/src/store/session.ts+++ b/apps/desktop/src/store/session.ts@@ -659,26 +659,30 @@ export function mergeSessionPage(// root so a mid-turn refresh can't drop a touchSessionActivity bump.const prevByLineage = new Map(previous.map(session => [lineageIdentity(session), session]))- const merged = incoming.map(session => {- const prev = prevById.get(identity(session)) ?? prevByLineage.get(lineageIdentity(session))- // User-send stamps last_active before the DB flushes the user row- // (last_active = MAX(messages.timestamp)). Keep the fresher of the two.- const last_active = Math.max(prev?.last_active ?? 0, session.last_active ?? 0)- const title = session.title?.trim() ? session.title : prev?.title?.trim() ? prev.title : session.title- // Carry the owning connection onto a row that arrives untagged. The- // primary aggregate serves a `local` registry source's rows as plain- // local rows (the unified-list splice tags only NON-local sources), so- // the first refresh after a routed create used to replace the optimistic- // row's exact owner (connection_id + profile) with a bare profile — after- // which only the transient owner hint knew which socket held the runtime.- // A refresh is new information layered over what we know, not a clobber;- // the tag is kept only while the row still names the same profile.- const connection_id = carriedConnectionId(prev, session)-- return last_active === session.last_active && title === session.title && connection_id === session.connection_id- ? session- : { ...session, last_active, title, ...(connection_id ? { connection_id } : {}) }- })++ const merged = incoming+ .filter(session => !session.is_internal_child)+ .map(session => {++ const prev = prevById.get(identity(session)) ?? prevByLineage.get(lineageIdentity(session))+ // User-send stamps last_active before the DB flushes the user row+ // (last_active = MAX(messages.timestamp)). Keep the fresher of the two.+ const last_active = Math.max(prev?.last_active ?? 0, session.last_active ?? 0)+ const title = session.title?.trim() ? session.title : prev?.title?.trim() ? prev.title : session.title+ // Carry the owning connection onto a row that arrives untagged. The+ // primary aggregate serves a `local` registry source's rows as plain+ // local rows (the unified-list splice tags only NON-local sources), so+ // the first refresh after a routed create used to replace the optimistic+ // row's exact owner (connection_id + profile) with a bare profile — after+ // which only the transient owner hint knew which socket held the runtime.+ // A refresh is new information layered over what we know, not a clobber;+ // the tag is kept only while the row still names the same profile.+ const connection_id = carriedConnectionId(prev, session)++ return last_active === session.last_active && title === session.title && connection_id === session.connection_id+ ? session+ : { ...session, last_active, title, ...(connection_id ? { connection_id } : {}) }+ })if (keep.size === 0) {return merged@@ -732,6 +736,9 @@ export function mergeSessionPage(const survivors = previous.filter(session =>+ // An internal delegate child is never listed; the authoritative page+ // already omits it, so the keep-list must not resurrect it (#94124).+ !session.is_internal_child &&// The keep-list answers "live, not listed yet" — a hidden row (canonical// Bot Chat, room plumbing) is LISTED-NEVER by design, so a live turn or// open tab must not resurrect it into the sidebar (#113273).diff --git a/apps/desktop/src/types/hermes.ts b/apps/desktop/src/types/hermes.tsindex 2b648a98afc..d8727a9d41e 100644--- a/apps/desktop/src/types/hermes.ts+++ b/apps/desktop/src/types/hermes.ts@@ -596,6 +596,10 @@ export interface SessionInfo {_reset_from?: null | string/** Parent of a genuine /branch fork. The sidebar nests only these. */_branched_from?: null | string+ /** True for an internal delegate_task child. Exact-id endpoints return these+ * rows for direct watch/resume, but ordinary session lists must not surface+ * them. Undefined against backends predating the projection. */+ is_internal_child?: boolean/** Durable server-side pin flag (`sessions.pinned`). The list endpoints* back-fill pinned conversations past their LIMIT, so a pinned row is* always present in a page — which makes this authoritative for thediff --git a/gateway/platforms/api_server.py b/gateway/platforms/api_server.pyindex 6195403c905..0031de039f5 100644--- a/gateway/platforms/api_server.py+++ b/gateway/platforms/api_server.py@@ -3023,6 +3023,23 @@ class APIServerAdapter(OpenAICompatRoutesMixin, BasePlatformAdapter):# Full system prompts / model_config never cross the client API; only their presence.payload["has_system_prompt"] = bool(session.get("system_prompt"))payload["has_model_config"] = bool(session.get("model_config"))+ raw_model_config = session.get("model_config")+ try:+ model_config = (+ json.loads(raw_model_config)+ if isinstance(raw_model_config, str)+ else raw_model_config+ )+ except (TypeError, json.JSONDecodeError):+ model_config = None+ # Exact-id consumers may inspect/resume delegate children even though+ # list endpoints intentionally omit them. Project only the provenance+ # bit the client needs so it cannot accidentally promote such a row+ # into an ordinary session list; never expose the model snapshot.+ payload["is_internal_child"] = bool(+ isinstance(model_config, dict)+ and model_config.get("_delegate_from") is not None+ )return payload@staticmethoddiff --git a/tests/gateway/test_session_api.py b/tests/gateway/test_session_api.pyindex 54313492174..675ec6a8891 100644--- a/tests/gateway/test_session_api.py+++ b/tests/gateway/test_session_api.py@@ -79,6 +79,39 @@ async def test_capabilities_advertises_session_control_surface(adapter):}+async def test_get_session_projects_delegate_provenance_without_model_config(+ adapter, session_db+):+ session_db.create_session("parent", "desktop")+ child_id = session_db.create_session(+ "delegate-child",+ "desktop",+ parent_session_id="parent",+ model_config={"_delegate_from": "parent", "api_key": "must-not-leak"},+ )+ branch_id = session_db.create_session(+ "visible-branch",+ "desktop",+ parent_session_id="parent",+ model_config={"_branched_from": "parent"},+ )++ app = _create_session_app(adapter)+ async with TestClient(TestServer(app)) as cli:+ child_resp = await cli.get(f"/api/sessions/{child_id}")+ branch_resp = await cli.get(f"/api/sessions/{branch_id}")+ assert child_resp.status == 200+ assert branch_resp.status == 200+ child = (await child_resp.json())["session"]+ branch = (await branch_resp.json())["session"]++ assert child["is_internal_child"] is True+ assert branch["is_internal_child"] is False+ assert "model_config" not in child+ assert "must-not-leak" not in str(child)++@pytest.mark.asyncioasync def test_session_messages_default_to_latest_bounded_page(adapter, session_db):session_id = session_db.create_session("bounded-messages", "api_server")