Skip to content

3.x.x: operator docs and the #731 checker catch up with 3.1.1 (#814) - #848

Merged
kiwidream merged 1 commit into
3.x.xfrom
orca/814-docs-catch-up
Nov 13, 2026
Merged

kiwidream merged 1 commit into
3.x.xfrom
orca/814-docs-catch-up

Conversation

@kiwidream

@kiwidream kiwidream commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

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 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 UPDATEs 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:

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 2.x.x: bound Rust payout-window paging memory #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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T20:31:51.697788Z 7e572ab 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.

1 finding posted inline.

Not posted: 2 nits. Reviews post bugs and security points only; the rest stay in Sixth Man's ledger.

Reviewed by Claude Opus 5.5.

Comment thread tests/perf/window_paging_allocation.md Resolved

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

Still open from earlier reviews

  • [low] Re-run recipe cds into the 527b3ac worktree, so docker run mounts a tests/ without the harness: tests/perf/window_paging_allocation.md:453, first reported at 36f0c92

Not posted: 3 nits. Reviews post bugs and security points only; the rest stay in Sixth Man's ledger.

Reviewed by Claude Opus 5.5.

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

No bugs or security points found.

Not posted: 3 nits and 2 leads. Reviews post bugs and security points only; the rest stay in Sixth Man's ledger.

Reviewed by Claude Opus 5.5.

kiwidream added a commit that referenced this pull request Nov 13, 2026
… not the run's worst case (#859)

The bound's doc comment said four times the 15 s each statement and
checkout may take, but a run makes up to seven statements on the share
writer's pool, each with up to 15 s of checkout wait and the statement
timeout's 15 s of execution. Under a saturated writer pool, or with a
raised statement timeout, a valid run can pass 60 s every time, and the
route then answers 503 read_timeout until a run fits again, where before
#859 it answered slowly. The bound stays fixed, as #833's integrity
runs' is; the comment and docs/prism-ledger-ops.md now say what an
operator sees in that state and why.

docs/prism-deleted-test-map.md no longer calls /audit/latest a
per-request query. docs/prism-share-ledger-partitioning.md's stale
/audit/latest-evidence name is left to #848, which changes that line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kiwidream
kiwidream force-pushed the orca/814-docs-catch-up branch from da36f25 to dea2d9a Compare November 13, 2026 14:36

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

Approved: a complete review with no bugs found.

No bugs or security points found.

Not posted: 3 nits and 2 leads. Reviews post bugs and security points only; the rest stay in Sixth Man's ledger.

Reviewed by Claude Opus 5.5.

