The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): refuse remote-only profile spawns when the connection id is missing
brooklyn!76460be82dba
diff --git a/apps/desktop/electron/connection-registry.test.ts b/apps/desktop/electron/connection-registry.test.tsindex 2c37e4179f6..705ce0a0aae 100644--- a/apps/desktop/electron/connection-registry.test.ts+++ b/apps/desktop/electron/connection-registry.test.ts@@ -28,6 +28,7 @@ import {reconcileAppliedGlobalConnection,reconcileRegistryDrift,REGISTRY_VERSION,+ registryDialConnectionId,registrySourceOwnsPrimaryBackend,rememberSshEnumeration,removeConnection,@@ -744,6 +745,49 @@ test('registry local route: per-profile override wins when global remote is alsoassert.deepEqual(route, { delegate: true, poolKey: 'research' })})+test('registry local route: a concrete remote-only profile is refused on the forced-local branch, including default', () => {+ // globalRemote still force-locals a profile that exists on this machine+ // (This device must not dial the remote). A profile that exists only on the+ // remote must not spawn a local child — including default, which the+ // ordinary existence guard exempts and would otherwise start silently.+ const named = resolveRegistryLocalRoute('inbox', { globalRemote: true, localProfileExists: false })+ const fallback = resolveRegistryLocalRoute('default', { globalRemote: true, localProfileExists: false })++ assert.match(String(named.refuse ?? ''), /Profile "inbox" no longer exists/)+ assert.equal(named.delegate, false)+ assert.match(String(fallback.refuse ?? ''), /Profile "default" no longer exists/)+ assert.equal(fallback.delegate, false)++ const present = resolveRegistryLocalRoute('research', { globalRemote: true, localProfileExists: true })++ assert.equal(present.refuse, undefined)+ assert.equal(present.delegate, false)+ assert.equal(present.poolKey, 'conn:local::research')++ // The override remains the authoritative route even when the profile is+ // absent locally. Unprofiled enumeration is not a concrete dial.+ assert.deepEqual(+ resolveRegistryLocalRoute('research', {+ globalRemote: true,+ localProfileExists: false,+ profileRemoteOverride: true+ }),+ { delegate: true, poolKey: 'research' }+ )+ assert.equal(resolveRegistryLocalRoute(null, { globalRemote: true, localProfileExists: false }).refuse, undefined)+ assert.equal(resolveRegistryLocalRoute('', { globalRemote: true, localProfileExists: false }).refuse, undefined)+})++test('registry dial: an empty connection id is not registry.primary', () => {+ assert.throws(() => registryDialConnectionId('', 'ssh-other-host'), /No connection with id/)+ assert.throws(() => registryDialConnectionId(' ', 'ssh-other-host'), /No connection with id/)+ assert.throws(() => registryDialConnectionId(null, 'ssh-other-host'), /No connection with id/)+ assert.throws(() => registryDialConnectionId(undefined, 'homelab'), /No connection with id/)+ assert.equal(registryDialConnectionId('local', 'ssh-other-host'), 'local')+ assert.equal(registryDialConnectionId('homelab', 'ssh-other-host'), 'homelab')+ assert.equal(registryDialConnectionId('ssh-other-host', 'ssh-other-host'), 'ssh-other-host')+})+// --- shouldDeferLocalEnumeration (roster's connect-on-demand for 'local') ---test('local enumeration: delegate route (local-primary desktop) always enumerates', () => {diff --git a/apps/desktop/electron/connection-registry.ts b/apps/desktop/electron/connection-registry.tsindex 69b4a48ef7d..f3713570f00 100644--- a/apps/desktop/electron/connection-registry.ts+++ b/apps/desktop/electron/connection-registry.ts@@ -220,6 +220,10 @@ export interface RegistryLocalRoute {delegate: boolean/** Pool key for the forced-local child when not delegating. */poolKey: string+ /** Set when a concrete remote-only profile must not spawn a local child.+ * Includes `default`: the ordinary existence guard exempts it, so a+ * forced-local default spawn would otherwise succeed with no error. */+ refuse?: string}export interface ResolvedConnectionSshDescriptor {@@ -522,13 +526,17 @@ function normalizedSshTarget(route: { host?: unknown; port?: unknown; user?: unk* the BARE profile key by design, and that slot may already hold the v1* route's REMOTE descriptor — so the forced-local child pools under the* `conn:local::<profile>` form instead (colons are invalid in profile names,- * so it cannot collide).+ * so it cannot collide). A concrete profile that does not exist on this+ * machine, including default, is refused instead of spawned. A per-profile+ * remote override still delegates to the legacy profile route.*/export function resolveRegistryLocalRoute(profile: null | string | undefined,- opts: { globalRemote?: boolean; profileRemoteOverride?: boolean } = {}+ opts: { globalRemote?: boolean; localProfileExists?: boolean; profileRemoteOverride?: boolean } = {}): RegistryLocalRoute {- const profileKey = String(profile ?? '').trim() || 'default'+ const raw = String(profile ?? '').trim()+ const profileKey = raw || 'default'+ const concrete = raw.length > 0// A per-profile SSH/remote override is an explicit per-profile routing// decision: the override owns this profile's backend, so the 'local' entry@@ -541,12 +549,40 @@ export function resolveRegistryLocalRoute(}if (opts.globalRemote) {- return { delegate: false, poolKey: `${backendScopePrefix(LOCAL_CONNECTION_ID)}${profileKey}` }+ const poolKey = `${backendScopePrefix(LOCAL_CONNECTION_ID)}${profileKey}`++ // A concrete profile that does not exist on this machine is remote-only.+ // Spawning it locally is the #90477 loop (and, for default, a silent+ // success — the ordinary guard exempts default). Refuse instead. An+ // unprofiled call is enumeration, not a dial, and a profile that exists+ // locally still force-locals so "This device" does not dial the remote.+ if (concrete && opts.localProfileExists === false) {+ return { delegate: false, poolKey, refuse: `Profile "${profileKey}" no longer exists.` }+ }++ return { delegate: false, poolKey }}return { delegate: true, poolKey: profileKey }}+/**+ * Connection id for a registry dial. A missing id is not `registry.primary`:+ * substituting primary opens another SSH host when a scoped caller drops the+ * id (#90477). `primary` is accepted so that substitution stays visible at the+ * call site and cannot sneak back in.+ */+export function registryDialConnectionId(connectionId: unknown, primary: unknown): string {+ const id = String(connectionId ?? '').trim()++ if (!id) {+ void primary+ throw new Error('No connection with id "".')+ }++ return id+}+/*** Whether the roster enumeration should SKIP the registry's local entry as* connect-on-demand. True when the local source is the forced-local routediff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.tsindex e792b5ffb9a..7804fabd89d 100644--- a/apps/desktop/electron/main.ts+++ b/apps/desktop/electron/main.ts@@ -166,6 +166,7 @@ import {parseBackendScopeKey,reconcileAppliedGlobalConnection,reconcileRegistryDrift,+ registryDialConnectionId,rememberSshEnumeration,removeConnection,type ResolvedConnectionDescriptor,@@ -10565,7 +10566,7 @@ async function ensureRegistryBackend(const spawnPriority = spawnPriorityFrom(opts.spawnPriority)const passive = Boolean(opts.passive)const registry = readDesktopConnectionsRegistry()- const id = String(connectionId || '').trim() || registry.primary+ const id = registryDialConnectionId(connectionId, registry.primary)const source = registry.connections.find(c => c.id === id)if (!source) {@@ -10659,11 +10660,24 @@ async function ensureRegistryBackend(// can't collide with the v1 remote descriptor cached at the bare key.profileDeletionGate.assertCanStart(profileKey)- const localRoute = resolveRegistryLocalRoute(profileKey, {+ const rawProfile = String(profile ?? '').trim()++ const localProfileExists = rawProfile+ ? directoryExists(path.join(HERMES_HOME, 'profiles', rawProfile.toLowerCase()))+ : undefined++ // Pass the raw profile, not profileKey: profileKey collapses null to+ // 'default' and would refuse an unprofiled enumeration as a concrete dial.+ const localRoute = resolveRegistryLocalRoute(rawProfile || null, {globalRemote: globalRemoteActive(),- profileRemoteOverride: Boolean(profileHasRemoteOverride(profileKey))+ profileRemoteOverride: Boolean(profileHasRemoteOverride(profileKey)),+ ...(rawProfile ? { localProfileExists } : {})})+ if (localRoute.refuse) {+ throw new Error(localRoute.refuse)+ }+if (localRoute.delegate) {return ensureBackend(profile, { passive, spawnPriority })}@@ -11662,8 +11676,11 @@ async function spawnPoolBackend(// here, and logging "Starting" first left an orphaned line with no READY// and no exit — the exact undiagnosable burst signature in remote-gateway// user bundles (Aug 2026, Dash's report).- assertLocalProfileCanStart(profile, profileDeletionGate, key =>- directoryExists(path.join(HERMES_HOME, 'profiles', key))+ assertLocalProfileCanStart(+ profile,+ profileDeletionGate,+ key => directoryExists(path.join(HERMES_HOME, 'profiles', key)),+ { allowImplicitDefault: !opts.forceLocal })rememberLog(`Starting Hermes backend for profile "${profile}" via ${backend.label}`)@@ -14557,14 +14574,16 @@ async function connectDesktopProfileRoute(}// Registry-scoped variant: resolve a backend for (connectionId, profile).-// connectionId '' / 'local' / the registry primary all behave sensibly; the-// local kind delegates to ensureBackend when the v1 route is local, and-// forces a genuinely-local child when the v1 global mode is remote (the-// registry 'local' entry always means this machine).+// An empty connection id is not registry.primary — that substitution dials+// another SSH host when a scoped caller drops the id. 'local' and an explicit+// primary id still resolve to those sources. The local kind delegates to+// ensureBackend when the v1 route is local, and forces a genuinely-local+// child when the v1 global mode is remote (the registry 'local' entry always+// means this machine) unless the profile is remote-only.ipcMain.handle('hermes:connection:for', async (_event, payload) => {const { connectionId, profile, priority } = payload && typeof payload === 'object' ? (payload as any) : ({} as any)const registry = readDesktopConnectionsRegistry()- const id = String(connectionId || '').trim() || registry.primary+ const id = registryDialConnectionId(connectionId, registry.primary)const spawnPriority = spawnPriorityFrom(priority)return connectDesktopProfileRoute(diff --git a/apps/desktop/electron/profile-delete-routing.test.ts b/apps/desktop/electron/profile-delete-routing.test.tsindex 2ef4720e318..1b756788f34 100644--- a/apps/desktop/electron/profile-delete-routing.test.ts+++ b/apps/desktop/electron/profile-delete-routing.test.ts@@ -140,6 +140,16 @@ test('assertLocalProfileCanStart rejects a delayed retry after the profile direcassert.doesNotThrow(() => assertLocalProfileCanStart('selena', gate, profile => profile === 'selena'))})+test('assertLocalProfileCanStart does not exempt default when a forced-local spawn asks', () => {+ const gate = new ProfileDeletionGate()++ assert.throws(+ () => assertLocalProfileCanStart('default', gate, () => false, { allowImplicitDefault: false }),+ /Profile "default" no longer exists/+ )+ assert.doesNotThrow(() => assertLocalProfileCanStart('default', gate, () => true, { allowImplicitDefault: false }))+})+test('localProfilePoolKeys returns every local process scope for one profile', () => {assert.deepEqual(localProfilePoolKeys('Selena'), ['selena', 'conn:local::selena'])assert.deepEqual(localProfilePoolKeys(''), [])diff --git a/apps/desktop/electron/profile-delete-routing.ts b/apps/desktop/electron/profile-delete-routing.tsindex 39bada976a7..9b37e110acc 100644--- a/apps/desktop/electron/profile-delete-routing.ts+++ b/apps/desktop/electron/profile-delete-routing.ts@@ -184,7 +184,8 @@ export class ProfileDeletionGate {export function assertLocalProfileCanStart(profile: unknown,gate: ProfileDeletionGate,- profileDirectoryExists: (profile: string) => boolean+ profileDirectoryExists: (profile: string) => boolean,+ opts: { allowImplicitDefault?: boolean } = {}): void {const key = String(profile ?? '').trim()@@ -192,7 +193,12 @@ export function assertLocalProfileCanStart(gate.assertCanStart(key)- if (key && key !== 'default' && !profileDirectoryExists(key)) {+ // `default` is `$HERMES_HOME`, not `profiles/default`, so the ordinary local+ // start exempts it. A forced-local spawn must not: that exemption is how a+ // remote-only default starts a local agent with no error (#90477).+ const implicitDefault = opts.allowImplicitDefault !== false && key === 'default'++ if (key && !implicitDefault && !profileDirectoryExists(key)) {throw new Error(`Profile "${key}" no longer exists.`)}}diff --git a/apps/desktop/src/sdk/index.ts b/apps/desktop/src/sdk/index.tsindex 64c5e7572f5..297be359cc1 100644--- a/apps/desktop/src/sdk/index.ts+++ b/apps/desktop/src/sdk/index.ts@@ -960,12 +960,16 @@ export const host = {// path below still keys off the explicit cross-connection route, so a plain// local open dials exactly as before (openGatewayForProfile), never the// registry-secondary path.- const localConnectionId = activeGatewayConnectionId()+ const liveConnection = $connection.get()+ const liveRemote = liveConnection?.mode === 'remote'+ const liveConnectionId = String(liveConnection?.connectionId ?? '').trim()+ const ambientConnectionId = (liveRemote && liveConnectionId) || activeGatewayConnectionId()+ const ambientMode = liveRemote ? ('remote' as const) : ('local' as const)const ownerRoute =explicitRoute ??- (options.workspaceMode === 'bots' && profile && localConnectionId- ? { connectionId: localConnectionId, mode: 'local' as const, profile: targetProfile }+ (options.workspaceMode === 'bots' && profile && ambientConnectionId+ ? { connectionId: ambientConnectionId, mode: ambientMode, profile: targetProfile }: null)const expectHistory = options.expectHistory ?? false@@ -1004,16 +1008,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 })+ // Plugin-owned opens without a cross-connection route still carry an+ // explicit owning profile. Record it: hidden sessions have no sidebar+ // row, so this hint is the only durable owner record the session-RPC+ // router can consult. Do not stamp mode local when the live connection+ // is remote — that hint persists and the next open resolves the profile+ // against this machine (#90477).+ if (ambientConnectionId) {+ setSessionOwnerHint(storedSessionId, {+ connectionId: ambientConnectionId,+ mode: ambientMode,+ profile: targetProfile+ })}}diff --git a/apps/desktop/src/sdk/profile-routing.test.ts b/apps/desktop/src/sdk/profile-routing.test.tsindex cc78201afa0..53e31a11770 100644--- a/apps/desktop/src/sdk/profile-routing.test.ts+++ b/apps/desktop/src/sdk/profile-routing.test.ts@@ -162,6 +162,7 @@ const { setWorkspaceScope } = await import('@/components/pane-shell/workspace-scconst {$activeSessionId,+ $connection,$messages,$selectedStoredSessionId,requestSessionResume,@@ -185,6 +186,7 @@ afterEach(() => {vi.clearAllMocks()vi.mocked(sessionTileDelegate).mockReturnValue(null)vi.mocked(activeGatewayConnectionId).mockReturnValue('local')+ $connection.set(null)$activeGatewayProfile.set('remote-worker')$gatewaySwapTarget.set(null)setMockAtom($hydrationSyncProfile, null)@@ -547,6 +549,51 @@ describe('connection-aware plugin host APIs', () => {})describe('profile-aware plugin session opens', () => {+ it('does not stamp mode local when a profile open has no owner route and the live connection is remote', async () => {+ $connection.set({+ baseUrl: 'http://127.0.0.1:9',+ connectionId: 'ssh-vps',+ isFullscreen: false,+ logs: [],+ mode: 'remote',+ nativeOverlayWidth: 0,+ token: 'token',+ windowButtonPosition: null,+ wsUrl: 'ws://127.0.0.1:9'+ })+ vi.mocked(activeGatewayConnectionId).mockReturnValue('ssh-vps')++ await host.openSession('remote-session', { profile: 'publisher' })++ expect(setSessionOwnerHint).toHaveBeenCalledWith(+ 'remote-session',+ expect.objectContaining({ connectionId: 'ssh-vps', mode: 'remote', profile: 'publisher' })+ )+ expect(vi.mocked(setSessionOwnerHint).mock.calls.some(call => call[1]?.mode === 'local')).toBe(false)+ })++ it('still stamps mode local when a profile open has no owner route and the live connection is local', async () => {+ $connection.set({+ baseUrl: 'http://127.0.0.1:9',+ connectionId: 'local',+ isFullscreen: false,+ logs: [],+ mode: 'local',+ nativeOverlayWidth: 0,+ token: 'token',+ windowButtonPosition: null,+ wsUrl: 'ws://127.0.0.1:9'+ })+ vi.mocked(activeGatewayConnectionId).mockReturnValue('local')++ await host.openSession('local-session', { profile: 'worker' })++ expect(setSessionOwnerHint).toHaveBeenCalledWith(+ 'local-session',+ expect.objectContaining({ connectionId: 'local', mode: 'local', profile: 'worker' })+ )+ })+it('captures the full owner route before opening a remote session', async () => {const route = {connectionId: 'source-a',