Repository navigation
fix(relay): stop reporting an unavailable home cell as exhausted capacity - #21518
Conversation
…city A host whose home cell is not live — readiness false, drained, or inside a boot window — is refused by the committed-fence branch in assignOnce() without any capacity being consulted. It answered relay_capacity_exhausted, so every cell boot and every readiness dip printed capacity rejections at 17% fleet utilisation and sent an investigation after headroom that was never short. The branch now raises RelayHomeCellUnavailableError, which carries the cell id and which of cellIsLive()'s conditions failed (draining / booting / unheard / not_ready). The director logs reason, cause and cell, and returns the new reason in the same retryable 503. Nothing on the wire reads the body: the desktop client discards it unread and branches on status only, and no log-based metric or alert parses the reason. The load harness, the only body-reading consumer, gets its own bucket so a home-cell rejection no longer inflates the capacity count. Hinted grants are now logged on whichever lane served them, so a host that failed sticky verification and was rehomed by placement leaves a record of where it landed. Unhinted placement grants stay silent.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe relay now reports fenced home-cell unavailability separately from capacity exhaustion. The assignment store classifies causes and exposes a typed error. Assignment and resolve routes return Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The change consistently distinguishes unavailable home cells from capacity exhaustion through assignment, routing, logging, and load classification. No merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, implementation, rationale, testing, compatibility, and operational impact. However, the required Linked Issue section is incomplete because it contains only "Fixes #" without an issue reference.
✨ Finishing Touches 💡 1📝 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.
✅ No new issues found.
Reviewed changes — the full single-commit diff, plus the surrounding store, app, and load-harness code it depends on.
- New refusal reason. The
assignOncebranch that refuses a host on a non-live, fenced-required home cell now throwsRelayHomeCellUnavailableError(relay_home_cell_unavailable) instead of a plainError('relay_capacity_exhausted'), carrying the cell id and adraining/booting/unheard/not_readycause. - Cause derivation.
homeCellUnavailableCause()re-readsrelay_cells+relay_cell_runtimeand mirrorscellIsLive()'s conditions; the TTL comparison and readiness fallthrough line up exactly. - Director logging/response.
isRelayAssignmentUnavailableErrorincludes the new message,homeCellRejectionDetailappendscause=/cell=to the rejection line, and the same retryable 503 is returned. - Sweep and harness.
evacuateDeadCellskeeps skipping an unplaceable host; the load harness regex/buckets and reportable-error list pick up the new code. - Grant logging. Hinted placement-lane grants are now logged, recording where a host whose sticky lane failed verification landed.
I verified the throw branch is only reachable when cellIsLive() is false, that the cause precedence matches cellIsLive's strict TTL boundary, and that no consumer branches on the reason string — the desktop discards the 503 body unread, mobile never calls the endpoint, and neither relay-observability.tf nor incident-monitor.ts parses reason=. The new tests discriminate the fix rather than the setup.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When a phone or desktop asks Relay "where do I connect?", Relay usually sends it back to the same machine it used last time — its home cell. If that machine is restarting, draining, or failing its health check, Relay refuses the request. Until now the refusal said "we're out of capacity", which is not what happened: there was plenty of room everywhere else. This PR makes the refusal say what actually went wrong, and which machine.
What Changed
Before (what an operator sees): during a cell roll, or whenever a cell's readiness probe goes red, the director logs a burst of
On 2026-09-16/17 that was 85–685 lines per minute per cell boot at roughly 17% fleet utilisation, plus a continuous 9–20/min from the Asia cells whose readiness probe was timing out behind a saturated Postgres pool. The line is indistinguishable from a real capacity rejection, so an incident was spent hunting for headroom that was never short.
After:
causeis one ofdraining,booting,unheard(heartbeat older than the TTL) ornot_ready(heartbeat fresh, readiness false). Genuine headroom exhaustion is untouched and still readsrelay_capacity_exhausted.The mechanism.
assignOnce()inassignment-store.tshas a branch that is only reachable when the host's current cell failedcellIsLive()— readiness false, heartbeat older than the TTL, or no runtime row. If that cell is connection-limited or carries a post-drain migration pin, the host may not be moved without a committed fence, and the branch refused it. It refused it by throwingrelay_capacity_exhausted, having consulted no capacity counter at all. It now throwsRelayHomeCellUnavailableError, carrying the cell id and which ofcellIsLive()'s conditions failed; the director logsreason,causeandcelland returns the new reason in the same retryable 503.Because the sticky lane's
resolve()also returnsnullfor a cell that is not live, these requests always arrive aslane=placement hinted=true. Hinted grants are now logged on whichever lane served them, so a host that failed sticky verification and was rehomed by the placement lane leaves a record of where it landed — previously only sticky-lane grants were logged and that half of the story was missing. Unhinted placement grants stay silent; they are every brand-new host and would be unbounded volume.The dead-cell evacuation sweep keeps skipping a host it cannot place, as it did for the old reason, instead of aborting the sweep.
Why
The reason string is the operator's only first-order signal for "why was this host refused", and it was lying about the most common refusal on the fleet. A wrong reason is worse than a vague one: it names a specific, expensive thing to go investigate.
Why change the reason at the source rather than add a side channel. Every consumer of the string was checked. No client branches on it — the desktop's only caller of
/v1/assigndiscards the response body unread (cancelUnreadResponseBody) and keys its retry and backoff on the HTTP status plusRetry-After; mobile never calls the endpoint. No Terraform log-based metric, alert policy or dashboard parses the reason or the rejection log line; Cloud Monitoring sees these only asassignment_5xx, which counts statuses. The shared contract packages encode no enum of these strings. The one consumer that does read the 503 body is the dev load harness, updated here. So the safer-looking option — keep the misleading wire value and carry the truth only in a side field — would have bought nothing and left the wrong string in the logs, which is the actual problem.Why not a new optional field on the existing reason. That is the wire-compatibility rulebook's Rule 1 and is normally the right call, but it only helps a reader that opts in, and there are no readers. The misleading value would have stayed in the log line and in the body.
Why the cause is derived rather than passed down.
cellIsLive()answers a single boolean over three conditions. Rather than restructure it and every one of its ~10 callers to return a reason, the refusal path re-reads the two columns it needs. It runs once per rejection, on a path that is already refusing the request.Linked Issue
Fixes #
Visual Proof
N/A — this changes a server-side log line and an HTTP error body that no client renders or reads.
Testing
cloud/apps/relay/src/assignment-home-cell-unavailable.test.ts(new) covers the branch end to end against the store: a not-ready home cell, a stale heartbeat, and a drained cell each produce the new reason with the right cause; a full fleet still producesrelay_capacity_exhausted; and a host whose unavailable cell needs no fence is still rehomed rather than rejected. Reverting only the newthrowreddens exactly the three cause assertions and leaves the two capacity/rehome controls green, so the tests discriminate the fix rather than the setup.assignment-rejection-logging.test.tscovers the director: the new reason returns 503, logslane=placement hinted=true reason=relay_home_cell_unavailable cause=not_ready cell=…and contains no capacity wording; and a hinted grant served by the placement lane is logged.Run locally on macOS:
cd cloud/apps/relay && pnpm typecheck— clean.cd cloud/apps/relay && ORCA_RELAY_TEST_POSTGRES_URL=… pnpm test— 91 files passed, 846 passed, 1 skipped. The Postgres-backed suites were run against a real Postgres 16, not skipped.cd cloud && node --test dev/scripts/relay-load-*.test.mjs dev/scripts/deploy-relay-gce-multi-target.test.mjs— 162 passed, 0 failed.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Retry-Afterheader and the retry policy are unchanged.reason=/cause=metric is now possible where it was not before, but this PR adds none.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)