Skip to content

feat(relay): step-5 reserve core: the cell's booking book and the director's placer (inert) - #27038

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

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

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{+}}}$​287 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​287
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​454 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​454

ELI5

Step 5 takes desktop connections off the database: a director asks a cell to hold a seat, and the cell says yes or no itself. This PR adds only the two decision-makers as pure code — the cell's booking book and the director's placer — with nothing calling them yet.

What Changed

  • cell-reserve-contract.ts: the v1 wire for POST /internal/reserve (batched items, dryRun, per-item ok / full / intake / draining / off / seated-newer {epoch}) and POST /internal/demote (names one seat by epoch and joinedAt). Readers are lenient: an unknown outcome counts as a no.
  • cell-reserve-book.ts: the cell's authority. One event loop makes "check cap and budget, then count the booking" atomic. A booking holds a connection unit until its hello consumes it or its 30 s TTL ends; a token bucket (burst 20) enforces the intake rate; a post-restart sticky re-booking skips the bucket but never the cap; a lower-epoch booking hands its unit to its successor.
  • reserve-placement.ts: the director's estimate. Candidates are switched-on, polled within 3 s, general, not draining, with an estimated seat and budget. Power of two choices, at most 3 reserve calls, re-mint above a seated-newer, then the database path, pacing (503 + Retry-After 1–10 s) or spill. Each director assumes 1/5 of each cell's intake and starts empty after a restart. Also the epoch mint and deterministic demotion: the newest cell-reported join wins (ties: higher epoch, then lower cell id); a seat is demoted once it has been outranked for the grace period, so a host flapping across cells cannot keep an old seat alive.

No behaviour changes: nothing imports these modules yet.

Why

Both sides must be exactly the code the simulation (next PR) drives, so they are pure, I/O-free modules. Design: DESIGN-step5-placer-2026-10-09.md rev 2 (no placer services).

Linked Issue

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

Visual Proof

N/A: server-side, no UI.

Testing

  • Automated tests added: cell-reserve-book.test.ts, reserve-placement.test.ts (cap, intake refill, seated-newer, sticky, consume-once, off/draining/dryRun, three-try cap, re-mint, pacing bound, candidate filters, own-booking count, pool share, demotion order).
  • pnpm typecheck and the relay suite pass locally.

Notes

Ships dark. Stack: this PR → simulation, cell reserve mode, director placement, ledger writer, census.

Stacked on #27057 (so the cell-flags.ts switches from both land without a conflict). Merge order: #27049, #27057, then this stack.

@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: 2e966aa8-5202-48ae-95a0-854a407d2e00

📥 Commits

Reviewing files that changed from the base of the PR and between 530cef8 and b989459.


📒 Files selected for processing (2)
  • cloud/apps/relay/src/reserve-placement.test.ts
  • cloud/apps/relay/src/reserve-placement.ts

💤 Files with no reviewable changes (1)
  • cloud/apps/relay/src/reserve-placement.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.



📝 Walkthrough

Walkthrough

Adds v1 reservation and demotion schemas, cell booking and intake management, and reserve placement logic. Placement selects eligible cells, makes up to three reserve calls, and returns a database fallback or pacing result when placement does not succeed. The change also adds reserve-pool share calculations, epoch minting, and tests for reservation and placement behavior.


Priority: ⬇️ Low

Merge Risk: 🔵 Low · up to b9894

The placement helper has a failure path that should be fixed before it is connected to live requests. No production caller was found, so current live traffic is not affected.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 5 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 reserve core, the cell booking book, and the director placer. It also indicates that the modules are inert.
Description check Passed The description covers the purpose, implementation scope, rationale, testing, visual proof, and runtime impact. The missing linked issue is acceptable because the PR is identified as an internal redes…


  • 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: 3cb5641d-8a9e-4d78-ba16-c676b7022f08
📥 Commits

Reviewing files that changed from the base of the PR and between f434e43 and 530cef8.

📒 Files selected for processing (2)
  • cloud/apps/relay/src/reserve-placement.test.ts
  • cloud/apps/relay/src/reserve-placement.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.

calls += 1
const answer = await input.reserve(cell.cellId, epoch)
if (answer.outcome === 'ok') return { kind: 'placed', cellId: cell.cellId, epoch, calls }
this.uncountBooking(cell, countedAt)

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 | 🟠 Major | ⚡ Quick win

Roll back bookings when a reserve call rejects.

If input.reserve rejects on a transport failure, place skips uncountBooking and never reaches database fallback. The failed attempt also remains in the seat estimate until it expires or a poll clears it. Catch the rejection, roll back that attempt, and handle it as an unreachable outcome. Add a rejection case to the placement tests.

@Jinwoo-H
Jinwoo-H changed the base branch from main to relay-cell-switches-fence-timeout October 10, 2026 02:02
@Jinwoo-H
Jinwoo-H force-pushed the relay-cell-switches-fence-timeout branch from 1368e38 to e505a90 Compare October 10, 2026 05:43
…ector's placer (inert)

Rebased onto main as one commit after its parent squash-merged.
@Jinwoo-H
Jinwoo-H changed the base branch from relay-cell-switches-fence-timeout to main October 10, 2026 05:54
@Jinwoo-H
Jinwoo-H merged commit 2f26788 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