Skip to content

2.x.x: bound Rust payout-window paging memory - #241

Merged
kiwidream merged 8 commits into
2.x.xfrom
fix/prism-240-rust-window-paging-20260906
Sep 6, 2026
Merged

kiwidream merged 8 commits into
2.x.xfrom
fix/prism-240-rust-window-paging-20260906

Conversation

@kiwidream

@kiwidream kiwidream commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Full snapshots and large advance deltas retained oversized page vectors and repeatedly copied the remaining records. At a 210k-share window, the prior synthetic reproduction reached 9,613 MiB of builder memory. This change consumes each retained record through an owning iterator into a page-sized allocation, preserving eligibility, weighted cutoff, canonical bytes, and immutable page sharing.

Adds structural capacity regression tests, optional timing metrics on successful prepare_window responses, and a reproducible benchmark with memory limits, exchange deadlines, and process-cleanup tests. The committed measurement report includes source/binary provenance and separate host and locally built coordinator-image results.

Validation:

  • 241 Rust workspace tests and 48 Python window-contract/harness tests on the initial head; final corrective head adds a sixth capacity test and six harness tests, with all 22 window tests and 11 harness tests passing; real-daemon parity gate (35 full preparations and 16 advances across 15 cases).
  • New capacity tests fail against the original paging implementation; 22 window tests pass with the fix.
  • 40 benchmark phases on host and CPython 3.14.7 coordinator image: all prepared successfully and all canonical digests matched the Python oracle.
  • Observed cold full-snapshot daemon high-water marks: 435 MiB at 210k shares and 826 MiB at 400k. Across full/advance/recenter phases with cached generations: 601 and 1,142 MiB. These pre-exit observations are lower bounds on final lifetime peaks; structural tests establish the page-capacity bound. The unsafe large baseline was cited from the earlier report, not repeated.

Implements the Rust allocation portion of #240, related to #236, on top of merged #237–#239. These synthetic measurements do not establish cold-start time to first usable Stratum work with the real lease heartbeat. Deployed-image validation and testnet/mainnet soak remain open operator gates; the requested rollout will be tracked by a separate qbit-tools pin update, and both issues remain open pending operational evidence. No schema or deployment changes.

kiwidream and others added 3 commits September 6, 2026 10:28
`PayoutWindow::from_full_snapshot` paged the retained records by repeatedly
`split_off`-ing the tail from one owning Vec and storing the head as each
page. `Vec::split_off` keeps the original allocation, so page k retained
backing capacity for every record still unpaged when it was cut (N, N-P,
N-2P, ...) and the tail was copied again on every iteration: O(N^2/P)
retained memory and copying -- 9.6 GB of resident builder memory and a 12 s
response at the ~210k-share mainnet window of #236, and a SIGKILL at 400k.

Page by moving every retained record exactly once out of the snapshot's own
buffer (now filtered in place with `retain`) into a vector allocated for
exactly the records that page holds, so aggregate page capacity is the
retained count and the work is linear in it. The `advance` delta loop had
the same `split_off` shape and is paged the same way, and the merged
boundary page is allocated for its final length. Eligibility on both
timestamps, ascending share_seq order, the whole-share crossing-row cutoff,
duplicate and zero-difficulty rejection, u128 overflow handling, canonical
fragments and digests, the advance byte surgery and immutable page sharing
across generations are unchanged.

Structural regression tests assert the bound directly -- no page vector's
capacity above page_size, aggregate capacity at most one page's worth per
page -- across page sizes 1, 3, 7 and 512 at empty input, one record, one
short of a page, exact single and multiple boundaries, one past a boundary
and long partial tails; plus the weight cutoff, unsorted input, page-size
and weight validation, page-size-independent items/digest/payout totals,
Rc page sharing and a full-rebuild digest match across an advance with a
multi-page delta. Appended to the previous implementation, four of them
fail at the capacity assertion; the other 17 window tests pass on both.

The daemon's prepare_window success envelopes gain an additive `metrics`
object (request parse, fold/advance and canonical serialization seconds)
so a measurement can separate Rust processing from pipe transport; the
coordinator's parser ignores it, and the rust-daemon parity gate passes
against the rebuilt binary.

