Skip to content

The agent that grows with you

fix(desktop): keep $connection on a profile picked during boot

Tekniumbc3356d0ac74
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot-profile-pick.test.tsx b/apps/desktop/src/app/gateway/hooks/use-gateway-boot-profile-pick.test.tsx
index 8a9a4da1f9d..531e6a1c628 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot-profile-pick.test.tsx
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot-profile-pick.test.tsx
@@ -167,5 +167,9 @@ it('a profile picked while boot is still connecting survives the primary adoptio
expect($desktopBoot.get().running).toBe(false)
expect($activeGatewayProfile.get()).toBe('coder')
expect(isActivePrimary()).toBe(false)
+ // Socket, profile and connection descriptor agree on the pick
+ // (apps/desktop/AGENTS.md): boot records the primary, it doesn't publish it.
+ expect($connection.get()?.connectionId).toBe('coder-remote')
+ expect($connection.get()?.profile).toBe('coder')
expect(scopes).toEqual(['coder'])
})
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
index 902cb80bacb..a013ec93356 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
@@ -1487,7 +1487,15 @@ export function useGatewayBoot({
message: translateNow('boot.steps.connectingGateway'),
progress: 95
})
- publish(conn)
+
+ // A profile picked while the primary lookup was in flight already
+ // published its own descriptor with its socket (T19, #134889). Record
+ // the primary, but keep $connection on the pick so socket, profile and
+ // connection agree.
+ if (currentProfileSelectionRevision() === selectionRevision) {
+ publish(conn)
+ }
+
recordPrimaryConnection(conn)
// Seed the workspace BEFORE the gateway opens: every session-restore