Skip to content

The agent that grows with you

fix(desktop): a rejected background primary offers Settings instead of parking silently

kshitijk4poord7778e1435ab
diff --git a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
index 8feb88f73cd..44e5f722cc7 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.test.tsx
@@ -383,11 +383,13 @@ describe('default-route profile adoption', () => {
async connectionId => {
const base = fakeDesktop()
const route = { connectionId, profile: 'coder' }
+
const desktop = {
...base,
getConnectionFor: vi.fn(async () => ({ ...coderConn, registryScoped: true })),
profile: { ...base.profile, getDefault: vi.fn(async () => route) }
}
+
;(window as { hermesDesktop?: unknown }).hermesDesktop = desktop
render(<Harness />)
await flushAsync()
@@ -398,6 +400,7 @@ describe('default-route profile adoption', () => {
expect(desktop.getConnection).toHaveBeenCalledWith('coder')
expect(desktop.getConnectionFor).not.toHaveBeenCalled()
}
+
expect($connection.get()?.profile).toBe('coder')
expect($desktopBoot.get().running).toBe(false)
}
@@ -512,6 +515,41 @@ describe('primary failure foreground isolation', () => {
expect($desktopBoot.get().visible).toBe(false)
}
)
+ it('a rejected background primary offers Settings instead of parking silently', async () => {
+ const desktop = Object.assign(fakeDesktop(), {
+ getConnectionFor: vi.fn(async () => ({
+ ...coderConn,
+ connectionId: 'local',
+ profile: 'default',
+ mode: 'local',
+ baseUrl: 'http://127.0.0.1:9191',
+ wsUrl: 'ws://127.0.0.1:9191/api/ws?token=c'
+ }))
+ })
+
+ desktop.getConnection.mockResolvedValue({ ...primaryConn, mode: 'remote', remoteKind: 'cloud', authMode: 'oauth' } as typeof primaryConn)
+ ;(window as { hermesDesktop?: unknown }).hermesDesktop = desktop
+ render(<Harness />)
+ await flushAsync()
+ let opening!: Promise<boolean>
+ act(() => {
+ opening = ensureGatewayForAgent('local', 'default')
+ })
+ await flushAsync()
+ expect(await opening).toBe(true)
+
+ desktop.getGatewayWsUrl.mockRejectedValue(Object.assign(new Error('Sign in again'), { needsOauthLogin: true }))
+ act(() => FakeWebSocket.instances[0].drop())
+ await advanceBackoff()
+
+ // The parked primary no longer retries by itself, so the user must learn
+ // about it from where they are — without the foreground being hijacked.
+ expect(isActivePrimary()).toBe(false)
+ expect($desktopBoot.get().error).toBeNull()
+ const toast = $notifications.get().find(entry => entry.kind === 'error')
+ expect(toast?.action?.label).toBe('Open Gateways')
+ })
+
it.each(['progress', 'reconnect'] as const)(
'primary auth via %s follows the foreground, including a latched error',
async path => {
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 128a78fa5ef..e678b755dc0 100644
--- a/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
+++ b/apps/desktop/src/app/gateway/hooks/use-gateway-boot.ts
@@ -460,23 +460,24 @@ export function useGatewayBoot({
if (!cancelled && isGatewayReauthRequired(err) && !reauthNotified) {
primaryReauthError = err instanceof Error ? err.message : String(err)
syncPrimaryReauthError()
-
- if (isActivePrimary()) {
- reauthNotified = true
- // Plain "signed out" copy; the raw ticket/HTTP text stays under
- // Details. The boot overlay carries the sign-in flow itself, so
- // the button hands off to it (desktop-14).
- notify({
- kind: 'error',
- title: translateNow('boot.errors.gatewaySignInRequired'),
- message: translateNow('boot.errors.gatewaySignInRequiredDetail'),
- detail: primaryReauthError,
- action: {
- label: translateNow('boot.errors.signInAgain'),
- onClick: () => failDesktopBoot(primaryReauthError ?? '')
- }
- })
- }
+ reauthNotified = true
+ // Plain "signed out" copy; the raw ticket/HTTP text stays under
+ // Details. In the foreground the boot overlay carries the sign-in
+ // flow, so the button hands off to it (desktop-14). A parked
+ // background primary no longer retries by itself, so it must still
+ // offer a way to Settings instead of failing silently.
+ notify({
+ kind: 'error',
+ title: translateNow('boot.errors.gatewaySignInRequired'),
+ message: translateNow('boot.errors.gatewaySignInRequiredDetail'),
+ detail: primaryReauthError,
+ action: isActivePrimary()
+ ? {
+ label: translateNow('boot.errors.signInAgain'),
+ onClick: () => failDesktopBoot(primaryReauthError ?? '')
+ }
+ : RECOVERY_ACTIONS.openGateways()
+ })
}
} finally {
reconnecting = false