Repository navigation
feat(relay): read-only seat feed on cells for the directors' shadow directory - #26803
Conversation
…irectory Cells keep an in-memory log of host joins, leaves and drain notices and serve it at GET /v1/admin/cell-seats, authenticated with the directors' existing rehome identity. Nothing reads it yet.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughThe relay now maintains a bounded log of cell seat joins, drain-only transitions, and leaves. It provides snapshots and cursor-based changes through an authenticated Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk is established for the cell-seat endpoint. Merge readiness remains subject to normal checks. 🚥 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: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7406e51e-e248-4d71-bea7-352c1cde167c
📒 Files selected for processing (7)
cloud/apps/relay/src/app.tscloud/apps/relay/src/cell-seat-feed-route.tscloud/apps/relay/src/cell-seat-feed.test.tscloud/apps/relay/src/cell-seat-log.test.tscloud/apps/relay/src/cell-seat-log.tscloud/apps/relay/src/host-session-registry.tscloud/apps/relay/src/relay-server.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
Apply a change only at or above the seat's generation (a superseded generation's leave can follow its successor's join), take a join's state when sent, and follow a cut page (more: true) at once, up to five pages a poll.
… own seats counts.controls drops when a socket starts closing, but the leave lands only at its close event, so a full snapshot built from open sockets could disagree with a reader that applied every change. The log now keeps its own seats under the readers' generation rule and reports counts.seats.
…ontrols counts.seats (#26803) comes from the cell's own seat log under the same generation rule, so it equals the map exactly; controls drops when a close handshake starts, up to ~30 s before the leave lands, and is kept only as a below-the-map cross-check.
…d changes The heartbeat's auth-expiry drain-only and an auth refresh back to active changed session state without a feed entry, so a reader's seat state drifted from the cell's. Both now go through the log; the refresh is a new 'active' kind.
A token refresh after an auth-expiry drain-only now logs 'active'; at or above the seat's generation it sets the seat back to active, and with no seat it does nothing.
fixLevel, counts.splices, counts.enforcedUnits and counts.hardCap had no reader, so they leave before they become a cross-version contract. The admin middleware no longer verifies /v1/admin/cell-seats polls, which the route already gates on the rehome identity.
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.
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.
…26810) 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.
ELI5
Directors will soon keep their own in-memory map of which desktop is connected to which relay cell, so a later step can stop asking the database on every reconnect. To build that map they need each cell to say who is connected. This PR gives every cell a read-only list it can hand to a director. Nothing calls it yet.
What Changed
GET /v1/admin/cell-seats. No user-visible change, no database access, no new environment or startup-script setting.cell-seat-log.ts, 20,000 entries) is appended at three points in the host session registry: after a control connection is wired (join, including rebinds), when the live control socket closes (leave, with the close code; a rebind's retired socket is not a leave), when a seated host is told to drain or its token expires (drain-only), and when a token refresh makes it active again (active). A first poll, an unknown incarnation, or a cursor older than the ring gets a full snapshot of the log's own seats, kept under the same generation rule readers apply, so a reader that applied every change holds exactlycounts.seats. (counts.controlscan briefly run below it while a socket's close handshake is in flight.)verifyRegionalRehomeToken, the check/v1/admin/host-drainuses). Only cells that already hold the rehome env pair serve it; others answer404 seat_feed_unavailable. No cell gains the pair, so rehome turns on nowhere new (review B1). A test pins thatregionalRehomeProtocolstill comes from the existing env alone.Endpoint contract (v1, stable; director side builds against this)
Reader rules: seqs in
changesare contiguous fromsince+1; ignore unknown fields and unknown kinds; apply a change only if itsgenerationis >= the seat's (a superseded generation's socket can close after its successor joined); adrain-onlyoractivefor a host with no seat is a no-op (activelifts a drain-only the host cleared itself, by refreshing an expired token); onfull, replace the cell's seats. An old cell answers 404 (no route), which readers record as "no feed".Why
Design
DESIGN-step3-and-step5-prep-2026-10-09.md§2.2, PR 6 in §6. Reusing the rehome credential keeps this update image-only (Jinwoo, Q6): a dedicated credential would need a startup-script change and a template update at the slower 300 s pace. A ring plus full-resync is simpler than a durable log and loses nothing: a cell restart is a new incarnation, and the director resyncs.Linked Issue
N/A (internal relay redesign, step 3).
Visual Proof
N/A: server-only, no UI.
Testing
cell-seat-log.test.ts: cursor continue, ring overflow resyncs, cursor ahead of head resyncs, paging, cursor parsing.cell-seat-feed.test.ts: realHostSessionRegistrywith fake sockets: first poll equalscounts.seats; a socket mid-close stays seated until its close lands; join, drain-only, leave in order with close code; a rebind is a join without a leave; a superseded generation's leave carries the old generation; other incarnation resyncs; only the rehome identity is accepted; cell without the pair and directors answer 404; rehome protocol unchanged.vitest runincloud/apps/relay: 91 files passed, 32 skipped (Postgres suites);tsc --noEmitclean.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
Mixed versions: a new director polling an old cell gets 404; a new cell with an old director is never polled. Memory: at most 20,000 change entries (~2.6 MB). Not on the public wire. Rides the next image-only cell update; do not merge without the owner's go.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)