Skip to content

3.1 dual-writer (5/5): dual-writer E2E simulation and CI - #763

Merged
RobertClarke merged 65 commits into
3.x.xfrom
RobertClarke/p31-dual-writer-e2e
Oct 19, 2026
Merged

RobertClarke merged 65 commits into
3.x.xfrom
RobertClarke/p31-dual-writer-e2e

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Do not merge: part of the 3.1 stack, teed up for review.

Stack position 5/5, on the readiness-routing branch (RobertClarke/p31-readiness-routing, 4/5). That branch holds the whole 3.1 stack at its final heads: D1's peer sync engine (036d449), D2's window cuts (5e7eac6), D3's carry owner (61eacad) and D4's readiness routing (686cd9a). This PR merges it.

What this adds

crates/qbit-prism-dual-sim simulates the whole PRISM pair on one runner and holds it to the 3.1 payout invariants:

  • The pair. Each node gets:

    • one PostgreSQL 16 cluster: in the 3.0 pair a primary and its streaming standby, in the 3.1 pair two primaries;
    • one regtest qbitd, plus one for the network (ramped once to 1e7fffc0 and cached);
    • the real qbit-prism-server frontend.

    Every path between the nodes goes through a relay that a fault can cut or slow down.

  • Routing and load. A balancer stand-in shaped like the Hashbalancer's pair configuration:

    • A is preferred and B is the backup;
    • checks run every 2 s, with fall 3 and rise 2, against the token-protected /readyz in dual mode;
    • sessions close on mark-down, and failback is paced.

    It records every mark-up, mark-down and failed check. qbit-prism-load's Stratum client mines through it, and a block finder per node solves one of that node's own blocks on its work on demand.

  • Faults.

    • kill -9 or SIGSTOP of a frontend or a PostgreSQL;
    • a node's whole network dropped;
    • the link between the databases cut. A cut is a reset, a blackhole that delivers held bytes on heal, or a discarding link that models a dead client: its server's replies drain and no close arrives.
    • one-way link latency. The relays are delay lines, so a stream keeps its rate, a close waits the latency, and a reset crosses as a reset.
    • restores from an older base backup onto a new timeline;
    • a disk rebuilt from the peer;
    • a submitblock held or withheld at the instant a node dies;
    • locks held and grants revoked on either database.
  • The checker.

    • The census of pool blocks comes from the chain, never from a database.
    • Per account, no block raises the debt except a recorded 3.x.x: An own block found 9 s after the previous landing was refused unknown-job and never reached the node #478 race.
    • The non-owner's blocks are carry-free.
    • Every pool block is landed, and its landing is the same on both nodes in every column the peer sync carries, provenance included. Its audit is verified by qbit-prism-audit-verify against the chain's coinbase with pinned keys, and its fanouts are byte-identical.
    • Every acknowledged share is present, except a measured, documented tail.
    • Nothing is credited twice.
    • The other copied tables are the same on both nodes: prepared records with their template and balance blobs, and the carry-owner journal.
    • Every window is unchanged, and reproducible on both nodes with its per-node cut.
    • Local state is never copied (D-2): candidates, deferred shares, issued jobs, offer decisions, the node's identity.
    • Negative controls prove the checker fails when it must.
  • Scenarios. The 3.1 matrix S1 to S11: S2 in four variants, S6 and S7 per node, S8 in three. Also the checker controls and S10 (single-writer parity), plus:

    • D-5 and D-10, sampled live in S1 and S5: no peer block is seen before its window's shares, or with part of its landing missing;
    • D-8 in S4: a link loss never withdraws a serving node;
    • a frozen peer never stalls the survivor. S2 holds A frozen for 60 s while B keeps landing blocks, and a variant freezes A 20 times, aimed at the moments its puller holds the sync barrier or a transaction on B.
    • the three P1s of the review of the peer sync engine: an unreadable peer at restart, a puller dying mid-read unseen by its peer, and a transient apply failure;
    • with A's PostgreSQL killed: A's readiness is sampled every 200 ms until the heal. A must withdraw within 12 s and stay out, and the balancer must never fail miners back to A while its database is dead.

    Each scenario writes report.md, report.json, invariants.json, the share log, the verified audits and every process's log.

  • CI.

    • Fast lane. prism-dual-writer in ci.yml is required. It runs test/prism-dual-writer-gated-tests.txt: the checker control, S10, S1, S2 kill -9, S4 and S5.
    • Full matrix. dual-writer-nightly in prism-load-nightly.yml runs test/prism-dual-writer-nightly-gated-tests.txt, all 24 scenarios. It runs nightly, on dispatch (dual_writer=true), and on a PR labelled run-dual-writer-e2e.
    • Both lanes prove execution with scripts/check_gate_manifest.py, upload the reports, and list every scenario that cannot run yet.
    • The matrix is registered in test/e2e-scenarios.toml.