tests/perf/window_paging_allocation.py is the bounded measurement harness:
old and new binaries through the real --serve protocol over blocking pipes
(full, small advance, multi-page advance, re-center, advance) with RLIMIT_AS
on the daemon and a MemAvailable guard, VmHWM peaks, per-phase timing split
into transport and the daemon's own metrics, digest self-checks and the
shipped Python fold as an oracle. Its report follows in
tests/perf/window_paging_allocation.md.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vb3bGmWxUvZuRReN3Sfkpy
Add daemon deadlines and cleanup coverage, plus host and CPython 3.14 image measurements for issue #240. Keep raw local evidence outside tracked history.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 6, 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-09-06T15:38:46.156072Z 7afbc37 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.

kiwidream and others added 2 commits September 6, 2026 11:08
…eak RSS

window.rs: a focused test folds one exactly full page (4 records at page
size 4, within bound even under the previous paging) and advances it by a
23-record delta at a weight that expires nothing, asserting every record
and fragment page stays within page_size, the full base page is shared
rather than rebuilt, the previous generation is unchanged, and the result
matches a full rebuild with exact byte surgery. Against the base
implementation it fails on its own at the advance loop ("page 1 of 7
retains capacity 23 for 4 records") while the snapshot page passes, so the
delta split_off defect is pinned independently of the full-snapshot one;
the broader sharing/expiry test is retained. The paging comment now cites
the prior synthetic 9,613 MiB measurement instead of an approximate figure
in a different unit.

window_paging_allocation.py: the daemon outcome records where peak_rss_mb
came from -- the kernel VmHWM read live at close (vmhwm), the watchdog's
read before a kill (vmhwm_before_kill), a lower bound reconstructed from
earlier per-phase VmHWM reads and the sampler's running maxima after the
daemon exited on its own (lower_bound), or unavailable. Lower bounds
render as ">= N" beside a peak-source column; the summary header no longer
calls every figure VmHWM. Numeric data and existing JSON keys are
unchanged; peak_rss_source is added. Every published measurement exited
cleanly and stays a kernel VmHWM.

Harness tests add deterministic cases for resolve_peak_rss provenance and
exact-vs-lower-bound rendering, a live-at-close VmHWM read, and a fake
daemon that exits after its handshake (never labelled VmHWM); the stall
and reaping tests are retained.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vb3bGmWxUvZuRReN3Sfkpy

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

ℹ️ 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 tests/perf/window_paging_allocation.py Resolved

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 998507a79a

ℹ️ 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 tests/perf/window_paging_allocation.py Resolved

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57f2739c2f

ℹ️ 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 tests/perf/window_paging_allocation.py Resolved
@kiwidream

Copy link
Copy Markdown
Member Author

Final Fable mergeability review at 7afbc37959c652dffce6355b119d1c9168a26500: READY, no material correctness or rollout-safety blocker. All seven prior findings are resolved; the final focused Linux harness suite passes 11/11. The latest automated review completed without new findings. Final-head CI must finish before merge.

Per the operator’s “defer unless blocking” direction, optional parent-memory admission and benchmark phase hardening are tracked in #242 rather than extending this release. Production heartbeat, deployed-image RSS, cold first usable mining work and soak evidence remain open in #236/#240. The qbit-tools pin PR will use the actual merged 2.x.x SHA; this PR does not deploy production.

@kiwidream
kiwidream merged commit 8b02c72 into 2.x.x Sep 6, 2026
11 checks passed
kiwidream added a commit that referenced this pull request Nov 12, 2026
…s the harness (#814)

The recipe changed into a 527b3ac worktree before the docker build, so the
run line mounted that tree's tests/ and wrote out/ into it. 527b3ac holds
an earlier harness than the one committed beside the report.

Today's tree holds no harness, nor the Python lab/ modules it imports, so
none of the recipe's lines ran from it. The recipe now starts in a worktree
of #241's commit, which added the report and its harness. The image is
still built from 527b3ac's tree, named by path, so the run line is as it
was and mounts #241's tests/.

Co-Authored-By: Claude Fable 5.2 <[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:
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