Skip to content

feat(relay): read-only seat feed on cells for the directors' shadow directory - #26803

Merged
Jinwoo-H merged 5 commits into
mainfrom
relay-step3-cell-seat-feed
Oct 9, 2026
Merged

Jinwoo-H merged 5 commits into
mainfrom
relay-step3-cell-seat-feed

Conversation

@Jinwoo-H

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

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

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

  • Before: a cell knows its connected desktops only in memory; the only shared record is the database.
  • After: a cell also keeps a short in-memory log of seat changes (a desktop joined, left, or was told to move) and serves it at GET /v1/admin/cell-seats. No user-visible change, no database access, no new environment or startup-script setting.
  • Mechanism: a new ring buffer (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 exactly counts.seats. (counts.controls can briefly run below it while a socket's close handshake is in flight.)
  • Auth: checked once per poll by the route. The admin middleware skips this path, as it does for the heartbeat routes. The identity is the directors' existing rehome identity (verifyRegionalRehomeToken, the check /v1/admin/host-drain uses). Only cells that already hold the rehome env pair serve it; others answer 404 seat_feed_unavailable. No cell gains the pair, so rehome turns on nowhere new (review B1). A test pins that regionalRehomeProtocol still comes from the existing env alone.

Endpoint contract (v1, stable; director side builds against this)

GET /v1/admin/cell-seats[?since=<incarnation>:<seq>]
Authorization: Bearer <Google ID token: audience = ORCA_RELAY_REHOME_AUDIENCE
                       (<base>/v1/admin/host-drain), email = director runtime SA>

200 {
  v: 1, cellId, incarnation, at, draining,
  counts: { controls, seats },
  // seats: the log's own view; a reader that applied every change holds exactly this many.
  // controls drops when a socket starts closing (ws close handshake), seats when its close lands.
  seq,                          // cursor for the next poll
  // exactly one of:
  changes: [{ seq, kind: 'join'|'leave'|'drain-only'|'active', userId, relayHostId,
              epoch, generation, state?: 'active'|'drain-only' /* join only */,
              closeCode? /* leave only */, at }],
  more: boolean,                // with changes: page cut at 2,000, poll again at once
  full: [{ userId, relayHostId, epoch, generation, state, joinedAt }]
  // later, additive: flagsApplied: { generation, flags } (the flag-channel PR)
}
400 invalid_request            // malformed since
401 invalid_token
404 cell_only | seat_feed_unavailable   // director, or a cell without the rehome pair

Reader rules: seqs in changes are contiguous from since+1; ignore unknown fields and unknown kinds; apply a change only if its generation is >= the seat's (a superseded generation's socket can close after its successor joined); a drain-only or active for a host with no seat is a no-op (active lifts a drain-only the host cleared itself, by refreshing an expired token); on full, 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: real HostSessionRegistry with fake sockets: first poll equals counts.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 run in cloud/apps/relay: 91 files passed, 32 skipped (Postgres suites); tsc --noEmit clean.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

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

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

  • 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)

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

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Review in 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: 2eebe454-d256-4402-a568-25113ceec51b

📥 Commits

Reviewing files that changed from the base of the PR and between 0e05061 and 8e55ebe.


📒 Files selected for processing (3)
  • cloud/apps/relay/src/app.ts
  • cloud/apps/relay/src/cell-seat-feed-route.ts
  • cloud/apps/relay/src/cell-seat-feed.test.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.



📝 Walkthrough

Walkthrough

The 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 GET /v1/admin/cell-seats endpoint. The route validates availability, authorization, and cursor format, then returns seat data with cell and runtime metadata. Tests cover log pagination, session events, endpoint responses, and runtime protocol reporting.


Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 8e55e

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)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: adding a read-only seat feed on relay cells for directors.
Description check Passed The description is mostly complete and covers the user impact, implementation, authentication, endpoint contract, rationale, testing, compatibility, and checklist items. The required linked issue is m…
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.


  • Fix all pre-merge checks with AI
✨ 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: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7406e51e-e248-4d71-bea7-352c1cde167c
📥 Commits

Reviewing files that changed from the base of the PR and between 6ef42ad and bc51ef6.

📒 Files selected for processing (7)
  • cloud/apps/relay/src/app.ts
  • cloud/apps/relay/src/cell-seat-feed-route.ts
  • cloud/apps/relay/src/cell-seat-feed.test.ts
  • cloud/apps/relay/src/cell-seat-log.test.ts
  • cloud/apps/relay/src/cell-seat-log.ts
  • cloud/apps/relay/src/host-session-registry.ts
  • cloud/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.

Jinwoo-H added a commit that referenced this pull request Oct 9, 2026
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.
Jinwoo-H added a commit that referenced this pull request Oct 9, 2026
…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.
Jinwoo-H added a commit that referenced this pull request Oct 9, 2026
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.
@Jinwoo-H
Jinwoo-H merged commit 37d2154 into main Oct 9, 2026
23 checks passed
Jinwoo-H added a commit that referenced this pull request Oct 9, 2026
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 added a commit that referenced this pull request Oct 9, 2026
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 added a commit that referenced this pull request Oct 9, 2026
…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.
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