Skip to content

The agent that grows with you

fix(desktop): drop dead pooled remote backends with a cadence-sized failure window

mfwagner1b62c4e44216
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 885465bddaa..d662a5ad3a6 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -485,6 +485,7 @@ import * as remoteLifecycle from './remote-lifecycle'
import {
attachPowerResumeRemoteRevalidation,
ensureHealthyPooledRemoteBackendForDispatch,
+ REMOTE_POOLED_LIVENESS_FAILURE_WINDOW_MS,
RemoteLivenessTracker,
RemoteRevalidationCoordinator,
revalidatePooledRemoteBackends,
@@ -1743,6 +1744,14 @@ function spawnOwnedBackend(...args: Parameters<typeof spawn>): ChildProcess {
}
const remoteLiveness = new RemoteLivenessTracker()
+// Pooled remotes are probed on the renderer reconnect cadence (minutes apart),
+// not the primary's sub-minute retry loop, so they need a failure window wider
+// than that cadence or a dead pooled descriptor's streak resets on every tick
+// and it is never dropped (#94381).
+const pooledRemoteLiveness = new RemoteLivenessTracker(
+ undefined,
+ REMOTE_POOLED_LIVENESS_FAILURE_WINDOW_MS
+)
const remoteRevalidation = new RemoteRevalidationCoordinator()
const registryDispatchRevalidation = new RemoteRevalidationCoordinator()
// Single-owner reconnect/dial claim (#90812): reconnectGateway()'s in-flight
@@ -15577,7 +15586,7 @@ function revalidatePool() {
log: rememberLog,
probe: (connection, path, options) => fetchJsonForBackend(connection, path, options),
stopBackend: stopPoolBackend,
- tracker: remoteLiveness
+ tracker: pooledRemoteLiveness
})
}
diff --git a/apps/desktop/electron/remote-liveness.test.ts b/apps/desktop/electron/remote-liveness.test.ts
index fe268bfe601..f24129048dc 100644
--- a/apps/desktop/electron/remote-liveness.test.ts
+++ b/apps/desktop/electron/remote-liveness.test.ts
@@ -7,6 +7,7 @@ import {
REMOTE_LIVENESS_FAILURE_LIMIT,
REMOTE_LIVENESS_FAILURE_WINDOW_MS,
REMOTE_LIVENESS_TIMEOUT_MS,
+ REMOTE_POOLED_LIVENESS_FAILURE_WINDOW_MS,
RemoteLivenessTracker,
RemoteRevalidationCoordinator,
revalidatePooledRemoteBackends,
@@ -455,6 +456,56 @@ describe('revalidatePooledRemoteBackends', () => {
expect(pool.stopBackend).toHaveBeenCalledWith('coder')
})
+ it('accumulates failures across probes minutes apart under the pooled failure window', async () => {
+ // Regression test for #94381: the pool revalidation tick is driven by the
+ // renderer's reconnect IPC, which fires minutes apart once the primary
+ // connection is healthy — far beyond the primary's 60s failure window.
+ // With that window a dead pooled descriptor's streak reset on every tick
+ // and the drop path was never reached; the pool served ECONNRESETs until
+ // app restart.
+ const pool = harness([['coder', { process: null, remoteBaseUrl: 'https://remote.example.com' }]])
+ pool.unreachable.add('https://remote.example.com')
+
+ let now = 1_000_000
+
+ const tracker = new RemoteLivenessTracker(
+ REMOTE_LIVENESS_FAILURE_LIMIT,
+ REMOTE_POOLED_LIVENESS_FAILURE_WINDOW_MS,
+ () => now
+ )
+
+ for (let attempt = 1; attempt < REMOTE_LIVENESS_FAILURE_LIMIT; attempt += 1) {
+ await expect(pool.run(tracker)).resolves.toEqual({ dropped: [] })
+ expect(pool.stopBackend).not.toHaveBeenCalled()
+ now += 4 * 60_000 // observed production cadence: ~4 minutes between probes
+ }
+
+ await expect(pool.run(tracker)).resolves.toEqual({ dropped: ['coder'] })
+ expect(pool.stopBackend).toHaveBeenCalledWith('coder')
+ })
+
+ it('still resets a genuinely stale streak past the pooled window', async () => {
+ const pool = harness([['coder', { process: null, remoteBaseUrl: 'https://remote.example.com' }]])
+ pool.unreachable.add('https://remote.example.com')
+
+ let now = 1_000_000
+
+ const tracker = new RemoteLivenessTracker(
+ REMOTE_LIVENESS_FAILURE_LIMIT,
+ REMOTE_POOLED_LIVENESS_FAILURE_WINDOW_MS,
+ () => now
+ )
+
+ // Two failures 20 minutes apart (beyond the pooled window): each must
+ // count as a fresh streak of 1, not silently accumulate across outages.
+ await expect(pool.run(tracker)).resolves.toEqual({ dropped: [] })
+ now += 20 * 60_000
+ await expect(pool.run(tracker)).resolves.toEqual({ dropped: [] })
+ now += 4 * 60_000
+ await expect(pool.run(tracker)).resolves.toEqual({ dropped: [] })
+ expect(pool.stopBackend).not.toHaveBeenCalled()
+ })
+
it('clears the streak when the host answers again', async () => {
const pool = harness([['coder', { process: null, remoteBaseUrl: 'https://remote.example.com' }]])
const tracker = new RemoteLivenessTracker()
diff --git a/apps/desktop/electron/remote-liveness.ts b/apps/desktop/electron/remote-liveness.ts
index f9ab632c6a3..ba1fe1e1da6 100644
--- a/apps/desktop/electron/remote-liveness.ts
+++ b/apps/desktop/electron/remote-liveness.ts
@@ -13,6 +13,14 @@ export const REMOTE_LIVENESS_FAILURE_LIMIT = 3
// about 48s apart (ticket mint + socket open + backoff + the next status probe).
// One minute keeps a continuous outage together without carrying old failures.
export const REMOTE_LIVENESS_FAILURE_WINDOW_MS = 60_000
+// Pooled remote backends are probed from the renderer's reconnect IPC, which
+// fires on a minutes-long cadence once the primary connection is healthy — far
+// beyond REMOTE_LIVENESS_FAILURE_WINDOW_MS. With the primary's 60s window a
+// dead pooled descriptor's failure streak resets on every tick, the drop path
+// is never reached, and the pool serves the dead descriptor until app restart
+// (every call fails with ECONNRESET). A successful probe still clears the
+// streak via recordSuccess(), so a wide window cannot produce false drops.
+export const REMOTE_POOLED_LIVENESS_FAILURE_WINDOW_MS = 15 * 60_000
export interface RemoteLivenessFailure {
failures: number