Skip to content

3.x.x: the server times each stage of a share's path to its append, the load report reads them, and a warning fires when appends queue for a slot (#829, #844) - #850

Merged
kiwidream merged 1 commit into
3.x.xfrom
orca/829-share-append-stages
Nov 13, 2026
Merged

kiwidream merged 1 commit into
3.x.xfrom
orca/829-share-append-stages

Conversation

@kiwidream

@kiwidream kiwidream commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Follows #835, which is merged. 3.1.2 doesn't wait for this PR. It also carries #844's alert on the append-slot queue, as its own commit after the stages it reads.

Problem

#835's accounting attributed its own run-load occurrence of #829 (run 41734520778, throughput-400k-window-1fe-async steady_state, shortfall 2,784):

  • 98.5% of 61,082 accepted-ack seconds sat before ORDER_LOCK, in a remainder nothing measures: the append-admission queue, the submit checks, the pool checkout and BEGIN, and the response write.
  • ORDER_LOCK was saturated for roughly 50 s with holds of 2 ms or more, against 0.96 ms at saturation. WAL syncs (mean 0.184 ms) cover at most about a third of that.
  • The rest of the extra hold is either in the call (full-page images after a checkpoint starts) or in the frontend, between the call's reply and COMMIT. The harness's pg_stat_statements split can't separate the two.

Change

Server: qbit_prism_share_append_stage_seconds{stage,outcome}

The histogram uses the ORDER_LOCK hold ladder (1 ms to 10 s) and records four stages:

stage from → to outcomes clock where
submit_checks submit_share entry → the append's start (readiness, fee, tip, the payout-revision read and its checkout, the fences) passed frontend monotonic coordinator/miner_submit.rs
admission the wait for one of the max_connections - 1 append permits admitted, closed (pool closed first), cancelled (dropped while queued: a drop guard records the time actually waited, EP-ERRORS) frontend monotonic ledger/append_admission.rs
locked_call the one-call append's own lock_held_us, from its grant to its reply replied PostgreSQL clock_timestamp() ledger/window.rs append_called
commit the COMMIT round trip, either append path committed, failed frontend monotonic ledger/window.rs commit_gated

No behaviour change on the share path:

  • Outside ORDER_LOCK. Each stage is recorded after it ends, never while ORDER_LOCK is held:
    • commit is recorded once COMMIT's reply or failure is in and the hold has ended. commit_gated now takes the hold's guard and drops it as COMMIT returns, so the recorded hold still ends where it did and neither stage's recording falls inside it;
    • locked_call once the transaction and its hold have ended, by COMMIT or the gate's ROLLBACK;
    • admission before the append's checkout.
  • Nothing new in the locked section except the COMMIT round trip's two clock reads: no lock, await or allocation. Results, errors and their order are unchanged. commit_gated became a &self method to reach the registry.
  • Not recorded. A refusal, a reply the ledger then rejects, a closed commit gate (no COMMIT sent), and a submission refused or abandoned during its checks all record nothing. EP-OBSERVABILITY: nothing is recorded as zero.
  • Fixed cardinality. AppendStage::outcomes lists the pairs. The family declares its seven series at start as reserved keys with no samples, so recording allocates nothing (pinned in metrics_allocation) and a series appears on its first observation.
  • Docs. The metric docs are docs/prism-metric-metadata.json, the regenerated docs/prism-native-metrics.md and a reading note in docs/prism-metrics-histogram-consumers.md. The two Admission::acquire sites keep their non-database classification in scripts/prism_pool_acquires.json under their new call text.

Harness: the stages in share_ack_accounting

