Skip to content

feat(relay): dark shadow seat directory poller on directors (step 3) - #26810

Merged
Jinwoo-H merged 1 commit into
mainfrom
relay-step3-director-seat-poller
Oct 9, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
relay-step3-director-seat-poller

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​491 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​491
Prod 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​610 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​608

ELI5

Step 5 of the relay redesign wants directors to know, from memory, which cell each desktop is connected to, instead of asking the database. Before we trust that, we build the memory copy and watch it for a week next to the database. This PR adds the part of the director that would build that copy. It ships switched off and polls nothing until an operator names cells.

What Changed

  • Before: directors learn where a desktop is only from the database.
  • After (off by default): a new shadow-seat-directory.ts on directors:
    • Polls GET /v1/admin/cell-seats?since=<incarnation>:<seq> on each switched-on cell once a second (single flight per cell, 2 s timeout), with the directors' existing rehome identity token (reused for 10 minutes instead of minted per poll).
    • Builds host -> seats from the first full snapshot, then from join / leave / drain-only changes. A leave only removes the seat of the same generation, so a newer connection that joined first survives. A new cell incarnation, a sequence gap, or a delta against a cursor it does not hold triggers a full resync. Seats dropped by a resync go to the recently-left memory, marked resync.
    • Keeps a recently-left memory (24 h, at most 100k hosts, 4 entries each) with close codes.
    • Liveness: a timeout, 5xx, or malformed body marks the cell unverifiable and keeps its seats. A 404 marks it no feed (an old cell, or one without the rehome credential). Neither is read as "the desktops left".
    • "Complete" only after every live cell has answered once since start (the step-5 startup gate, measured here). Live means: heartbeat fresh (45 s), capacity above 0, and not roll-isolated. Every cell is still polled, because a draining or isolated cell still has seated hosts. But a dead, empty or fenced cell cannot hold the measurement back.
    • Re-reads every cell, enabled or not, every 30 s, with heartbeat, capacity and isolation. An existing-only cell (enabled = 0) takes no new hosts but still holds the ones it has, so it must be polled. The list is RelayAssignmentStore.seatFeedCells(), which uses the store's own heartbeatTtlMs and requireLiveCells. That keeps one liveness rule for placement, resolve and the map, and each cell carries its heartbeat expiry for the compare. The poller starts inside createRelayServer with that store. If that read fails, it keeps the last list and retries after 1, 2, 4 ... seconds, capped at 30 s. A database stall is then not asked once a second on the director's 3-connection pool.
    • The director asks for a full snapshot only when it holds no valid cursor: first poll, after a 404, after a sequence gap, or after a mislabelled reply. Every other poll sends since=<incarnation>:<seq>. The cell also answers full on its own when the cursor is older than its 20k change ring or the incarnation changed.
    • Logs orca_relay_shadow_seat_summary once a minute (cell statuses, seats, hosts, recently-left size, cells whose reported counts.seats differs from the map (expected 0), cells whose controls count is below the map (a cross-check: closing sockets lag up to ~30 s), oldest live poll age, complete).
  • Switch: ORCA_RELAY_SHADOW_SEAT_FEED_CELLS = unset/empty (default, polls nothing), all, or a comma list of cell ids. It also needs the director's existing ORCA_RELAY_REHOME_AUDIENCE.
  • Nothing reads the map yet. The comparison and the admin lookup are separate follow-up PRs.

Why

Step-3 design DESIGN-step3-and-step5-prep-2026-10-09.md §3.1-3.2 and §6 PR 9. Jinwoo's decision Q6: the feed reuses the directors' existing rehome credential, so no cell gains a credential and no Terraform or startup-script change is needed.

  • The design's long-term switch is the Cloud Storage directors.json object (§2.1/§3.6). That flag channel is a separate PR. Until it exists, an env var gives the same "off until named, one cell at a time" ramp, and turning it off is a director revision.
  • Lenient parsing (unknown fields and change kinds ignored) follows docs/reference/remote-wire-compatibility.md: directors and cells run mixed versions.

Fixes # (no issue; relay step-3 build, approved by Jinwoo 2026-10-09)

Visual Proof

N/A: background director code with no UI, switched off.

Testing

  • pnpm --filter @orca-cloud/relay test (non-Postgres suites), tsc --noEmit, the floating-promise census.

  • New shadow-seat-directory.test.ts with stub cells: off unless a director has cells and the rehome audience; full snapshot first, then deltas from the cursor; incarnation change resyncs and records resync leaves; sequence gap asks for a full snapshot next poll; short page resumes from its last change; older-generation leave ignored; timeout and 503 keep seats as unverifiable with the cursor intact; 404 reads as no feed and counts toward complete; malformed or mislabelled body is unverifiable; unknown change kinds accepted; only listed cells polled; recently-left bounded at 100k hosts; one identity token across polls.

  • 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 copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Load once switched on: 1 small request per second per polled cell per director instance. That is ~5/s per cell, and ~130/s fleet-wide at 5 directors × 26 cells.

Load-balancer logging. Each poll goes through the cell's load balancer, which logs every request. At full ramp that is ~130 lines/s, or ~11M log lines a day. I propose a separate, targeted Terraform follow-up that excludes /v1/admin/cell-seats from load-balancer logging, or samples it (for example a logging exclusion filter on that path). The director's own once-a-minute summary already covers feed health. Ramping a few cells first keeps the volume small until that lands. Memory at full fleet: ~23k seats + up to 100k recently-left entries (design estimate 20-30 MB). The endpoint itself is built on the cell side in a separate PR. Until a cell runs it, the director records that cell as "no feed". No SSH, desktop, or mobile impact.

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)

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: f5d9922e-75b9-4ee7-b553-f769943ddeab

📥 Commits

Reviewing files that changed from the base of the PR and between f43f1ae and e9742b7.


📒 Files selected for processing (2)
  • cloud/apps/relay/src/shadow-seat-directory.test.ts
  • cloud/apps/relay/src/shadow-seat-directory.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

The relay configuration now accepts a selection of shadow seat feed cells. A new directory tracks seat snapshots, deltas, cell status, and recently departed seats. A poller discovers selected cells, requests their feeds, and applies valid responses. The relay starts the poller and stops it during shutdown. Tests cover directory updates, polling, failure handling, and cell-list changes.


Priority: ➖ Normal

Merge Risk: 🔵 Low · up to e9742

The shadow seat directory is disabled by default and nothing reads its output yet. The remaining concerns are minor edge cases around shutdown and a pagination cursor, so the risk is bounded and the PR is mergeable with follow-up.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check Passed The title clearly identifies the main change: a director-side shadow seat directory poller. It is concise and specific.
Description check Passed The description is detailed and covers the change, rationale, behavior, testing, performance, and compatibility impact. The linked issue field has no issue number, and the full lint, typecheck, test, …


✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eee37ede-038e-4285-8a6d-c3145351f7f6
📥 Commits

Reviewing files that changed from the base of the PR and between 8213197 and bdb7f8d.

📒 Files selected for processing (2)
  • cloud/apps/relay/src/shadow-seat-directory.test.ts
  • cloud/apps/relay/src/shadow-seat-directory.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

const since = directory.since(cell.cellId)
if (since !== undefined) url.searchParams.set('since', since)
const response = await fetchImpl(url, {
headers: { authorization: `Bearer ${await identity()}` },

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Check stopped after each pending operation.

If stop() runs while identity() is pending, this code can start a request after shutdown. If stop() runs while response.json() is pending, this code can still apply the page and request another one. Recheck stopped before fetchImpl and before directory.apply. Reading a response body is asynchronous. (developer.mozilla.org)

Based on learnings, an async poll must check for a state reset after an await and before writing its result.

Also applies to: 481-482

Source: Learnings

Comment on lines +481 to +482
directory.apply(cell.cellId, body.data, now())
return body.data.more === true && directory.cellState(cell.cellId)?.status === 'live'

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Reject a cut page that does not advance the cursor.

If a cell returns more: true without advancing directory.since(cell.cellId), the next request asks for the same page. Each later poll can repeat five requests while the cell remains live. Compare the cursor before and after applying the page. If it does not advance, mark the cell unverifiable instead of following the page.

Based on learnings, pagination must reject more: true when the cursor does not advance.

Source: Learnings

@Jinwoo-H
Jinwoo-H force-pushed the relay-step3-director-seat-poller branch from d5354fe to 72f5fab Compare October 9, 2026 21:01
Directors can poll each cell's read-only seat feed (#26803) once a second
and keep an in-memory map of which host is seated on which cell, plus a
bounded 24 h recently-left memory. Off unless ORCA_RELAY_SHADOW_SEAT_FEED_CELLS
names cells. Applies a change at or above the seat's generation, follows
cut pages, resyncs on a gap or new incarnation, and checks the map against
counts.seats. A 404 reads as no feed; timeouts and errors keep the last
seats as unverifiable. The cell list is every cell (an existing-only cell
still seats hosts), from RelayAssignmentStore.seatFeedCells with
placement's liveness rule; completeness waits only on live cells, and a
failed list read backs off. Nothing reads the map yet.
@Jinwoo-H
Jinwoo-H force-pushed the relay-step3-director-seat-poller branch from 72f5fab to 793bb07 Compare October 9, 2026 22:25
@Jinwoo-H
Jinwoo-H merged commit f514cb2 into main Oct 9, 2026
23 checks passed
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