Repository navigation
3.x.x: append a share without a block in one server-side call, so ORDER_LOCK is held for that call and the COMMIT (#711) - #802
Merged
Conversation
kiwidream
changed the base branch from
3.x.x
to
orca/738-ledger-clock-append-only
October 28, 2026 17:33
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…ER_LOCK is held for that call and the COMMIT (#711) A share append held ORDER_LOCK across the lock statement, three statements and the COMMIT, each a client round trip that every other share of the cluster waited behind (#719). Migration 032 (additive, no table altered, no capability): - qbit_prism_append_share takes ORDER_LOCK and runs, each as a statement of its own and so each with a snapshot after the lock and any wait, what the frontend's statements ran: the write guard, the payout-revision fence (FOR SHARE when fenced), the share_id probe's inputs, the probe and its fallback, and for a new share the stamped row and its header mapping. - It returns the new share_seq and accepted_at, or the existing row for the frontend to compare, with its own measure of the lock wait and hold. - Refusals are raised before any write with SQLSTATEs QP001 to QP007, which the frontend maps back to the exact errors, and so the answers to miners, the statements gave (halted, legacy lease, PayoutRevisionChanged, the three duplicate-share refusals, a job from the future). - qbit_prism_ledger_clock is #738's clock, now one definition: the call, the statement-by-statement append (a share with a block, the settlement's deferred-share credit, a share whose fields fail its checks) and the snapshot anchor all stamp with it. - It alters no table, so #791's up-front table locks have nothing to take; its unit tests derive that from the file. Required from this release on. The frontend (ledger/window.rs): - A share without a block takes the call; the pre-commit gate and COMMIT stay with the frontend (commit_gated, shared with the statement path), so #716/#788's gate and its Contended retry are unchanged. - A lock or statement timeout, or a cancellation, fails the call before COMMIT and rolls the whole transaction back; the 23514 retry still sees the ledger INSERT's error. - Metrics: the ORDER_LOCK wait and the append hold are the server's measures (CalledOrderLock); a call that fails before reporting is a failed wait, and one that fails past its lock statement records neither. Mixed versions: a 3.1.0 frontend appending with its own statements beside one calling the function keeps share_seq order and rising stamps (its stamps are stored in the floor the clock reads); only a backward step of the database's own clock while both serve can break that. Tests: - append_admission: one call and the COMMIT under ORDER_LOCK for a new share, fenced or not, and a duplicate; refusals, the fence's waits, the probe after the fence, the 23514 retry and the uncertain COMMIT as before; a call cancelled waiting for the lock or past it rolls back whole without asking its gate, with the wait and hold recorded as above. - ledger_clock: the 3.1.0 statements interleaved with the call. - share_partitions_postgres: the probes' pruning is pinned by the leaves the append's transaction scanned, since EXPLAIN cannot reach them now. - commit_reconcile: an append abandoned while queued on ORDER_LOCK waits inside its call, which, once granted, runs to its end before the connection's cleanup rolls it back: no row, ORDER_LOCK released, at most one share_seq drawn (it was none before). - Migration: 032 in the native list, the required versions, the recovery evidence script, the schema rewinds to before 028 and to rc.6, and every hard-coded version list in the tests and the rc.6 pre-migrate scenario. Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream
force-pushed
the
orca/711-append-server-call
branch
from
October 28, 2026 18:11
dbdbeb1 to
0112b52
Compare
This was referenced Oct 28, 2026
kiwidream
added a commit
that referenced
this pull request
Nov 13, 2026
## Problem #814: after 3.1.1, several operator docs and the #731 parts-digest checker still described pre-3.1.1 behaviour. #819 shipped part of the fix; this PR does the rest. - The docs said every share append updates the cluster row, which stopped being true in #801. They gave that as the reason for the long-snapshot guidance and the backfill's 5 s cap. - The docs called the peer-sync prepared apply one transaction. Since #799 it runs in chunks. - The docs priced the share path at "ten statements and a ping", which #802 changed. - On 3.1.1, the checker reported `import_refuses` and exited 3 for 2.x v2 bodies that the import accepts. - Some references were already wrong in 3.1.0. ## The change **Cluster row (#801).** Each passage is now scoped to "while a frontend before 3.1.1 serves the database": - the files: prism-rust-migration.md, prism-ledger-ops.md (including the line next to the `/audit` routes) and the admission-gate comment; - the backfill's 5 s cap stays, explicitly as a conservative choice. The backfill can't tell which releases are serving, and a rolling upgrade mixes them; - MultiXact estimate: the clock `UPDATE`s left are the snapshot anchor's and the own-log floor's. A fenced append still locks the row `FOR SHARE` (032), so the MultiXact rate still grows with the share rate. **Prepared apply (#785/#799).** It is now described as chunks of at most 1,000 jobs and 2 MiB; a job whose blobs alone are larger goes in a chunk by itself. Each chunk is its own transaction under the cluster row's `FOR KEY SHARE`. - Files: prism-ledger-ops.md, prism-configuration.md, and the `config/dual_writer.rs` doc comment (comment only). - New peer-sync rows in the lock matrix and the lock-order table: prepared apply, and the own-log floor (SETTLEMENT → ORDER → cluster `NO KEY UPDATE`). **Share path (#802).** A share without a block takes three round trips and four statements: `BEGIN; SET LOCAL`, one call, `COMMIT`. A share that carries a block keeps the ten. **#731 checker.** `scripts/prism_legacy_parts_digest_check.py` gets an opt-in `--with-731-fix` mode, which models 3.1.1's import: - what it recomputes: 2.x's parts digest over the parts as 3.x parses them. That means known fields in declaration order with `kind` first, and inline shares in `AcceptedShare` form, using the sidecar tool's model. Non-ASCII is escaped; - statuses: `ok-in-3x` or `matches-neither`; - if `prism_legacy_range_sidecars.py` is not beside the checker, the mode refuses up front; - the default mode is byte-identical to before, with the same statuses, output and exit codes; - the docstring's "3.x refuses every 2.x v2 body" is corrected; - the #731 runbook gets a 3.1.1 command variant. **References.** - `/audit/latest-evidence` → `/audit/latest`. - Migration 17's refusals are no longer quoted as "migration 16". - The truncated native-collision quote is completed. - prism-alert-migration.md now says eight native rules page, with `critical` and `page: "true"`. - tests/perf/window_paging_allocation.md's re-run recipe starts from a worktree of #241's commit, which holds the harness that today's tree lacks. The image is built from 527b3ac's tree by path, since today's Dockerfile builds a different image. **#820 follow-up.** The `PrismAcceptedRevisionWorkTrackingUnknown` description now says an idle backup's unknown wait also ends when the block matures, if no authorized miner was connected since its acceptance. The text was changed at its source in `scripts/generate_prism_alerts.py`. The rule JSON, the migration doc tables and the qbit-tools patch were regenerated with `--snapshot` from the pinned qbit-tools a007a142 templates. ## Tests run (minidev-alex1) - `PRISM_AUDIT_CANONICALIZE_BIN=target/debug/qbit-prism-audit-canonicalize python3 -m unittest tests.test_prism_legacy_range_sidecars tests.test_prism_legacy_parts_digest_check tests.test_docs_lab_prism_references tests.test_prism_legacy_import_admission_gate`: OK (1 skipped). The canonicalizer was built with `cargo build --locked -p qbit-prism --bin qbit-prism-audit-canonicalize --bin qbit-prism-build-audit-bundle`. - New tests cover the fixed mode on both 2.x fixtures and on sorted-key and other digests. - They cover unknown keys, null bounds and escaping. - Inline-share variants are checked against the real canonicalizer: null `credit_policy`, an unknown key, reordered keys. - They check that the other statuses are unchanged, that `--jobs 3` parity holds, and that the checker runs when copied alone. - `python3 scripts/generate_prism_alerts.py --check`, `generate_prism_metrics.py --check`, `check_prism_settings.py`, `check_prism_alert_uids.py`, `check_gate_env_reads.py`: pass. - `python3 scripts/test_prism_alert_deployment.py --snapshot <qbit-tools a007a142 templates>`: patch applies, 10 Jinja gate combinations pass. - `cargo fmt --all -- --check`: pass. `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings`: pass (only the 3 known vendored sqlx-core warnings). - `bash -n scripts/prism_legacy_import_admission_gate.sh`: pass. ## What CI must cover - the Python test shards; - `make test-prism-legacy-range-sidecars`, which uses the real canonicalizer; - the alert PromQL check with promtool, not run here (only a description changed); - the full Rust suites. No Rust code changed, only one doc comment. Refs #814 🤖 Generated with [Claude Code](https://claude.com/claude-code) Squashed commits: 27d51e6 3.x.x: operator docs and the #731 checker catch up with 3.1.1 (#814) f84b602 3.x.x: --with-731-fix parses inline shares as 3.x does; review fixes (#814) 88f3ee3 3.x.x: the 3.1.1 #731 runbook still proves listed rows; checker loads its share model lazily (#814) 36f0c92 3.x.x: --with-731-fix refuses up front without its share model; wording fixes (#814) 99ada68 Merge remote-tracking branch 'origin/3.x.x' into orca/814-docs-catch-up da36f25 3.x.x: the window-paging re-run starts from #241's commit, which holds the harness (#814) Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream
added a commit
that referenced
this pull request
Nov 13, 2026
## Problem #814: after 3.1.1, several operator docs and the #731 parts-digest checker still described pre-3.1.1 behaviour. #819 shipped part of the fix; this PR does the rest. - The docs said every share append updates the cluster row, which stopped being true in #801. They gave that as the reason for the long-snapshot guidance and the backfill's 5 s cap. - The docs called the peer-sync prepared apply one transaction. Since #799 it runs in chunks. - The docs priced the share path at "ten statements and a ping", which #802 changed. - On 3.1.1, the checker reported `import_refuses` and exited 3 for 2.x v2 bodies that the import accepts. - Some references were already wrong in 3.1.0. ## The change **Cluster row (#801).** Each passage is now scoped to "while a frontend before 3.1.1 serves the database": - the files: prism-rust-migration.md, prism-ledger-ops.md (including the line next to the `/audit` routes) and the admission-gate comment; - the backfill's 5 s cap stays, explicitly as a conservative choice. The backfill can't tell which releases are serving, and a rolling upgrade mixes them; - MultiXact estimate: the clock `UPDATE`s left are the snapshot anchor's and the own-log floor's. A fenced append still locks the row `FOR SHARE` (032), so the MultiXact rate still grows with the share rate. **Prepared apply (#785/#799).** It is now described as chunks of at most 1,000 jobs and 2 MiB; a job whose blobs alone are larger goes in a chunk by itself. Each chunk is its own transaction under the cluster row's `FOR KEY SHARE`. - Files: prism-ledger-ops.md, prism-configuration.md, and the `config/dual_writer.rs` doc comment (comment only). - New peer-sync rows in the lock matrix and the lock-order table: prepared apply, and the own-log floor (SETTLEMENT → ORDER → cluster `NO KEY UPDATE`). **Share path (#802).** A share without a block takes three round trips and four statements: `BEGIN; SET LOCAL`, one call, `COMMIT`. A share that carries a block keeps the ten. **#731 checker.** `scripts/prism_legacy_parts_digest_check.py` gets an opt-in `--with-731-fix` mode, which models 3.1.1's import: - what it recomputes: 2.x's parts digest over the parts as 3.x parses them. That means known fields in declaration order with `kind` first, and inline shares in `AcceptedShare` form, using the sidecar tool's model. Non-ASCII is escaped; - statuses: `ok-in-3x` or `matches-neither`; - if `prism_legacy_range_sidecars.py` is not beside the checker, the mode refuses up front; - the default mode is byte-identical to before, with the same statuses, output and exit codes; - the docstring's "3.x refuses every 2.x v2 body" is corrected; - the #731 runbook gets a 3.1.1 command variant. **References.** - `/audit/latest-evidence` → `/audit/latest`. - Migration 17's refusals are no longer quoted as "migration 16". - The truncated native-collision quote is completed. - prism-alert-migration.md now says eight native rules page, with `critical` and `page: "true"`. - tests/perf/window_paging_allocation.md's re-run recipe starts from a worktree of #241's commit, which holds the harness that today's tree lacks. The image is built from 527b3ac's tree by path, since today's Dockerfile builds a different image. **#820 follow-up.** The `PrismAcceptedRevisionWorkTrackingUnknown` description now says an idle backup's unknown wait also ends when the block matures, if no authorized miner was connected since its acceptance. The text was changed at its source in `scripts/generate_prism_alerts.py`. The rule JSON, the migration doc tables and the qbit-tools patch were regenerated with `--snapshot` from the pinned qbit-tools a007a142 templates. ## Tests run (minidev-alex1) - `PRISM_AUDIT_CANONICALIZE_BIN=target/debug/qbit-prism-audit-canonicalize python3 -m unittest tests.test_prism_legacy_range_sidecars tests.test_prism_legacy_parts_digest_check tests.test_docs_lab_prism_references tests.test_prism_legacy_import_admission_gate`: OK (1 skipped). The canonicalizer was built with `cargo build --locked -p qbit-prism --bin qbit-prism-audit-canonicalize --bin qbit-prism-build-audit-bundle`. - New tests cover the fixed mode on both 2.x fixtures and on sorted-key and other digests. - They cover unknown keys, null bounds and escaping. - Inline-share variants are checked against the real canonicalizer: null `credit_policy`, an unknown key, reordered keys. - They check that the other statuses are unchanged, that `--jobs 3` parity holds, and that the checker runs when copied alone. - `python3 scripts/generate_prism_alerts.py --check`, `generate_prism_metrics.py --check`, `check_prism_settings.py`, `check_prism_alert_uids.py`, `check_gate_env_reads.py`: pass. - `python3 scripts/test_prism_alert_deployment.py --snapshot <qbit-tools a007a142 templates>`: patch applies, 10 Jinja gate combinations pass. - `cargo fmt --all -- --check`: pass. `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings`: pass (only the 3 known vendored sqlx-core warnings). - `bash -n scripts/prism_legacy_import_admission_gate.sh`: pass. ## What CI must cover - the Python test shards; - `make test-prism-legacy-range-sidecars`, which uses the real canonicalizer; - the alert PromQL check with promtool, not run here (only a description changed); - the full Rust suites. No Rust code changed, only one doc comment. Refs #814 🤖 Generated with [Claude Code](https://claude.com/claude-code) Squashed commits: dea2d9a 3.x.x: operator docs and the #731 checker catch up with 3.1.1 (#814) 27bec61 Merge 3.x.x (3d48a8f) into the #814 branch: the backfill passage keeps #801's note and #824's SQLSTATE rule 1fe7fba Merge 3.x.x (582849b) into the #814 branch: the deployment patch is regenerated beside #843's listener rule Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #711. Stacked on #801 (#738). A share append held ORDER_LOCK across the lock statement, three statements and the COMMIT, each a client round trip that every other share in the cluster waited behind (#719 cut it from nine). This does the in-lock work in one server-side call.
What changes
qbit_prism_append_sharetakes ORDER_LOCK and runs what the frontend's statements ran, each as its own statement with a snapshot taken after the lock: the write guard, the payout-revision fence (FOR SHARE when fenced), the share_id probe and its fallback, and for a new share the stamped row and its header mapping. It returns the newshare_seqandaccepted_at, or the existing row for the frontend to compare, plus its own measure of the lock wait and hold.qbit_prism_ledger_clockbecomes 3.x.x: every share append UPDATEs the qbit_prism_cluster singleton (ledger_clock_ms), so any snapshot held on the primary bloats it and saturates ORDER_LOCK in ~20 s at 400 shares/s; derive the clock from append-only state (rc.5) #738's clock in one definition, used by the call, the statement path and the snapshot anchor.ledger/window.rs): a share without a block takes the call. The pre-commit gate and COMMIT stay client-side, so 3.x.x: a share under a tip-change lease is refused 'commit gate closed' when the authority try_read meets a writer, which can drop a valid share's credit and fires PrismShareAppendFailures #716/3.x.x: wait out commit-gate contention and append again, so a lease's share keeps its credit (#716) #788's gate and its Contended retry are unchanged. ORDER_LOCK wait and hold metrics now come from the server's own measures.share_seqorder and rising stamps. Only a backward step of the database host's clock while both serve can break that, anddocs/prism-rust-migration.mddocuments it.Behaviour note
An append abandoned while queued on ORDER_LOCK now runs its call to the end once granted, then the connection cleanup rolls it back. There is still no row, no credit and no gate, but it can draw one
share_seqfrom the sequence, leaving a gap.share_seqalready comes from a sequence, so rollbacks have always left gaps, and the window proofs tolerate them. The contiguity check inaudit_body_refapplies only to legacy 2.x segment formats, which no 3.x writer produces.Tests
append_admission32: one call plus COMMIT under ORDER_LOCK; refusals; the fence's waits; the 23514 retry; an uncertain COMMIT; cancellation before and after the lock.ledger_clock8, including the 3.1.0 statements interleaved with the call.window_read_oracle8,b602_order_lock_hold22,ledger_postgres253,offer_lifecycle26,dual_writer_sync24,share_partitions_postgres10,migration_rollback13, and libledger::240 (including 3.x.x: lock 027's and 028's tables at once so the pre-migrate cannot deadlock (#789) #791's table-lock tests).Not run locally: the dual-sim rc.6 scenario, the replica and live suites, and a production re-measure of throughput.
🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.