Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(relay): a refused host-token mint backs off instead of re-minting in a tight loop
review7d2e6003e900
diff --git a/src/main/remote/standing-host.test.ts b/src/main/remote/standing-host.test.tsindex 13e3d6139..b5a194f07 100644--- a/src/main/remote/standing-host.test.ts+++ b/src/main/remote/standing-host.test.ts@@ -292,3 +292,28 @@ describe('standing phone approval lifecycle (#819)', () => {expect(sessions[0].session.approve).not.toHaveBeenCalled()})})++describe('standing host: a refused token mint backs off', () => {+ afterEach(() => {+ vi.useRealTimers()+ })++ it('does NOT re-mint in a tight loop when the API refuses (429)', async () => {+ // Field evidence (relay API log, 2026-09-25): one free host hit /v1/relay/host-token every+ // ~175 ms — its own round-trip time — 35k 429s in a day. connectOne()'s `finally` topped the+ // pool back up on a microtask even after a FAILED mint, so the backoff scheduleReconnect()+ // had just armed never got a chance to run.+ vi.useFakeTimers()+ const fetchMock = vi.fn(async () => ({ ok: false, status: 429, json: async () => ({}) }))+ vi.stubGlobal('fetch', fetchMock)+ const host = makeHost()+ host.syncFromSettings()+ for (let i = 0; i < 20; i++) await settle()+ expect(fetchMock).toHaveBeenCalledTimes(1)+ // The backoff then retries — refusal is not a permanent stop.+ await vi.advanceTimersByTimeAsync(1000)+ for (let i = 0; i < 5; i++) await settle()+ expect(fetchMock).toHaveBeenCalledTimes(2)+ host.stop()+ })+})diff --git a/src/main/remote/standing-host.ts b/src/main/remote/standing-host.tsindex dbc94f60f..6bea3e696 100644--- a/src/main/remote/standing-host.ts+++ b/src/main/remote/standing-host.ts@@ -264,6 +264,11 @@ export function initStandingHost(async function connectOne(): Promise<void> {if (!running || opening || pendingCount() >= TARGET_PENDING) returnopening = true+ // Only a SUCCESSFUL attempt may chain straight into the next one. A failed one has armed+ // scheduleReconnect()'s backoff, and chaining anyway made that backoff dead code: a host whose+ // mint was refused re-minted at its own round-trip time (~175 ms, 35k 429s/day in the relay+ // API log, 2026-09-25) instead of waiting 1 s → 15 s.+ let opened = falsetry {const entitlement = getStoredEntitlement() // null on free tier → mint by deviceId// The host key is the identity every paired phone PINNED. If the OS keyring is locked we@@ -328,6 +333,7 @@ export function initStandingHost(}})pool.add(pooled)+ opened = truescheduleRefreshFor(pooled, token.exp)// A listener is registered at the relay → advertise the identity for LATE ADOPTION// (~/.nodeterm/relay.json — see relay-advertise.ts): a phone whose pairing predates the@@ -344,7 +350,7 @@ export function initStandingHost(} finally {opening = false// If we're still short (e.g. TARGET_PENDING > 1, or one was consumed while minting), continue.- if (running && pendingCount() < TARGET_PENDING) queueMicrotask(() => void connectOne())+ if (opened && running && pendingCount() < TARGET_PENDING) queueMicrotask(() => void connectOne())}}