The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): route hidden Bot Chat RPCs to the owning profile backend (4001 session-not-found) (#92928)
Teknium2c244f0751b2
diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 9495cc969c4..4f4d7b83607 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -755,6 +755,18 @@ export const host = {if (ownerRoute) {setSessionOwnerHint(storedSessionId, ownerRoute)+ } else if (profile) {+ // Local plugin-owned opens (Bot Mode without a cross-connection route)+ // still carry an explicit owning profile. Record it: hidden sessions+ // (canonical Bot Chats) have no sidebar row, so this hint is the only+ // durable owner record the session-RPC router can consult — without it+ // a later prompt.submit resolves to the ACTIVE profile's backend and+ // 4001s while the bot's own backend is healthy.+ const connectionId = activeGatewayConnectionId()++ if (connectionId) {+ setSessionOwnerHint(storedSessionId, { connectionId, mode: 'local', profile: targetProfile })+ }}// Bounded to 2 attempts (never more): a cold profile backend can lose thediff --git a/apps/desktop/src/sdk/profile-routing.test.ts b/apps/desktop/src/sdk/profile-routing.test.tsindex e70116947f6..78dae20be49 100644--- a/apps/desktop/src/sdk/profile-routing.test.ts+++ b/apps/desktop/src/sdk/profile-routing.test.ts@@ -82,6 +82,7 @@ vi.mock('@/store/gateway', async () => {return {$gateway: atom(null),+ activeGatewayConnectionId: vi.fn(() => 'local'),ensureGatewayForAgent: vi.fn(),openGatewayForAgent: vi.fn(),openGatewayForProfile: vi.fn(),diff --git a/apps/desktop/src/store/session.test.ts b/apps/desktop/src/store/session.test.tsindex f4e0e7487b1..a2bcb462288 100644--- a/apps/desktop/src/store/session.test.ts+++ b/apps/desktop/src/store/session.test.ts@@ -918,6 +918,32 @@ describe('rememberedSessionProfile', () => {expect(rememberedSessionProfile([], 'uncached', 'research')).toBe('research')})+ it('consults the owner hint for a hidden session absent from the list (Bot Chat 4001 class)', () => {+ // Bot Mode's canonical chats are born hidden: no sidebar row ever exists,+ // so without the hint the router would fall back to the ACTIVE profile and+ // land prompt.submit on a backend that never owned the session.+ setSessionOwnerHint('hidden-bot-chat', { connectionId: 'local', mode: 'local', profile: 'developer' })++ expect(rememberedSessionProfile([], 'hidden-bot-chat', 'default')).toBe('developer')+ })++ it('prefers the routed targetProfile over the route profile in the hint fallback', () => {+ setSessionOwnerHint('hidden-remote-chat', {+ connectionId: 'ssh-1',+ profile: 'default',+ targetProfile: 'clippy'+ })++ expect(rememberedSessionProfile([], 'hidden-remote-chat', 'default')).toBe('clippy')+ })++ it('still prefers a real session row over the hint', () => {+ setSessionOwnerHint('rowed-session', { connectionId: 'local', profile: 'wrong-hint' })+ const sessions = [session({ id: 'rowed-session', profile: 'right-owner' })]++ expect(rememberedSessionProfile(sessions, 'rowed-session', 'default')).toBe('right-owner')+ })+it('normalizes a blank active profile to default', () => {expect(rememberedSessionProfile([], null, '')).toBe('default')expect(rememberedSessionProfile([], null, null)).toBe('default')diff --git a/apps/desktop/src/store/session.ts b/apps/desktop/src/store/session.tsindex 9539761593a..f3c555aa613 100644--- a/apps/desktop/src/store/session.ts+++ b/apps/desktop/src/store/session.ts@@ -135,6 +135,21 @@ export function rememberedSessionProfile(if (owner) {return owner}++ // Hidden / plugin-owned sessions (Bot Mode's canonical "Bot Chat" rows are+ // born hidden) never appear in the sidebar list, so the row lookup above+ // misses for them whenever the aggregator page replaced the in-memory row.+ // Falling straight through to the ACTIVE profile routed their session RPCs+ // at a backend that never owned the session — prompt.submit answered 4001+ // "session not found" while the bot's own backend sat healthy. The open+ // path records an owner hint for exactly this; honor it before falling+ // back to the active profile.+ const hint = getSessionOwnerHint(sessionId)+ const hinted = (hint?.targetProfile ?? hint?.profile)?.trim()++ if (hinted) {+ return hinted+ }}return (activeProfile ?? '').trim() || 'default'