Repository navigation
Replay per-node consensus streams with a group scheduler - #8735
Conversation
10a67ea to
dd60783
Compare
08efc82 to
f561b3c
Compare
f561b3c to
f581f30
Compare
f581f30 to
4786eb5
Compare
4786eb5 to
b785699
Compare
b785699 to
917310c
Compare
917310c to
4ac693d
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Waiting receive retries repeatedly render and sort the full pending queue for diagnostics that are discarded, adding substantial avoidable work even when replay succeeds.
1 open issue
What changed in this PR
This PR extends CCF's Lean consensus replayer from a globally ordered driver trace to per-node streams, allowing traces from separate processes to be scheduled against the model despite clock skew.
Changes:
- Orders records by process-local counters, reduces node streams into atomic groups, and schedules groups when their dependencies are satisfied.
- Adds schedule diagnostics, stream validation, and updated bootstrap and snapshot-hook handling.
- Updates fixtures and CI checks for shuffled records and alternative cross-process schedules.
Custom instructions used
Applied the supplied CCF repository guidance; no additional repository instruction files were loaded.
| File | Description |
|---|---|
lean/consensus/replay/ReplayMain.lean |
Uses group scheduling and adds --schedule output. |
lean/consensus/replay/README.md |
Documents stream ordering and scheduling contracts. |
lean/consensus/replay/fixtures/valid/replication.ndjson |
Adds process identifiers and ordering counters. |
lean/consensus/replay/fixtures/valid/rejected-replicate.ndjson |
Adapts rejected-replication control to the input format. |
lean/consensus/replay/fixtures/valid/interleaved.ndjson |
Adds cross-process clock-skew coverage. |
lean/consensus/replay/fixtures/valid/bootstrap.ndjson |
Adds ordering metadata and pre-genesis nomination coverage. |
lean/consensus/replay/fixtures/README.md |
Explains updated controls and overlap rejection. |
lean/consensus/replay/fixtures/invalid/unsupported-snapshot-field.ndjson |
Updates input metadata for unsupported-field rejection. |
lean/consensus/replay/fixtures/invalid/ungrouped-event.ndjson |
Updates input metadata for ungrouped-event rejection. |
lean/consensus/replay/fixtures/invalid/uncommitted-snapshot.ndjson |
Updates input metadata for uncommitted-snapshot rejection. |
lean/consensus/replay/fixtures/invalid/snapshot-mismatch.ndjson |
Updates input metadata for state-mismatch rejection. |
lean/consensus/replay/fixtures/invalid/retirement-signature.ndjson |
Updates input metadata for invalid retirement coverage. |
lean/consensus/replay/fixtures/invalid/retirement-seqno-mismatch.ndjson |
Preserves retirement sequence-mismatch coverage. |
lean/consensus/replay/fixtures/invalid/retirement-orphan.ndjson |
Preserves orphan-retirement rejection coverage. |
lean/consensus/replay/fixtures/invalid/retirement-nonadjacent.ndjson |
Preserves retirement adjacency checks. |
lean/consensus/replay/fixtures/invalid/retirement-node-mismatch.ndjson |
Preserves retirement node-mismatch coverage. |
lean/consensus/replay/fixtures/invalid/process-order.ndjson |
Adds overlapping same-process group rejection. |
lean/consensus/replay/fixtures/invalid/packet-mismatch.ndjson |
Updates input metadata for packet-mismatch rejection. |
lean/consensus/replay/fixtures/invalid/missing-packet.ndjson |
Updates input metadata for missing-packet rejection. |
lean/consensus/replay/fixtures/invalid/malformed-append.ndjson |
Updates input metadata for malformed-append rejection. |
lean/consensus/replay/fixtures/invalid/disabled-append.ndjson |
Updates input metadata for disabled-append rejection. |
lean/consensus/replay/fixtures/invalid/bootstrap-flush-send.ndjson |
Preserves invalid genesis-flush send coverage. |
lean/consensus/replay/fixtures/invalid/bootstrap-event.ndjson |
Preserves invalid pre-genesis event coverage. |
lean/consensus/replay/check-order.py |
Compares replay results across record and schedule variations. |
lean/consensus/Consensus/Tests/ReplayStreams.lean |
Checks stream validation, waiting receives, and atomic groups. |
lean/consensus/Consensus/Replay/Reduction.lean |
Separates snapshot hooks and exposes per-group rules. |
lean/consensus/Consensus/Replay/Interpreter.lean |
Adds dependency-aware scheduling and blocked-group diagnostics. |
lean/consensus/Consensus/Replay/Input.lean |
Validates ordering keys and builds per-node streams. |
lean/consensus/Consensus/Replay/Groups.lean |
Builds process queues and rejects overlapping groups. |
lean/consensus/Consensus.lean |
Imports group reduction and stream checks. |
.github/workflows/lean.yml |
Checks native scenario trace order independence. |
.github/workflows/lean-package.yml |
Checks fixture trace order independence. |
Review effort: Balanced
1a5246d to
5ed9777
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Discarding bootstrap removes the genesis replicate lock-hold span from overlap validation, allowing an impossible same-process tick interleaving to be accepted.
1 open issue
1 resolved since last review
Review effort: Balanced
Replay takes one NDJSON file of {process_id, h_ts, msg} records from all
nodes in any order. It orders each process's records by h_ts, splits them
into per-node streams, and reduces each stream into groups by grammar
alone. A scheduler repeatedly runs, atomically, the next group of any node
whose group is enabled, preferring the earliest h_ts. Receives wait for a
matching queued packet and init_as_backup for a committed source; replay
fails if groups remain but none is enabled, listing the waiting groups.
Fixtures gain process_id and h_ts. The interleaved control records the
joiner's events among the leader's, including a same-name event inside
the leader's group, receives before their sends, and initialization
before the leader commits.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
check-order.py replays each trace after shuffling its records, and after also moving each node into its own process with a random, gapped h_ts counter, which changes the order in which enabled groups run. CI runs it on the fixtures and on the cft_scenario_test captures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Each node's events are still reduced in h_ts order, which is the order of its lock holds. Replay now treats h_ts as the order of execution within a process, prefers the earliest wall-clock time among processes, and waits only for a group that is not enabled, so clock skew cannot fail a trace. Snapshot hooks, which run outside the lock, no longer absorb the groups that fall before the initialization, and bootstrap accepts a nomination before genesis. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Reduction.lean now only defines the rules, each consuming one lock hold of a node. Groups.lean peeks a node's next event, runs one rule from it and takes what the rule emitted as a group, so the rules track neither the group's node nor where it starts and ends. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A snapshot hook is valid if its node initializes later, which the hook rule can read from the node's remaining events, so the rules no longer track whether the node is initialized or a hook is pending. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The snapshot hooks stay in the init_as_backup rule, which now stops after them when the initialization does not directly follow and requires it later in the node's events. The rules otherwise differ from main only in accepting a nomination before genesis. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
A group that waits is retried after every other group that runs. Its reason rendered and sorted the whole pending queue between its sender and receiver each time, and was discarded whenever another group could run. The waiting check now returns the reason as a thunk, forced only by the stuck report. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Snapshot hooks run outside the consensus lock, so they are not part of the initialization's lock hold even when it directly follows them in the node's events. Grouping them made the group start at the hook, and another node's group between hook and initialization in the same process was then rejected as overlapping. Hooks now never emit, so the group starts at init_as_backup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The fixtures and captures exercise input ordering and scheduling through the replayer itself, so the hand-built groups and the replay wrapper they needed are removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Exported records carry pid instead of process_id, and the consensus replayer, its fixtures and the capture tests follow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The per-process counter in exported records is monotonic, unlike the event time, so it is named m_ts instead of h_ts. The consensus replayer, its fixtures and the capture tests follow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The step rule now tries bootstrap like any other rule, at a node's first event, and records the bootstrapping node in the rule state, so the driver only repeats the step rule. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Events and groups carry m_ts rather than time, and each field says which trace field it comes from. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Real-node traces, which exercise the cross-process scheduler directly, are to be replayed in CI by a follow-up, so the script and its two workflow steps are removed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Groups were queued per process, with overlapping groups rejected, so that a trace edited into an order one thread could not have produced was refused. A real capture cannot have that order, and the model already rejects a group it is not ready for, so each node's groups now form their own queue. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e6de9e0 to
c799d4e
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The scheduler’s soundness depends on inferred lock holds and order independence that need model-owner review, while real multithreaded, clock-skewed replay validation remains outstanding.
No open issues 🎉
1 resolved since last review
Review effort: Balanced