ACCOUNTED_SERIES adds the four series.

  • Measured parts, each with its clock: submit_checks, admission, locked_call and commit.
  • Derived parts, each naming its formula:
    • hold_unattributed = order_lock_hold_append − locked_call − commit, the hold the stages leave over. For a one-call append it is only microseconds, because nothing awaits between granted() and the COMMIT clock. What it carries is:

      • the hold of appends that record no locked_call: a block-bearing share's less its COMMIT, and the whole of one refused in its call;
      • failed COMMITs and closed gates' ROLLBACKs, because only committed COMMITs are subtracted.

      Its meaning says so, and the counts beside each figure show how many.

    • before_lock_unattributed = before_lock_and_response − submit_checks − admission: the Stratum handling, the append task's start, the block-only work, the append's pool checkout and BEGIN, the call's trip to its lock, its reply's trip back and the runtime's wake to it, and the response write.

  • Where the runtime's lag lands. The hold the frontend records starts at the grant the call reports, counted back from when the frontend processes the reply. So the reply's trip back and the runtime's wake to it are in before_lock_and_response, although PostgreSQL holds the lock through them. The runtime's wake to COMMIT's reply is inside commit. after_call and the gate row no longer name a "runtime turnaround".
  • Unknown, never 0, against an older server. A server without the family doesn't declare it, so every stage and every part derived from one reads unknown, with the reason. The split at ORDER_LOCK is unchanged. As before, a declared series that hasn't been observed is a real zero.
  • Gate row. When the report has the stages, the informational row on a failed gated phase splits the remainder before the lock into submit checks, the admission queue and the rest. It then adds a sentence giving the append's hold and its split into the call's reported hold, COMMIT and the rest. A report without the stages prints the line as before.

The first commit is the doc fix for qbit-reviewer's nit on #835: the accounting's histograms come from the frontend's metrics snapshot while pg_stat_statements is read live.

#844: PrismShareAppendAdmissionWaitHigh

A warning (no page label) on the admission stage. It fires when a frontend's admission-wait p99 over five minutes is above 1 s, from at least 100 admissions in that window, and that holds for 10 minutes. scripts/generate_prism_alerts.py builds the expression, dwell and texts from named constants, in a function of its own.

  • Threshold. One second is the ORDER_LOCK hold ladder's boundary, PrismShareAckP99High's bound and the load gate's.

  • Duration. Ten minutes is twice the window. One landing's queue leaves the window five minutes after it forms, so a landing never warns on its own. At 25/s, a settlement would have to hold ORDER_LOCK for more than about 4.6 s even to lift the five-minute p99 over a second; 2.x.x's 4–5 s block minutes would. A queue that persists does warn.

  • Outcomes. All are combined. An append dropped at the share-commit deadline while it queued is counted as cancelled with the time it waited, so a hard stall still warns.

  • Absent series. A frontend without the stage histogram (older than this PR) has no admission series and stays quiet. No-data and evaluation errors are OK, because the snapshot and no-data rules own missing measurements. A stale or unpublished snapshot suppresses the rule, since the family is served from the cached body.

  • Runbook. A new subsection of docs/prism-ledger-ops.md, "Shares queued for an append slot (3.x.x: alert when share appends queue for an append slot (follow-up to #829's stage metric) #844)". It reads, in order:

    1. arrivals;
    2. every ORDER_LOCK holder on every frontend;
    3. the append's locked_call and commit;
    4. the time no stage covers: the call's reply on its way back, the runtime's wake to it, an abandoned append's later ROLLBACK, and the connection's return to the pool with sqlx's release ping. PrismRuntimeLagHigh fires only above 2 s, while 0.6 s of lag fills the slots;
    5. WAL syncs and checkpoints;
    6. pool saturation.

    The load report's share_ack_accounting, database_counters and checkpoint log lines are the offline equivalent.

  • Deployment. The review-only docs/prism-alert-rules-qbit-tools.patch is regenerated from the pinned qbit-tools templates (a007a142; sha256 matches tests/fixtures/prism-deployed-alerts.json). The rule reaches the pair at qbit-tools' next native-rule re-vendor.

  • Overlap. 3.x.x: alert when a frontend's payout-revision listener stays down (follow-up to #816 and #834) #843's listener-down rule edits the same generated files. Whichever PR merges second merges 3.x.x in and regenerates.