How it is tested

  • On this head (c2f5b3a), approved by Codex on round 11. Its CI full matrix passed 24 of 24: https://github.com/Qbit-Org/qbit-mining-bootstrap/actions/runs/38099346126. Every other CI check passed, apart from one documented flake in an unchanged server test: 3.1 dual-writer (5/5): dual-writer E2E simulation and CI #763 (comment). The stack is at its final state. D4's final head 686cd9a is merged in 68a87ad, whose CI full matrix passed 24 of 24 (https://github.com/Qbit-Org/qbit-mining-bootstrap/actions/runs/38090359463). Since then, only the harness has changed:

    • Codex round 7: D-2 checks deferred shares, and S9's cutover digest covers every column the sync carries, fanout sets included.
    • Codex round 8:
      • S9 keeps the prepared state (prepared records, their blobs, the journal) exactly through the cutover's promotion and bootstrap, on both nodes: nothing lost, changed or added (round 9);
      • copied-state-identical fixes the rows it requires when it begins, and reads the peer before the origin when it looks for lost rows.
    • Codex round 10: S11 reads the transfer's outcome from the journal (B alone the carry owner, on both databases) before the frontends get their new roles, and S9 probes D-12's refusal on both databases.
    • Before this push, a sweep of the families Codex kept finding. Copied state:
      • a new copied-state-identical check compares prepared records, with their template and balance blobs, and the carry-owner journal, in both directions;
      • D-2 covers issued jobs;
      • S7 checks re-personalise against D1's table inventory before the rebuilt node starts;
      • S6 checks prepared records and journal rows at readiness;
      • inv3-audits-verify reports a stopped frontend.
    • Premises:
      • every miner moves to the survivor within 30 s (S2, S10), and fails back (S10);
      • A holds none of B's blocks before the heal (S2);
      • S4's transient apply shows a retry;
      • S6's restore lacks its later rows;
      • S9's refusal is D-12's own;
      • a PRISM setting a frontend leaves unread fails the scenario;
      • the checker control's failures must name their causes through both databases, and D-2 has its own negative control.
    • Fair numbers:
      • a scenario that dies leaves a failed report;
      • S3 and S4 are judged by the longest gap over each whole window;
      • S7 excuses only a tail within the sync lag;
      • the matrix summary marks runs that stopped before their checker;
      • unplaced offers are reported.

    Run on this host:

    • the full matrix on 99d4528 passed 23 of 24. The 24th was the checker control's new D-2 control, fixed in 49964b7 and passing since;
    • on ed500cb (round 8), the fast lane, S6, S7, both S8 accepted variants, S9 and S11 pass. S9 kept 74 pre-promotion rows whole on both nodes: 44 prepared records, 26 templates and 4 balance snapshots;
    • on 1e5403e, S1, S5, S6 and S7 pass; on 1623090, S9 (75 rows kept exactly on both nodes) and the checker control pass; on c2f5b3a's change, S9 (D-12 refused on both) and S11 (the journal names B alone) pass.
  • The previous head (81d65c7, on D4 c2eae8d). Codex approved it on the first pass, every CI check passed, and the CI full matrix passed 24 of 24: https://github.com/Qbit-Org/qbit-mining-bootstrap/actions/runs/38063678705.

  • Round 1 (58b0f0c, on D4 6cc825b). The full matrix passed 24 of 24 in CI (https://github.com/Qbit-Org/qbit-mining-bootstrap/actions/runs/38051882931, 29 min) and in a local run of the same head. No acknowledged share was lost apart from S7's measured dead-node tail, and the first share after each fault came 4.4 to 6.5 s after it.

  • Every check against D1's fixes passes. Run on this host on D4 c22bd1f merged with D1 193e7fd, before round 1, with the peer role holding exactly D1's grants:

    • the barrier: S2 frozen mid-pull, no stall in 20 freezes;
    • P1 2: the puller death, 0 of 1654 samples idle in transaction;
    • P1 3: the transient apply, retried 3 times and landed 0.2 s after the lock cleared;
    • P1 1: S6 unreadable, refused and locked, A ready about 1 s after its restart;
    • D-19: S8 accepted, adopted 8 s after the block was 60 deep;
    • D-16: S7 on both nodes, repersonalised after the runbook's 60 s wait.
  • The full matrix on that tree. 24 scenarios in one run: 23 passed. The 24th could not start, because a frontend's port was taken between free_port and its bind. That scenario passed on its rerun, and the harness now gives no two parts of a scenario the same port.

  • D4's dead-PostgreSQL fix. S2's PostgreSQL kill samples A's readiness every 200 ms until the heal. A answered 503 7.1 s after its PostgreSQL died and stayed out; the balancer marked A down 12.1 s after the kill and never marked it up again. Before the fix, A was readmitted after its first withdrawal, and miners waited 37.6 s.

  • Unit and repository tests. Unit tests cover the relay (latency, closes, resets, Discard), the port registry, the balancer, the readiness trace, process control, the gate, the gap and tail measurements, the landing-order verdicts, the D-13 eligibility predicate, the debt walk and ownership epochs. Python tests cover the scenario lists and the matrix summary. cargo fmt, clippy -D warnings and the repository's workflow-pinning tests pass.

Follow-ups

  • D1: the peer apply lets migration 016's solver-capture trigger fill a carried NULL. No payout impact.

    • A block captured on a superseded revision (3.x.x: An own block found 9 s after the previous landing was refused unknown-job and never reached the node #478) lands on its origin with its four solver_* columns NULL, because its solving share is credited only at confirmation.
    • On the peer, apply_block's insert fires migration 016's BEFORE INSERT trigger. It finds that share in the peer's ledger and fills the columns, so the two nodes differ in columns the sync carries.
    • The solver columns are informational, and readers fall back on NULL.
    • The suggested fix is one statement in apply_block's transaction, right after it inserts a peer block whose carried solver_share_id is NULL: UPDATE qbit_pool_blocks SET solver_miner_id=NULL, solver_share_id=NULL, solver_share_difficulty=NULL, solver_network_difficulty=NULL WHERE block_hash=$1.
    • inv3-landing-rows stays strict, so a capture in a matrix run would show as a solver_* difference between the nodes.
  • Harness: the checker control's owner-balances failure stays conditional. It is expected only when B's control block leaves some account a carry delta. With the harness's payout floor every account is paid in full, so it has not fired in recent runs. Forcing a carry would need a payout floor that the pool-fee output cannot clear, which stops template building ("cannot select a settlement mode"). The control's other four expected failures are judged by their causes through both databases.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-dual-writer-e2e branch 2 times, most recently from 0490fcd to a6f0a1d Compare October 10, 2026 10:05
@RobertClarke
RobertClarke changed the base branch from RobertClarke/p31-identity-sync to RobertClarke/p31-readiness-routing October 10, 2026 10:05
@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-readiness-routing branch from c22bd1f to 2daef48 Compare October 10, 2026 11:21
@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-readiness-routing branch from 2daef48 to 6cc825b Compare October 10, 2026 12:16
@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-dual-writer-e2e branch from a6f0a1d to 58b0f0c Compare October 10, 2026 12:23
@RobertClarke RobertClarke added the run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) label Oct 10, 2026
@RobertClarke

Copy link
Copy Markdown
Member Author

Dual-writer scenario matrix on 58b0f0c: 24 of 24 passed.

This head is the 3.1 stack after rebase round 1: D4 6cc825b, D3 7a2ea81, D2 a07a594, D1 31bf958.

  • CI: the run-dual-writer-e2e label run, job "Dual-writer scenario matrix", passed all 24 in 29 minutes: https://github.com/Qbit-Org/qbit-mining-bootstrap/actions/runs/38051882931. The matrix table is in the run's summary. Every scenario's report.md, report.json, invariants.json, share log, verified audits and process logs are in the prism-dual-writer-nightly artifact.
  • Local cross-check: the same 24 on the same head also passed.
    • No acknowledged share was lost, apart from S7's measured dead-node tail.
    • The first accepted share after each fault came 4.4 to 6.5 s after it, against the 30 s bound.
  • Scope: S1 to S11, with all S2 variants, S6 and S7 on both nodes, and all three S8 cases, plus the checker control and S10.

The other red checks on this head (shard 3's repersonalise_makes_a_physical_copy_of_node_a_node_b, the gated-test proof and the roll-up) come from a known fixture flake in the stack below this PR, which its next rebase round fixes. They are not in this PR's files.

@RobertClarke RobertClarke added run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) and removed run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) labels Oct 10, 2026
@RobertClarke
RobertClarke marked this pull request as ready for review October 10, 2026 15:27
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T20:20:15.026464Z 327e596 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@RobertClarke

