Skip to content

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
kiwidream merged 2 commits into
3.x.xfrom
orca/711-append-server-call
Oct 28, 2026
Merged

kiwidream merged 2 commits into
3.x.xfrom
orca/711-append-server-call

Conversation

@kiwidream

@kiwidream kiwidream commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

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

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_seq from the sequence, leaving a gap. share_seq already comes from a sequence, so rollbacks have always left gaps, and the window proofs tolerate them. The contiguity check in audit_body_ref applies only to legacy 2.x segment formats, which no 3.x writer produces.

Tests

  • append_admission 32: 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_clock 8, including the 3.1.0 statements interleaved with the call.
  • window_read_oracle 8, b602_order_lock_hold 22, ledger_postgres 253, offer_lifecycle 26, dual_writer_sync 24, share_partitions_postgres 10, migration_rollback 13, and lib ledger:: 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).
  • fmt, clippy (server and dual-sim) and the guards pass.

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


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

@kiwidream
kiwidream changed the base branch from 3.x.x to orca/738-ledger-clock-append-only October 28, 2026 17:33
@kiwidream
kiwidream added this pull request to stack #803 October 28, 2026 17:33
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-28T19:02:09.878901Z 2813187 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.

@qbit-reviewer qbit-reviewer 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.

Incomplete review: only the available changes were reviewed.

No findings in the reviewed changes.

Base automatically changed from orca/738-ledger-clock-append-only to 3.x.x October 28, 2026 18:11
…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]>

@qbit-reviewer qbit-reviewer 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.

Incomplete review: only the available changes were reviewed.

No findings in the reviewed changes.

@kiwidream
kiwidream removed this pull request from stack #803 October 28, 2026 18:59

@qbit-reviewer qbit-reviewer 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.

Incomplete review: only the available changes were reviewed.

No findings in the reviewed changes.

@kiwidream
kiwidream merged commit 852e20e into 3.x.x Oct 28, 2026
41 checks passed
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]>
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