Repository navigation
fix(relay): back off overloaded assignments - #10894
Conversation
📝 WalkthroughWalkthroughRelay HTTP errors now parse and carry bounded 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
config/reliability-gates.jsonc (1)
195-199: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
relay-http-client.test.tsassertionRefs omit the five-minute cap test.Two new tests were added to
relay-http-client.test.ts("preserves a bounded Retry-After hint" and "caps an excessive Retry-After hint at five minutes"), but only the first is listed here even though the gate's owninvariant/oracletext explicitly calls out the five-minute cap. Adding the second assertion keeps the evidence trail for this gate's central invariant complete.📝 Proposed addition
{ "file": "src/main/runtime/relay/relay-http-client.test.ts", "assertions": [ - "assignment overload preserves a bounded Retry-After hint" + "assignment overload preserves a bounded Retry-After hint", + "an excessive assignment Retry-After hint is capped at five minutes" ] },
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cb09f6b9-1396-4205-9a5d-7965325db071
📒 Files selected for processing (8)
config/reliability-gates.jsoncsrc/main/runtime/relay/relay-auth-coordinator-recovery.test.tssrc/main/runtime/relay/relay-auth-coordinator.tssrc/main/runtime/relay/relay-drain-retry-schedule.tssrc/main/runtime/relay/relay-http-client.test.tssrc/main/runtime/relay/relay-http-client.tssrc/main/runtime/relay/relay-origin-pool.tssrc/main/runtime/relay/relay-session-broker.test.ts
| const RETRY_BASE_MS = 1_000 | ||
| const RETRY_MAX_MS = 5 * 60_000 | ||
|
|
||
| export class RelayDrainRetrySchedule { | ||
| private timer: ReturnType<typeof setTimeout> | null = null | ||
| private attempt = 0 | ||
|
|
||
| constructor(private readonly random: () => number = Math.random) {} | ||
|
|
||
| get pending(): boolean { | ||
| return this.timer !== null | ||
| } | ||
|
|
||
| schedule(retryAfterMs: number, retry: () => void): void { | ||
| if (this.timer) { | ||
| return | ||
| } | ||
| const exponent = Math.min(this.attempt, Math.ceil(Math.log2(RETRY_MAX_MS / RETRY_BASE_MS))) | ||
| const capMs = Math.min(RETRY_MAX_MS, RETRY_BASE_MS * 2 ** exponent) | ||
| this.attempt++ | ||
| const jitterMs = Math.floor(this.random() * (capMs + 1)) | ||
| this.timer = setTimeout( | ||
| () => { | ||
| this.timer = null | ||
| retry() | ||
| }, | ||
| Math.max(jitterMs, retryAfterMs) | ||
| ) | ||
| } | ||
|
|
||
| reset(): void { | ||
| this.attempt = 0 | ||
| } | ||
|
|
||
| cancel(): void { | ||
| if (this.timer) { | ||
| clearTimeout(this.timer) | ||
| this.timer = null | ||
| } | ||
| this.reset() | ||
| } | ||
| } |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Full-jitter backoff formula and its five-minute cap are independently duplicated across three files. RelayDrainRetrySchedule.schedule and RelayAuthCoordinator.scheduleRetry implement the identical exponent/jitter/Math.max(jitter, retryAfterMs) math with their own copies of the base/max constants, and relay-http-client.ts separately hardcodes the same 300000ms cap for parsing Retry-After. Nothing ties these together, so a future change to any one of them can silently break the documented "capped at five minutes" reliability guarantee.
src/main/runtime/relay/relay-drain-retry-schedule.ts#L1-L42: extract the exponent/jitter/max-with-retryAfter computation (and its cap constant) into a shared exported helper other retry sites can import.src/main/runtime/relay/relay-auth-coordinator.ts#L2-L2,193-215: replacescheduleRetry's hand-rolled formula with the shared helper (or reuseRelayDrainRetryScheduledirectly) instead of maintaining a second copy ofRETRY_BASE_MS/RETRY_MAX_MS.src/main/runtime/relay/relay-http-client.ts#L7-L7: import the same shared cap constant forRELAY_RETRY_AFTER_MAX_MSinstead of hardcoding5 * 60_000a third time.
📍 Affects 3 files
src/main/runtime/relay/relay-drain-retry-schedule.ts#L1-L42(this comment)src/main/runtime/relay/relay-auth-coordinator.ts#L2-L2src/main/runtime/relay/relay-http-client.ts#L7-L7
Co-authored-by: OrcaWin <[email protected]>
Summary
Tradeoffs
Recovery is intentionally slower while the director reports overload or remains unavailable. Healthy relay connections, pairing, LAN, and Tailscale behavior are unchanged. Legacy desktop versions remain protected by the already-deployed cloud overload shield; this PR reduces load as updated desktops roll out.
Verification
Full repository lint currently reaches a pre-existing localization-coverage failure for six Ghostty keyword strings in untouched settings files on main.