The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(desktop): mark the immediate active-route redial too, via one reopen helper
teknium111a12f201e7e
diff --git a/apps/desktop/src/store/gateway-connection-lifecycle.test.ts b/apps/desktop/src/store/gateway-connection-lifecycle.test.tsindex 9592285f9fc..7bab024916a 100644--- a/apps/desktop/src/store/gateway-connection-lifecycle.test.ts+++ b/apps/desktop/src/store/gateway-connection-lifecycle.test.ts@@ -134,6 +134,25 @@ describe('a redial of the active route', () => {expect(activeGateway()).toBe(gatewayMocks.instances.at(-1))})})++ it('survives a prune when the edit redials immediately (no lease to drain)', async () => {+ // Same window, sibling entry point: an unleased active scope is disposed and re-activated+ // straight from disposeSecondariesForConnection instead of the drain.+ installDesktop({+ getConnectionFor: vi.fn(async ({ connectionId, profile }: { connectionId: string; profile: string }) =>+ descriptorFor(connectionId, profile)+ )+ })++ await ensureGatewayForAgent('homelab', 'writer')++ disposeSecondariesForConnection('homelab', { redial: true }) // dispose, evict, re-activate+ pruneSecondaryGateways(new Set()) // the steal, while the redial is still suspended++ await vi.waitFor(() => {+ expect(activeGateway()).toBe(gatewayMocks.instances.at(-1))+ })+ })})describe('disposeSecondariesForConnection', () => {diff --git a/apps/desktop/src/store/gateway.ts b/apps/desktop/src/store/gateway.tsindex 5445a118eee..27a134f4559 100644--- a/apps/desktop/src/store/gateway.ts+++ b/apps/desktop/src/store/gateway.ts@@ -1255,26 +1255,33 @@ function drainPendingConnectionRedial(entry: Secondary): boolean {const wasActive = g.activeKey === entry.scopedisposeSecondary(entry)g.secondaries.delete(entry.scope)+ reopenAfterRedial(entry, wasActive)+ return true+}++// Re-open a redialed scope after its entry left the map. An active scope's+// re-activation is asynchronous, and until it lands+// restoreActiveToPrimaryIfEvicted sees an active scope with no entry, calls+// setActive(primary) and bumps the activation epoch — which turns this redial's+// own applyActive(epoch) into a no-op. The window would then sit on the primary+// backend with the redial silently discarded, after nothing more than an edit+// to the connection being viewed. Mark the scope for the pruner while the+// re-activation is in flight; the finally clears it on both outcomes so a+// redial that never lands still falls back.+function reopenAfterRedial(entry: Secondary, wasActive: boolean): void {if (!wasActive) {void openGatewayForAgent(entry.connectionId, entry.profile).catch(() => undefined)- return true+ return}- // The re-activation is asynchronous and the entry is already out of the map. Until it lands,- // restoreActiveToPrimaryIfEvicted sees an active scope with no entry, calls setActive(primary)- // and bumps the activation epoch — which turns this redial's own applyActive(epoch) into a- // no-op. The window would then sit on the primary backend with the redial silently discarded,- // after nothing more than an edit to the connection being viewed.reactivatingScopes().add(entry.scope)void ensureGatewayForAgent(entry.connectionId, entry.profile).catch(() => undefined).finally(() => {reactivatingScopes().delete(entry.scope)})-- return true}/**@@ -2208,11 +2215,7 @@ export function disposeSecondariesForConnection(connectionId: string, opts: { reg.secondaries.delete(key)if (opts.redial) {- const reopen = wasActive- ? ensureGatewayForAgent(entry.connectionId, entry.profile)- : openGatewayForAgent(entry.connectionId, entry.profile)-- void reopen.catch(() => undefined)+ reopenAfterRedial(entry, wasActive)}}