Copy link
Copy Markdown
Member Author

Dual-writer scenario matrix on 81d65c7: 24 of 24 passed.

This head is the final-round merge of the whole 3.1 stack: D4 c2eae8d, D3 476fdd9, D2 5e7eac6 and D1 036d449.

@RobertClarke RobertClarke added run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) and removed run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) labels Oct 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bfc581f6e1

ℹ️ 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".

@RobertClarke RobertClarke added run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) and removed run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) labels Oct 10, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8c7ac95fd4

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e21a428ebe

ℹ️ 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".

Comment thread crates/qbit-prism-dual-sim/src/sim.rs Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ac54ef80c7

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: efc90dff97

ℹ️ 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".

@RobertClarke RobertClarke added run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) and removed run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml) labels Oct 10, 2026
@RobertClarke

RobertClarke commented Oct 10, 2026 •

Copy link
Copy Markdown
Member Author

Full dual-writer matrix (all 24 scenarios) on the stack's final head 68a87ad, which merges D4's final head 686cd9a. It was started at 22:09Z by applying run-dual-writer-e2e again: https://github.com/Qbit-Org/qbit-mining-bootstrap/actions/runs/38090359463

Result: 24 of 24 passed (the matrix job ran 22:10Z to 22:40Z). Every other CI check on 68a87ad passed too.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68a87ade90

