The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): trim #120899 salvage — owner route only, one window per chat (#120213, salvage #120899)
teknium13361ac4a8257
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex f5eb877b78b..d26ecf60120 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -13688,8 +13688,7 @@ function spawnSecondaryWindow({// Open (or focus) a standalone window for a single chat session.function createSessionWindow(sessionId, { connectionId = null, profile = null, watch = false } = {}) {- const key = JSON.stringify([connectionId, profile, sessionId])- return sessionWindows.openOrFocus(key, () => spawnSecondaryWindow({ connectionId, sessionId, profile, watch }))+ return sessionWindows.openOrFocus(sessionId, () => spawnSecondaryWindow({ connectionId, sessionId, profile, watch }))}// Popped-out in-app Browser: same webview + address bar as a docked Browserdiff --git a/apps/desktop/src/store/windows.test.ts b/apps/desktop/src/store/windows.test.tsindex 97844e5f90b..4457419b3fb 100644--- a/apps/desktop/src/store/windows.test.ts+++ b/apps/desktop/src/store/windows.test.ts@@ -1,7 +1,7 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'import { $activeGatewayProfile } from './profile'-import { $sessions, setSessionOwnerHint } from './session'+import { $sessions } from './session'import {isPeerInstanceWindow,isProfilePinnedWindow,@@ -62,23 +62,6 @@ describe('isProfilePinnedWindow', () => {})describe('openSessionInNewWindow', () => {- it('carries an exact session or parent route through the window bridge independently of the foreground', async () => {- const open = vi.fn().mockResolvedValue({ ok: true })- installBridge(open)- $activeGatewayProfile.set('unrelated')- $sessions.set([{ id: 'remote-session', profile: 'writer', connection_id: 'remote-a' } as never])- setSessionOwnerHint('parent-session', { connectionId: 'remote-b', profile: 'research' })-- await openSessionInNewWindow('remote-session')- await openSessionInNewWindow('unlisted-child', { watch: true, parentSessionId: 'parent-session' })- await openSessionInNewWindow('remote-session')-- expect(open.mock.calls).toEqual([- ['remote-session', { connectionId: 'remote-a', profile: 'writer', watch: undefined }],- ['unlisted-child', { connectionId: 'remote-b', profile: 'research', watch: true }],- ['remote-session', { connectionId: 'remote-a', profile: 'writer', watch: undefined }]- ])- }, 60_000)it('no-ops without a session id', async () => {const open = vi.fn().mockResolvedValue({ ok: true })installBridge(open)@@ -97,19 +80,20 @@ describe('openSessionInNewWindow', () => {expect(notifyError).not.toHaveBeenCalled()})- it('carries the owning profile: stamped row wins, an unstamped child inherits the viewed profile (#82768)', async () => {+ it('carries the owner route: tagged row wins, an unlisted child rides its parent (#82768, #120213)', async () => {const open = vi.fn().mockResolvedValue({ ok: true })installBridge(open)$activeGatewayProfile.set('work')- $sessions.set([{ id: 's1', profile: 'research' } as never])+ $sessions.set([{ id: 's1', profile: 'research', connection_id: 'remote-a' } as never])await openSessionInNewWindow('s1')await openSessionInNewWindow('child-not-listed-yet', { watch: true, parentSessionId: 's1' })- expect(open).toHaveBeenCalledWith('s1', { profile: 'research', connectionId: null })- expect(open).toHaveBeenCalledWith('child-not-listed-yet', { profile: 'research', connectionId: null, watch: true })+ expect(open).toHaveBeenCalledWith('s1', { profile: 'research', connectionId: 'remote-a', watch: undefined })+ expect(open).toHaveBeenCalledWith('child-not-listed-yet', { profile: 'research', connectionId: 'remote-a', watch: true })expect(notifyError).not.toHaveBeenCalled()- })+ // The owner resolver's lazy import is the heavy session-actions module.+ }, 60_000)it('notifies on an ok:false result', async () => {installBridge(vi.fn().mockResolvedValue({ ok: false, error: 'invalid-session-id' }))diff --git a/apps/desktop/src/store/windows.ts b/apps/desktop/src/store/windows.tsindex 322a2d70fda..8c73b456245 100644--- a/apps/desktop/src/store/windows.ts+++ b/apps/desktop/src/store/windows.ts@@ -212,8 +212,14 @@ async function runWindowOpen(call: () => Promise<WindowOpenResult>, failMessage:// Open (or focus) a standalone OS window for a single chat session. No-ops// gracefully outside Electron so callers can wire it unconditionally.// `watch: true` opens a spectator window (lazy resume, live-mirror stream).-// Carry the exact owner route into the new renderer. Unlisted children use-// their parent surface to resolve the same backend.+// The window is a full renderer that adopts the PRIMARY backend unless told+// otherwise, so the session's exact owner route (connectionId + profile) rides+// along: a bare profile is not enough on a remote registry — the new window+// would dial the local pool and 4007 on the remote-owned id (#120213). An+// unlisted subagent child is routed via its parent surface+// (`parentSessionId`), because a child lives on the backend that spawned it;+// with no owner anywhere it inherits the profile the user is looking at+// (#82768, #61286).export async function openSessionInNewWindow(sessionId: string,opts?: { watch?: boolean; parentSessionId?: null | string }@@ -224,23 +230,15 @@ export async function openSessionInNewWindow(// Lazy imports: `./profile` subscribes to the API client on load, so a// static import here would drag it into every page that opens windows.- const [- { $activeGatewayProfile, normalizeProfileKey },- { resolveSessionOwner },- { assertSessionOwnerResolved },- { isSessionOwnerRoute }- ] = await Promise.all([- import('./profile'),- import('@/app/session/hooks/use-session-actions/utils'),- import('./session-owner-resolution'),- import('./session-request-router')- ])+ const [{ $activeGatewayProfile, normalizeProfileKey }, { resolveSessionOwner }, { isSessionOwnerRoute }] =+ await Promise.all([+ import('./profile'),+ import('@/app/session/hooks/use-session-actions/utils'),+ import('./session-request-router')+ ])await runWindowOpen(async () => {- // Unlisted children live on the same backend as the parent surface.- const routingId = opts?.parentSessionId || sessionId- const owner = await resolveSessionOwner(routingId)- assertSessionOwnerResolved(owner, { method: 'openSessionWindow', sessionId: routingId })+ const owner = await resolveSessionOwner(opts?.parentSessionId || sessionId)const profile = normalizeProfileKey(isSessionOwnerRoute(owner) ? owner.profile : (owner ?? $activeGatewayProfile.get())