Skip to content

3.1 dual-writer (2/5): per-node window cuts and audit cut field - #768

Merged
RobertClarke merged 16 commits into
3.x.xfrom
RobertClarke/p31-window-cuts
Oct 19, 2026
Merged

RobertClarke merged 16 commits into
3.x.xfrom
RobertClarke/p31-window-cuts

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 2/5: the base is D1's RobertClarke/p31-identity-sync, with node identity and peer sync. D3's carry-owner branch builds on this one.

What changed

In dual-writer mode (PRISM_DUAL_WRITER=true), each node writes only to its own PostgreSQL and pulls the rows the peer originated. A peer's share can therefore reach a node after that node's own, higher-numbered shares. A payout window bounded only by its anchor timestamp would change when the late row arrived, and the landing proof would refuse a block found on it. Every window now records a per-node cut, {"0": <share_seq or null>, "1": <share_seq or null>}: the highest share_seq of each node's rows it may include.

Eligibility. A row is in a window when it is eligible as in 3.0 (accepted, and accepted and issued at or before the anchor), and its share_seq is at most its own node's entry in the cut.

  • This node's entry is its newest own row eligible at the anchor, read under ORDER_LOCK in the cutoff's statement, once the anchor is taken.
  • The peer's entry is the peer's newest row at or below qbit_prism_peer_share_mark() (D-14) that is stamped at or before the anchor. The mark the cutoff's statement read and the mark when the entry is read both bound it, so a mark rewound in between never admits a row whose lower rows are gone.
  • So both entries are rows the window's predicate admits, and the higher one is the window's newest row, as the accepted cutoff is without a cut.

The anchor rule and peer rows (CONTRACT D-13). The anchor rule stays on every row. The peer's entry stops below its first row stamped after the anchor, and each node's stamps rise with its share_seq, so the cut alone decides membership and the anchor rule only confirms it.

  • Clock skew. Rows and their stamps are copied verbatim, so both nodes and every verifier evaluate one deterministic predicate. A peer clock running ahead only delays that peer's newest shares. It cannot make a window irreproducible or a landing fail.
  • Why the rule stays on peer rows. The verifier binaries re-filter every bundle share by the anchor. Exempting peer rows would put shares in the coinbase that the audit drops.

Every path uses the cut (ledger/window/cut.rs):

A late peer row is above the peer's entry, so it never makes a landed or offered block unverifiable. It joins later windows.

The #619 holding probe. A dual-writer node has no physical standby (D-19), so the rows it can lose are each log's newest, to a restore. A dual-writer window is held when three things hold:

  • its last row still matches the window's predicate, whichever node wrote it;
  • this node's entry is its row under the window's predicate, since own-log recovery restores own rows in share_seq order;
  • the peer sync's mark is at or above the peer's entry.

A rewound mark or a lost own entry is not held. Retention under the first row is still a pruned prefix.

Incremental advance. A refresh reads each node's rows between the retired window's cut and the fresh one, at or above the retired window's first row. It merges the peer's late rows into the retired window in share_seq order (advance_in_cut). The margin below the first row reads the fresh predicate, so nothing is read twice. The delta is bounded by the slots it reads, the union of the nodes' ranges, as the cutoff's difference bounds it in 3.0. The margin walk and the proof (the single-leaf witness and the eligible-row count, under the fresh cut) are now shared with 3.0's advance, with 3.0's statements. Anything else falls back to the full scan.

200k-row window, local PG 16, loaded host time
full scan 1.5 to 1.6 s
delta merging 1,000 late peer rows and 1,000 own appends 92 ms

The cut reads. Both are shaped so that only the (origin_node, share_seq) index can serve them: origin_node BETWEEN $1 AND $1 … ORDER BY origin_node DESC, share_seq DESC LIMIT 1.

  • A plain max(share_seq) WHERE origin_node = N was measured walking the primary key through the other node's whole run (300,000 rows filtered), inside ORDER_LOCK. That happens whenever a node's rows are a fair share of a partition but all lie under the peer's run, as after failback.
  • This node's entry is first probed at or above the retained window's entry, so under ORDER_LOCK it reads the newest partitions, usually one, as 3.0's cutoff does. The probe of every partition runs only for a first snapshot, or when that one finds nothing.
  • Gated plan-shape tests guard both reads.

Uses D1's migration 031. The index is the base's migration 031 (CONTRACT D-14), qbit_share_ledger_origin_seq_idx. Without a valid btree index on those columns, a dual-writer snapshot refuses before taking any lock, so it never scans the ledger inside ORDER_LOCK. While it refuses, the frontend publishes no new work, and two things say why:

  • the refresh loop logs an ALERT at most once a minute;
  • qbit_prism_dual_writer_origin_index_missing reads 1.

