Skip to content

The agent that grows with you

🐛 fix(desktop): include route scope in gateway dial errors

墨綠BG477053538c73
diff --git a/apps/desktop/src/store/gateway.test.ts b/apps/desktop/src/store/gateway.test.ts
index 708476242b9..f92dec3b0b4 100644
--- a/apps/desktop/src/store/gateway.test.ts
+++ b/apps/desktop/src/store/gateway.test.ts
@@ -50,6 +50,7 @@ const {
closeSecondaryGateways,
configureGatewayRegistry,
ensureGatewayForProfile,
+ openGatewayForAgent,
pruneSecondaryGateways,
setPrimaryGateway
} = await import('./gateway')
@@ -179,6 +180,48 @@ describe('ensureGatewayForProfile — secondary connect failure surfaces (#81094
})
})
+describe('connection-scoped dial failure identity (#95421)', () => {
+ it('logs the route scope while preserving the original dial error', async () => {
+ const dialError = new Error('backend unreachable')
+
+ const getConnectionFor = vi.fn(async ({ connectionId, profile }: { connectionId: string; profile: string }) => ({
+ authMode: 'token',
+ connectionId,
+ profile,
+ wsUrl: `wss://${connectionId}.invalid/ws`
+ }))
+
+ installDesktop({ getConnectionFor })
+ gatewayMocks.connect.mockRejectedValue(dialError)
+
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => undefined)
+
+ try {
+ await expect(openGatewayForAgent('work', 'default')).rejects.toBe(dialError)
+ await expect(openGatewayForAgent('homelab', 'default')).rejects.toBe(dialError)
+
+ const messages = errorSpy.mock.calls.map(([message]) => String(message))
+
+ expect(messages).toHaveLength(2)
+ expect(messages).toEqual(
+ expect.arrayContaining([
+ expect.stringContaining('scope="conn:work::default"'),
+ expect.stringContaining('scope="conn:homelab::default"')
+ ])
+ )
+ expect(messages.every(message => message.includes('profile="default"'))).toBe(true)
+ expect(new Set(messages).size).toBe(2)
+ expect(messages.join(' ')).not.toContain('wss://')
+
+ for (const [, error] of errorSpy.mock.calls) {
+ expect(error).toBe(dialError)
+ }
+ } finally {
+ errorSpy.mockRestore()
+ }
+ })
+})
+
describe('profile switch mid-WS-handshake (#92434 close-candidate pin)', () => {
// Reported shape: Bot ↔ Default switching killed the socket until an app
// restart. The activation-epoch guard (applyActive) + open-socket-publish
diff --git a/apps/desktop/src/store/gateway.ts b/apps/desktop/src/store/gateway.ts
index c7c553d65ab..b2c1d0ddbf3 100644
--- a/apps/desktop/src/store/gateway.ts
+++ b/apps/desktop/src/store/gateway.ts
@@ -533,7 +533,7 @@ async function openSecondary(entry: Secondary): Promise<void> {
// reconnectSecondary classifies failures by message ("No connection
// with id", "no longer exists") to fail-stop permanent conditions, and
// wrapping here would break that. Callers decide surfacing (#81094).
- console.error(`[gateway] dial for profile "${entry.profile}" failed:`, error)
+ console.error(`[gateway] dial failed for scope="${entry.scope}" profile="${entry.profile}":`, error)
throw error
}