kiwidream added a commit that referenced this pull request Nov 13, 2026
…ed, for 10 s (#859)

## Problem

`/audit/latest` rebuilt its evidence on every call (#859). Each request:

- decoded the newest confirmed block's whole audit bundle, only to count its shares;
- counted the share tail;
- took a `UNION` over every daily miner rollup.

All of it ran on the share writer's pool, with no route timeout and no limit on concurrent calls.

`ApiState.latest_evidence` looked like the cache for this, but nothing ever wrote it. History (`git log -S latest_evidence`) shows it was never added rather than removed. The field arrived with the Python-to-Rust port (#244, 1398bbc), together with its reader in the handler, and no Rust writer has existed since. It mirrors the Python runtime's `_latest_evidence`, which that runtime's coordinator set on block confirmation.

## Change

This follows #833's integrity routes (`api/integrity.rs`). The code stays in `api.rs` and `api/read_models.rs`, as this wave's file split requires, so it reimplements #833's pattern rather than sharing its code. Generalizing `IntegrityReports` would have meant editing `integrity.rs`. Its semantics also differ: it remembers failures, and it turns every failure into a 503 `integrity_report_unavailable`, while `/audit/latest` must keep its 404.

- **One run at a time per frontend**, spawned, bounded by a fixed 60 s, as #833's integrity runs have a fixed bound. That is far beyond the run's usual time, but not its worst case: a run makes up to seven statements on the share writer's pool (the evidence key, the rollup check, the counts, the payout count, then, for new evidence, the bundle row and its canonical bytes, or its share snapshot and window), and each may wait up to the pool's 15 s for a connection and then run up to the statement timeout, 15 s by default. So while every writer connection is busy and checkouts queue for seconds (each under the 15 s at which one fails), with a raised `PRISM_DATABASE_STATEMENT_TIMEOUT_MS`, or with a slow decode of a new bundle (it runs last and untimed, after a wait for a decode permit), a valid run can pass 60 s every time. The route then answers every request, after up to 60 s, with 503 `read_timeout` and serves nothing until a whole run fits again, where before it answered slowly. Each abandoned run's statement in flight holds its writer connection until it ends, and an abandoned decode keeps its permit, while the next request starts the next run. The bound stays fixed by decision; the code comment and `docs/prism-ledger-ops.md` say all this.
  - Requests that arrive during a run wait for it.
  - A request that gives up (its client disconnects) leaves the run going for the next request.
  - A stopping frontend abandons its run in flight and starts none. It uses the same stop signal as the integrity routes.
  - Runs are numbered, and an older run's answer never replaces a newer one. A drop guard clears the run in flight on panic, abort or shutdown.
- **Dated answer, reused for 10 s.** An answer is served for 10 s after its run ends. It carries `computed_at`, `age_seconds` and `run_seconds`, as #833's reports do. These keys are added; every existing key keeps its name and value.
  - **Why a short lifetime and not a freshness key:** no cheap key covers the lifetime share counts. `max(share_seq)` misses shares committed out of order, and counting is the very work being saved.
  - **How stale:** the counts can trail the ledger by up to 10 s plus the run's own time. A newly confirmed block shows up after at most as long.
  - **Polling:** after an answer, a poller starts a run on each frontend at most once per run time plus 10 s.
- **The bundle is decoded once per new evidence.** A run reads the newest confirmed block with a bundle, then the counts, then the block's payout entries, then decodes the bundle last. It decodes only when the newest block, its bundle digest or its payout manifest differs from the previous answer's evidence. That evidence is keyed by what the decoded body itself says it is, so a row re-imported between the reads is decoded again by the next run. A run that fails before the decode decodes nothing.
- **Failures are never remembered,** and each is logged (`latest evidence run failed`, with its code and run time). The request that waited for a failed run gets its error:
  - 404 "no PRISM evidence has been produced", as before;
  - 503 `read_timeout` when the run hits its 60 s;
  - 503 when the frontend stopped;
  - otherwise whatever the read returned, as before.

  The next request starts a run.

  Because the bundle is now decoded last, a request on which both the counts and the bundle would fail gets the counts' error. Before, the bundle's error won: for example a 404 for an unreadable legacy body, where now it can be a 503 after a slow counts statement. A request on which only one of them fails gets the same error as before. A frontend that has already decoded the evidence keeps serving it if the body later becomes unreadable under the same key, until the key changes or the frontend restarts. A fresh frontend reports the read failure, as before.
- **The field is gone.** `ApiState.latest_evidence` is now the run state (private). `ApiState::with_latest_evidence_reuse` is a `#[doc(hidden)]` test hook, like `with_integrity_report_timing`.
- **Docs:** `docs/prism-ledger-ops.md` describes the route as it now behaves, after the integrity routes' passage, including what an operator sees when runs pass the 60 s bound and why. It also corrects a stale route name (`/audit/latest-evidence` → `/audit/latest`). `docs/prism-deleted-test-map.md:90` no longer calls `/audit/latest` "a per-request query".

## Tests run

All cargo commands ran through the host gate with `CARGO_PROFILE_DEV_DEBUG=line-tables-only`.

- `cargo test --offline -p qbit-prism-server --lib -- api::read_models api::integrity`: 19 passed, including 8 new tests in `api/read_models/latest_evidence_tests.rs`, with runs injected:
  - `concurrent_requests_share_one_run`
  - `an_answer_is_dated_and_served_until_its_window_ends` (it also checks that the next run is handed the previous evidence)
  - `a_failure_is_not_remembered`
  - `an_earlier_run_never_replaces_a_later_answer`
  - `a_run_past_its_timeout_fails_and_leaves_nothing_in_flight`
  - `a_request_that_stops_waiting_leaves_its_run_to_finish`
  - `a_run_that_panics_leaves_nothing_in_flight`
  - `a_stop_abandons_the_run_in_flight_and_starts_none`
- `PRISM_TEST_PG_BIN_DIR=/usr/lib/postgresql/16/bin test/prism-native-tests.sh cargo-args --offline -p qbit-prism-server --test share_partitions_postgres -- --test-threads=4 latest_evidence`: 2 passed, both recorded `executed`.
  - **New:** `latest_evidence_is_shared_dated_and_refreshed_after_its_window`. It checks that:
    - eight concurrent requests get one run's answer (same `computed_at`), with counts equal to the raw ledger's;
    - within the window, a new share does not change the served answer;
    - after the window, the counts include it, and the answer equals what a frontend that never answered computes;
    - a newly landed block becomes the answer;
    - with the newest bundle's share snapshot detached and its inline shares emptied (key unchanged), the next run still serves the share count it decoded, while a fresh frontend's decode reads 0;
    - a changed payout manifest makes the next run decode again.

    It is listed in `test/prism-gated-tests.txt`.
  - **Existing:** `latest_evidence_counts_lifetime_shares_across_the_rollup_watermark` now sets the reuse window to zero, so every request still reads the ledger it asserts on.
- `cargo fmt --all -- --check`, `cargo clippy --offline --locked -p qbit-prism-server --all-targets -- -D warnings` (clean apart from the three known vendored sqlx-core warnings) and `python3 scripts/check_prism_pool_acquires.py`: all clean. The run keeps `latest_evidence`'s four acquire sites. Re-run on the follow-up commit (comments and docs only), with `python3 scripts/check_prism_settings.py`: all clean.
- Follow-up (run bound and docs, comments and docs only): two `/code-review xhigh` rounds in an Opus 5.5 subagent; their findings on the new text's accuracy are fixed (abandoned statements hold their writer connection, the 15 s checkout failure's message, the decode as a second cause, `with_shutdown`'s comment). Their findings on the route's design are reported to the coordinator rather than changed here.
- Local review: two `/code-review xhigh`-level rounds in an Opus 5.5 subagent, the second ending with nothing left worth fixing. Round one's findings, all fixed:
  - the doc passage sat inside the integrity report's guidance;
  - the bundle was decoded before the counts;
  - the evidence key came from another statement than the body;
  - no test showed evidence reuse.

## Other consumers of `/audit/latest`, with the 10 s reuse

| Consumer | How it reads the route | With the 10 s reuse |
| --- | --- | --- |
| `tests/live_regtest.rs` | polls every 200 ms for up to 30 s | holds, with about 20 s to spare |
| `scripts/prism_shipped_image_lane.py` quiesce | polls every 2 s for up to 90 s | holds |
| `tests/support/ledger_2x.rs` | one first request on a fresh router | unaffected |
| `tests/api_database.rs` | one first request on a fresh router | unaffected |

## Not in this PR

`docs/prism-share-ledger-partitioning.md:260` still names the route `/audit/latest-evidence`. Open PR #848 changes that line to `/audit/latest`, so it is left to #848: `git merge-tree --write-tree` of this branch with #848's head (da36f25) merges cleanly, and the merged passages read correctly. Its line 249 (the `latest_evidence` lifetime counts row) describes how the counts are read, which this PR does not change.

The other writer-pool operator routes (`/owed`, `/miners/{id}/status`) are #859's stated follow-up.

## What CI must cover

The lib suite, `share_partitions_postgres`, `ledger_postgres`, `live_regtest` (polls `/audit/latest`) and the shipped-image lane.

Refs #859

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Squashed commits:
39b8a91 3.x.x: /audit/latest is computed by one run at a time and served, dated, for 10 s (#859)
dfccd9e 3.x.x: /audit/latest's 60 s run bound is documented as a fixed bound, not the run's worst case (#859)
a298ec5 3.x.x: /audit/latest's docs say an abandoned statement holds its writer connection, and when a decode keeps runs failing (#859)
828690e 3.x.x: /audit/latest's docs describe a decode that keeps runs failing, and when a checkout queues (#859)
207ac1e Merge 3.x.x (fa8ac84) into orca/859-audit-latest-cache: take in the PostgreSQL 16.15 service pin (#866)
b2b7c67 Merge 3.x.x (234ff1c) into orca/859-audit-latest-cache: take in the landed 3.1.2 PRs and the collate test fix (#874)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Nov 13, 2026
… nobody serves (#857)

## Problem

The public dashboard queries run on the read pool on every cache miss, and several of them do work that nobody reads, or that the rollups and existing indexes already hold (#857). The issue's findings came from a code read. Each one was checked here against real plans and timings, and old and new SQL were compared on the same data.

## Measurements

Seeded data: 200,000 shares over 25 h from 500 miners, a 50,000-share reward window (difficulty 6,250,000,000), 5,000 blocks, rollups current. Each figure is the median of five `EXPLAIN ANALYZE` runs of the prepared statement, on PostgreSQL 16 on a shared dev host.

| Query (per cache miss) | 3.1.1 | Now | Ledger rows read |
| --- | --- | --- | --- |
| Miner page share summary | 4.83 ms | 0.22 ms | 24,774 → 783 |
| Miner page reward share | 93.8 ms | 58.5 ms | 106,496 → 106,496 (the window itself) |
| Pool summary snapshot + sums | 143.4 ms | 52.0 + 7.5 ms | 298,485 → 106,496 + 865 |
| Blocks page, `active`, 15 rows | 3.81 ms | 0.97 ms | none |

## Each finding

1. **Miner page: whole-pool 3-hour sum. Changed.** `pool_h3_difficulty` from `dashboard_miner_share_summary.sql` was read by nothing: `miner()` never reads it, it is not in any response, and nothing else in the repo reads it. The `pool` CTE and the key are dropped.

2. **Miner page: whole reward window grouped for one miner. Changed.** `miner()` reads three figures from `reward_leaderboard(…, Some(id))`: the miner's row's `share_percent` (null without a row), its `counted_share_difficulty`, and the window's `counted_window_weight`. The new `dashboard_miner_reward_share.sql` computes exactly those in one aggregate over the same `qbit_prism_window` rows, with the same numeric expressions. It skips grouping and ranking every miner and attributing blocks to them. Materialising the window is unavoidable, because the share is a fraction of the whole window's counted weight. So the saving is the per-miner work, about a third here. The leaderboard route itself is unchanged.

3. **Pool snapshot (`dashboard_pool_snapshot.sql`).**
   - **24 hours of raw shares. Changed**, following the chart rollups (`dashboard_hashrate_rollups.sql`). The sums now come from the new `dashboard_pool_hashrate_rollups.sql`, and the 3-hour participants from the miner rollups' `UNION` with the raw parts. For each window `[ended_at − span, ended_at]`, the query reads:
     - the 5-minute rollups for whole buckets before the current one;
     - raw shares at or below the watermark in the window's two partial buckets (its leading slice, and the current bucket up to `ended_at`);
     - raw shares past the watermark.

     The three spans are whole multiples of 5 minutes, so they share one current slice.
     - **No watermark, or a stale one:** when there is no watermark row, or the share at the watermark is older than the 24 hours (rollups disabled, stalled or still backfilling), the query reads the 24 hours' raw range instead. So a lagging watermark never turns the tail into a walk longer than the range it saves, at any share rate. Unlike the charts, which walk everything past their watermark.
     - **No rollup schema:** a database without it (a public replica may lack it) runs the old raw scan, now `dashboard_pool_hashrate.sql`, chosen as the charts choose.
     - **Separate statement:** the sums are read by `read_models::pool_hashrate_sums`, apart from the snapshot. Each takes its own `clock_timestamp()` and snapshot, milliseconds apart: the same answer on the same data, while under concurrent writes the two groups of fields can be milliseconds apart. That adds a `to_regclass` check and a pool acquisition per miss, as the charts have.
   - **Four `count(*)` over the blocks. Changed** to one pass with `FILTER`.
   - **`total_mined_bits` over all carry-forward history. Left alone.** No rollup or counter holds the total. An exact one needs a new table or trigger, which means a migration, and this change has none.

4. **Blocks page (`dashboard_blocks.sql`). Changed.**
   - **The rewrite:** the `public_blocks` CTE (`block.*`, referenced twice, so materialised over every block) and its `CASE` filter are gone. The page filters on plain columns, one `UNION ALL` branch per filter, each behind a one-time test of `$3`.
   - **Why it now uses the index:** the `active` branch's own predicate (`chain_state = 'confirmed'`) implies the index's (`chain_state <> 'reversed'`). So an `active` page is an ordered read of `qbit_pool_blocks_public_recent_idx` that stops at its page, under custom and generic plans alike. A single `$3`-dependent `OR` would keep generic plans off the index.
   - **Why `reversed` and `all` don't:** they include reversed rows, which the partial index excludes, so they still scan. The total count still counts the matching blocks.

## Same responses on the same data

`dashboard_queries_answer_what_their_3_1_1_queries_answer` (tests/api_2x.rs) runs the 3.1.1 SQL, kept verbatim as test fixtures under `tests/fixtures/dashboard_queries_3_1_1/`, and the new SQL on the same data, and compares the JSON.

**The clock:** every comparison runs on a pool whose sessions resolve `clock_timestamp()`, the only clock either side reads, to a function in a test schema placed before `pg_catalog` in their `search_path`. It is pinned at one fixed instant, 150 s into its 5-minute bucket and weeks before the wall clock. The phases the rollups can serve are compared at that instant and four more: bucket-aligned (every window's leading slice empty), a second into the bucket, its last second and a fractional one. The test asserts which path each phase reads: the rollups after they advance, at every instant, and the raw 24 hours before that and with the watermark a day behind. So the old and new statements answer at one instant, every window's first bucket is partial at the pinned instant, the shares placed on the exact 24-hour, 3-hour, 1-hour and bucket edges are on the edges they read on every run, no mismatch is retried, and a statement that read the real clock would fail every run.

### What can differ from 3.1.1

- **Shares younger than 24 hours that a detach removed.** `share-archive detach --retention-days 0`, on a network whose payout window is under a day of shares (signet, regtest), can detach a partition holding shares less than 24 hours old. 3.1.1's raw scan stopped counting them. The new sums keep counting them through the 5-minute rollups for whole buckets, as the hashrate charts already do; the partial buckets, read raw, drop them. Until the rollup sweep moves the watermark past the detached partition's newest share, the readiness check can find no attached share at or below it and read the raw 24 hours instead, which drops them too; the next sweep brings them back. So `h24` (and in the extreme `h3`, `h1` and `participants_3h`) can differ from 3.1.1 on the same database, and agree with the charts. Accepted. With any retention of a day or more a detached partition holds no share younger than 24 hours, so this cannot happen. `docs/prism-share-ledger-partitioning.md`'s reader inventory states it.
- **Concurrent writes:** the snapshot and the sums are separate statements, milliseconds apart (above).

**The data:**

- an empty database;
- shares on both sides of every window start and 5-minute bucket edge, others spread over 26 h, and one in the future;
- a miner with one share, and a miner with none;
- blocks in every chain state, including a reversed one, a disconnected-but-published one (public `reversed`), and two at one height;
- miners that tell the 3-hour participants from the 24-hour ones:
  - eve only older than 3 hours, in a whole bucket, just before the window and past the watermark;
  - frank, grace and henry only in the current, 3-hour or 24-hour partial slice;
- each with no rollup progress, with the rollups current, with shares past the watermark (in the current bucket, in each window's partial bucket, in an already rolled bucket, and from a miner the rollups have never seen), and with the watermark set a day behind while the rollups hold more than it.

Mutation checks:

- Four deliberate bugs in the participants CTE each fail the test:
  - the rollup bound widened to 24 hours;
  - the slice list widened;
  - the boundary branch dropped;
  - the tail time filter dropped.
- Reverting the watermark-age rule fails both the equivalence test and the plan test.
- Making the 24-hour slice's lower bound exclusive (`>` for `>=`) in `dashboard_pool_hashrate_rollups.sql` fails the equivalence test, which only a share on the exact window start can show. So does making the whole buckets' lower bound exclusive. Both fail in the "current watermark" phase, where the rollup path is read. Shares past the watermark sit on each side of every window's start, at the pinned instant and after it, and two miners sit only on either side of the 3-hour start: making the tail's 24-hour bound or its 3-hour participants bound exclusive, or dropping its upper bound, fails the test in the "lagging watermark" phase.

**What it compares:**

- the miner share summary, minus the dropped key, for four miners;
- the reward share at three difficulties, against the 3.1.1 leaderboard's row and totals;
- the pool snapshot plus sums, through both the raw and the rollups SQL, at two difficulties;
- the blocks page for every filter and six pages, including past the end.

The Rust that turns these into the public responses is unchanged, apart from reading the same three figures from the new query in `miner()`.

## Plan assertions

These follow the style of #849 and the chart rollups' plan test.

- `an_active_blocks_page_reads_the_public_recent_index_under_any_plan`: 5,000 blocks, with `force_custom_plan` and `force_generic_plan`, each at `random_page_cost` 4 and 1.1, for three pages. Every plan reads `qbit_pool_blocks_public_recent_idx`, and that read stops at the page.
- `pool_hashrate_sums_read_only_the_partial_buckets_and_the_lag`: 20,000 rolled shares over 25 h, at both page costs, in four states. With the watermark current, then with 300 shares past it, the rollups query reads at most 1,000 ledger rows plus the lag and makes no one-sided ledger scan, while the raw query it replaces reads over 19,000. With the watermark a day behind, and with no progress row, it reads the 24-hour range, no more than the raw scan, again with no one-sided scan.
- Mutation check: pointed at the 3.1.1 SQL, both tests fail.

## Tests run

All cargo commands ran through the host gate with `CARGO_PROFILE_DEV_DEBUG=line-tables-only`, against a private PostgreSQL 16 cluster.

- `PRISM_TEST_PG_BIN_DIR=/usr/lib/postgresql/16/bin test/prism-native-tests.sh cargo-args --offline -p qbit-prism-server --test api_2x --test window_multiplier_invariant`: 12 and 1 passed, the three new tests included.
- After the pinned clock: `PRISM_TEST_PG_BIN_DIR=/usr/lib/postgresql/16/bin test/prism-native-tests.sh cargo-args --offline --locked -p qbit-prism-server --test api_2x -- --test-threads=4 dashboard_queries_answer pool_hashrate_sums an_active_blocks_page`: 3 passed, all recorded `executed`; with either mutation above, the equivalence test fails. `cargo fmt`, `cargo clippy` and the pool-acquire guard as below: clean. The follow-up had two more `/code-review xhigh` rounds in an Opus 5.5 subagent; their findings are fixed (a wall-clock epoch that left the rollup path uncompared at bucket-aligned instants, missing timeouts on the pinned pool, the readiness fallback after a detach).
- The follow-up's last commit (more instants, tail edges, readiness assertions) applies the second review round's own findings and was not reviewed locally again; Codex reviews it.
- The same with `--test api_database --test api_contract -- --test-threads=4`: 3 and 6 passed.
- `cargo test --offline -p qbit-prism-server --lib -- api::`: 43 passed.
- `cargo fmt --all -- --check`: clean.
- `cargo clippy --offline --locked -p qbit-prism-server --all-targets -- -D warnings`: clean, apart from the three known vendored sqlx-core warnings.
- `python3 scripts/check_prism_pool_acquires.py`: passes. The new sites are `miner_reward_share` (1) and `pool_hashrate_sums` (2), both public.
- Local review: two `/code-review xhigh`-level rounds in an Opus 5.5 subagent. Their findings are fixed:
  - the invariant's missing site, which would have turned CI red;
  - test data that couldn't tell the participants' windows apart;
  - a tail walk unbounded without rollup progress or with a stale watermark;
  - tail shares placed by a stale clock.

## Docs

`docs/prism-share-ledger-partitioning.md`'s reader inventory no longer lists `dashboard_pool_snapshot.sql` as an `accepted_at`-range reader. It lists `dashboard_pool_hashrate.sql` with those readers, and `dashboard_pool_hashrate_rollups.sql` in a row of its own, with the detach case above. It merges cleanly with open PR #848, which changes a line further down the same file.

## Not in scope

`OFFSET` pagination and the `strpos(lower(...))` searches, as the issue says.

## What CI must cover

The PostgreSQL-gated suites, `api_2x` in particular, and the lib suite.

Refs #857

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Squashed commits:
1cce087 3.x.x: the miner page, pool summary and blocks page stop reading what nobody serves (#857)
ae57486 3.x.x: the dashboard equivalence test reads one pinned clock, and the partitioning doc lists the pool summary's new readers (#857)
387b570 3.x.x: the dashboard equivalence test pins one fixed mid-bucket instant, and the reader row covers the readiness fallback after a detach (#857)
7987d38 3.x.x: the dashboard equivalence test compares at five clock instants and on every tail edge, and asserts which path it reads (#857)
fb26a94 Merge 3.x.x (fa8ac84) into orca/857-dashboard-queries: take in the PostgreSQL 16.15 service pin (#866)
0cdbb30 Merge 3.x.x (234ff1c) into orca/857-dashboard-queries: take in the landed 3.1.2 PRs and the collate test fix (#874)

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.

Approved: a complete review with no bugs found.

No bugs or security points found.

Not posted: 3 nits and 2 leads. Reviews post bugs and security points only; the rest stay in Sixth Man's ledger.

Reviewed by Claude Opus 5.5.

## 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]>
@kiwidream
kiwidream force-pushed the orca/814-docs-catch-up branch from 1fe7fba to 7e572ab Compare November 13, 2026 20:28

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

Approved: a complete review with no bugs found.

No bugs or security points found.

Not posted: 3 nits and 2 leads. Reviews post bugs and security points only; the rest stay in Sixth Man's ledger.

Reviewed by Claude Opus 5.5. Red team (deepseek-v4.1-flash-abliterated): found nothing.

@kiwidream
kiwidream merged commit 3e8795e into 3.x.x Nov 13, 2026
46 checks passed
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