diff --git a/apps/desktop/electron/remote-liveness.test.ts b/apps/desktop/electron/remote-liveness.test.ts index 70e8d45396..fe268bfe60 100644 --- a/apps/desktop/electron/remote-liveness.test.ts +++ b/apps/desktop/electron/remote-liveness.test.ts @@ -329,6 +329,36 @@ describe('ensureHealthyPooledRemoteBackendForDispatch', () => { expect(retire).toHaveBeenCalledOnce() expect(reconnect).toHaveBeenCalledOnce() }) + + it('falls back to /api/status when /api/health returns 404 on older backends', async () => { + const legacy = { baseUrl: 'http://127.0.0.1:49525', mode: 'remote' } + const legacyPromise = Promise.resolve(legacy) + + const retire = vi.fn() + const reconnect = vi.fn() + + const probe = vi.fn(async (_connection, path) => { + if (path === '/api/health') { + throw new Error('404: Not Found') + } + }) + + await expect( + ensureHealthyPooledRemoteBackendForDispatch({ + connectionPromise: legacyPromise, + currentConnectionPromise: () => legacyPromise, + probe, + reconnect, + retire + }) + ).resolves.toBe(legacy) + + expect(probe).toHaveBeenCalledWith(legacy, '/api/status', { + timeoutMs: POOLED_REMOTE_DISPATCH_PROBE_TIMEOUT_MS + }) + expect(retire).not.toHaveBeenCalled() + expect(reconnect).not.toHaveBeenCalled() + }) }) describe('revalidatePooledRemoteBackends', () => { diff --git a/apps/desktop/electron/remote-liveness.ts b/apps/desktop/electron/remote-liveness.ts index 2160abce6b..f9ab632c6a 100644 --- a/apps/desktop/electron/remote-liveness.ts +++ b/apps/desktop/electron/remote-liveness.ts @@ -1,3 +1,5 @@ +import { isMissingHealthEndpointError } from './backend-health' + export const REMOTE_LIVENESS_TIMEOUT_MS = 10_000 // Dispatch is synchronous user intent: a cached descriptor must prove its // forwarded endpoint is alive before it can be returned. Probe cheap @@ -102,9 +104,22 @@ export async function ensureHealthyPooledRemoteBackendForDispatch