Skip to content

The agent that grows with you

fix(desktop): a second gateway owner on the same stale code is restarted too

Teknium196b6890cb0d
diff --git a/apps/desktop/electron/local-gateway-stale-restart-owner.test.ts b/apps/desktop/electron/local-gateway-stale-restart-owner.test.ts
new file mode 100644
index 00000000000..84300510392
--- /dev/null
+++ b/apps/desktop/electron/local-gateway-stale-restart-owner.test.ts
@@ -0,0 +1,20 @@
+import { expect, test } from 'vitest'
+
+import { createStaleGatewayRestarter } from './local-gateway'
+
+// dokterdok N71: two owners (the multiplexer and a standalone profile with multiplex off) on the
+// same stale code are two processes; the second must be restarted too, not attached as-is.
+test('a second owner on the same stale code is restarted, while a served sibling shares its multiplexer restart', async () => {
+ const restarted: string[] = []
+ const restart = createStaleGatewayRestarter(async owner => { restarted.push(owner) }, () => undefined)
+ const stale = { gateway: 'old', client: 'new' }
+
+ const owner = (profile_id: string, control_home: null | string = null) =>
+ ({ profile_id, control_home, instance_id: 'i', authority_epoch: 1, runtime_protocol: 1, api_origin: 'http://127.0.0.1:1', capabilities: [], supervisor: 'none' })
+
+ expect(await restart(owner('/h'), stale)).toBe(true)
+ expect(await restart(owner('/h/profiles/work'), stale)).toBe(true)
+ // A served secondary lives in the multiplexer already restarted above: no second restart.
+ expect(await restart(owner('/h/profiles/ops', '/h'), stale)).toBe(false)
+ expect(restarted).toEqual(['default', 'work'])
+})
diff --git a/apps/desktop/electron/local-gateway.ts b/apps/desktop/electron/local-gateway.ts
index 12382d4b58c..66d68b68382 100644
--- a/apps/desktop/electron/local-gateway.ts
+++ b/apps/desktop/electron/local-gateway.ts
@@ -82,7 +82,7 @@ export function gatewayOwnerProfile(endpoint: GatewayEndpoint): string {
return path.basename(path.dirname(home)) === 'profiles' ? path.basename(home) : 'default'
}
-/** One restart per stale (gateway, client) code pair per process. An owner a restart cannot move
+/** One restart per (owner process, stale gateway, client) per Desktop process. An owner a restart cannot move
* (a service unit pinned to another checkout) is then attached as-is instead of being restarted
* on every dial. */
export function createStaleGatewayRestarter(
@@ -94,7 +94,7 @@ export function createStaleGatewayRestarter(
const restarts = new Map<string, { done: boolean; promise: Promise<void> }>()
return async (endpoint, stale) => {
- const key = `${stale.gateway}\n${stale.client}`.toLowerCase()
+ const key = `${gatewayOwnerProfile(endpoint)}\n${stale.gateway}\n${stale.client}`.toLowerCase()
const pending = restarts.get(key)
if (pending && !pending.done) {