Refresh. Published work keeps 3.0's same-template cadence. As in 3.0, empty-window (bootstrap) work is the exception: the first share replaces it at once, and so does any move of the peer's mark until a window holds shares, labelled shares. A cached window is not reused for a new template once the peer's mark has moved (D-13), because the peer's newer rows can all lie below this node's cutoff. Nor is it reused while an accepted peer row at or below the mark waits for a later anchor (stamped ahead by a peer clock running ahead), so that row joins the next template's window instead of waiting for the reanchor. In dual-writer mode, the refresh probe reads the mark in the statement that already reads the revision and the writer timeline.

Storage.

  • The window reference carries cut (absent when None) inside the candidate document and the prepared-job payload, both digest-checked. compact_issued's jsonb column check compares the payload's window without it in every mode, since the typed columns never carry it and a single writer started under D-12's downgrade must accept dual-era prepared rows.
  • Migration 028 adds cut_seq_0 and cut_seq_1 to qbit_prism_audit_snapshots. Both are NULL without a cut, 0 means no row of that node, and a CHECK enforces the shape. It is additive, needs no capability or shutdown proof, and is registered after 027, before the online 031. The table inventory copies both columns as content, since the table has no local parts.
  • The recovery evidence exports the cut only where a row has one, and its tamper test changes a cut.
  • The public read's schema-readiness probe requires both new columns, since audit reconstruction selects them.

Audit bundle (crates/qbit-prism).

  • reward_manifest.cut and the stored header carry the cut, absent when None. The coinbase commits it through the reward-manifest leaf.
  • The builders take the cut, and the verifier rebuilds a manifest under its own cut.
  • A window share above the cut's highest entry is refused (ShareOutsideWindowCut). A dropped, added or altered cut fails at the commitment leaf.
  • qbit-prism-build-audit-bundle accepts window_cut, one-shot and over --serve, whose protocol goes to 3 so a client that sends a cut can refuse a daemon that would drop it. audit-verify and audit-canonicalize handle both shapes.
  • A 3.0 verifier refuses a dual-writer bundle rather than mis-verifying it. reorg-verify reads only policy manifests and is unchanged. The --serve daemon's legacy window fold (window.rs) serves only the 2.x coordinator and is unchanged.

Single-writer parity (CONTRACT §4.5). With dual-writer mode off, no window has a cut. Every eligibility, snapshot, probe and refresh statement is 3.0's text, and a unit test pins the predicate. Two statements differ in text only, both so a single writer started under D-12's downgrade handles the rows a dual-writer frontend wrote:

  • audit reconstruction's primary-key lookup of the snapshot row also selects cut_seq_0 and cut_seq_1, which are NULL on every single-writer row;
  • the issued-job dependency check compares the payload's window without its cut key, which a single writer's payloads do not have. A unit test pins it to 3.0's text with that one expression swapped back.

Both give 3.0's results on a single writer's rows.

  • Every existing golden, money-path vector and fixture verifies byte-identically.