ℹ️ 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".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b91dde2487

ℹ️ 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".

ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e5403e014

ℹ️ 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".

Robert Clarke and others added 19 commits October 19, 2026 16:16
… names what it was binding again

This comes from the local review of 11fc9378. In
from_std(fresh_listener()?).with_context(..), the ? returned
fresh_listener's error before the context was added. An EMFILE, or 64
draws without a new port, then reported no "binding relay public-stratum-a"
or "binding the balancer". The context now wraps both calls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ived; the share fingerprint keeps origin_node

These are Codex's two P1s on bfc581f.

1. S1's lag check dropped unresolved samples from its percentiles. One
   share that synced quickly, among many that took tens of seconds, could
   pass the 2 s p95 bound.
   - lag_report now ranks every sample, an unresolved one above every
     resolved lag. A percentile that falls on one is None, which fails the
     check.
   - So that this is fair, the sampler stops taking samples when told to,
     but keeps polling the pending ones for LAG_DRAIN_MS (3 s). Every
     sample has then had more than the bound to arrive.
   - The report counts the unresolved samples, and S1's detail names them.
   - The unit test checks that one quick sample among nineteen that never
     arrived does not pass.
2. inv4-no-double-credit compared each header's row across nodes without
   origin_node. A sync that copied a share with the wrong provenance would
   have passed. origin_node is now part of the fingerprint.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…es and each header with its share's own hash

These are Codex's two P1s on 8c7ac95. Both are gaps in
inv4-no-double-credit.

