Repository navigation
test(relay): check invariant 4 (one demotion winner) in the step-5 simulation - #28696
Conversation
…mulation Every demotion now names its winner (the newer booking, or the row). The model flags a director that names a different winner for a divergence another already named, and a host whose two seats are each demoted for the other. A fault where directors break level ties by their own cell order shows the check fires. Violations are capped per invariant so one flood cannot hide another class. Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to
|
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:
c8af369e-15b4-4747-97da-a65d3f5ec707
📒 Files selected for processing: 2
cloud/apps/relay/src/reserve-placement-simulation.test.tscloud/apps/relay/src/reserve-placement-simulation.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.
…all invariants on contested ties A reserve seat the booking director's map had not seen (joined, then half-open within a poll) is never superseded and has no lease to re-check, so it lasts until the cell's control silence close (75 s + one 15 s ping). Invariant 3 now uses that bound for such seats, and the level-divergence config asserts every invariant. Stale maps now judge a divergence another director already demoted, so the config's "contested" counter (divergences judged by two or more directors) is the case invariant 4 guards. The silence-close constant now matches production (90 s, not 100 s). Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
7e619916-3692-4d6f-aaea-895f2a95a76f
📒 Files selected for processing: 2
cloud/apps/relay/src/reserve-placement-simulation.test.tscloud/apps/relay/src/reserve-placement-simulation.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.
…el contests A reconcile whose map has not seen another director's demotion still demotes in production, which raises its epoch floor; the model now does too. The contested counter counts only same-epoch pairs, the only ones invariant 4 can split. The keep-this-seat rule is one helper. Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
…fault Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
…gment, and bound duplicates by placement records alone Claude-Session: f2fe8cb5-4467-4a25-8aab-98598b70791f
ELI5
The relay test that replays many desktops connecting through five directors at once is supposed to check the design's safety rules. Rule 4 says: when a desktop ends up connected to two cells, every director must agree on which connection survives, so the desktop never loses both. Nothing in the test checked that rule. Now it does, and a deliberately broken version of the rule makes the test fail.
Building the test for rule 4 also showed that rule 3 (an old duplicate connection closes quickly) is promised too strongly in the design. Safety still holds; the promise needs a longer time limit in one case. This PR models that case and the design doc needs the same correction.
What Changed
localTieBreak, makes each director break a same-number tie by its own cell order instead of the row. The fault table shows rule 4 then fires.host-session-registry.tsheartbeat) plus one 15 s ping (RELAY_PROTOCOL_LIMITS.controlPingIntervalMs), 90 s, not the 100 s the model used before.relay-server.tscallsraiseEpochFloor). Rule 8 still holds in every run.Rule 3 finding: a dead control, not a second owner
With the new settings and no fault, the old rule-3 check failed. The sequence also happens in production:
reserve-assignment.ts, around lines 395-417) only closes the seats that director's map holds, so A is never told to close.This is a dead connection, not two owners: a desktop holds one control connection at a time (it left A when it connected to B), and the sticky answer only names the newest number, so nothing routes to A. Safety holds; only the time bound is wrong.
The model's rule 3 now says: a seat the booking director's map held at booking time closes within that director's poll lag plus a round trip (as before); a seat that map had not seen gets the silence-close bound (90 s plus round trips). With that bound every rule holds in every run, and turning the narrowing off makes rule 3 fire again in all three seeds.
The design doc needs two different corrections. Section 9, invariant 3 needs a wording fix only: it calls the old seat a live duplicate, but a half-open seat arguably is not live. Section 3.5 describes the right mechanism (supersede at placement, silence close otherwise); what it lacks is the time bound for a seat the booking director had not seen, which is the silence close (up to 90 s plus round trips), not the poll lag plus a round trip.
Optional production improvement, not in this PR: when a director's feed shows a reserve seat outranked by a join it already knows on another cell, it could close that seat then, instead of waiting for the silence timeout.
Why
The rule-4 check sits where directors judge duplicates: at placement (the newer booking wins) and in the ledger reconcile (the row wins). Those are the only places that name a winner, so recording it there covers every judgement without a second model of the rules. A reconcile whose map is behind still records its judgement even though the cell would drop the duplicate close; that is what a real director does, since it reads its map, not the cell. I considered flagging any desktop whose seats are all closed, but that is normal when a third, newer seat outranks both, so the check works on pairs instead.
Linked Issue
Follows #27040.
Visual Proof
N/A: test-only change to a simulation, no UI or runtime behaviour.
Testing
vitest run src/reserve-placement-simulation.test.ts --maxWorkers=4incloud/apps/relay: 28 of 28 pass, including the contested-tie runs (seeds 11, 23, 47, all rules) and the rule-4 fault.tsc --noEmitreports no errors in the changed files.AI Disclosure
Review
Two Opus reviews (design, bugs). Fixed: rule-3 bound narrowed for unseen seats; contested count limited to same-number pairs and required only on the new settings; map-judged closes raise the epoch floor; tie-break rule factored into one helper; main test retitled "invariants 1-8".
Agent skill upstream boundary
Notes
Test-only; no production code, wire, SSH or platform impact.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)