Skip to content

The agent that grows with you

fix(desktop): dispatch probe falls back to /api/status on pre-/api/health remotes

Tekniumd1bd7b00df6c
diff --git a/apps/desktop/electron/remote-liveness.test.ts b/apps/desktop/electron/remote-liveness.test.ts
index 70e8d453966..fe268bfe601 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 2160abce6b7..f9ab632c6a3 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<TConnection ex
return reconnect()
}
- await probe(connection, '/api/health', {
- timeoutMs: POOLED_REMOTE_DISPATCH_PROBE_TIMEOUT_MS
- })
+ try {
+ await probe(connection, '/api/health', {
+ timeoutMs: POOLED_REMOTE_DISPATCH_PROBE_TIMEOUT_MS
+ })
+ } catch (healthError) {
+ // A remote that predates /api/health would otherwise 404 every dispatch,
+ // retire the tunnel and reconnect forever; the boot probe falls back the
+ // same way (backend-health.ts).
+ if (!isMissingHealthEndpointError(healthError)) {
+ throw healthError
+ }
+
+ await probe(connection, '/api/status', {
+ timeoutMs: POOLED_REMOTE_DISPATCH_PROBE_TIMEOUT_MS
+ })
+ }
} catch (error) {
if (currentConnectionPromise() === connectionPromise) {
await retire(error)