Repository navigation
feat(id): coordinator state machine + recovery for region-seam handoff (#3903) - #9000
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 23 minutes. View limit details
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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d38afd67ca
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if self.active_by_id(handoff_id).is_some() { | ||
| return Err(CoordinatorError::InvalidTransition( | ||
| "handoff id is already in flight for another entity", | ||
| )); |
There was a problem hiding this comment.
Reject handoff IDs used by completed or cancelled transfers
After completion or cancellation removes a handoff from active, this check allows its ID to be reused. For example, completing A→B and starting B→A with the same ID succeeds here, but the shard transfer ledgers retain historical IDs for deduplication (WorldCore::validate_entity_export and validate_entity_import), so the new crossing conflicts with the previous transfer and cannot progress. Track previously used IDs across terminal transitions and recovery, and reject reuse before appending another start.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in dc3f9af: the coordinator now tracks every handoff ID it has ever started (used_handoff_ids, populated in apply_started so live starts and journal replay share it). start_handoff rejects a previously used ID with InvalidTransition, and replay rejects a journal that reuses an ID with Integrity. Covered by handoff_ids_are_single_use_across_terminal_transitions and the model property test ID-uniqueness invariant.
| if let Some(receipt) = source_receipt { | ||
| self.observe_export(receipt, observed_at)?; | ||
| } | ||
| if let Some(receipt) = destination_receipt { | ||
| self.observe_import(receipt, observed_at)?; |
There was a problem hiding this comment.
Correlate reconciliation receipts with the requested handoff
When two handoffs are active, reconcile(A, receipt_for_B, ...) passes the receipt to observation methods that select their own active handoff using the receipt's ID. Consequently, reconciliation for A can journal progress for B and return an outcome for A without reporting any mismatch. Validate both supplied receipts against the requested handoff_id before applying either observation, so receipts from concurrent recovery queries cannot mutate another transfer.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in dc3f9af: reconcile now validates both supplied receipts against the requested handoff_id up front and returns ReceiptMismatch(handoff_id) before applying either observation, so a receipt for a concurrent handoff can no longer mutate it. Covered by reconcile_rejects_receipts_for_another_handoff.
| } | ||
| self.apply_started(entry); | ||
| Ok(()) |
There was a problem hiding this comment.
Validate replayed starts against recovered ownership
If a journal contains a stale or corrupted start, recovery checks only whether the entity already has an active handoff; it never verifies the source region, expected owner epoch or region-map epoch against the recovered map. A start claiming owner epoch 1 against a seeded owner at epoch 10, followed by otherwise matching observations and completion, is accepted and overwrites ownership with epoch 2. Validate these correlations and the live start preconditions before applying the entry, returning Integrity rather than allowing recovery to roll ownership backward.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in dc3f9af: replay of HandoffStarted now validates the entry against recovered ownership before applying it - the entity must be a known owner and its region, owner epoch, and the entry region-map epoch must match the recovered map exactly (and source != target); any disagreement is Integrity. The completion replay check also verifies the source region. Covered by replay_rejects_a_start_that_disagrees_with_recovered_ownership.
| // after every protocol transition and rebuild from the journal. | ||
| for prefix in 1..=4 { | ||
| let live = match prefix { | ||
| 1 => started(), | ||
| 2 => exported(), |
There was a problem hiding this comment.
Add generated invariant tests for the coordinator
The new state machine is covered only by hand-written examples, including this fixed four-prefix restart test. Root AGENTS.md explicitly requires property tests for state-machine invariants and model-generated tests when a behavioral specification exists; examples alone do not satisfy that requirement. Add generated transition sequences and crash prefixes, checked against a reference model, covering replay equivalence, monotonic ownership epochs and handoff-ID uniqueness. These combinations are particularly important because the current examples miss terminal-ID reuse and inconsistent replayed starts.
AGENTS.md reference: AGENTS.md:L38-L42
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in dc3f9af: added world::coordinator::model_tests, a proptest model-based suite generating transition sequences (starts, export/import observations with digest faults, completions, cancels, crash-recoveries, schema-mismatch probes) over a two-entity/three-ID universe, checked step-by-step against a reference model. Invariants asserted throughout: replay equivalence (recover of the live journal equals the live coordinator, including after every generated crash), monotonic owner and region-map epochs, and handoff-ID uniqueness; every crash prefix of the final journal is replayed as well. 17/17 coordinator tests pass locally.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dc3f9af41a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| new_owner_epoch, | ||
| new_region_map_epoch, | ||
| .. |
There was a problem hiding this comment.
Validate completion module and schema during replay
When a recovered HandoffCompleted entry has a different program_module_hash or payload_schema from its journaled start, replay ignores both fields and switches ownership anyway. This accepts an inconsistent journal that the live complete() path could never produce, rather than stopping recovery with CoordinatorError::Integrity. Compare both completion fields with the active handoff before applying the ownership change.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 39bae6a: replay of HandoffCompleted now binds the entry's program_module_hash and payload_schema and compares both against the active (journaled-start) handoff before applying the ownership switch; any disagreement returns CoordinatorError::Integrity, matching what the live complete() path could produce. Covered by the new test replay_rejects_completion_with_mismatched_module_or_schema (both fields, independently). Coordinator suite: 18/18 pass locally (cargo test -p id-worlds --lib world::coordinator, pkgs/id workspace).
Phase 4 of #3870 (issue #3903, task 5866), per design #2818 sections 5/6 and phased plan packet 4. Gate re-checked: phase 3 issue #3902 is CLOSED.
Adds pkgs/id/crates/id-worlds/src/world/coordinator.rs, the coordinator state machine on the phase-1 CoordinatorJournalEntry records:
Tests: 13 new coordinator tests including restart-at-each-transition recovery, reconcile-from-both-receipts, one-side-alone refusal, cancel rules, and stuck classification. Full id-worlds lib suite: 729 passed, 0 failed. cargo clippy on the new module: no findings; rustfmt clean (the crate carries pre-existing fmt diffs in other files, untouched).
Client routing (packet 5) remains a separate follow-on; nothing here enables the handoff path end-to-end (per the phased plan, no packet before 5 does).
Closes #3903 on merge.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.