The Lean consensus replayer needed one globally ordered event stream, which only the single-threaded
cft_drivercan produce. Real nodes are separate multi-threaded processes with unsynchronised clocks, so their traces could not be replayed. This PR makes the replayer take one file of{pid, m_ts, msg}records from all nodes, in any order, and work out a valid order itself, so that traces from real networks can be checked against the model.Within a node no clock is needed: consensus emits every event while holding the node's consensus lock, so the per-process counter
m_tsalready gives the order of its critical sections, whichever threads ran them. The existing reduction rules turn each node's stream into groups, one per lock hold. Across nodes, replay runs groups in wall-clock order (ts, when records carry it), but a group waits if it is not yet enabled (a receive whose packet is not yet sent, or aninit_as_backupwhose prefix is not yet committed), so clock skew between hosts cannot cause a false rejection.The trace envelope now names the process identifier
pidinstead ofprocess_id, and the per-process counterm_tsinstead ofh_ts, since it is monotonic where the event time is not.Replaying real-node traces is not part of CI yet; #8732 adds that. #8779 separately adds a trace field that would let replay check the lock assumption instead of relying on it.
Alternatives
Why the verdict does not depend on the order chosen
A node's state changes only through its own groups, which run in its lock order. Other nodes only add packets for it to receive, and a committed prefix stays committed, so a group that is enabled stays enabled until it runs.
Replay checks that a trace is consistent with the model, not that one thread could have produced its order. A trace from a process that hosts several nodes, as
cft_driverdoes, is therefore accepted even if its records are rearranged so that a receive precedes its send; a real capture cannot have that order.Other behaviour changes and diagnostics
init_as_backup, so they form no group; a tick or nomination between a hook and the initialization replays as an ordinary group instead of being absorbed.--scheduleprints the groups in the order they ran, ending with the one that failed.m_tswithin a process, a node traced by two processes, or anything other than exactly one bootstrapping node is rejected. The JSON summary reportsgroupsinstead ofinstructions.