Skip to content

fix(relay): stop reporting an unavailable home cell as exhausted capacity - #21518

Merged
Jinwoo-H merged 1 commit into
mainfrom
fix/relay-home-cell-unavailable-reason
Sep 18, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
fix/relay-home-cell-unavailable-reason

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​195 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110 $\color{#cf222e}{\Huge{\mathbf{−}}}$​27 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​83

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

[orca-relay] assignment rejected route=assign lane=placement hinted=true reason=relay_capacity_exhausted host=…

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:

[orca-relay] assignment rejected route=assign lane=placement hinted=true reason=relay_home_cell_unavailable host=… cause=not_ready cell=asia-1

cause is one of draining, booting, unheard (heartbeat older than the TTL) or not_ready (heartbeat fresh, readiness false). Genuine headroom exhaustion is untouched and still reads relay_capacity_exhausted.

The mechanism. assignOnce() in assignment-store.ts has a branch that is only reachable when the host's current cell failed cellIsLive() — 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 throwing relay_capacity_exhausted, having consulted no capacity counter at all. It now throws RelayHomeCellUnavailableError, carrying the cell id and which of cellIsLive()'s conditions failed; the director logs reason, cause and cell and returns the new reason in the same retryable 503.

Because the sticky lane's resolve() also returns null for a cell that is not live, these requests always arrive as lane=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/assign discards the response body unread (cancelUnreadResponseBody) and keys its retry and backoff on the HTTP status plus Retry-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 as assignment_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 produces relay_capacity_exhausted; and a host whose unavailable cell needs no fence is still rehomed rather than rejected. Reverting only the new throw reddens 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.ts covers the director: the new reason returns 503, logs lane=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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Backwards compatibility: the new reason reaches old clients in a 503 body they discard unread, so mixed director versions during a roll are indistinguishable to them. The HTTP status, the Retry-After header and the retry policy are unchanged.
  • Mobile: not affected; mobile does not call the director's assignment endpoint.
  • Monitoring: no alert or log-based metric keys on the reason string, so none needed updating. A reason=/cause= metric is now possible where it was not before, but this PR adds none.
  • Performance: one extra two-column read, on the rejection path only.
  • Security: the log line adds a cell id, which already appears on grant lines; the host id remains digested.
  • Cross-platform and SSH are not in scope — this is server-side relay code.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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.
@coderabbitai

coderabbitai Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 3f160654-1ab6-42c4-b4f4-f76eb66f32f1

📥 Commits

Reviewing files that changed from the base of the PR and between fc3a5d7 and 0f4d147.

📒 Files selected for processing (6)
  • cloud/apps/relay/src/app.ts
  • cloud/apps/relay/src/assignment-home-cell-unavailable.test.ts
  • cloud/apps/relay/src/assignment-rejection-logging.test.ts
  • cloud/apps/relay/src/assignment-store.ts
  • cloud/dev/scripts/relay-load-connection-failure.mjs
  • cloud/dev/scripts/relay-load-control-peer.mjs

Included review availability: Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The 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 503 with detailed rejection logs. Reconnect grants include placement-lane and cell details. Relay load scripts classify the new error code separately. Tests cover assignment behavior, logging, rehoming, and load classification.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 0f4d1

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, implementation, rationale, testing, compatibility, and operational impact. However, the required Linked Issue section is incomplete because it contains only "Fixe… Add the complete linked issue reference after "Fixes #". For example: "Fixes #1234".
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 6 files. 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 clearly and concisely describes the main change: unavailable home cells no longer report as exhausted capacity.
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.
Full details: Description check

Explanation

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog 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.

✅ 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 assignOnce branch that refuses a host on a non-live, fenced-required home cell now throws RelayHomeCellUnavailableError (relay_home_cell_unavailable) instead of a plain Error('relay_capacity_exhausted'), carrying the cell id and a draining/booting/unheard/not_ready cause.
  • Cause derivation. homeCellUnavailableCause() re-reads relay_cells + relay_cell_runtime and mirrors cellIsLive()'s conditions; the TTL comparison and readiness fallthrough line up exactly.
  • Director logging/response. isRelayAssignmentUnavailableError includes the new message, homeCellRejectionDetail appends cause=/cell= to the rejection line, and the same retryable 503 is returned.
  • Sweep and harness. evacuateDeadCells keeps 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 164c714 into main Sep 18, 2026
27 checks passed
@Jinwoo-H
Jinwoo-H deleted the fix/relay-home-cell-unavailable-reason branch September 18, 2026 21:55
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.

1 participant