Repository navigation
feat(relay): flip a reserve-mode cell back without disconnecting anyone (E-mix) - #27043
Conversation
b5609e3 to
6b8db7b
Compare
9c5b54c to
0577e93
Compare
6b8db7b to
5204a20
Compare
0577e93 to
6097f66
Compare
4825aef to
753e89d
Compare
5a86f72 to
bc52197
Compare
…ne (E-mix) Rebased onto main as one commit after its parent squash-merged.
9e4cc29 to
2e86afa
Compare
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to A rapid reserve-to-database transition can leave the cell’s reservation count below its active leases. The issue is localized, but the delta should have a stable owner before merging. Pre-merge checks |
|
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:
66fa23c6-61a1-4ed0-8cfc-48bfb3f982f0
📒 Files selected for processing (11)
cloud/apps/relay/src/app.tscloud/apps/relay/src/assignment-store.tscloud/apps/relay/src/cell-flags.tscloud/apps/relay/src/cell-reserve-dead-man.tscloud/apps/relay/src/cell-reserve-flip-back-postgres.test.tscloud/apps/relay/src/cell-reserve-rollback.blackbox.test.tscloud/apps/relay/src/cell-seat-feed-route.tscloud/apps/relay/src/cell-seat-feed.test.tscloud/apps/relay/src/host-session-registry.tscloud/apps/relay/src/relay-server.tscloud/apps/relay/src/test-fixtures/reserve-mode-cell.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
| private flushReregistrationCellDelta(state: NonNullable<HostSessionRegistry['reregistration']>): void { | ||
| if (state.cellDelta === 0 || state.cellWriteInFlight) return | ||
| const delta = state.cellDelta | ||
| state.cellDelta = 0 | ||
| state.cellWriteInFlight = true | ||
| void this.assignments | ||
| .commitCellReservationDelta(this.config.cellId, delta) | ||
| .catch(() => { | ||
| // Retried next tick: the leases exist, only the cell's count is behind. | ||
| state.cellDelta += delta | ||
| }) | ||
| .finally(() => { | ||
| state.cellWriteInFlight = false | ||
| }) | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Fix the lost-delta case when a newer flip back replaces the state.
reregisterMemoryControls() replaces this.reregistration with a new state object. The old state's in-flight commitCellReservationDelta can fail after that. Its .catch then adds the delta back to the old state.cellDelta. No timer flushes the old state, so the relay_cells.reserved_requests increment is lost. The same loss applies to any cellDelta that stays unflushed on the old state when it is replaced, and to activations that finish after the replacement and add their reservationDelta to the old state. Leases exist, but the cell counter stays below them until a reconcile runs.
The trigger is realistic. A switch flip goes reserve → db → reserve → db within a few seconds. Another trigger is a dead-man trip during an active pass.
Carry any unflushed delta into the new state when you replace it. Alternatively, keep cellDelta on the registry instead of on the per-pass state.
Proposed fix
- if (this.reregistration) clearInterval(this.reregistration.timer)
+ const carried = this.reregistration?.cellDelta ?? 0
+ if (this.reregistration) clearInterval(this.reregistration.timer)
this.reregistration = null
const state: NonNullable<HostSessionRegistry['reregistration']> = {
queue: [],
seen: new Set(),
inFlight: 0,
- cellDelta: 0,
+ cellDelta: carried,This fix does not cover late completions on the old state. To cover those, move the delta accumulator to a registry field.
ELI5
If anything looks wrong on a cell running step 5, an operator flips that one cell back to the database. This PR makes the flip back safe: no desktop is disconnected, and within about a minute the database again holds a record for every desktop on the cell.
What Changed
admitModewith the last one. On leavingreserveit voids its bookings and starts re-registering every control it admitted from memory (rules 1–3 of the parent PR), which has no database lease.activateControlfor each such control at 50 a second, with at most 20 in flight while the database is slow. A control whose row is not written yet (the ledger writer lags by up to a second) retries with backoff for about a minute; one whose row never names it (a duplicate the ledger did not follow) is logged asorca_relay_cell_reregistration_gave_upand keeps its connection.Why
Design §7 (E-mix): a flip back must take effect in seconds, disconnect nobody, and rebuild the cell's rows.
activateControlis the one path that already writes a control's lease, capability row and cell counter together, so reusing it rebuilds exactly what a database-mode admission writes.Deviation: the design ends with "one counter reconcile". It is not needed: memory-admitted controls never moved the cell counter, so each
activateControladds exactly the unit it owes. The existing reconcile is a multi-row locking transaction meant for drains, which a cell should not run on every flip.Linked Issue
N/A (internal relay redesign, step 5).
Visual Proof
N/A: server-side, no UI.
Testing
cell-reserve-rollback.blackbox.test.ts: a real cell on SQLite admits three hosts from bookings (no leases), flips todb, and one host's row lands only after the flip. All three sockets stay open; the leases equal the seat report (cell,control:<cell>:<generation>); a second flip back has nothing to do.The staging E-mix loop (10 flips each way under load, design §7) is a separate staging-harness item.