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(hosted-team): a throttled join waits at most ten minutes (D2)
review699eaa50af2a
diff --git a/docs/hosted-team-relay.md b/docs/hosted-team-relay.mdindex c69558aa8..db31e88c5 100644--- a/docs/hosted-team-relay.md+++ b/docs/hosted-team-relay.md@@ -268,8 +268,8 @@ joining answers `E_JOIN_BUSY`.with one notice ("Couldn't reconnect to X. Click its tab to try again."). A click is a freshattempt. A boot reconnect that runs out says to paste the invite code instead.- Unattended attempts (boot and drop reconnects) retry `E_JOIN_NETWORK` on 1, 2, 4, 8, 15 s, then- every 60 s, and `E_JOIN_THROTTLED` no sooner than 60 s (or the Retry-After), announced once per- streak. Nothing else retries, and a pasted code never retries: it is told once.+ every 60 s, and `E_JOIN_THROTTLED` no sooner than 60 s (or the Retry-After, capped at 10 minutes),+ announced once per streak. Nothing else retries, and a pasted code never retries: it is told once.- Closing or deleting the tab cancels its team's attempt in any phase. At most one attempt and onelive connection exist per team.- A code pasted into a greyed tab's prompt must be for that tab's team. A code for another team isdiff --git a/src/renderer/lib/hostedAttempts.test.ts b/src/renderer/lib/hostedAttempts.test.tsindex 685bea8d7..0a4d6945f 100644--- a/src/renderer/lib/hostedAttempts.test.ts+++ b/src/renderer/lib/hostedAttempts.test.ts@@ -482,6 +482,26 @@ describe('hosted attempts: one attempt and one live connection per team (R38/R39expect(h.stopped).toEqual([])})+ it('D2: a Retry-After longer than ten minutes waits ten minutes — a huge one never fires at once', async () => {+ const h = harness()+ const a = createHostedAttempts(h.deps)+ a.run(boot())+ // 99 999 999 s: past 2^31-1 ms, where a timer would fire immediately.+ h.connects[0].reject(wrap('[E_JOIN_THROTTLED] limiting [retry-after:99999999]'))+ await flush()+ expect(h.armed()[0].ms).toBe(600_000)+ h.fire()+ // Too many digits to be a number at all (Infinity): still ten minutes.+ h.connects[1].reject(wrap(`[E_JOIN_THROTTLED] limiting [retry-after:${'9'.repeat(400)}]`))+ await flush()+ expect(h.armed()[0].ms).toBe(600_000)+ h.fire()+ // Just under the ceiling is honoured as is.+ h.connects[2].reject(wrap('[E_JOIN_THROTTLED] limiting [retry-after:599]'))+ await flush()+ expect(h.armed()[0].ms).toBe(599_000)+ })+it('R41: a throttle streak is announced once; a new streak (after the service answered) again', async () => {const h = harness()const a = createHostedAttempts(h.deps)diff --git a/src/renderer/lib/hostedAttempts.ts b/src/renderer/lib/hostedAttempts.tsindex cf49908e2..a6eb47778 100644--- a/src/renderer/lib/hostedAttempts.ts+++ b/src/renderer/lib/hostedAttempts.ts@@ -21,7 +21,7 @@// Pure orchestration over injected deps, so every rule is testable without React or a relay.// See docs/hosted-team-relay.md.import type { RelayClosedReason } from '@shared/types'-import { classifyJoinFailure, DROP_RETRY_MAX, reconnectDelayMs, THROTTLE_MIN_DELAY_MS, type JoinFailure } from './hostedTeam'+import { classifyJoinFailure, DROP_RETRY_MAX, reconnectDelayMs, throttleDelayMs, type JoinFailure } from './hostedTeam'/** The ladder rung of the 60 s tail (1/2/4/8/15 s come before it). */const TAIL_RUNG = 5@@ -230,13 +230,14 @@ export function createHostedAttempts(deps: HostedAttemptDeps): HostedAttempts {const failure = classifyJoinFailure(err instanceof Error ? err.message : String(err))if (failure.throttled && e.req.retry) {// The per-network limiter clears within a minute: wait at least that long (or its- // Retry-After), and stay on the 60 s tail after it — never a burst back down to 1 s.+ // Retry-After, never more than ten minutes), and stay on the 60 s tail after it — never a+ // burst back down to 1 s.if (!e.throttleSaid) {e.throttleSaid = truedeps.throttled(e.req)}e.attempt = Math.max(e.attempt, TAIL_RUNG)- retryAfter(e, Math.max(THROTTLE_MIN_DELAY_MS, failure.retryAfterMs ?? 0))+ retryAfter(e, throttleDelayMs(failure.retryAfterMs))return}if (failure.retry && e.req.retry) {diff --git a/src/renderer/lib/hostedTeam.ts b/src/renderer/lib/hostedTeam.tsindex fd92ca5b5..cf1376f4e 100644--- a/src/renderer/lib/hostedTeam.ts+++ b/src/renderer/lib/hostedTeam.ts@@ -18,6 +18,17 @@ export const THROTTLED_NOTICE = 'The nodeterm service is limiting requests from/** A throttled retry never comes sooner than this, whatever Retry-After says (R41). */export const THROTTLE_MIN_DELAY_MS = 60_000+/** ...and never later than this. The per-network limiter clears within a minute, so a longer+ * Retry-After is not a reason to go quiet for longer, and a huge one (past 2^31-1 ms, or too many+ * digits to be a number) would make the timer fire at once: exactly the burst the floor prevents. */+export const THROTTLE_MAX_DELAY_MS = 600_000++/** How long a throttled join waits: its Retry-After, clamped to [1 min, 10 min]. */+export function throttleDelayMs(retryAfterMs: number | null): number {+ const asked = retryAfterMs === null || Number.isNaN(retryAfterMs) ? 0 : retryAfterMs+ return Math.min(THROTTLE_MAX_DELAY_MS, Math.max(THROTTLE_MIN_DELAY_MS, asked))+}+/** How many times an unattended attempt retries a connection that dropped before the host answered* (a host restarting): the short steps of the ladder, 1/2/4/8/15 s, and then it stops and says so* (R40). Each try mints a join token and opens a relay socket, so this one is bounded — unlike a