How it was tested

  • crates/qbit-prism/tests/window_cut_bundles.rs (14 tests):
    • a dual-writer fixture: both nodes' parities, pre-3.1 history, a gap, late node-1 rows outside the cut, a partially counted crossing share;
    • library and binary build, verify and canonicalize, one-shot and through --serve;
    • pinned coinbase and CTV-settlement goldens;
    • parallel equal to serial;
    • tampering, and shares above the cut;
    • header compatibility, and a duplicate share_id across nodes refused;
    • a randomized two-node reproduction model.
  • snapshot_delta/cut_merge_tests.rs: a 512-case proptest of the merge, the margin and the assembly against a model of the full scan, plus the per-node refusals and the union bound.
  • Gated PostgreSQL tests with both nodes' rows in one ledger (ledger::window::cut::dual_writer_tests):
    • cut selection against a model;
    • late peer rows never changing a built window under any proof, with a no-cut negative control that does fail;
    • peer clock skew, checked against the verifier;
    • the same window reproduced on the other node's database;
    • a seeded incremental-advance walk that merges late rows;
    • single-writer parity on a ledger holding peer rows;
    • the refusal without the origin index (a BRIN index included), its typed error and its gauge;
    • the holding probe under a rewound mark, a lost own entry and a pruned prefix;
    • the refresh probe's and the snapshot's peer mark, and a peer row pending a later anchor;
    • the plan-shape guards, pinned to 031's index, and the bounded own-cut read across four partitions.
  • Gated landings through the production path:
    • coordinator::window_switch_tests, through process_candidate (the offer, then the rebuild and the landing): an idle peer with direct settlement, both nodes' rows with CTV, and a block whose first landing failed, which lands on its reconciliation retry without a second offer;
    • tests/dual_writer_windows.rs: landings from the rebuilt audit, with late peer rows between snapshot, enqueue and landing, an idle peer, and a dual-writer bootstrap block; a bundle whose cut disagrees with its reference is refused.
    • Without the rebuild's cut, the five non-bootstrap landings fail as D6's integration run did.
  • miner_tests::refresh: bootstrap work replaced when only the peer mark moves, full work keeping its cadence, and new templates not reusing a window while a peer row is pending.
  • A measurement harness (measure_dual_writer_refresh, ignored).
  • Every version pin gains 28 beside the base's 31, undo_006 undoes it, and the new gated tests are registered in test/prism-gated-tests.txt.
  • Local runs on a shared, loaded host (private PostgreSQL 16, pinned qbitd):
    • every suite this branch touches passes on the final head, with the lock-timeout-prone modules rerun at one thread;
    • the full gated suite (CI's shard commands, without live_regtest and the release-mode compact_runtime_scale, which CI runs) is running on d04cdc46, this branch before the last review's fixes, on D1's 193e7fd8. Its results follow in a comment.

Docs: dual-writer window cuts, the 028 paragraph in prism-rust-migration.md, and the new gauge in prism-native-metrics.md.

🤖 Generated with Claude Code

@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-19T18:48:18.372089Z ddd3139 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.

@blacksmith-sh

This comment has been minimized.

@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: a07a594dfe

ℹ️ 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 added a commit that referenced this pull request Oct 10, 2026
A build request's window_cut, added for PRISM 3.1's dual-writer windows,
changes what the daemon signs. A protocol 2 daemon ignores the field and
signs a reward manifest without the cut, and the build summary cannot show
that. The handshake now announces 3, so a client that checks the version
exactly refuses a pre-cut daemon instead of distributing work that does
not commit to the cut it asked for.

The native server builds in process and never starts the daemon. The doc
comment now says so, and that the client which checked the version was the
retired Python coordinator.

A new test sends the dual-writer fixture's window, with its cut, through
--serve. The daemon's job summary must equal a one-shot build's with the
cut, and that differs from the build without it. The serve tests that pin
the handshake, and the deleted-test map, now say 3. From Codex's review of
#768.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke

Copy link
Copy Markdown
Member Author

Reply to the review thread Bump the serve protocol for cut-aware requests. The token cannot reply in the thread itself.

Fixed in 2b4e819. SERVE_PROTOCOL_VERSION is now 3. Its doc comment explains why: a version 2 daemon would ignore window_cut and sign a manifest without the cut, so a client that sends a cut needs a daemon announcing 3. The handshake checks in audit_cli.rs and window_daemon_gate.rs and the deleted-test map now say 3.

A new test, window_cut_bundles.rs::a_serve_build_with_a_cut_signs_what_the_one_shot_build_signs, sends the dual-writer fixture's window with its cut through --serve. The daemon's job summary must equal a one-shot build's with the cut, which differs from the build without it.

For context: the native server builds in process and never starts the daemon, and the client that checked this version was the retired Python coordinator. So this guards future clients; no deployed path is affected.

@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: 2b4e819c21

ℹ️ 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 added a commit that referenced this pull request Oct 10, 2026
… every mode

The issued-job saves check that a prepared row's payload agrees with its
typed columns. In dual-writer mode the payload's window was compared
without its cut, which the columns never carry. A single writer issued
3.0's whole-window comparison. A single writer started under D-12's
downgrade would therefore refuse every live prepared row a dual-writer
frontend wrote, though the work is valid and lands under its stored cut.

The comparison now drops the cut key in every mode. On a 3.0 payload,
which has no cut, that changes nothing. The window must be an object, and
a cut in it an object too, so a malformed payload is a mismatch, as 3.0
reported it, and never a statement error. It is the statement's one
difference from 3.0's text: the second deliberate single-writer exception,
beside audit reconstruction's read of the cut columns, and for the same
D-12 reason.

A unit test pins the statement to 3.0's digest once that one expression is
swapped back. A gated test writes a dual-writer prepared row and checks it
on a ledger with no dual-writer identity. The row matches its columns
there, and 3.0's whole-window comparison refuses it. Another key, a null
or scalar cut, a scalar window or a changed column still fails. From Codex's review of #768.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke

Copy link
Copy Markdown
Member Author

Reply to the review thread Preserve cut-aware prepared jobs during downgrade. The token cannot reply in the thread itself.

Fixed in 72572fe, taking the second option: the dependency statement compares the payload's window without its cut key in every mode, so a single writer started under D-12's downgrade accepts the prepared rows a dual-writer frontend wrote. The typed window columns never carried the cut. On a 3.0 payload, which has no cut, the expression is the whole window. The mode-dependent statement pair is gone, and dependency_row no longer takes the mode.

The window must be an object, and a cut in it an object too, so a malformed payload reads as a mismatch, as 3.0 reported it, and never raises "cannot delete from scalar".

Tests:

  • A unit test pins the statement to 3.0's text digest once that one expression is swapped back.
  • A gated test writes a dual-writer prepared row (its cut serialized by WindowCut) and checks it on a ledger with no dual-writer identity. The row matches its columns, and 3.0's whole-window comparison refuses it. Another key, a null or scalar cut, a scalar window, or a changed column still fails.

This is the second single-writer text exception, beside audit reconstruction's read of the cut columns, and for the same D-12 reason. The PR body lists both.

@RobertClarke

Copy link
Copy Markdown
Member Author

Local full-suite results, as the PR body promised.

The suite ran CI's shard commands as one shard, without live_regtest and the release-mode compact_runtime_scale, on d04cdc46: this branch before the last review's fixes, on D1's 193e7fd8. The host is a shared one under heavy load (load average 8 to 20). I stopped the run at 95 of 142 targets once CI went green on the final head, 72572fe1, which runs all of them.

  • 83 of the 95 targets passed.
  • The 12 others each failed one or a few tests, and every failure was a timeout or a timing budget, never a correctness check:
    • canceling statement due to lock timeout in tests that migrate schemas in one shared database: park_tests, share_hashes and the acquire job_tests in the lib, plus compact_runtime_observer;
    • statement timeouts in b478_payout_integrity, candidate_window_switch and compact_issued_repair;
    • test deadlines in b478_capture_overpay, chain_epoch_migration, b602_order_lock_hold and b275_persistence_measure;
    • latency budgets in the qbit-prism-load harness (faults, load_smoke, real_node). Their durability and reconciliation checks passed: no acknowledged share lost, reconciliation exact.
  • On the final head, CI passes every one of these targets, including all four PostgreSQL shards and the proof that every gated test executed.
  • Every suite this branch touches also passed locally on the final code. The lock-timeout-prone modules passed when rerun at one thread.

@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: 22abcd9601

ℹ️ 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 added a commit that referenced this pull request Oct 10, 2026
… pending its anchor

Codex on #768 (PRRT_kwDOS9jIOc6rEtvE): a peer row at or below the mark
but stamped after the window's anchor, by a peer clock running ahead,
joins a later anchor's window with no new row and no move of the mark.
The reuse rule compared only the mark and the accepted cutoff, so a new
template could keep the old window, and leave that share out of the
work, until the reanchor interval ran out.

The peer-cut statement now also returns the peer's newest accepted row
under the same bounds, whatever its stamps, by the same index walk on
031's index, which stops there. When that row is above the peer's entry,
the snapshot reports a peer row pending (PeerCut::pending, carried on
SnapshotCapture and RefreshWindow), and RefreshWindow::reusable refuses
the window, so the next template reads a fresh one. Same-template work
keeps 3.0's cadence, as before.

Tests: the gated clock-skew test asserts the flag while the rows wait,
its clearing once this node's clock passes them, and that a rejected row
above the entry is never pending. A unit test covers reusable, and a
coordinator test shows new templates at an unchanged revision reading a
snapshot while a row is pending and reusing the window once none is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke

Copy link
Copy Markdown
Member Author

Re the P2 at refresh_window.rs:113 (thread PRRT_kwDOS9jIOc6rEtvE, "Re-evaluate peer rows that age into the anchor"): fixed in 5e7eac6.

  • The peer-cut statement now also returns the peer's newest accepted row at or below the mark, whatever its stamps. It uses the same walk on migration 031's index and stops at that row.
  • When that row is above the peer's entry, the snapshot reports a peer row pending (PeerCut::pending, carried on SnapshotCapture and RefreshWindow).
  • RefreshWindow::reusable refuses a pending window, so the next template reads a fresh window instead of holding the row back until the reanchor.
  • Same-template work keeps 3.0's cadence, as before.

Tests:

  • the gated clock-skew test asserts the flag while the rows wait, its clearing once this node's clock passes them, and that a rejected peer row above the entry is never pending;
  • a unit test covers reusable;
  • a coordinator test drives new templates at an unchanged revision, which read a snapshot while a row is pending and reuse the window once none is.

The plan-shape guard still pins both cut reads to 031's index, with no filtered rows.

@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: 6bf65fea7f

ℹ️ 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/src/audit_body_ref.rs Resolved
@RobertClarke

Copy link
Copy Markdown
Member Author

Re the P1 at crates/qbit-prism/src/audit_body_ref.rs:358 (thread PRRT_kwDOS9jIOc6tByaz, "Allow gapped sequences in cut-aware audit bundles"): addressed in 0217e3c by refusing, not by supporting gaps.

  • qbit.prism.audit-body-ref.v1 and qbit.prism.audit-bundle.v2 are 2.x storage envelopes. The cutover import, the read-model API's legacy bodies and the verify and canonicalize CLIs read them; no 3.x writer produces them, and 2.x never wrote a window cut. Their completeness checks rely on one contiguous share_seq run, which a cut window need not be.
  • Both resolvers now refuse a bundle whose reward manifest carries a cut, by name ("… predates dual-writer window cuts: a bundle whose reward manifest has a cut is only valid as a flat audit bundle"), before any reconstruction. A cut window travels only as a flat logical bundle, which is what every 3.x path stores and serves.
  • window_cut_bundles::the_legacy_envelopes_refuse_a_window_cut_by_name wraps the gapped cut fixture in each envelope and checks the named refusal, and that the same bundle parses flat.

RobertClarke added a commit that referenced this pull request Oct 16, 2026
Codex on #768 (PRRT_kwDOS9jIOc6tByaz): the audit-body-ref.v1 and
audit-bundle.v2 envelopes check that their shares form one contiguous
share_seq run, which a dual-writer window with a cut need not be (a late
peer row outside the cut leaves a gap), so such an envelope failed as
non-contiguous.

These envelopes are 2.x storage artifacts: the cutover import, the
read-model API's legacy bodies and the verify and canonicalize CLIs read
them, no 3.x writer produces them, and 2.x never wrote a cut. Both
resolvers now refuse a bundle whose reward manifest has a cut, by name and
before any reconstruction, rather than half-checking it; such a bundle is
valid only as a flat logical bundle, which every 3.x path stores and
serves. A test wraps the gapped cut fixture in each envelope and checks
the named refusal, and that the flat bundle still parses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke and others added 13 commits October 19, 2026 14:43
A new WindowCut type ({"0": share_seq|null, "1": share_seq|null}) names
the highest share_seq of each node's rows a dual-writer window may include.
The reward manifest and its stored header carry it as `cut`, absent when
None, so every existing bundle, fixture and vector keeps its bytes. The
coinbase commits the cut through the reward-manifest leaf.

The builders take the cut as an input, and the verifier rebuilds a manifest
under its own cut. Every window share must be at or below the cut's highest
entry (ShareOutsideWindowCut). Dropping, adding or altering a cut fails at
the commitment leaf. The build-audit-bundle binary accepts `window_cut`.

Adds a dual-writer fixture: both nodes' share_seq parities, pre-3.1
history, a gap, late node-1 rows outside the cut, and a partially counted
crossing share. Also adds the window_cut_bundles tests (library and binary
build, verify and canonicalize; tampering; parallel equals serial; a
randomized two-node reproduction model) and pinned golden digests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…are_id from both nodes

The CTV-settlement build of the dual-writer fixture is pinned beside the
coinbase-options build: the reward manifest, cut included, also feeds every
fan-out precommitment, and both builds commit to the same manifest. A
window holding one share_id from both nodes is refused by the fold in the
builder and every verifier, never credited twice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ation 028

In dual-writer mode every payout window records a per-node cut: the
highest share_seq of each node's rows it may include. A row is eligible
when it is eligible as in 3.0 (accepted, and accepted and issued at or
before the anchor) and its share_seq is at most its node's entry.

This node's entry is its newest own row, read under ORDER_LOCK in the
cutoff's statement. The peer's entry is its newest row at or below the
peer sync's safe mark (qbit_prism_peer_share_mark(), D-14) that is stamped
at or before the anchor. A peer row that arrives late is above the peer's
entry, so it is outside every window built before it and joins later
ones.

The anchor rule stays on every row (D-13). Each node's stamps rise with
its share_seq, so the cut alone decides membership. Clock skew can only
delay a peer's newest shares, never make a window irreproducible or a
landing fail.

Every path that selects, re-reads or proves a window applies the cut: the
snapshot and full scan, read_window, verify_durable_range, the in-lock
count, audit persistence and reconstruction, the #619 holding probe and
the leaf witness. The incremental advance reads each node's new rows
between the old and fresh cuts and merges the peer's late rows in
share_seq order (advance_in_cut), proved by the existing leaf witness and
eligible-row count.

At a 200k-row window a merge of 1,000 late peer rows and 1,000 own appends
takes about 92 ms, against 1.5 to 1.6 s for the full scan.

The cut reads are shaped so only the (origin_node, share_seq) index can
serve them. A plain max() with an equality filter was measured walking the
primary key through the other node's whole run inside ORDER_LOCK. The
index ships as D1's migration 031; until a ledger has a valid one, a
dual-writer snapshot refuses before it takes any lock. The dual-writer
test fixtures create the same index meanwhile.

A cached window is not reused for a new template once the peer's mark has
moved, since the peer's newer rows can all lie below this node's cutoff.
The refresh probe reads the mark in dual-writer mode only.

WindowRef carries the cut, absent when None, inside the digest-checked
candidate document and prepared payload. Migration 028 adds cut_seq_0 and
cut_seq_1 to qbit_prism_audit_snapshots. Bundles commit the cut in
reward_manifest.cut, except a bootstrap window's. With dual-writer mode off
nothing has a cut, and every eligibility, snapshot, probe and dependency
statement is 3.0's.

Tests:
- a 512-case proptest of the merge against the full scan;
- gated tests with both nodes' rows in one ledger: the model, late rows
  with a no-cut negative control, clock skew, reproduction on the other
  node's database, a seeded advance walk, single-writer parity, the plan
  shape, the refusal without the index, and the peer mark;
- gated landings with late peer rows;
- a measurement harness.

Every version pin gains 28.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…w's cut, so it lands

The audit rebuild that every post-offer landing and every reconciliation
retry runs (build_claim_parts) called the serial builders, which build
without a cut. The coinbase was built by bundle_build with the window's
cut. So every dual-writer block was accepted on chain, but its landing
failed with "audit parts' window cut None differs from the candidate's
window reference" and the row stayed in reconciliation. D6 found it in
its S1 and S5 scenarios.

The rebuild now applies the rule bundle_build applies. A dual-writer
window's audit carries the reference's cut, whether or not the peer's
entry is empty. A single writer's window, and the bootstrap window with
its one synthetic share, carry none, so those bytes are 3.0's.

A row the failed landing left in reconciliation lands on its next retry:
it keeps every input, and the retry rebuilds the audit from them.

Tests:
- three coordinator tests through process_candidate (offer, rebuild,
  landing): an idle peer with no mark, under direct settlement; both
  nodes' rows, under CTV settlement; and a block whose first landing
  failed, which lands on its reconciliation retry without a second offer;
- the ledger-level landing tests now land the rebuilt audit, check it is
  the one the coinbase committed to, and gain an idle-peer case.

Without the fix, the three coordinator tests and both non-bootstrap
ledger tests fail with D6's error. The window_switch fixture now builds
coinbases with the snapshot's cut. That cut is None for every
single-writer test, so their bytes are unchanged.

The test fixtures' stand-in index takes migration 031's name,
qbit_share_ledger_origin_seq_idx (CREATE INDEX IF NOT EXISTS). The
plan-shape guard pins its cut reads to that index or its partitions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t 031's index, with a gauge

Without migration 031's (origin_node, share_seq) index, a dual-writer
snapshot refuses before it takes any lock, and the refresh loop logged
that refusal on every tick and wake: 920 lines in three minutes per
frontend in D6's integration run.

The refusal is now typed (OriginIndexMissing). The refresh loop logs it
as an ALERT at most once a minute, and again at once after a successful
refresh. The snapshot sets a new gauge,
qbit_prism_dual_writer_origin_index_missing: 1 while it refuses, 0 once
it finds the index. A single writer declares the gauge without a sample.
The metric census pins move with it. They also take in the peer sync's
families, which the base had not counted.

The refusal test checks the type, the gauge in both states, and only its
own database's advisory locks; other tests share the cluster.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lding probe and bootstrap work

Fixes from the second local review and the coordinator's review of
a3e9854.

The cut entries:
- This node's entry is now its newest own row eligible at the anchor, so
  both entries are rows the window's predicate admits, and the higher one
  is the window's newest row. A rejected or future-stamped legacy row on
  top no longer stops the incremental advance.
- The own-cut read inside ORDER_LOCK first probes at or above the
  retained window's entry, which reads only the newest partitions, as
  3.0's cutoff does. The probe of every partition runs only for a first
  snapshot, or when that one finds nothing.
- The index check requires a btree whose two columns share one
  direction.

The #619 holding probe of a dual-writer window also checks this node's
entry row, and that the peer sync's mark covers the peer's entry. A
restore can lose each log's newest rows while the window's last row
survives.

Bootstrap work: empty-window work is replaced as soon as the peer mark
moves, as a first share replaces it. The refresh trigger label and the
work's equivalence check now see the cut.

The incremental advance:
- the delta bound counts the union of the nodes' ranges, not their sum;
- the margin walk and the witness-and-count proof are shared with 3.0's
  advance, and its statements keep 3.0's text.

Statements:
- The refresh probe reads the peer mark in its revision statement. A
  single writer's statement is 3.0's.
- compact_issued's two dependency statements are built at compile time
  from one text. A test pins the single writer's to 3.0's digest.

Tests:
- the holding probe under a rewound mark, a lost own entry and a pruned
  prefix;
- the bounded own-cut read across four partitions;
- the plan guards with the new parameters;
- a BRIN index refused;
- bootstrap work replaced when the mark moves, while full work keeps its
  cadence;
- the union bound;
- pinned statement texts.
audit_completeness's hand-made snapshot table gains 028's columns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s, one margin step, wording

Fixes from the last local review before the PR:

- The peer's entry is read in the second transaction, after ORDER_LOCK.
  It is now bounded by the mark read there as well as by the mark the
  cutoff's statement read, so a mark rewound in between never admits a
  peer row whose lower rows this database no longer holds. The cutoff
  still bounds every admitted row.
- The dual-writer cutoff statement is planned with its values, as every
  bounded ledger read here is, so the retained entry prunes partitions in
  every plan.
- Both merges carry one Margin, whose take step is the only copy of the
  saturating fold below the retained first row. The proptest uses it too.
- read_range_paged says it applies 3.0's predicate with no cut.
- The ops doc says a held window's last row matches the window's
  predicate, whichever node wrote it. It also says bootstrap work is
  replaced whenever the peer's mark moves until a window holds shares.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The base now carries migration 031, which creates
qbit_share_ledger_origin_seq_idx on every fixture the tests migrate. The
fixtures' own CREATE INDEX IF NOT EXISTS is gone. The refusal test, which
drops the index, still restores it under 031's name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e readiness probe, evidence

Fixes from the last local review before the PR:

- The peer's entry is bounded by the mark now inside the peer-cut
  statement itself, beside the mark the cutoff's statement read, so a
  rewind between statements is covered too, with one round trip fewer.
  The statement also returns the mark the entry used, and the snapshot
  records that one for the refresh to compare. A rewound mark that comes
  back then rebuilds the window.
- The dual-writer cutoff statement is cached again, as 3.0's cutoff is,
  so no plan is made under ORDER_LOCK. A generic plan prunes the leaves
  below the retained entry at executor start, which the bounded-probe
  guard checks.
- The public read's schema-readiness probe requires 028's cut_seq_0 and
  cut_seq_1, which audit reconstruction selects.
- The recovery-evidence tamper test also changes a snapshot's cut and
  expects the evidence to see it.
- migration.rs and the migration guide say 028 is taken, and 29 and 30
  stay reserved.
- The measurement harness drops 031's index for its no-index case. The
  refusal test drops its BRIN index before it restores 031's. The
  plan-shape guard sets a peer mark, as a synced ledger has one, so the
  peer read's walk is bounded and planned on 031's index. The
  dual-writer ops paragraphs are rewrapped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Three of this branch's checkout sites changed shape:
- audit reconstruction's read_range call now passes the stored cut;
- the snapshot's advance call now passes the cut;
- verify_durable_range's newer-row probe is now two timed checkouts, one
  per branch, with only one running.

The census entries are updated to match. The timed count goes from four to
five, and the policies stay the same.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A build request's window_cut, added for PRISM 3.1's dual-writer windows,
changes what the daemon signs. A protocol 2 daemon ignores the field and
signs a reward manifest without the cut, and the build summary cannot show
that. The handshake now announces 3, so a client that checks the version
exactly refuses a pre-cut daemon instead of distributing work that does
not commit to the cut it asked for.

The native server builds in process and never starts the daemon. The doc
comment now says so, and that the client which checked the version was the
retired Python coordinator.

A new test sends the dual-writer fixture's window, with its cut, through
--serve. The daemon's job summary must equal a one-shot build's with the
cut, and that differs from the build without it. The serve tests that pin
the handshake, and the deleted-test map, now say 3. From Codex's review of
#768.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… every mode

The issued-job saves check that a prepared row's payload agrees with its
typed columns. In dual-writer mode the payload's window was compared
without its cut, which the columns never carry. A single writer issued
3.0's whole-window comparison. A single writer started under D-12's
downgrade would therefore refuse every live prepared row a dual-writer
frontend wrote, though the work is valid and lands under its stored cut.

The comparison now drops the cut key in every mode. On a 3.0 payload,
which has no cut, that changes nothing. The window must be an object, and
a cut in it an object too, so a malformed payload is a mismatch, as 3.0
reported it, and never a statement error. It is the statement's one
difference from 3.0's text: the second deliberate single-writer exception,
beside audit reconstruction's read of the cut columns, and for the same
D-12 reason.

A unit test pins the statement to 3.0's digest once that one expression is
swapped back. A gated test writes a dual-writer prepared row and checks it
on a ledger with no dual-writer identity. The row matches its columns
there, and 3.0's whole-window comparison refuses it. Another key, a null
or scalar cut, a scalar window or a changed column still fails. From Codex's review of #768.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
D1's 7658fa2 made a cursor's ingested_through the highest peer row a
pull refused as a conflict, quarantined for good, NULL while none was.
The window-cut fixtures still set it to the mark, which now reads as a
pull that refused every peer row through it, a state the peer's
found-block wait would never confirm a block under. They now set only
scanned_through, as a clean pull leaves the cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke and others added 3 commits October 19, 2026 14:43
…d the quarantine in D-14's wording

D1's the_sync_carries_every_column_the_inventory_does_not_keep_local pins
every column the peer sync copies, and failed on the merge: 028 added
cut_seq_0 and cut_seq_1 to qbit_prism_audit_snapshots. The sync carries
that table whole, so a synced block's snapshot already brings its cut;
both columns are now pinned. The snapshot conflict check still compares
only the content-determined columns, as D1 wrote it for windows that
share one share array.

Since D1's 7658fa2 a peer row the sync refused as a conflict is
quarantined for good, below a mark that moves past it. Windows taken here
leave it out and stay whole, but one whose range spans it reproduces only
on the node that took it. cut.rs and the ops doc said every peer row at or
below the mark is committed here; they now name the exception. The
window-cut integration helper's mark upsert also sets peer_node, as its
twin in cut/dual_writer_tests does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… pending its anchor

Codex on #768 (PRRT_kwDOS9jIOc6rEtvE): a peer row at or below the mark
but stamped after the window's anchor, by a peer clock running ahead,
joins a later anchor's window with no new row and no move of the mark.
The reuse rule compared only the mark and the accepted cutoff, so a new
template could keep the old window, and leave that share out of the
work, until the reanchor interval ran out.

The peer-cut statement now also returns the peer's newest accepted row
under the same bounds, whatever its stamps, by the same index walk on
031's index, which stops there. When that row is above the peer's entry,
the snapshot reports a peer row pending (PeerCut::pending, carried on
SnapshotCapture and RefreshWindow), and RefreshWindow::reusable refuses
the window, so the next template reads a fresh one. Same-template work
keeps 3.0's cadence, as before.

Tests: the gated clock-skew test asserts the flag while the rows wait,
its clearing once this node's clock passes them, and that a rejected row
above the entry is never pending. A unit test covers reusable, and a
coordinator test shows new templates at an unchanged revision reading a
snapshot while a row is pending and reusing the window once none is.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codex on #768 (PRRT_kwDOS9jIOc6tByaz): the audit-body-ref.v1 and
audit-bundle.v2 envelopes check that their shares form one contiguous
share_seq run, which a dual-writer window with a cut need not be (a late
peer row outside the cut leaves a gap), so such an envelope failed as
non-contiguous.

These envelopes are 2.x storage artifacts: the cutover import, the
read-model API's legacy bodies and the verify and canonicalize CLIs read
them, no 3.x writer produces them, and 2.x never wrote a cut. Both
resolvers now refuse a bundle whose reward manifest has a cut, by name and
before any reconstruction, rather than half-checking it; such a bundle is
valid only as a flat logical bundle, which every 3.x path stores and
serves. A test wraps the gapped cut fixture in each envelope and checks
the named refusal, and that the flat bundle still parses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke changed the base branch from RobertClarke/p31-identity-sync to 3.x.x October 19, 2026 18:43
@RobertClarke
RobertClarke force-pushed the RobertClarke/p31-window-cuts branch from b81f111 to ddd3139 Compare October 19, 2026 18:43
@RobertClarke
RobertClarke merged commit 1a750c9 into 3.x.x Oct 19, 2026
39 checks passed
RobertClarke added a commit that referenced this pull request Oct 19, 2026
The notes cover everything since v3.0.0-rc.6: #770's import-audits fix
(#765) and #760's idle-connection bound (#759), which would have shipped as
rc.7, and the 3.1 dual writer (#766, #768, #767, #769, #763), off by
default. They describe the new settings, migrations 027, 028 and 031 (029
and 030 reserved), the upgrade from rc.6 with the migrate run while rc.6
serves, the rollbacks, and the dual writer's known limits. The migration
guide's import-audits paragraph names this candidate in place of the
skipped rc.7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
RobertClarke added a commit that referenced this pull request Oct 20, 2026
* 3.x.x: version 3.1.0-rc.1

VERSION, the workspace version and both lockfiles move to 3.1.0-rc.1.
The fuzz lockfile also picks up hyper and hyper-util, which #769 added to
the server without refreshing it. The 3.0.0 and development-line notes
point at the new candidate; its own notes follow in this pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 release notes

The notes cover everything since v3.0.0-rc.6: #770's import-audits fix
(#765) and #760's idle-connection bound (#759), which would have shipped as
rc.7, and the 3.1 dual writer (#766, #768, #767, #769, #763), off by
default. They describe the new settings, migrations 027, 028 and 031 (029
and 030 reserved), the upgrade from rc.6 with the migrate run while rc.6
serves, the rollbacks, and the dual writer's known limits. The migration
guide's import-audits paragraph names this candidate in place of the
skipped rc.7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 notes: #773's pre-migrate tests

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* 3.x.x: 3.1.0-rc.1 notes: the rollback to one writer stops and syncs the peer first

Codex on #774: DOWNGRADE fences nothing, so the peer must be stopped, and its
tail pulled, before the single-writer start; declare the tail lost only for a
peer that never returns with its own database.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke deleted the RobertClarke/p31-window-cuts branch November 3, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant