Skip to content

fix(relay): back off overloaded assignments - #10894

Merged
Jinwoo-H merged 1 commit into
mainfrom
relay-issue-2
Jul 27, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
relay-issue-2

Conversation

@Jinwoo-H

Copy link
Copy Markdown
Contributor

Summary

  • replace fixed drain-assignment retries with one full-jitter exponential schedule capped at five minutes
  • parse and honor bounded Retry-After hints during initial relay setup and drain recovery
  • cancel pending drain retries on broker shutdown and reset the schedule after recovery
  • register deterministic reliability evidence for duplicate drains, overload hints, recovery, and cleanup

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

  • 51 relay tests passed across 9 files
  • 25 focused assignment-backpressure tests passed across 3 files
  • Node typecheck passed
  • reliability gate manifest passed
  • max-lines ratchet passed
  • focused lint passed

Full repository lint currently reaches a pre-existing localization-coverage failure for six Ghostty keyword strings in untouched settings files on main.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Relay HTTP errors now parse and carry bounded Retry-After delays. Authentication retries and relay drain recovery apply those delays alongside exponential backoff and jitter, while preventing duplicate pending retries and cancelling work during shutdown. New tests cover HTTP parsing, delayed authentication setup, drain retry behavior, shutdown, and recovery across origins. The reliability-gates manifest adds the desktop-relay.assignment-backpressure gate and updates its timestamp.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning It covers Summary/Tradeoffs/Verification, but the required Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections are missing. Add the missing template sections, including screenshots/no visual change, the testing checklist, AI review report, security audit, and notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title concisely matches the PR's relay backoff change and is specific enough for history.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
config/reliability-gates.jsonc (1)

195-199: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

relay-http-client.test.ts assertionRefs 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 own invariant/oracle text 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3830851 and 553e85e.

📒 Files selected for processing (8)
  • config/reliability-gates.jsonc
  • src/main/runtime/relay/relay-auth-coordinator-recovery.test.ts
  • src/main/runtime/relay/relay-auth-coordinator.ts
  • src/main/runtime/relay/relay-drain-retry-schedule.ts
  • src/main/runtime/relay/relay-http-client.test.ts
  • src/main/runtime/relay/relay-http-client.ts
  • src/main/runtime/relay/relay-origin-pool.ts
  • src/main/runtime/relay/relay-session-broker.test.ts

Comment on lines +1 to +42
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()
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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: replace scheduleRetry's hand-rolled formula with the shared helper (or reuse RelayDrainRetrySchedule directly) instead of maintaining a second copy of RETRY_BASE_MS/RETRY_MAX_MS.
  • src/main/runtime/relay/relay-http-client.ts#L7-L7: import the same shared cap constant for RELAY_RETRY_AFTER_MAX_MS instead of hardcoding 5 * 60_000 a 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-L2
  • src/main/runtime/relay/relay-http-client.ts#L7-L7

@Jinwoo-H
Jinwoo-H merged commit c53a12e into main Jul 27, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants