Skip to content

3.x.x: retire landing waits no miner could receive, so an idle frontend can't latch identity tracking and silence the revision-work critical after a failover (#758) - #820

Merged
kiwidream merged 3 commits into
3.x.xfrom
orca/landing-idle-identities
Oct 29, 2026
Merged

kiwidream merged 3 commits into
3.x.xfrom
orca/landing-idle-identities

Conversation

@kiwidream

@kiwidream kiwidream commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

After a failover, a long-idle backup frontend could not page on a revision-work stall until it was restarted. This was a medium finding in the review of #811 (v3.1.1); it predates 3.1.1. #800 fixed the revision-history half of #758's latch, and this fixes the identity half.

The problem

  • How an idle frontend fills the tracker:
    • Landing tracking caps open block identities at 4,096 (metrics/landing.rs).
    • A frontend with no miners still opens a wait for every pool block it reconciles. Only a mining.notify write or an orphan proof closes such a wait, and the mature checkpoint kept open waits.
    • So after about 4,096 pool blocks, which is days at the documented rate, saturated latched.
  • What happens after a failover:
    • PrismAcceptedRevisionWorkTrackingUnknown warns.
    • Every new block goes untracked, and the pending age reads -1.
    • PrismAcceptedRevisionWorkPendingCritical, which needs pending >= 0, cannot page on the frontend that now serves every miner, until it is restarted.

The change

  • Retirement: at the mature checkpoint, an open landed wait is closed without a sample when no authorized Stratum session existed at any instant since its acceptance. No delivery was due, so there is nothing to measure. Its identity is then released, and the existing watermark keeps it from being counted again.
  • What is kept:
    • waits accepted while a miner was connected, or before the Stratum listener started, so a real stall still saturates and reports unknown, as before;
    • unlanded and orphan-verdict waits;
    • waits whose settlement reply is still out.
  • The session signal: the Stratum listener reports session authorization and end to the tracker (stratum.rs). It does this on the same transitions that drive qbit_prism_authorized_clients, which 3.x.x: the revision-work warnings (PrismAcceptedRevisionWorkPending, ...TrackingUnknown) fire on an idle backup frontend: not gated on authorized clients like their critical twin (post-cutover) #758's alert gate uses.
  • Unchanged: no metric, label, unit or alert rule changes. The state is process-local, so a rollback restores the old behaviour.

Tests

  • an_idle_frontend_cannot_exhaust_identities_and_hide_a_stall_after_failover:
    • LIMIT + 1 pool blocks on a frontend with no session;
    • then a session and a delivery;
    • then a new block at 308 s, which reads age 308 and unknown 0, so the critical can page.
    • Its variant with a miner present still saturates.
  • the_mature_checkpoint_retires_only_waits_no_miner_could_have_received.
  • a_wait_whose_settlement_is_in_flight_retires_only_after_it_reports, for both a committed reply and a lost one.
  • stratum::landing_session_tests::an_authorized_session_keeps_its_waits_and_its_end_lets_later_ones_retire:
    • It drives serve_connection with a stub backend.
    • It fails if serve_connection stops reporting sessions to the tracker, or if a session's end stops being reported.
  • Seen failing first: each new test failed with its behaviour disabled or mutated.

Run on minidev-alex1:

  • cargo test --locked -p qbit-prism-server --lib metrics::landing: 46 passed.
  • landing_metrics (gated): 41 passed, on db723039.
  • cargo fmt --check, and clippy --lib --tests -D warnings.
  • generate_prism_metrics.py --check and generate_prism_alerts.py --check.

Follow-ups, not in this PR

Release

The note is in db723039, which touches only doc/release-notes-3.1.1.md. If this misses 3.1.1, that commit moves to 3.1.2's notes.

🤖 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 and others added 3 commits October 29, 2026 11:56
An idle frontend opens a delivery wait for every pool block it reconciles,
and only a mining.notify write or an orphan proof closes it. The mature
checkpoint kept open waits, so after about 4,096 pool blocks the identity
tracker saturated and latched until restart. After a failover that frontend
reported tracking unknown, ignored every new block and read -1 pending age,
so PrismAcceptedRevisionWorkPendingCritical could not page on it.

The mature checkpoint now closes, without a sample, an open landed wait (known
or with an unknown first revision) when no authorized Stratum session existed
at any instant since its acceptance, and releases its identity behind the
existing watermark. The tracker learns of sessions from the transitions that
drive qbit_prism_authorized_clients (SessionObservation authorize and drop),
and from both Stratum listeners once they start; before that, every wait
counts as attended. A wait a miner may have needed stays, so a real stall
with miners still saturates and reports unknown. Unlanded acceptances and
unsettled orphan verdicts keep their own terminal evidence. Metric names,
labels and alert rules are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ring (#758)

The mature checkpoint retired an unattended wait even while a settlement
observer for it was mid-COMMIT, so its later report found no block and its
evidence was dropped. It now retires only a wait with no observer out, as
covered() requires; that wait retires at the next checkpoint after its
report. A retired wait then pins no revision history, so nothing is left to
release after retirement.

A Stratum unit test drives serve_connection with an authorizing backend and
checks through the landing tracker that the authorized session keeps a wait
open at the checkpoint and that its end lets a later wait retire. It fails if
serve_connection stops calling reporting_to or the observation's Drop stops
reporting the end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 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-29T16:19:59.951869Z 8a7c5ec PR opened
ℹ️ 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.

Approved: a complete review with no bugs found.

3 findings posted inline.

confirmed the block first (a peer's, or its own attempt whose reply was
lost): its own later settlement proves a covering revision, and its next
write at or above it ends the wait without a sample.
write at or above it ends the wait without a sample. Nor can an idle

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. [low · nit] The identity-exhaustion fix is appended to the #800 (#758) bullet, so #820 is never credited

doc/release-notes-3.1.1.md:184

Each change in the release notes has its own bullet that opens with #PR (#issue): (for example release-notes-3.1.1.md:31, 42, 161 and 194). This PR appends its fix (lines 184-190) to the end of the existing #800 (#758) bullet, and #820 appears nowhere in the file. A reader or bisector looking for the change that retires unattended waits is sent to #800. A separate '#820 (#758):' bullet would match the file's convention.

for block in self.blocks.values_mut().filter(|block| {
!block.closed
&& !block.unlanded
&& !block.orphan_uncertain

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2. [low · nit] The orphan_uncertain exclusion in retire_unattended is not covered by any test

crates/qbit-prism-server/src/metrics/landing.rs:480

retire_unattended only runs once revision_work_sessions_tracked has been called, and only the new tests call it (tests.rs:1046, 1097, 1140 and the stratum test). None of those tests calls revision_work_orphan_settlement, which is the only place orphan_uncertain is set (landing.rs:552). The older orphan tests never turn session tracking on. If someone removed the !block.orphan_uncertain filter, an orphan wait whose settlement is still unresolved would be retired at maturity and dropped by retain (landing.rs:669-671), which would silently clear its unknown() signal. Every test would still pass.

assert_eq!((age(&m), unknown(&m)), (1., 0.));
assert_eq!(unlanded(&m), 1.);
assert_eq!(m.landing.lock().unwrap().blocks.len(), 4);
// A retired identity is never recounted, and retirement measured nothing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3. [low · nit] The 'retired identity is never recounted' step would pass even if retirement were broken

crates/qbit-prism-server/src/metrics/landing/tests.rs:1123

After revision_work_matured(1), re-accepting idle at height 1 is rejected by the existing watermark check height <= retired_height (landing.rs:599). If retirement had not run, the early return for an existing open entry (landing.rs:590-597) would reject it instead. Either way nothing is counted twice, so this step cannot show whether retirement worked. Only the later published == 3 assertion catches that.

@kiwidream
kiwidream merged commit 7a47dd0 into 3.x.x Oct 29, 2026
41 checks passed
kiwidream added a commit that referenced this pull request Oct 29, 2026
…'s fixes

Merge 3.x.x at 987027f into the promotion branch: #818 (verify-ca trusts
only sslrootcert), #819 (3.1.1 notes, release steps and runbooks), #820
(an idle frontend's landing waits retire at maturity) and #821 (the
pre-migrate lowers its own deadlock_timeout for a blocking autovacuum
pass), from the review of this promotion.

The promotion's edits: the release date (2026-10-29), the fix PRs' numbers
in the 3.1.1 notes, and the 3.1.1 record in docs/releasing.md with the new
cutoff.

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