Skip to content

feat(relay): directors place on reserve-mode cells from memory (off) - #27047

Merged
Jinwoo-H merged 1 commit into
mainfrom
relay-step5-director
Oct 10, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
relay-step5-director

Conversation

@Jinwoo-H

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

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​422 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​421
Prod 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​836 $\color{#cf222e}{\Huge{\mathbf{−}}}$​49 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​787

ELI5

This is the director half of "desktops connect without the database". When a cell reports that it is switched on, a director answers a reconnecting desktop from memory, and books new desktops on that cell by asking the cell to hold a seat. Every other desktop keeps today's path. Off by default.

What Changed

All behind ORCA_RELAY_RESERVE_PLACEMENT (off default, dry-run, on; director deploy) and, per request, only for cells whose applied admitMode is reserve (the per-cell switch, read from each cell's seat feed):

  • Sticky from memory. A reconnect for a host the map shows seated (active) or recently left (≤ 10 min, not for a drain or demotion) on a switched-on cell that is polled within 3 s, general and not draining (and, for a leaver, under its ceiling) is answered at the same epoch: no sticky slot, no database read, no row lock. If the cell restarted since that seat, it is re-booked first (sticky: true, no intake token).
  • Fresh placement. Pool choice weighted by free seats (zero unless every database-mode cell in the region reports a ceiling). Power of two choices, a 1/5 intake share, at most 3 reserve calls (batched per cell, 5 ms / 64 items, 1 s timeout), re-mint above seated-newer; then today's database path if the region has database-mode cells, 503 + Retry-After 1–10 s if switched-on cells have seats but no budget, else a spill to us-central1, else the database path.
  • Who owns which host. A host the map last saw on a database-mode cell keeps today's path, sticky included; only if today's sticky declines is its fresh placement offered to the reserve pool (a new placeFresh hook in assign, outside any transaction). Every database mint now takes the map's highest epoch as a floor.
  • Epochs. max(seat, booking, recently-left) + 1; a host the map never saw costs one primary-key read, and gets 503 while the database is down.
  • Startup. Until every live cell has answered once, at most 30 s, the director answers 503 Retry-After: 1 (only with the switch on and some cell switched on).
  • Demotion. For a host seated on two cells where one is switched on, a seat outranked for 10 s (5 min if a seat is drain-only) gets POST /internal/demote {epoch, joinedAt}, once per minute at most; the winner is reported for the ledger writer.
  • dry-run. For each real fresh placement, the would-be cell is asked to check a booking without making it; outcomes and p50/p99 latency are logged per minute. Never changes an answer (the design's reserve-latency gate).
  • The seat feed parser reads the cell PR's new fields (bookings, units, ceiling, intake, reserve entries, reservedBy, recentlyLeft), leniently.

Why

Design §3–§6 rev 2: every director places and the cell decides, with no placer services. 84–94 % of last night's refused reconnects were desktops queueing to re-check, in the database, the cell they were already on; the sticky answer from memory removes that path for switched-on cells.

Deviations from the design.

  • The startup gate is in the app (503 for ≤ 30 s) rather than a Cloud Run startup probe: it needs no Terraform change and only applies when the switch is on.
  • A drain-only seat in a duplicate gets a 5-minute grace (the design says "drain or rehome grace"; that is the upper bound of either).
  • The database-pool exclusion of switched-on cells is in the census PR (fix(relay): database sweeps and ops reads skip reserve-mode cells (step-5 census, inert) #27046), which must merge before any flip.

Linked Issue

N/A (internal relay redesign, step 5).

Visual Proof

N/A: server-side, no UI.

Testing

  • reserve-assignment.test.ts: off and no-switched-on-cell keep today's path; the startup gate and its cap; a reconnect answered from memory with no booking and no database read; a restarted cell re-booked first; a drained leaver booked elsewhere above every known epoch; a host last seen on a database-mode cell keeps today's path with its floor; one row read for a never-seen host, 503 with the database down; pacing; one demotion per duplicate; dry-run books nothing.
  • cell-reserve-client.test.ts: batching, answer mapping, every failure shape reads unreachable.
  • The full relay suite passes locally; today's assign calls are byte-identical when the switch is off (existing call-shape tests unchanged).

Stacked on #27043 (one chain: #27038 → #27041 → #27043 → this → #27048 → #27046 → #27096), so the relay-server.ts and app.ts changes it shares with the cell PRs are merged once here.

@Jinwoo-H
Jinwoo-H force-pushed the relay-step5-director branch 2 times, most recently from d94b447 to d4853e9 Compare October 10, 2026 01:06
@Jinwoo-H
Jinwoo-H changed the base branch from relay-step5-core to relay-step5-rollback October 10, 2026 02:39
@Jinwoo-H
Jinwoo-H force-pushed the relay-step5-rollback branch from 9e4cc29 to 2e86afa Compare October 10, 2026 06:11
Rebased onto main as one commit after its parent squash-merged.
@Jinwoo-H
Jinwoo-H force-pushed the relay-step5-director branch from b6ee5a7 to 71aa37b Compare October 10, 2026 06:18
@Jinwoo-H
Jinwoo-H changed the base branch from relay-step5-rollback to main October 10, 2026 06:18
@Jinwoo-H
Jinwoo-H merged commit 5493c5e into main Oct 10, 2026
28 of 46 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