The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): cleared SSH fields reach main as '' and drift heal aligns route identity
LordMelkor1c659fe53a3b
diff --git a/apps/desktop/electron/connection-registry.test.ts b/apps/desktop/electron/connection-registry.test.tsindex dd2a34558d3..a3095aa474b 100644--- a/apps/desktop/electron/connection-registry.test.ts+++ b/apps/desktop/electron/connection-registry.test.ts@@ -45,6 +45,7 @@ import {updateEligibility,upsertConnection} from './connection-registry'+import { matchingConnectionId } from './connection-route-identity'// Non-literal specifier on purpose: tsconfig.electron.json's project boundary// excludes apps/shared sources, but vitest resolves the workspace package fine@@ -1920,6 +1921,46 @@ test('drift heal leaves a registry that already knows the v1 SSH route untouchedassert.equal(drifted.registry, first.registry)})+test('drift heal aligns a registered SSH route whose identity fields drifted from the v1 route', () => {+ // Same host/user as the registered entry, but the v1 route carries a keyPath+ // the entry never had. matchingConnectionId compares keyPath too, so the live+ // window would resolve to no connectionId and be treated as the local device.+ const first = reconcileRegistryDrift(emptyRegistry(), {+ mode: 'ssh',+ remote: { host: 'devbox.example.com', user: 'omar' }+ })++ assert.equal(first.changed, true)++ const drifted = reconcileRegistryDrift(first.registry, {+ mode: 'ssh',+ remote: { host: 'devbox.example.com', user: 'omar', keyPath: '~/.ssh/id_rsa' }+ })++ assert.equal(drifted.changed, true)+ const sshEntries = drifted.registry.connections.filter(connection => connection.kind === 'ssh')+ assert.equal(sshEntries.length, 1)+ assert.equal(sshEntries[0].keyPath, '~/.ssh/id_rsa')+ assert.equal(drifted.registry.primary, first.registry.primary)+ assert.equal(+ matchingConnectionId(+ drifted.registry,+ { host: 'devbox.example.com', user: 'omar', keyPath: '~/.ssh/id_rsa', kind: 'ssh' },+ 'primary'+ ),+ sshEntries[0].id+ )++ // Clearing the keyPath again re-aligns the entry.+ const cleared = reconcileRegistryDrift(drifted.registry, {+ mode: 'ssh',+ remote: { host: 'devbox.example.com', user: 'omar' }+ })++ assert.equal(cleared.changed, true)+ assert.equal(cleared.registry.connections.find(connection => connection.kind === 'ssh')?.keyPath, undefined)+})+test('drift heal respects a deliberate primary pick on a registered SSH route', () => {let registry = reconcileRegistryDrift(emptyRegistry(), {mode: 'ssh',diff --git a/apps/desktop/electron/connection-registry.ts b/apps/desktop/electron/connection-registry.tsindex 3e51f96a1ee..2322ad91794 100644--- a/apps/desktop/electron/connection-registry.ts+++ b/apps/desktop/electron/connection-registry.ts@@ -1697,20 +1697,41 @@ export function reconcileRegistryDrift(const target = normalizedSshTarget(ssh)- const alreadyRegistered = registry.connections.some(+ const registered = registry.connections.find(connection =>connection.kind === 'ssh' &&normalizedSshTarget(connection) === target &&(connection.port ?? 22) === (ssh.port ?? 22))- if (alreadyRegistered) {+ const { mode: _mode, ...sshFields } = ssh++ if (registered) {// Route is known; if primary names another source, that is the user's// Connections-panel choice, not drift.- return unchanged+ //+ // Known by target is not enough, though: the router tags the live+ // window by the FULL route identity (matchingConnectionId also compares+ // keyPath, remoteHermesPath and remoteProfile). A v1 route carrying a+ // keyPath the registered entry never had resolves to no connectionId,+ // the renderer treats the untagged window as the unscoped local backend+ // ("This device") and the roster force-spawns a phantom local child.+ // Align the registered entry's identity fields with the route the app+ // actually dials so both sides compare equal.+ if (matchingConnectionId(registry, { ...ssh, kind: 'ssh' }, 'unique')) {+ return unchanged+ }++ const { host: _host, user: _user, port: _port, ...identityFields } = sshFields+ const aligned: RegistryConnection = { ...registered }+ delete aligned.keyPath+ delete aligned.remoteHermesPath+ delete aligned.remoteProfile+ Object.assign(aligned, identityFields)++ return { changed: true, registry: upsertConnection(registry, aligned) }}- const { mode: _mode, ...sshFields } = sshlet entry: RegistryConnectiondiff --git a/apps/desktop/src/app/settings/gateway-settings.tsx b/apps/desktop/src/app/settings/gateway-settings.tsxindex dee26655ef3..e8684806578 100644--- a/apps/desktop/src/app/settings/gateway-settings.tsx+++ b/apps/desktop/src/app/settings/gateway-settings.tsx@@ -541,9 +541,15 @@ function GatewayConnectionSettings({ embedded, standalone }: { embedded: booleanremoteAuthMode: state.remoteAuthMode,remoteUrl: coerceRemoteUrlScheme(state.remoteUrl),sshHost: state.sshHost.trim(),- sshUser: state.sshUser.trim() || undefined,+ // Send an explicit '' for cleared fields. Main merges with `??`, so+ // `undefined` means "inherit the saved value" and a cleared Identity+ // file (or User) could never be removed once saved: the form kept+ // refilling the stale path, and the stale key path made the v1 SSH+ // route's identity differ from the registered gateway's, leaving+ // the window unscoped.+ sshUser: state.sshUser.trim(),sshPort: state.sshPort,- sshKeyPath: state.sshKeyPath.trim() || undefined,+ sshKeyPath: state.sshKeyPath.trim(),sshRemoteHermesPath: state.sshRemoteHermesPath.trim(),// A blank clears an existing remote-profile mapping.sshRemoteProfile: state.sshRemoteProfile.trim()