1. A header-to-share mapping was only required to point at some accepted
   ledger row. A sync that swapped two valid mappings would have passed.
   Each mapping's header must now equal its share id's hash
   (lower(right(share_id, 64)), the server's own mapping), or the check
   fails with "header mapped to another share".
2. The cross-node comparison used a hand-picked list of columns, which
   left out payout_order_key, template_height, credit_policy and others.
   The ledger is append-only and copied whole (D1's table inventory leaves
   no column out). So each header's row is now compared on both nodes as
   to_jsonb, every column, read under SET LOCAL TIME ZONE 'UTC' so that
   timestamps render alike. A mismatch names each differing column with
   both values. A unit test covers that naming.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and the pair converges by content, not counts

These are Codex's two P1s on e21a428.

1. inv4-acked-shares-present looked each acknowledged share up by its
   header only. A committed row under the same header but with another
   worker prefix would have passed for it. The check now binds the exact
   share ids the miners were answered for, which the load client builds as
   the server does ({username}:{header hash}). Each must be an accepted
   ledger row with its mapping.
2. wait_converged, which settle uses for the dual-writer pair, compared
   the share and block counts. A sync that dropped one A row and a
   different B row would have left the counts equal and the ledgers
   different. Each reading is now a count plus an md5 digest of every
   share mapping (header=share_id) and every block hash, ordered under the
   C collation so that both clusters sort alike. The pair converges only
   when the two digests match and still match a second later.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s, and a peer block counts as arrived only whole

These are Codex's two P1s on ac54ef8.

1. inv3-landing-rows compared a hand-picked set of landing facts across
   nodes. A block copied with the wrong origin_node, or with another
   carried column wrong (sync_seq, found_at, the solver), would have
   passed. Each node's landing is now one document holding every row of
   it: the block, bundle, payout entries, carry rows, fanout set and
   artifacts. Each row has exactly the columns D1's peer sync carries of
   its table, read from that node's catalog with D1's CarriedColumns. The
   snapshot is compared by its content-determined facts. Timestamps are
   read in UTC. A block both nodes hold must have the same document on
   both, and a difference names each differing column by its path, with
   both values. Only the columns the sync leaves to each node are left
   out: chain and maturity state, publication order and claims.
2. The D-10 sampler of S1 and S5 settled a peer block once its audit
   bundle and snapshot were there. Payout, carry or fanout rows committed
   in a later transaction would have gone unseen. A block now counts as
   arrived only when its whole landing is there in the same statement:
   the bundle, the snapshot, a payout entry per manifest account, a carry
   row per miner account, and the fanout set and artifacts the bundle
   names. That is the condition inv3-landing-rows holds a landed block to.
   A block seen with part of its landing missing is torn and fails the
   scenario.

S8's adoption is the one path on which both nodes could land one block
themselves. B adopts A's block while A is down, and A's restarted
frontend could land it too. A cannot do so before it has waited out the
120 s candidate lease, and by then it has pulled B's adoption, so it
skips its own. If it ever did land its own, the pair would hold two
landings of one block, and the checker now says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…missing share counts once

These are Codex's P1 and P2 on efc90df.

1. S8's accepted variants never required the block to reach the chain.
   The RPC gate records a submitblock as answered once its forward ends,
   also when the forward failed. Without the D-19 wait, the adoption
   expectation passes either way, and every landing check sits under
   `if on_chain`. So the no-wait variant could pass without its premise:
   that the node accepted the block before A died. Both variants now
   expect the block on the chain. Only the adoption's timing stays
   ungated without the wait. The gate's docs now say what "answered"
   records.
2. inv4-acked-shares-present counted a missing acknowledged share once
   per database that lacked it. S7's unsynced tail is missing from both
   the survivor and the rebuilt copy, so the report's excused tail
   doubled. A lost share missing from both nodes was likewise reported
   twice, and the report counts those problems as shares lost. A pure
   tally_missing now sorts the missing ids into excused shares (by
   reason) and lost shares (with the nodes that lack each). Each share
   counts once and gets one problem naming its nodes. A unit test covers
   a share missing from both databases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and only a "not found" means no

S8 read "the block reached the chain" as any successful getblockheader
on C, and anything else as "not there". A failed call to C (C
unreachable, a timeout) therefore passed the lost variant's "the lost
block never reached the chain" without proving it.

The chain node now has knows_block. It returns false only on the node's
own "block not found" answer (RPC error -5, as qbitd and the server's own
RPC code use it), and an error for any other failure. S8 propagates that
error, so an unreachable C fails the scenario instead of deciding it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…est covers every carried column

These are Codex's two P1s on 68a87ad.

1. d2-local-state-not-copied checked candidates and offer decisions, but
   never qbit_prism_deferred_shares. D1's table inventory keeps that
   table local and clears the peer's rows on re-personalise, because a
   copied deferred solving share could be credited twice. A deferred
   share's foreign key ties it to a candidate in its own node's outbox,
   but a copied candidate with fresh timestamps and no claim would slip
   past the candidate checks. So the check now also requires that no
   deferred share whose candidate dates from the dual epoch is on both
   nodes, by block and share digest. The counts per node are in the
   check's data.
2. S9's before/after digest covered picked columns of some tables and
   none of qbit_ctv_fanout_sets. A cutover that corrupted a fanout set,
   or any unpicked column, identically on both promoted databases would
   have passed it, and every later cross-node check too. Each copied
   table is now digested whole over every column the peer sync carries,
   read from the database's catalog with D1's CarriedColumns: shares,
   share hashes, blocks, bundles, payout entries, carry rows, fanout sets
   and artifacts. Snapshots are digested by their content-determined
   facts. Timestamps are read in UTC. Only each node's own columns are
   left out (chain and maturity states, claims, schedules). The cutover
   never rewrites a carried column: origin_node and sync_seq are set
   only at insert.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…numbers, from a sweep of the families Codex keeps finding

Before pushing round 7, three read-only passes over the whole harness
looked for the classes Codex's rounds kept finding: never-copied and
copied state left unchecked, a variant's premise assumed rather than
measured, and report numbers that misstate an outcome. All harness-only.

Copied and never-copied state (D-1, D-2, D-11, D-16, D-17):
- copied-state-identical, a new check. For each origin node against its
  peer: the carry-owner journal is identical. Every unexpired prepared
  record the origin wrote, up to the peer's cursor, is on the peer, equal
  in every carried column but expires_at (D1's own comparison). Every
  unexpired copy is still on its origin. The templates and balance
  snapshots they reference are byte-identical. The check retries for up
  to 20 s for rows in flight.
- D-2 covers issued jobs: an issued job of the peer's, by origin or
  instance, since the epoch, is a copy that resume_job could replay.
- S7 checks re-personalise's work before the rebuilt node starts, from
  D1's TABLE_INVENTORY:
  - every cleared table is empty, and no Rows or Reset predicate matches;
  - the identity is the node's own, and the lineage is unverified;
  - every cursor follows the peer from at or below its highest key.
- S6's "held every own row before it was ready" now includes unexpired
  prepared records and journal rows.
- inv3-audits-verify reports a stopped frontend, unless its node is
  listed as away.
- The checker control runs the D-2 check on A's database in both slots,
  where it must name a candidate that is the same row in both outboxes.

Premises measured, not assumed:
- S2 and S10: every session that mined before the fault has a share
  accepted on the survivor's work within 30 s, read before the heal. Before,
  one share sufficed. S10's failback must route every session back to A.
- S2 (kill, freeze, network drop): A holds none of B's blocks before the
  heal. A's tail is checked to be on B at the end, not hard-coded true.
- S4's transient apply needs at least two attempts, which shows the
  retry.
- S6: right after the restore, the node lacks the block it found after
  the backup and own shares the peer holds.
- S9's D-12 refusal must be D-12's own text.
- A frontend that reports a PRISM setting unread ("set but unread by
  native PRISM") fails the scenario. This covers S8's no-wait override
  and every other one.
- The checker control's expected failures must name their causes through
  both databases: each block, fanout, share and window missing on the
  other node.

Fair numbers:
- A scenario that panics or is stopped leaves a failed report, written
  when its run starts, instead of vanishing from the matrix.
- S3 and S4 are judged by the longest stretch with no accepted share over
  each whole window (report::longest_gap), not only the one across the
  fault.
- S7 excuses only tail shares answered within the sync lag of the death.
  Older ones fail as lost.
- The matrix summary shows "not checked" and "not measured" for a run
  that stopped before its checker or before any fault.
- Unplaced offers are reported. The puller-death p95 counts refusals and
  unanswered shares, and S10's failback window ends where the load
  stopped.

Not changed: the checker control's owner-balances failure stays
conditional on B's block leaving a carry. Forcing one would need a payout
floor that template building rejects.

Unit tests cover the longest gap, per-session failover and the tail age
bound. Python tests cover the summary's rows for runs that stopped early.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…th nodes, past the capped problem list

The checker control runs the D-2 check on A's database in both slots, and
expected a "same row in both outboxes" problem among those listed. The
check failed as it must, with 245 problems. But it lists at most 40, and
its cross-node findings come after every node's own: the candidates A's
frontend claimed, and A's issued jobs, about 240 of them. So the expected
words were never listed, and the control failed on a correct check.

The D-2 check now counts its cross-node findings in its data
(same_rows_on_both_nodes: candidates, offer decisions, deferred shares).
The control requires each way of finding a copy to fire: a candidate
claimed by the peer's frontend and an issued job of the peer's (both
listed first), and at least one candidate that is the same row on both
nodes (counted).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ds it requires by what the origin had written, not by the peer's cursor

copied-state-identical required on the peer only the origin's prepared
records at or below the peer's cursor over that stream. A stream that
stopped would then pass. When apply_prepared fails, the engine retries
every pass and leaves the cursor where it is, so nothing would be
compared, and the fast lane would stay green while the peer could adopt
nothing. Only S8 would notice.

The bound is now the origin's highest prepared sync_seq when the check
begins. Every unexpired record up to it must reach the peer within the
check's 20 s retry, which already absorbs rows still in flight, whatever
the cursor says. The cursor stays in the check's data for diagnosis,
beside the new highest_at_start.

From the local review of 99d4528.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tover, and copied-state-identical fixes what it requires when it begins

These are Codex's P1 and P2 on b91dde2.

1. S9's cutover digest left out four copied tables: prepared records,
   their templates and balance snapshots, and the carry-owner journal. A
   promotion or bootstrap that lost or damaged them identically on both
   databases would have passed, and new work would then replace the lost
   records. A digest across the whole cutover cannot see this, because
   prepared records live about as long as the jobs that use them, which is
   shorter than a cutover. Instead, cutover_to_dual reads the four tables,
   whole and in UTC, at two points:
   - on A right after the drain;
   - on each node after the promotion and the bootstrap, before either
     frontend starts.
   Nothing writes or prunes these tables between those reads. S9 requires
   every row from the drain to survive identically on both nodes, and
   prepared records to exist at all, so the check cannot pass empty.
2. copied-state-identical recomputed the origin's unexpired prepared
   records on every retry. A missing record that drifted into the 5 s
   expiry cushion during the 20 s retry dropped out, and the check passed.
   Each origin's targets are now read once, when the check begins:
   - its unexpired prepared records up to its highest sync_seq;
   - its journal rows;
   - the md5s of the blobs those records reference.
   The retries then compare only the peer's copies against that fixed set.
   Copies are kept 24 h past expiry, so a record that ages meanwhile stays
   required. The rows the origin lost while its peer kept them are judged
   once, at the start: unexpired copies, journal rows, and blobs its
   records reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… origin when it looks for lost rows

copied-state-identical judges once, at the start, which rows the origin
lost while its peer kept them. It read the origin first and the peer
after. A prepared record or journal row could be written on the origin
just after that first read and pulled by the peer before the second.
That row then looked lost on the origin, and the check failed for good on
a correct pair: a rare flake, since the load-paused frontends still write
a prepared record about every second and the peer pulls every 250 ms.

The peer's unexpired copies and journal rows are now read first. Anything
the peer holds, the origin wrote before, so the origin's later read holds
it too, unless it really was lost there. An unexpired copy's original
cannot be pruned in between, since its expiry is the later one.

From the local review of ed500cb.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…in left, nothing added

This is Codex's P1 on 1e5403e. S9 compared the prepared state on each
node after the promotion and the bootstrap with A's right after the
drain, but only the rows from before. A promotion or bootstrap that
inserted a prepared record, a blob or a journal row would have passed,
and so would every later cross-node check once both databases held it.

Neither step writes these tables. node-identity set changes only column
defaults and sequences and the identity and lineage rows, and the
promotion replays exactly A's WAL. So each node's state must now equal
the drain's in both directions: nothing lost, changed or added. The added
rows are listed in the expectation's detail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l, and S9 probes D-12 on both databases

These are Codex's P1 and P2 on 1623090.

1. After S11's carry-owner transfer reported success, the harness gave
   the frontends their new roles (PRISM_CARRY_OWNER) and restarted them.
   It never read the journal the transfer wrote. A transfer that left A's
   claim standing beside B's would have been masked by those settings.
   Before the restart, S11 now reads each node's latest claim, on both
   databases, waiting up to 15 s for the pull each way. It requires that
   B alone is the carry owner (D-4).
2. S9's contract says a single-writer start on either cut-over database
   is refused (D-12), but it probed only B. It now probes A too, the
   carry owner.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ensus fails inv3-landing-rows

Codex's P1 on 7dccd65. The census takes the pool blocks from the
chain, and it silently dropped every database row it did not find
there. A landing or peer-sync regression that recorded a confirmed
block absent from the active chain would have escaped every landing,
audit and fanout check, which all iterate over the census.
inv3-landing-rows now reports each confirmed row whose block is not in
the census. Rows in other states may stay: a lost block's prepared row
(S8) and a reorged one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ned manifest's accounts field for field

Codex's P1 on c2adffb. inv3-landing-rows counted a landing's payout
entries and carry rows against the signed manifest's accounts. A landing
that wrote the right number of rows, but one with the wrong recipient,
program, amount or action, passed. The peer sync then copied the same
bad row, so the cross-node comparison passed too. inv3-audits-verify
checks only the separately stored bundle.

Each node's rows are now compared, as multisets and in both directions,
with the rows rebuilt from the bundle's own payout_policy_manifest
accounts, using the landing's own mapping (ledger/blocks.rs):
- payout entries: recipient, order key, program, on-chain amount, carry
  balance and action, one per account;
- carry rows: the miner accounts, with gross, prior, candidate, on-chain,
  settlement fee, carry balance and action.
Any difference is a fault, counted per table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…igned manifests in every field

Codex's P1 on a324fda. inv3-fanouts-identical matched each fanout
artifact to its bundle's manifests by the transaction hex alone. A
landing that kept the right hex but wrote a wrong fanout_txid, manifest,
manifest digest or recovery field, which the sync then copied, passed
both it and the cross-node comparison.

Each artifact must now equal one of the bundle's signed manifests in
every field the landing copies from it (ledger/blocks.rs,
persist_fanouts): the manifest JSON, both stored and as text, and every
scalar of the manifest and its precommitment. Its manifest digest must
recompute from its JSON, and its set digest must be its set row's. The
set row must be the bundle's signed manifest set, with its digest and
every scalar matching.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… recompute where they were built

inv3-landing-rows now holds each landed qbit_pool_blocks row's block_height
to the census height read from C, and every payout entry and carry row of
the block to that height. A landing that wrote a wrong height consistently
to all three passed before: the bundle is verified separately and the
cross-node comparison only shows both copied the same value.

inv4-windows-reproducible now recomputes each recorded window on the
database that built it as well as on the other one, so the single-writer
topology (S10) is no longer skipped. windows_unchanged reads only counts,
which an in-place edit of a share's difficulty or miner keeps.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke changed the base branch from RobertClarke/p31-readiness-routing to 3.x.x October 19, 2026 20:16
@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-dual-writer-e2e branch from e479006 to 327e596 Compare October 19, 2026 20:16

ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 327e596f22

ℹ️ 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".

sum(gross_amount_sats)::text AS gross, sum(onchain_amount_sats)::text AS onchain, \
sum(prior_balance_sats)::text AS prior \
FROM qbit_payout_carry_forward \
WHERE block_hash = $1 AND maturity_state <> 'reversed' GROUP BY p2mr_program",

ghost Oct 19, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject reversed carry rows for confirmed chain blocks

When a landing or reorg regression leaves a census block confirmed but marks its qbit_payout_carry_forward rows reversed, this filter removes those payouts from the chain truth. The current-balance view and integrity report also exclude reversed rows, while landing_rows compares amounts but not maturity_state, so both databases can contain the same erroneous reversal and every invariant still pass even though the owner's balance no longer includes an active-chain block. Explicitly reject reversed carry rows (and payout entries) belonging to confirmed census blocks.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-dual-writer-e2e Run the 3.1 dual-writer scenario matrix on this PR (prism-load-nightly.yml)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant