Repository navigation
feat(relay): dark shadow seat directory poller on directors (step 3) - #26810
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe 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 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)✅ Passed checks (4 passed)✨ 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.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
eee37ede-038e-4285-8a6d-c3145351f7f6
📒 Files selected for processing (2)
cloud/apps/relay/src/shadow-seat-directory.test.tscloud/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()}` }, |
There was a problem hiding this comment.
🩺 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
| directory.apply(cell.cellId, body.data, now()) | ||
| return body.data.more === true && directory.cellState(cell.cellId)?.status === 'live' |
There was a problem hiding this comment.
🩺 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
d5354fe to
72f5fab
Compare
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.
72f5fab to
793bb07
Compare
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
shadow-seat-directory.tson directors: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).host -> seatsfrom the first full snapshot, then fromjoin/leave/drain-onlychanges. Aleaveonly 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, markedresync.enabled = 0) takes no new hosts but still holds the ones it has, so it must be polled. The list isRelayAssignmentStore.seatFeedCells(), which uses the store's ownheartbeatTtlMsandrequireLiveCells. That keeps one liveness rule for placement,resolveand the map, and each cell carries its heartbeat expiry for the compare. The poller starts insidecreateRelayServerwith 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.fullsnapshot only when it holds no valid cursor: first poll, after a 404, after a sequence gap, or after a mislabelled reply. Every other poll sendssince=<incarnation>:<seq>. The cell also answersfullon its own when the cursor is older than its 20k change ring or the incarnation changed.orca_relay_shadow_seat_summaryonce a minute (cell statuses, seats, hosts, recently-left size, cells whose reportedcounts.seatsdiffers from the map (expected 0), cells whosecontrolscount is below the map (a cross-check: closing sockets lag up to ~30 s), oldest live poll age, complete).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 existingORCA_RELAY_REHOME_AUDIENCE.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.directors.jsonobject (§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.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.tswith stub cells: off unless a director has cells and the rehome audience; full snapshot first, then deltas from the cursor; incarnation change resyncs and recordsresyncleaves; 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
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-seatsfrom 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
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)