What it decides for #829

  • admission + submit_checks against the old remainder say where the queue is.
  • In the stall window:
    • locked_call rising with the full-page images means the call's work after a checkpoint starts. The next step would then be checkpoint spacing or wal_compression on the runner, or a production measurement.
    • locked_call and commit flat while ORDER_LOCK's waits imply longer holds means time inside the lock that no stage covers: the call's reply on its way back and the frontend runtime's wake to it. That time shows in before_lock_unattributed, and runtime_poll_lag_seconds names the runtime.
    • commit above pg_stat_wal's sync time means the COMMIT's round trip, the runtime's wake to its reply, or a COMMIT-path wait other than the fsync.

Tests run (minidev-alex1, through the host gate)

  • cargo test --locked -p qbit-prism-server --lib -- ledger::append_admission metrics:: api::metrics_snapshot passes: 83 tests. They include the new the_admission_wait_is_recorded_however_it_ends, which runs on a paused clock with a lazy pool and no PostgreSQL:
    • with 15 permits held, a 16th append waits 2 s and records admitted 2 s;
    • one aborted after 1 s records cancelled 1 s;
    • one queued when the pool closes records closed 0.5 s.
  • cargo test --locked -p qbit-prism-server --test observability --test metrics_allocation passes (17 and 4 tests). The census pins the seven series (105 families, 1,114 populated series), and every stage outcome records allocation-free.
  • PostgreSQL-gated, on a private PostgreSQL 16 with PRISM_TEST_REQUIRE_INTEGRATION=1; the gated list is unchanged:
    • --test append_admission passes (32 tests). an_append_call_reports_its_lock_and_a_cancelled_one_rolls_back_whole now asserts:
      • an append and a refusal are both admitted, but only the append records locked_call and commit;
      • the two cancelled calls are admitted and record neither;
      • the append's ORDER_LOCK hold covers its locked_call and commit.
    • --test b602_order_lock_hold passes (22 tests). a_landing_records_each_order_lock_hold_under_its_holder now asserts that the block-solving share submitted through Coordinator::submit records submit_checks, admission and commit once each, and no locked_call (it takes the statement path).
  • cargo test --locked -p qbit-prism-load --test harness passes: 156 tests.
    • New: the_server_append_stages_split_the_remainder_and_the_time_after_the_call. The stages are read by their exact labels (admission{outcome="cancelled"} is ignored), and the derived parts check out arithmetically. An older server leaves the stages and hold_unattributed unknown (locked_call is unknown: …) while before_lock_and_response and after_call stay known. A declared, unobserved family is zero.
    • The gate-row test now also covers a report with the stages, the joins between the sentences included.
  • With PRISM_TEST_PG_BIN_DIR=/usr/lib/postgresql/16/bin, cargo test --locked -p qbit-prism-load --test load_smoke passes against the real server. It now asserts that every stage is known and counted where shares were accepted. The two independent measures agree:
    • warm_up: locked_call 0.3 s against pg_stat_statements' derived in-call 0.3 s, and COMMIT 0.5 s against 598 WAL syncs × 0.762 ms (0.46 s); hold_unattributed is 0.0 s;
    • churn: locked_call 0.3 s against 0.3 s, and COMMIT 0.6 s against 1,119 syncs × 0.635 ms (0.71 s).
  • cargo fmt --all -- --check and cargo clippy --locked -p qbit-prism-server -p qbit-prism-load --all-targets -- -D warnings are clean apart from the three known vendored sqlx-core warnings.
  • python3 scripts/check_prism_pool_acquires.py, python3 scripts/generate_prism_metrics.py --check, check_prism_settings.py, check_gate_env_reads.py and check_vendored_sqlx_core.py all pass.
  • After merging 3.x.x (which brought only docs and rulesets), cargo test --locked -p qbit-prism-server --test observability passes again: 17 tests. They include native_rules_reference_only_inventory_families_for_their_role with the new rule.
  • 3.x.x: alert when share appends queue for an append slot (follow-up to #829's stage metric) #844's alert checks:
    • python3 scripts/generate_prism_alerts.py --check and python3 scripts/check_prism_alert_uids.py pass (46 UIDs).
    • python3 scripts/test_prism_alert_deployment.py --snapshot <the two pinned templates> passes: 10 Jinja gate combinations, 78 original / 80 proposed rules. The test now pins the new rule as a non-paging warning with a 10 m dwell and OK no-data.
    • python3 scripts/test_prism_alert_promql.py --promtool <prometheus 3.14.0 promtool> passes: 46 expressions, 214 scenarios, 438 expression and 333 alert assertions. As a negative control, the fourteen new scenarios rerun alone against the same expression with a 3 m dwell (PrismShareAckP99High's) fail exactly the two pending cases, the persistent queue at 14m50s and the landing at 10 m.
    • Fourteen new scenarios cover:
      • a persistent queue firing at 20 m and still pending at 14m50s;
      • a ten-second landing that lifts the p99 but stays pending at 10 m and is gone by 20 m;
      • landings once a minute: two-second settlement holds stay quiet and three-second ones warn;
      • fast admissions;
      • a hard stall's cancelled waits;
      • a trickle below 100 admissions;
      • slow locked_call and commit alone;
      • stale and unpublished snapshots;
      • an absent family;
      • two frontends judged apart.

What CI must cover

  • The full workspace tests, including the release-mode metrics_allocation run and every gated server suite on real PostgreSQL 16.
  • The run-load set on this PR's merge result. Every preset's share_ack_accounting then carries the stages; throughput-20k-window-1fe and throughput-400k-window-1fe-async are the ones to read for PRISM load nightly: a scheduled run failed #829.

Pre-push review (Opus, /code-review xhigh, three rounds)

None of the rounds found a correctness issue on the share path. The text findings are fixed in the last three commits. The most important was that hold − locked_call − commit cannot show runtime lag, so the part is now hold_unattributed and the runbook reads the lag where it lands.

Four points were left, deliberately:

  • locked_call is recorded beside the hold, not in the OrderHold guard. Moving it would change connect.rs for exits that are rare: an error after the reply, or a drop during COMMIT at runtime shutdown. hold_unattributed documents that it carries such holds.
  • The rule is snapshot-gated, like PrismShareAckP99High and the advisory-lock rule. A publisher stalled behind the database is owned by PrismMetricsSnapshotStale. Making the family live is a separate change.
  • The stage/outcome pairing is only debug_asserted. No caller passes an unlisted pair.
  • AdmissionWait keeps tokio::time::Instant, which its paused-clock test needs.

Refs #829
Refs #844

🤖 Generated with Claude Code


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

@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-12T21:44:52.545356Z 1bd1295 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 kiwidream added the run-load Run the PRISM load nightly preset set on this PR's merge result (#549) label Nov 11, 2026

@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: 2 nits. Reviews post bugs and security points only; the rest stay in Sixth Man's ledger.

Reviewed by Claude Opus 5.5.

@kiwidream

Copy link
Copy Markdown
Member Author

flake: qbit-prism-dual-sim --test scenarios, s10_single_writer_pair_keeps_every_share_and_pays_exactly_through_a_frontend_kill (node B did not settle within 60s: 1 unfinished candidates), known as #841; https://github.com/Qbit-Org/qbit-mining-bootstrap/actions/runs/43105904808/job/130809024546. Closing and reopening once to rerun CI.

@kiwidream kiwidream closed this Nov 11, 2026
@kiwidream kiwidream reopened this Nov 11, 2026
…he load report reads them, and a warning fires when appends queue for a slot (#829, #844)

Follows #835, which is merged. 3.1.2 doesn't wait for this PR. It also carries #844's alert on the append-slot queue, as its own commit after the stages it reads.

## Problem

#835's accounting attributed its own run-load occurrence of #829 (run 41734520778, `throughput-400k-window-1fe-async` steady_state, shortfall 2,784):
- 98.5% of 61,082 accepted-ack seconds sat **before ORDER_LOCK**, in a remainder nothing measures: the append-admission queue, the submit checks, the pool checkout and BEGIN, and the response write.
- ORDER_LOCK was saturated for roughly 50 s with holds of 2 ms or more, against 0.96 ms at saturation. WAL syncs (mean 0.184 ms) cover at most about a third of that.
- The rest of the extra hold is either **in the call** (full-page images after a checkpoint starts) or **in the frontend**, between the call's reply and COMMIT. The harness's pg_stat_statements split can't separate the two.

## Change

### Server: `qbit_prism_share_append_stage_seconds{stage,outcome}`

The histogram uses the ORDER_LOCK hold ladder (1 ms to 10 s) and records four stages:

| stage | from → to | outcomes | clock | where |
|---|---|---|---|---|
| `submit_checks` | `submit_share` entry → the append's `start` (readiness, fee, tip, the payout-revision read and its checkout, the fences) | `passed` | frontend monotonic | `coordinator/miner_submit.rs` |
| `admission` | the wait for one of the `max_connections - 1` append permits | `admitted`, `closed` (pool closed first), `cancelled` (dropped while queued: a drop guard records the time actually waited, EP-ERRORS) | frontend monotonic | `ledger/append_admission.rs` |
| `locked_call` | the one-call append's own `lock_held_us`, from its grant to its reply | `replied` | PostgreSQL `clock_timestamp()` | `ledger/window.rs` `append_called` |
| `commit` | the COMMIT round trip, either append path | `committed`, `failed` | frontend monotonic | `ledger/window.rs` `commit_gated` |

**No behaviour change on the share path:**
- **Outside ORDER_LOCK.** Each stage is recorded after it ends, never while ORDER_LOCK is held:
  - `commit` is recorded once COMMIT's reply or failure is in and the hold has ended. `commit_gated` now takes the hold's guard and drops it as COMMIT returns, so the recorded hold still ends where it did and neither stage's recording falls inside it;
  - `locked_call` once the transaction and its hold have ended, by COMMIT or the gate's ROLLBACK;
  - `admission` before the append's checkout.
- **Nothing new in the locked section** except the COMMIT round trip's two clock reads: no lock, await or allocation. Results, errors and their order are unchanged. `commit_gated` became a `&self` method to reach the registry.
- **Not recorded.** A refusal, a reply the ledger then rejects, a closed commit gate (no COMMIT sent), and a submission refused or abandoned during its checks all record nothing. EP-OBSERVABILITY: nothing is recorded as zero.
- **Fixed cardinality.** `AppendStage::outcomes` lists the pairs. The family declares its seven series at start as reserved keys with no samples, so recording allocates nothing (pinned in `metrics_allocation`) and a series appears on its first observation.
- **Docs.** The metric docs are `docs/prism-metric-metadata.json`, the regenerated `docs/prism-native-metrics.md` and a reading note in `docs/prism-metrics-histogram-consumers.md`. The two `Admission::acquire` sites keep their `non-database` classification in `scripts/prism_pool_acquires.json` under their new call text.

### Harness: the stages in `share_ack_accounting`

`ACCOUNTED_SERIES` adds the four series.

- **Measured** parts, each with its clock: `submit_checks`, `admission`, `locked_call` and `commit`.
- **Derived** parts, each naming its formula:
  - `hold_unattributed` = `order_lock_hold_append` − `locked_call` − `commit`, the hold the stages leave over. For a one-call append it is only microseconds, because nothing awaits between `granted()` and the COMMIT clock. What it carries is:
    - the hold of appends that record no `locked_call`: a block-bearing share's less its COMMIT, and the whole of one refused in its call;
    - failed COMMITs and closed gates' ROLLBACKs, because only committed COMMITs are subtracted.

    Its meaning says so, and the counts beside each figure show how many.
  - `before_lock_unattributed` = `before_lock_and_response` − `submit_checks` − `admission`: the Stratum handling, the append task's start, the block-only work, the append's pool checkout and BEGIN, the call's trip to its lock, its reply's trip back and the runtime's wake to it, and the response write.
- **Where the runtime's lag lands.** The hold the frontend records starts at the grant the call reports, counted back from when the frontend processes the reply. So the reply's trip back and the runtime's wake to it are in `before_lock_and_response`, although PostgreSQL holds the lock through them. The runtime's wake to COMMIT's reply is inside `commit`. `after_call` and the gate row no longer name a "runtime turnaround".
- **Unknown, never 0, against an older server.** A server without the family doesn't declare it, so every stage and every part derived from one reads unknown, with the reason. The split at ORDER_LOCK is unchanged. As before, a declared series that hasn't been observed is a real zero.
- **Gate row.** When the report has the stages, the informational row on a failed gated phase splits the remainder before the lock into submit checks, the admission queue and the rest. It then adds a sentence giving the append's hold and its split into the call's reported hold, COMMIT and the rest. A report without the stages prints the line as before.

The first commit is the doc fix for qbit-reviewer's nit on #835: the accounting's histograms come from the frontend's metrics snapshot while pg_stat_statements is read live.

### #844: `PrismShareAppendAdmissionWaitHigh`

A warning (no page label) on the `admission` stage. It fires when a frontend's admission-wait p99 over five minutes is above **1 s**, from at least **100** admissions in that window, and that holds for **10 minutes**. `scripts/generate_prism_alerts.py` builds the expression, dwell and texts from named constants, in a function of its own.

- **Threshold.** One second is the ORDER_LOCK hold ladder's boundary, `PrismShareAckP99High`'s bound and the load gate's.
  - At production's ~50 shares/s (about 25/s per frontend of the pair) an append holds its slot for milliseconds. A wait needs 15 appends in flight on one frontend, which takes an ORDER_LOCK hold of at least 0.6 s.
  - The load lanes' clean steady states acknowledge at a p99 of 3–8 ms. #829's occurrences queued for seconds: ack p99 5.5 s on 10-30 and 6.6 s in #835's run, while the 0.96 s repeat stays under.
- **Duration.** Ten minutes is twice the window. One landing's queue leaves the window five minutes after it forms, so a landing never warns on its own. At 25/s, a settlement would have to hold ORDER_LOCK for more than about 4.6 s even to lift the five-minute p99 over a second; 2.x.x's 4–5 s block minutes would. A queue that persists does warn.
  - Repeated landings are different. They warn when, in every five minutes for ten minutes, their holds' time beyond about 1.6 s adds up to more than about 3 s; for example, a hold over 2.2 s every minute.
  - With arrivals spread evenly, a hold under 0.6 s never fills the fifteen slots, and #602's R2 budget for settlement holds is 250 ms.
- **Outcomes.** All are combined. An append dropped at the share-commit deadline while it queued is counted as `cancelled` with the time it waited, so a hard stall still warns.
- **Absent series.** A frontend without the stage histogram (older than this PR) has no admission series and stays quiet. No-data and evaluation errors are OK, because the snapshot and no-data rules own missing measurements. A stale or unpublished snapshot suppresses the rule, since the family is served from the cached body.
- **Runbook.** A new subsection of `docs/prism-ledger-ops.md`, "Shares queued for an append slot (#844)". It reads, in order:
  1. arrivals;
  2. every ORDER_LOCK holder on every frontend;
  3. the append's `locked_call` and `commit`;
  4. the time no stage covers: the call's reply on its way back, the runtime's wake to it, an abandoned append's later ROLLBACK, and the connection's return to the pool with sqlx's release ping. `PrismRuntimeLagHigh` fires only above 2 s, while 0.6 s of lag fills the slots;
  5. WAL syncs and checkpoints;
  6. pool saturation.

  The load report's `share_ack_accounting`, `database_counters` and checkpoint log lines are the offline equivalent.
- **Deployment.** The review-only `docs/prism-alert-rules-qbit-tools.patch` is regenerated from the pinned qbit-tools templates (a007a142; sha256 matches `tests/fixtures/prism-deployed-alerts.json`). The rule reaches the pair at qbit-tools' next native-rule re-vendor.
- **Overlap.** #843's listener-down rule edits the same generated files. Whichever PR merges second merges 3.x.x in and regenerates.

### What it decides for #829
- `admission` + `submit_checks` against the old remainder say where the queue is.
- In the stall window:
  - `locked_call` rising with the full-page images means the call's work after a checkpoint starts. The next step would then be checkpoint spacing or `wal_compression` on the runner, or a production measurement.
  - `locked_call` and `commit` flat while ORDER_LOCK's waits imply longer holds means time inside the lock that no stage covers: the call's reply on its way back and the frontend runtime's wake to it. That time shows in `before_lock_unattributed`, and `runtime_poll_lag_seconds` names the runtime.
  - `commit` above pg_stat_wal's sync time means the COMMIT's round trip, the runtime's wake to its reply, or a COMMIT-path wait other than the fsync.

## Tests run (minidev-alex1, through the host gate)

- `cargo test --locked -p qbit-prism-server --lib -- ledger::append_admission metrics:: api::metrics_snapshot` passes: 83 tests. They include the new `the_admission_wait_is_recorded_however_it_ends`, which runs on a paused clock with a lazy pool and no PostgreSQL:
  - with 15 permits held, a 16th append waits 2 s and records `admitted` 2 s;
  - one aborted after 1 s records `cancelled` 1 s;
  - one queued when the pool closes records `closed` 0.5 s.
- `cargo test --locked -p qbit-prism-server --test observability --test metrics_allocation` passes (17 and 4 tests). The census pins the seven series (105 families, 1,114 populated series), and every stage outcome records allocation-free.
- PostgreSQL-gated, on a private PostgreSQL 16 with `PRISM_TEST_REQUIRE_INTEGRATION=1`; the gated list is unchanged:
  - `--test append_admission` passes (32 tests). `an_append_call_reports_its_lock_and_a_cancelled_one_rolls_back_whole` now asserts:
    - an append and a refusal are both admitted, but only the append records `locked_call` and `commit`;
    - the two cancelled calls are admitted and record neither;
    - the append's ORDER_LOCK hold covers its `locked_call` and `commit`.
  - `--test b602_order_lock_hold` passes (22 tests). `a_landing_records_each_order_lock_hold_under_its_holder` now asserts that the block-solving share submitted through `Coordinator::submit` records `submit_checks`, `admission` and `commit` once each, and no `locked_call` (it takes the statement path).
- `cargo test --locked -p qbit-prism-load --test harness` passes: 156 tests.
  - New: `the_server_append_stages_split_the_remainder_and_the_time_after_the_call`. The stages are read by their exact labels (`admission{outcome="cancelled"}` is ignored), and the derived parts check out arithmetically. An older server leaves the stages and `hold_unattributed` unknown (`locked_call is unknown: …`) while `before_lock_and_response` and `after_call` stay known. A declared, unobserved family is zero.
  - The gate-row test now also covers a report with the stages, the joins between the sentences included.
- With `PRISM_TEST_PG_BIN_DIR=/usr/lib/postgresql/16/bin`, `cargo test --locked -p qbit-prism-load --test load_smoke` passes against the real server. It now asserts that every stage is known and counted where shares were accepted. The two independent measures agree:
  - `warm_up`: `locked_call` 0.3 s against pg_stat_statements' derived in-call 0.3 s, and COMMIT 0.5 s against 598 WAL syncs × 0.762 ms (0.46 s); `hold_unattributed` is 0.0 s;
  - `churn`: `locked_call` 0.3 s against 0.3 s, and COMMIT 0.6 s against 1,119 syncs × 0.635 ms (0.71 s).
- `cargo fmt --all -- --check` and `cargo clippy --locked -p qbit-prism-server -p qbit-prism-load --all-targets -- -D warnings` are clean apart from the three known vendored sqlx-core warnings.
- `python3 scripts/check_prism_pool_acquires.py`, `python3 scripts/generate_prism_metrics.py --check`, `check_prism_settings.py`, `check_gate_env_reads.py` and `check_vendored_sqlx_core.py` all pass.
- After merging 3.x.x (which brought only docs and rulesets), `cargo test --locked -p qbit-prism-server --test observability` passes again: 17 tests. They include `native_rules_reference_only_inventory_families_for_their_role` with the new rule.
- #844's alert checks:
  - `python3 scripts/generate_prism_alerts.py --check` and `python3 scripts/check_prism_alert_uids.py` pass (46 UIDs).
  - `python3 scripts/test_prism_alert_deployment.py --snapshot <the two pinned templates>` passes: 10 Jinja gate combinations, 78 original / 80 proposed rules. The test now pins the new rule as a non-paging warning with a 10 m dwell and OK no-data.
  - `python3 scripts/test_prism_alert_promql.py --promtool <prometheus 3.14.0 promtool>` passes: 46 expressions, 214 scenarios, 438 expression and 333 alert assertions. As a negative control, the fourteen new scenarios rerun alone against the same expression with a 3 m dwell (`PrismShareAckP99High`'s) fail exactly the two pending cases, the persistent queue at 14m50s and the landing at 10 m.
  - Fourteen new scenarios cover:
    - a persistent queue firing at 20 m and still pending at 14m50s;
    - a ten-second landing that lifts the p99 but stays pending at 10 m and is gone by 20 m;
    - landings once a minute: two-second settlement holds stay quiet and three-second ones warn;
    - fast admissions;
    - a hard stall's `cancelled` waits;
    - a trickle below 100 admissions;
    - slow `locked_call` and `commit` alone;
    - stale and unpublished snapshots;
    - an absent family;
    - two frontends judged apart.

## What CI must cover

- The full workspace tests, including the release-mode `metrics_allocation` run and every gated server suite on real PostgreSQL 16.
- The `run-load` set on this PR's merge result. Every preset's `share_ack_accounting` then carries the stages; `throughput-20k-window-1fe` and `throughput-400k-window-1fe-async` are the ones to read for #829.

### Pre-push review (Opus, `/code-review xhigh`, three rounds)

None of the rounds found a correctness issue on the share path. The text findings are fixed in the last three commits. The most important was that hold − `locked_call` − `commit` cannot show runtime lag, so the part is now `hold_unattributed` and the runbook reads the lag where it lands.

Four points were left, deliberately:
- **`locked_call` is recorded beside the hold, not in the `OrderHold` guard.** Moving it would change `connect.rs` for exits that are rare: an error after the reply, or a drop during COMMIT at runtime shutdown. `hold_unattributed` documents that it carries such holds.
- **The rule is snapshot-gated, like `PrismShareAckP99High` and the advisory-lock rule.** A publisher stalled behind the database is owned by `PrismMetricsSnapshotStale`. Making the family live is a separate change.
- **The stage/outcome pairing is only `debug_assert`ed.** No caller passes an unlisted pair.
- **`AdmissionWait` keeps `tokio::time::Instant`,** which its paused-clock test needs.

Refs #829
Refs #844

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

Squashed commits:
2d23558 3.x.x: say that the share-ack accounting's histograms come from the frontend's metrics snapshot while pg_stat_statements is read live (#829)
42f25c0 3.x.x: the server times each share's submit checks, its wait for an append permit, its call's own ORDER_LOCK hold and its COMMIT, and the load report reads them (#829)
add8688 Merge remote-tracking branch 'origin/3.x.x' into orca/829-share-append-stages
347b318 3.x.x: warn when share appends queue for an append slot for ten minutes (#844)
845ec13 3.x.x: the append stages' texts say where the call's reply went and when a slot frees, and two landing cadences pin the slot-queue warning (#829, #844)
1e17a49 3.x.x: the hold the append stages leave over is hold_unattributed, not a runtime turnaround, and the runbook reads runtime lag where it lands (#829, #844)
e69b63d 3.x.x: the append-slot runbook reads arrivals, every holder and the time no stage covers, and the texts agree on the hold's remainder (#829, #844)
9ea60c2 Merge remote-tracking branch 'origin/3.x.x' into orca/829-share-append-stages

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. 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, checked by Claude Opus 5.5 (nothing it found held up).

@kiwidream
kiwidream merged commit 718fc51 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

run-load Run the PRISM load nightly preset set on this PR's merge result (#549)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant