Skip to content

doc: the pending 3.1.2 notes, and the runbook steps for an unclean failover and a mixed 3.1.1/3.1.2 cluster - #897

Open
kiwidream wants to merge 2 commits into
3.x.xfrom
orca/3.1.2-notes-and-runbooks
Open

kiwidream wants to merge 2 commits into
3.x.xfrom
orca/3.1.2-notes-and-runbooks

Conversation

@kiwidream

@kiwidream kiwidream commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Problem

Nothing in the repository yet tells a 3.1.1 operator what 3.1.2 changes for them. VERSION is 3.1.1 and there is no doc/release-notes-3.1.2.md. Three things in particular are silent today:

  • Three .env lines an existing deployment keeps. 3.1.1's .env.example shipped PRISM_STRATUM_MAX_AUTHORIZE_ATTEMPTS_PER_INTERVAL=0 (git show d0c649b4:.env.example, line 353). An explicit value wins over the new default of 32 (stratum.rs:341, compose.yaml:595 :-32), so an .env copied from it keeps the authorize budget off. Likewise QBIT_GIT_REF/QBIT_GIT_COMMIT: scripts/prepare-qbit-source.sh and scripts/check-env.sh read .env after config/upstream.env, so such an .env keeps building Qbit Core v1.0.0 and make doctor reports it verified.
  • The listener-down rule has to follow the binaries both ways. Its expression counts a scraped frontend without qbit_prism_payout_revision_listener_up as down (… or on(job, instance, network) (max_over_time(up[2m]) == bool 1)), and 3.1.1 doesn't export that gauge. Deployed before the last 3.1.1 frontend is gone, or left in place after a rollback, it warns on every 3.1.1 frontend that serves miners. 3.1.1's notes said its rules "need no change if the binaries roll back"; that is no longer true.
  • Work paid to the pool-fee address is a 3.1.2-only input (Review finding: a miner using the pool-fee program can fail template builds #822). 3.1.1's payout policy refuses it (DuplicatePoolFeeAccount, d0c649b4:crates/qbit-prism/src/lib.rs:1650), and AUDIT_BUILDER_VERSION stays 1, so the builder-version guard (stored_inputs_mismatch) doesn't stop a 3.1.1 frontend from trying. Its rebuild error propagates out of rebuild_claim_parts (build.await??) through land_offered to settle_offered_candidate, which parks the row in reconciliation with ALERT: offered candidate could not be processed; kept for reconciliation, never offered again and a LEAST(3600, 10*attempt_count) s backoff. A 3.1.1 dual-writer node's adoption (adoption.rs, build_claim_parts) and 3.1.1's verifier refuse it the same way. Nothing says so.

And the HA failover runbook promises that a block mid-landing "lands within seconds of the move", which isn't true when the fence leaves established ledger connections silent: the ledger pool sets no TCP keepalive or user timeout (ledger/connect.rs pool options; the vendored socket sets only TCP_NODELAY; sqlx's release ping has no timeout).

Change

Not touched, as the task says: VERSION, Cargo.toml, the lockfiles, the README banner, the development line's status, docs/releasing.md, .github/** and every generated file.

Confirmed in the code, and where the findings differ

Every default, refusal, metric, rule and precedence claim in the notes was traced to its code at af448068. Where the research findings and the code differ, the notes follow the code:

Tests

All on this head, from the worktree:

Command Result
python3 scripts/check_version_skew.py exit 0: VERSION 3.1.1 matches every workspace crate, with the notes file present
python3 scripts/generate_prism_alerts.py --check exit 0. Its listener and recent-miner prose checks read the edited prism-alert-migration.md and prism-ledger-ops.md
python3 scripts/generate_prism_metrics.py --check exit 0
python3 scripts/check_prism_settings.py exit 0
python3 scripts/check_prism_alert_uids.py 47 rule UIDs unique and within Grafana's limits
GIT_CONFIG_GLOBAL=/dev/null python3 -m unittest over the 21 tests/test_*.py modules that read docs/, doc/ or Markdown (test_docs_lab_prism_references, test_check_deleted_test_map, test_check_prism_alert_uids, test_check_prism_settings, test_prism_generated_artifact_checks, test_mainnet_compose_contract, test_check_gate_manifest, test_tree_pass_marker, test_check_version_skew, test_makefile_lifecycle, test_check_vendored_sqlx_core, test_ckpool_rejects_patch, test_prism_load_bridge, test_prism_load_probe, test_prism_load_regress, test_dual_writer_matrix_summary, test_prism_load_trend, test_run_rust_test_shard, test_run_python_test_shard, test_prism_shipped_image_lane, test_prism_soak_capture) 700 tests, OK
A local link and anchor check of the 7 changed files (relative links and GitHub heading slugs) every link resolves. It flagged one anchor, an explicit <a id> in prism-rust-migration.md that predates this change and is valid
git diff --check clean
Local review: /code-review xhigh in an Opus subagent, before the first push 12 findings. Fixed in the second commit: a 3.1.1 frontend can claim a 3.1.2 frontend's fee-program block with no frontend failing (the claim lane takes any due row), so the "finder dies" framing is gone; the old .env keeps three lines, not two; only the listener rule must follow rollbacks; the tag goes on the promotion into main; If-None-Match: * still answers 304; 924.6 s is the kernel's lower bound; the cache-eviction order now matches remember_at; the restart command uses the deployment's Compose files and project; the dual-writer "together" reason was inconsistent and is dropped; long lines reflowed. Not taken: setting keepalives in the ledger's sockets (code, finding C's part (b), planned for 3.1.3), and folding the repeated #822 explanation into one place (the notes stay self-contained; the copies now agree)

Not run, and not verified

  • No Rust build or test: docs only.
  • The rest of CI's Python shards, left to CI. test_check_vendored_sqlx_core's real-tree tests skip locally without SQLX_CORE_UPSTREAM_CRATE.
  • Finding C is traced, not reproduced: no silent-fence failover was run. The runbook step is worded as a precaution with its condition.
  • Statements carried from merged PRs and not re-measured: 3.x.x: render the shared part of mining.notify once per published work (#861) #864's "about 3.6 MB" for the eight kept notify bodies at a 2,600-output coinbase, and 3.x.x: build, download and test against Qbit Core v1.0.1 instead of v1.0.0 #876's analysis of Qbit Core v1.0.1, which the notes only link.
  • Outside this repository, not verified: qbit-tools' re-vendor procedure. Also not verified: whether GitHub enforces .github/rulesets/ as the files say; the "no ruleset requires CI" statement rests on those files and their README.

🤖 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 17, 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-18T15:26:34.480077Z b626def 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.

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.

kiwidream and others added 2 commits November 18, 2026 10:24
…ilover and a mixed 3.1.1/3.1.2 cluster

doc/release-notes-3.1.2.md describes, in 3.1.1's structure, every pull
request merged into 3.x.x since v3.1.1 (d0c649b..af44806): what changed,
what an operator must do and what they may now observe. It says that an
.env copied from 3.1.1's .env.example keeps the authorize budget off and
Qbit Core at v1.0.0, that the listener-down rule must follow the binaries
both ways, and what a 3.1.1 frontend, dual-writer node or verifier does
with work paid to the pool-fee address (#822). It ends with the pull
requests still in review, for the release coordinator to replace.

The runbooks follow:
- the HA failover's step 5 restarts both frontends after moving the
  writer endpoint, unless the move resets every established connection;
  ledger operations and the migration guide point to it;
- ledger operations gets the #822 mixed-version runbook, with pointers
  from PRISM.md and the pool-fee procedure;
- the configuration guide says an explicit =0 in .env wins over the new
  authorize default;
- the alert migration says to roll the listener rule back before the
  binaries, and adopts #844's rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ram block, three .env lines, the listener rule alone follows rollbacks

From the local review:
- any frontend's submit loop claims whichever candidate row is due, so a
  3.1.1 frontend can take a 3.1.2 frontend's fee-program block with no
  frontend failing (notes and ledger operations);
- the pin is two lines, so an old .env keeps three; only the listener
  rule must follow the binaries both ways;
- the tag goes on the promotion into main; If-None-Match: * still answers
  304; 924.6 s is the kernel's lower bound, not the expected wait;
- the identity cache's eviction order is the code's;
- the failover restart uses the deployment's own Compose files and
  project, and is checked;
- the in-review list names the accept() error fix only (ntime moved to
  #895).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kiwidream
kiwidream force-pushed the orca/3.1.2-notes-and-runbooks branch from 4be8587 to b626def Compare November 18, 2026 15:24

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

Reviewed by Claude Opus 5.5.

djh58 added a commit that referenced this pull request Nov 23, 2026
): fixes the coordinator CPU spin

Backports [transact-rs/sqlx#4289](transact-rs/sqlx#4289), "fix(pool): prevent num_idle underflow that wedges maintenance in a CPU spin" (merge commit `5d3787ef9d69947065085f46b58767a50b3d8e25`, merged 2026-09-10, first released in sqlx 0.9.1 on 2026-11-18), into the sqlx-core 0.8.6 that #794 vendored. It is in neither 0.8.6 nor 0.9.0.

## Observed in production

A production PRISM v3.1.1 coordinator stalled repeatedly, for minutes to hours at a time. One tokio worker thread sits at 100% user CPU and never enters a syscall, while every other thread waits. A read-only `perf` sample put 100% of that thread's samples in:

- `sqlx_core::pool::inner::spawn_maintenance_tasks::{closure#1}`
- `ArrayQueue<Idle<Postgres>>::pop`
- `tokio::sync::batch_semaphore::Semaphore::add_permits_locked`

That is the pool's maintenance sweep, `for _ in 0..pool.num_idle()`, running on an empty idle queue with `num_idle` wrapped to about `usize::MAX`.

0.8.6's `release()` pushes a connection onto the idle queue and releases its permit before it adds one to `num_idle`, while `pop_idle()` pops and then subtracts one. An acquire that lands between the two subtracts first, and with the count at 0 it wraps until the add lands. The maintenance task reads the count once as its loop bound. With the queue empty the loop body never awaits, so a task that read the wrapped count keeps its worker for good.

The stalls recur on a 30-minute rhythm, because every connection reopens together after each stall and they all reach the 30-minute `max_lifetime` together.

## The change

`vendor/sqlx-core/src/pool/inner.rs` takes upstream's diff:

- `release()` adds to `num_idle` before it pushes the connection;
- `pop_idle()` subtracts saturating at 0;
- the maintenance sweep makes at most `min(num_idle(), max_connections)` checks.

Those three code changes are upstream's, line for line (the added and removed lines of the hunks diff empty against upstream's commit). Nothing else in the vendored crate's code changes.

Upstream's stress test, `underflow_tests`, comes with them. It needed two adaptations to build and run on 0.8.6, both recorded in `vendor/sqlx-core/README.md`:

- its stub backend takes 0.8.6's `AnyConnectionBackend` signatures (`&str` and `Cow<'static, str>` where 0.9 has `SqlStr`, and `describe` without the `offline` gate);
- its pool sets neither `max_lifetime` nor `idle_timeout`, so that it spawns no maintenance task and needs no runtime.

`vendor/sqlx-core/README.md` gains the #4289 entry in the style of #4251's and #3861's.

## Test evidence

Upstream's test, run from a copy of the vendored crate with `cargo test --lib --features any,_rt-tokio underflow` (12 threads, 200,000 acquire and release cycles each, on a pool of 3):

| Pool code | Debug | Release |
| --- | --- | --- |
| 0.8.6 as vendored before this change | 5 of 5 fail: `saw 18446744073709551615, max 3` | 3 of 3 fail, same message |
| with this change | 5 of 5 pass | 3 of 3 pass |

Also run locally:

- `cargo check --lib --features _rt-tokio,_tls-rustls-ring-webpki,json,chrono,migrate` on the patched crate: clean, with only the three warnings upstream ships;
- `python3 scripts/check_vendored_sqlx_core.py`: both lock files use `vendor/sqlx-core` 0.8.6, 0 advisories;
- `python3 -m unittest tests.test_check_vendored_sqlx_core`: 11 tests pass.

Not run locally: the workspace build and test suites. The host had 1.6 GB of disk free, so CI is the first full build of this.

## What this does not cover

- **CI does not run upstream's test.** It is a unit test inside sqlx-core, and Cargo tests only workspace members. The README says how to run it. Nothing in CI fails if these hunks are lost; a regression test through the public pool API in `crates/qbit-prism-server/tests/`, as #4251 and #3861 have, would close that.
- **The sweep cap has no test of its own**, upstream's included: with the reordering in place the count cannot wrap, so the cap is never reached.
- **No version bump, tag or release.** `VERSION` stays 3.1.1.
- **Release notes.** The pending 3.1.2 notes in #897 need an entry for this fix; this PR adds none, as `main` has no unreleased notes file.
- **3.x.x.** The fix reaches 3.x.x by merging `main` into it after this lands. There, #836's source check requires the change recorded as a patch in `vendor/sqlx-core.patches/`, and the README has diverged, so that merge needs both resolved.

Refs #794.

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

Squashed commits:
192603d main: backport sqlx's pool num_idle underflow fix (transact-rs/sqlx#4289): fixes the coordinator CPU spin
6db3769 vendor/sqlx-core/README.md: say what the #4289 backport is for without deployment details

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Squashed-from: 6db3769
djh58 added a commit that referenced this pull request Nov 23, 2026
): fixes the coordinator CPU spin (#917)

Backports [transact-rs/sqlx#4289](transact-rs/sqlx#4289), "fix(pool): prevent num_idle underflow that wedges maintenance in a CPU spin" (merge commit `5d3787ef9d69947065085f46b58767a50b3d8e25`, merged 2026-09-10, first released in sqlx 0.9.1 on 2026-11-18), into the sqlx-core 0.8.6 that #794 vendored. It is in neither 0.8.6 nor 0.9.0.

## Observed in production

A production PRISM v3.1.1 coordinator stalled repeatedly, for minutes to hours at a time. One tokio worker thread sits at 100% user CPU and never enters a syscall, while every other thread waits. A read-only `perf` sample put 100% of that thread's samples in:

- `sqlx_core::pool::inner::spawn_maintenance_tasks::{closure#1}`
- `ArrayQueue<Idle<Postgres>>::pop`
- `tokio::sync::batch_semaphore::Semaphore::add_permits_locked`

That is the pool's maintenance sweep, `for _ in 0..pool.num_idle()`, running on an empty idle queue with `num_idle` wrapped to about `usize::MAX`.

0.8.6's `release()` pushes a connection onto the idle queue and releases its permit before it adds one to `num_idle`, while `pop_idle()` pops and then subtracts one. An acquire that lands between the two subtracts first, and with the count at 0 it wraps until the add lands. The maintenance task reads the count once as its loop bound. With the queue empty the loop body never awaits, so a task that read the wrapped count keeps its worker for good.

The stalls recur on a 30-minute rhythm, because every connection reopens together after each stall and they all reach the 30-minute `max_lifetime` together.

## The change

`vendor/sqlx-core/src/pool/inner.rs` takes upstream's diff:

- `release()` adds to `num_idle` before it pushes the connection;
- `pop_idle()` subtracts saturating at 0;
- the maintenance sweep makes at most `min(num_idle(), max_connections)` checks.

Those three code changes are upstream's, line for line (the added and removed lines of the hunks diff empty against upstream's commit). Nothing else in the vendored crate's code changes.

Upstream's stress test, `underflow_tests`, comes with them. It needed two adaptations to build and run on 0.8.6, both recorded in `vendor/sqlx-core/README.md`:

- its stub backend takes 0.8.6's `AnyConnectionBackend` signatures (`&str` and `Cow<'static, str>` where 0.9 has `SqlStr`, and `describe` without the `offline` gate);
- its pool sets neither `max_lifetime` nor `idle_timeout`, so that it spawns no maintenance task and needs no runtime.

`vendor/sqlx-core/README.md` gains the #4289 entry in the style of #4251's and #3861's.

## Test evidence

Upstream's test, run from a copy of the vendored crate with `cargo test --lib --features any,_rt-tokio underflow` (12 threads, 200,000 acquire and release cycles each, on a pool of 3):

| Pool code | Debug | Release |
| --- | --- | --- |
| 0.8.6 as vendored before this change | 5 of 5 fail: `saw 18446744073709551615, max 3` | 3 of 3 fail, same message |
| with this change | 5 of 5 pass | 3 of 3 pass |

Also run locally:

- `cargo check --lib --features _rt-tokio,_tls-rustls-ring-webpki,json,chrono,migrate` on the patched crate: clean, with only the three warnings upstream ships;
- `python3 scripts/check_vendored_sqlx_core.py`: both lock files use `vendor/sqlx-core` 0.8.6, 0 advisories;
- `python3 -m unittest tests.test_check_vendored_sqlx_core`: 11 tests pass.

Not run locally: the workspace build and test suites. The host had 1.6 GB of disk free, so CI is the first full build of this.

## What this does not cover

- **CI does not run upstream's test.** It is a unit test inside sqlx-core, and Cargo tests only workspace members. The README says how to run it. Nothing in CI fails if these hunks are lost; a regression test through the public pool API in `crates/qbit-prism-server/tests/`, as #4251 and #3861 have, would close that.
- **The sweep cap has no test of its own**, upstream's included: with the reordering in place the count cannot wrap, so the cap is never reached.
- **No version bump, tag or release.** `VERSION` stays 3.1.1.
- **Release notes.** The pending 3.1.2 notes in #897 need an entry for this fix; this PR adds none, as `main` has no unreleased notes file.
- **3.x.x.** The fix reaches 3.x.x by merging `main` into it after this lands. There, #836's source check requires the change recorded as a patch in `vendor/sqlx-core.patches/`, and the README has diverged, so that merge needs both resolved.

Refs #794.

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

Squashed commits:
192603d main: backport sqlx's pool num_idle underflow fix (transact-rs/sqlx#4289): fixes the coordinator CPU spin
6db3769 vendor/sqlx-core/README.md: say what the #4289 backport is for without deployment details


Squashed-from: 6db3769

Co-authored-by: Claude Fable 5.2 <[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