Skip to content

3.x.x: backport sqlx's TLS lost-wakeup fix (launchbadge/sqlx#4251) by vendoring sqlx-core 0.8.6 (#771) - #794

Merged
kiwidream merged 2 commits into
3.x.xfrom
orca/771-sqlx-tls-wakeup
Oct 28, 2026
Merged

kiwidream merged 2 commits into
3.x.xfrom
orca/771-sqlx-tls-wakeup

Conversation

@kiwidream

@kiwidream kiwidream commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #771. sqlx-core 0.8.6's TLS adapter waits for write readiness and then read readiness, one after the other (src/net/tls/util.rs). A TLS write that needs a read first, or the reverse, can miss its wakeup and stall until a client deadline. That holds the ledger connection and any advisory lock it owns (ORDER_LOCK, SETTLEMENT_LOCK). The upstream fix, transact-rs/sqlx#4251 (merged 2026-04-28), shipped only in 0.9.0; no 0.8.x release carries it.

What changes

  • Vendored sqlx-core 0.8.6 in vendor/sqlx-core. It is byte-identical to the crates.io crate (same .crate SHA-256 as the lock's old checksum) except for #4251's util.rs diff and a README. It is patched in with [patch.crates-io] in both workspaces (root and crates/qbit-prism-server/fuzz), and lab/prism/Dockerfile copies vendor/. Both lockfiles now resolve sqlx-core to the path.
  • Regression test tests/sqlx_tls_readiness.rs. It drives sqlx-core's real rustls client through two out-of-order readiness cases. It stalls on unpatched 0.8.6 and passes patched. It is deterministic: polled by hand on one thread, with no sleeps, timers or randomness, and it passed 400/400 repeat runs.
  • Guards, so the patch can't silently disappear. scripts/check_vendored_sqlx_core.py runs in CI and checks:
    • both manifests patch sqlx-core to vendor/sqlx-core;
    • each lockfile holds exactly one path sqlx-core at the vendored version, with the locked sqlx at that version and no unused patch, so a later cargo update -p sqlx that drops the patch fails CI;
    • after cargo deny, any non-withdrawn sqlx-core RustSec advisory that is not listed in vendor/sqlx-core/reviewed-advisories.toml fails the job. That list is empty today: the database has none. With a path dependency, cargo-deny itself no longer matches advisories to sqlx-core.
  • The test's dev-dependency is pinned to sqlx-core = "=0.8.6" with the rustls feature stated explicitly.
  • vendor/sqlx-core/README.md explains the patch, both checks, and how to drop the vendor on the move to 0.9.

#770's narrower repolled mitigation in import-audits is now redundant but is kept. #713 (the verify-ca host-name check) is a one-line follow-up in the vendored tls_rustls.rs and is out of scope here.

Tests

  • sqlx_tls_readiness: 2/2 patched, 0/2 with the unpatched util.rs.
  • Plain ledger_postgres 253/253 and import_audits_settlement_lock 13/13.
  • Over TLS (a private PostgreSQL 16 with ssl=on, sslmode=require, 3,666 TLSv1.3 sessions): ledger_postgres 250/253 and import_audits_settlement_lock 13/13, including a ~107 MB audit through the throttled relay. The 3 failures are candidates_recover tests whose ExecutionProxy answers SSLRequest with N (a harness limit, not this patch).
  • cargo build --locked, cargo deny --locked check, fmt, and cargo clippy --locked --workspace --all-targets -D warnings pass. The vendored crate's 3 rustc lints are warnings, not denied. hadolint passes, the fuzz workspace builds, and the guard's 11 unit tests pass.
  • An independent adversarial check made the fix break by putting back the unpatched util.rs and by removing the patch entry. Both are caught: the test fails in 0.01 s instead of hanging. It also confirmed that every build path (workspace, fuzz, Docker image, CI) resolves the vendored crate.

🤖 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 2 commits October 28, 2026 09:57
…stall a ledger connection (#771)

Cause. sqlx-core 0.8.6's StdSocket::poll_ready, under every rustls
connection, waited for write readiness and then for read readiness.
When a write blocks before sending anything, rustls 0.23.46's
complete_io tries a read too, so a large statement leaves both flagged.
Write readiness that arrives between the blocked write and the poll is
spent, and the task parks on read readiness while the server waits for
the rest of the statement (#765's suspected stall). Data that arrives
while the task waits to write has no waker at all. transact-rs/sqlx#4251 (merge c0ec9c0b, 2026-04-28) fixes
both: poll_ready registers both directions and returns when either is
ready. It is released in sqlx 0.9.0 only; no 0.8.x tag carries it.

Change.
- vendor/sqlx-core is sqlx-core 0.8.6 from the local registry cache,
  identical to the crates.io .crate whose SHA-256 the lockfile recorded
  (ee6798b1), plus #4251's diff to src/net/tls/util.rs and a README with
  the provenance. The diff applies as upstream wrote it; its import
  context differs only because 0.8.6 takes `future` from futures_util.
- The root Cargo.toml and the fuzz workspace's Cargo.toml patch
  sqlx-core to it. Both lockfiles change only in dropping sqlx-core's
  registry source and checksum; the root one also lists the test's two
  dev-dependencies, already in the graph.
- lab/prism/Dockerfile copies vendor/ into the build stage: without it
  the image's build context no longer resolves.
- tests/sqlx_tls_readiness.rs runs sqlx-core's rustls client against a
  rustls server over an in-memory socket whose readiness it controls,
  polling by hand. One case frees the send buffer between the blocked
  write and the readiness poll; the other has the server send while the
  client waits to write and read nothing more until the client reads.
  Against unpatched 0.8.6 both stall (parked on read with no write waker,
  and on write with no read waker); with the backport both finish, and the
  server receives the request byte for byte.

Not changed: #770's `repolled` in import-audits stays, sslmode handling
(#713) is untouched, and the vendored crate's three upstream
mismatched_lifetime_syntaxes warnings are left as shipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
)

Review follow-up to the backport.

The patch. sqlx pins its sqlx-core with `=`, so moving sqlx to another
0.8.x leaves `[patch.crates-io]` unused: Cargo only warns, the unfixed
crates.io sqlx-core returns, and nothing in the fuzz workspace would
notice. scripts/check_vendored_sqlx_core.py fails unless, for the
repository and the fuzz workspace alike:
- Cargo.toml patches sqlx-core to vendor/sqlx-core;
- Cargo.lock holds one sqlx-core, with no source or checksum, at the
  vendored version;
- the locked sqlx is that version too (sqlx X requires sqlx-core =X), and
  its sqlx-core dependency names no other copy;
- the lock file does not record the patch under [[patch.unused]].
The lint job runs it beside the other check scripts.

Advisories. cargo-deny matches RustSec advisories only against registry
crates, so it stopped checking sqlx-core. Right after `cargo deny check`,
the cargo-deny job runs the same script with --require-advisory-db.
- The script finds the database cargo-deny fetched from deny.toml's
  db-path, or from --advisory-db / RUSTSEC_ADVISORY_DB.
- It lists every sqlx-core advisory there and fails on any that is not
  withdrawn and not named, with a one-line reason, in
  vendor/sqlx-core/reviewed-advisories.toml.
- The database of 2026-10-28 holds none, so the list is empty.
The vendored README explains both checks and what to do when an
advisory appears. tests/test_check_vendored_sqlx_core.py covers:
- a registry or hand-edited sqlx-core in either lock;
- sqlx moved past the vendored version, with the patch unused;
- a second sqlx-core;
- a missing or misdirected patch;
- unreviewed, reviewed, withdrawn and malformed advisories;
- the database's location;
- the CI wiring.

The test. Its sqlx-core dev-dependency is pinned to =0.8.6, with the
_tls-rustls-ring-webpki feature that sqlx's runtime-tokio-rustls
enables. Moving sqlx or the test's backend then fails resolution or the
test instead of testing another copy. The first case no longer asserts
that a drain finds no write waker. A drain now wakes one it finds, as an
I/O driver would, and the test requires at least one drain that found
none: that is the lost-wakeup window. The module comment states the
dependency on rustls 0.23.46's complete_io, and how to re-validate the
harness on a rustls bump. Against the unpatched util.rs both cases still
stall.

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

chatgpt-codex-connector Bot commented Oct 28, 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-28T17:58:56.045743Z 32a576a Manual request
ℹ️ 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.

No findings.

@kiwidream

Copy link
Copy Markdown
Member Author

Closing and reopening to re-run CI (this token can't re-run workflows). Shard 1's only failure was coordinator::miner_submit::acquire_tests::block_only_poll_checkout_cancel_and_deadline_stay_unknown, a paused-clock checkout-cancellation test that this TLS-only change doesn't reach: CI's PostgreSQL connections are plaintext, and the patch touches only sqlx-core's TLS readiness. It passed 5/5 locally on this head. The two other red jobs fail only because that shard failed.

@kiwidream kiwidream closed this Oct 28, 2026
@kiwidream kiwidream reopened this Oct 28, 2026
@kiwidream

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 32a576a04e

ℹ️ 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".

@kiwidream
kiwidream merged commit 706e40f into 3.x.x Oct 28, 2026
79 of 82 checks passed
kiwidream added a commit that referenced this pull request Nov 12, 2026
…and CI checks vendored sqlx-core against upstream's .crate plus recorded patches (#825)

## Problem

#825 items 1 and 2, from #818's and #794's reviews:

1. **verify-ca without a root certificate passes startup.** Since #818, sqlx-postgres refuses every `sslmode=verify-ca` connect that has no `sslrootcert` (or `PGSSLROOTCERT`). But nothing at startup checked for it, so a `PRISM_DATABASE_URL` or peer URL like that passed `check-config` and startup, then failed every connect.
2. **Nothing ties `vendor/sqlx-core` to upstream.** `check_vendored_sqlx_core.py` checked that both lock files build the vendored copy and that its advisories are reviewed. It never checked the files, so an unrecorded edit to the vendored TLS code would pass CI.

## Change

### Startup refuses verify-ca without a root certificate (item 1)

- **Which settings.** `PRISM_DATABASE_URL` (frontend, `check-config`, the database commands and the public reader) and `PRISM_PEER_DATABASE_URL` / `PRISM_PEER_DATABASE_URL_FALLBACK` (the dual writer). Each is refused by name, with the connect's own message:
  > sslmode=verify-ca requires sslrootcert: verify-ca does not check the server's host name, so it trusts only the root certificates in sslrootcert, never the public roots; set sslrootcert, or use sslmode=verify-full
- **Resolved as the connect resolves them.** The mode and certificate come from SQLx's `PgConnectOptions::from_url`, the parser the connect itself uses, so there is no second parser: the URL's `sslmode` and `sslrootcert` win over `PGSSLMODE` and `PGSSLROOTCERT`. `ssl_root_cert` has no getter, so it is read back through `to_url_lossy()`, as the existing password check already does. An empty `sslrootcert` names no file, so it counts as none. The certificate file is not read here; a missing or unusable file is still the connect's error, as before.
- **Other modes are unchanged:** `verify-full`, `require`, `prefer`, `allow` and `disable`.
- **One more refusal.** `PRISM_DATABASE_URL` is now parsed with the client's parser, as the peer URLs already were. A URL the client can't use (for example `sslmode=sometimes`) is refused at startup, by name, instead of at the first connect.
- **`make doctor` shows it.** `scripts/check-env.sh` relays only known, value-free public-reader errors, so the new refusal showed as a generic image error. It now relays `public PRISM_DATABASE_URL: sslmode=verify-ca requires sslrootcert`.

### CI checks vendored sqlx-core against upstream's `.crate` plus recorded patches (item 2)

- **The recorded changes are patches.** `vendor/sqlx-core.patches/` holds one `diff -u` patch per change, each with a description above it:
  - `0001-sqlx-4251-poll-ready-waits-on-either-direction.patch` (transact-rs/sqlx#4251, #771);
  - `0002-sqlx-3861-verify-ca-accepts-not-valid-for-name-context.patch` (transact-rs/sqlx#3861, #713);
  - `0003-verify-ca-trusts-only-sslrootcert.patch` (the local change, #818).
- **CI rebuilds the tree from upstream and compares.** The step that checks the lock files now downloads `sqlx-core-0.8.6.crate` from static.crates.io, as the alert step downloads promtool. The checker:
  - refuses the `.crate` unless its SHA-256 is the `ee6798b1…68dc6` that `vendor/sqlx-core/README.md` records, and reads it in memory, never extracting it;
  - applies the patches in name order, each hunk only at the line it names and on exact context, with no offset and no fuzz;
  - accepts `\ No newline at end of file` only on a file's last line, so a marker can't join a line onto the next one that review reads as separate;
  - allows free text only before a patch's first file, and refuses anything else outside the hunks;
  - fails unless the result is `vendor/sqlx-core` byte for byte: no file differs, none is missing, none is a symbolic link, and none is added but `README.md` and `reviewed-advisories.toml`. The build reads neither of those: `Cargo.toml` names no `readme` or build script, and no source includes them.
- **A change to a patched file has to change its patch.** The review's edit, `tls_rustls.rs`'s verify-ca store to `let mut cert_store = public_roots();`, now fails. It passes only once a patch records it.
- **Recording a change.** `--unrecorded-diff` prints what the tree changes beyond the recorded patches, as the next patch. The README's "Changing this copy" gives the steps.
- **Two README rules.** The README must record the `.crate`'s SHA-256 exactly once, and it must name every patch file. The second keeps its change list in step with the patches; it checks nothing the README says.
- **Locally, no flag needed.** Without `--upstream-crate`, the script uses Cargo's cached `.crate` if there is one. Without one, it skips the source check and says so.
- **The Python tests use the real crate too.** The `python-tests` job downloads the same `.crate` and names it in `SQLX_CORE_UPSTREAM_CRATE`, so the real-tree tests run in CI. If it is named but missing, they fail rather than skip.
- **The manifest is gone.** I kept the earlier offline premise until review showed it was false: `ci.yml` already downloads promtool. The patch check covers everything `vendor/sqlx-core.sha256` did. The manifest's only extra was working without the `.crate`, which CI now always has. And its upstream/patched/added labels were the part offline CI could not check. Removing it also removes `--write-manifest` and its README gate, which a whitespace edit or a deleted manifest got past.

**What this proves, and what it doesn't.**
- **It proves** that `vendor/sqlx-core` is upstream 0.8.6 plus the recorded patches, byte for byte.
- **It doesn't judge the patches.** A patch that trusted the public roots again would pass, and so would a commit that changed both the code and its patch.
- **The control is review.** Review every change under `vendor/sqlx-core.patches/`, where each change to the vendored code is a diff against upstream. `sqlx_tls_verify_ca.rs` and `sqlx_tls_readiness.rs` check what the three changes do.
- **Two files are unchecked:** edits to the README and to `reviewed-advisories.toml`.

The README says the same.

## Tests run

All local. The Python checks and guards ran again on this head, after merging 3.x.x:

- **Vendored source:** `python3 -m unittest -v tests.test_check_vendored_sqlx_core`: 19 passed. I ran it with `SQLX_CORE_UPSTREAM_CRATE` set to a `.crate` freshly downloaded from static.crates.io, as CI sets it, and again with Cargo's cached copy. With the variable naming a missing file, the two real-tree tests fail. The tests cover:
  - the real tree is 0.8.6 plus the 3 patches: 4 of 100 files patched, README.md and reviewed-advisories.toml added;
  - the review's `public_roots()` edit to the real `tls_rustls.rs` fails, and passes only once its `--unrecorded-diff` is saved as a patch;
  - each of these fails: an edited upstream file, a patched file changed beyond its patch, a removed patch, an added source file, an added `build.rs`, `.cargo-ok`, a missing upstream file, a symbolic link, and a `.crate` other than the README's;
  - each of these patches is refused:
    - a hunk at another line, on other context, or with a `+` start that disagrees;
    - an insertion past a file's end, and a no-newline marker that joins two lines, even when the tree matches what a lenient applier makes of them;
    - a patch that creates a file, or touches a file upstream lacks or one outside the crate;
    - timestamps, two paths, short, long or miscounted hunks, text between hunks, a malformed header, or a hunk before any file;
    - no hunks, a file named twice, no final newline, or no file at all;
    - a stray file, an upper-case name, a symlink or a directory in `vendor/sqlx-core.patches/`;
  - a last line without a newline, on either side, round-trips through `--unrecorded-diff`;
  - edits to the README and to `reviewed-advisories.toml` pass. A README that records two `.crate` SHA-256s fails, and so does one that doesn't name a patch (without the hint to record a patch);
  - a `.crate` whose version is not the vendored `Cargo.toml`'s fails, and the error names the version;
  - without `--upstream-crate`, the script checks against Cargo's cached `.crate`, and skips the source check when there is none;
  - `ci.yml` downloads the `.crate` before the check and the Python shard, and passes it to both.
- **CI's step, run locally as written** (with `RUNNER_TEMP` set): it downloaded the `.crate` (SHA-256 `ee6798b1…68dc6`) and the check passed.
- **check-env:** `python3 -m unittest -v tests.test_check_env_public_credentials`: 13 passed. The new relay test fails without the `check-env.sh` line.
- **Startup, through the real binary** (unchanged by the follow-up commit; run on `d3cb5a92`):
  - `cargo test --locked -p qbit-prism-server --test config_cli --no-fail-fast`: 32 passed.
    - `verify_ca_without_a_root_certificate_fails_before_startup`: 10 cases over the three URL settings, covering `sslrootcert` absent or empty, `PGSSLROOTCERT`, `PGSSLMODE`, verify-full and require.
    - `startup_refuses_verify_ca_with_the_message_the_connect_gives`: startup's error equals `PgConnection::connect`'s, against a fake server that answers the SSLRequest with `S` and then sees no further byte.
  - `cargo test --locked -p qbit-prism-server --test public_database_config --no-fail-fast`: 6 passed, through `check-public-database-config` and `public-api`.
  - `cargo test --locked -p qbit-prism-server --lib config::`: 13 passed.
  - With the check disabled, the new verify-ca tests fail.
  - `cargo fmt --all -- --check` passes. `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings` passes, apart from the three known `mismatched_lifetime_syntaxes` warnings in vendored sqlx-core.
- **Guards:** `check_vendored_sqlx_core.py --upstream-crate <.crate>`, `check_prism_pool_acquires.py`, `check_gate_env_reads.py`, `check_prism_settings.py`, `check_deleted_test_map.py` and `check_toolchain_pin.py` all pass. `bash -n scripts/check-env.sh` passes, and the workflow parses as YAML.

No new PostgreSQL-gated tests, settings or deleted tests.

## CI

- **Correction to this PR's first body.** CI does run `tests/test_check_vendored_sqlx_core.py`: `run_python_test_shard.py` discovers `tests/test_*.py`, and run 41738227640's shard 2 ran all 18 of the earlier tests. Its upstream test was skipped there because no `.crate` was cached. The `python-tests` job now downloads one.
- **What CI runs.** The lint job's vendored-sqlx-core step runs the source check against the downloaded `.crate`. CI's full suites cover the rest of `qbit-prism-server`.

## Known, and out of scope

- **A whitespace-only `sslrootcert`** passes the startup check. The connect still refuses it.
- **Some `tools.rs` commands skip the startup check.** They read the database URLs directly:
  - `fatal-state show` (`tools.rs:902`)
  - `submission-hold show` (`:1142`)
  - `candidates list` (`:1242`)
  - recover planning (`:1410`)
  - node-identity repersonalise's peer URLs (`:971-976`)

  The connect still refuses each with the same message.
- **`policy-transition`** checks the target configuration with the process's own `PG*` environment. It applies only the `PRISM_` and `QBIT_` settings from its `--to` file, and it can't change `PRISM_DATABASE_URL` anyway.

Item 3 (the release notes rewrite) is #832. Items 4 and 5 are not in this PR.

Refs #825

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

Squashed commits:
d3cb5a9 3.x.x: startup refuses sslmode=verify-ca without a root certificate, and CI checks every vendored sqlx-core file against a manifest (#825)
3a7cfc8 3.x.x: CI checks vendored sqlx-core against upstream's .crate plus recorded patches, and doctor relays the verify-ca refusal (#825)
a078cba Merge remote-tracking branch 'origin/3.x.x' into orca/825-release-and-tls-guards
a18fba8 3.x.x: a vendored sqlx-core patch applies only as it reads: no line joined by a no-newline marker, no insertion past the end (#825)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kiwidream added a commit that referenced this pull request Nov 13, 2026
…and CI checks vendored sqlx-core against upstream's .crate plus recorded patches (#825)

## Problem

#825 items 1 and 2, from #818's and #794's reviews:

1. **verify-ca without a root certificate passes startup.** Since #818, sqlx-postgres refuses every `sslmode=verify-ca` connect that has no `sslrootcert` (or `PGSSLROOTCERT`). But nothing at startup checked for it, so a `PRISM_DATABASE_URL` or peer URL like that passed `check-config` and startup, then failed every connect.
2. **Nothing ties `vendor/sqlx-core` to upstream.** `check_vendored_sqlx_core.py` checked that both lock files build the vendored copy and that its advisories are reviewed. It never checked the files, so an unrecorded edit to the vendored TLS code would pass CI.

## Change

### Startup refuses verify-ca without a root certificate (item 1)

- **Which settings.** `PRISM_DATABASE_URL` (frontend, `check-config`, the database commands and the public reader) and `PRISM_PEER_DATABASE_URL` / `PRISM_PEER_DATABASE_URL_FALLBACK` (the dual writer). Each is refused by name, with the connect's own message:
  > sslmode=verify-ca requires sslrootcert: verify-ca does not check the server's host name, so it trusts only the root certificates in sslrootcert, never the public roots; set sslrootcert, or use sslmode=verify-full
- **Resolved as the connect resolves them.** The mode and certificate come from SQLx's `PgConnectOptions::from_url`, the parser the connect itself uses, so there is no second parser: the URL's `sslmode` and `sslrootcert` win over `PGSSLMODE` and `PGSSLROOTCERT`. `ssl_root_cert` has no getter, so it is read back through `to_url_lossy()`, as the existing password check already does. An empty `sslrootcert` names no file, so it counts as none. The certificate file is not read here; a missing or unusable file is still the connect's error, as before.
- **Other modes are unchanged:** `verify-full`, `require`, `prefer`, `allow` and `disable`.
- **One more refusal.** `PRISM_DATABASE_URL` is now parsed with the client's parser, as the peer URLs already were. A URL the client can't use (for example `sslmode=sometimes`) is refused at startup, by name, instead of at the first connect.
- **`make doctor` shows it.** `scripts/check-env.sh` relays only known, value-free public-reader errors, so the new refusal showed as a generic image error. It now relays `public PRISM_DATABASE_URL: sslmode=verify-ca requires sslrootcert`.

### CI checks vendored sqlx-core against upstream's `.crate` plus recorded patches (item 2)

- **The recorded changes are patches.** `vendor/sqlx-core.patches/` holds one `diff -u` patch per change, each with a description above it:
  - `0001-sqlx-4251-poll-ready-waits-on-either-direction.patch` (transact-rs/sqlx#4251, #771);
  - `0002-sqlx-3861-verify-ca-accepts-not-valid-for-name-context.patch` (transact-rs/sqlx#3861, #713);
  - `0003-verify-ca-trusts-only-sslrootcert.patch` (the local change, #818).
- **CI rebuilds the tree from upstream and compares.** The step that checks the lock files now downloads `sqlx-core-0.8.6.crate` from static.crates.io, as the alert step downloads promtool. The checker:
  - refuses the `.crate` unless its SHA-256 is the `ee6798b1…68dc6` that `vendor/sqlx-core/README.md` records, and reads it in memory, never extracting it;
  - applies the patches in name order, each hunk only at the line it names and on exact context, with no offset and no fuzz;
  - accepts `\ No newline at end of file` only on a file's last line, so a marker can't join a line onto the next one that review reads as separate;
  - allows free text only before a patch's first file, and refuses anything else outside the hunks;
  - fails unless the result is `vendor/sqlx-core` byte for byte: no file differs, none is missing, none is a symbolic link, and none is added but `README.md` and `reviewed-advisories.toml`. The build reads neither of those: `Cargo.toml` names no `readme` or build script, and no source includes them.
- **A change to a patched file has to change its patch.** The review's edit, `tls_rustls.rs`'s verify-ca store to `let mut cert_store = public_roots();`, now fails. It passes only once a patch records it.
- **Recording a change.** `--unrecorded-diff` prints what the tree changes beyond the recorded patches, as the next patch. The README's "Changing this copy" gives the steps.
- **Two README rules.** The README must record the `.crate`'s SHA-256 exactly once, and it must name every patch file. The second keeps its change list in step with the patches; it checks nothing the README says.
- **Locally, no flag needed.** Without `--upstream-crate`, the script uses Cargo's cached `.crate` if there is one. Without one, it skips the source check and says so.
- **The Python tests use the real crate too.** The `python-tests` job downloads the same `.crate` and names it in `SQLX_CORE_UPSTREAM_CRATE`, so the real-tree tests run in CI. If it is named but missing, they fail rather than skip. The download carries the same-tree skip's condition (#839), like the job's other steps, so a run that skips the shard skips it too.
- **The manifest is gone.** I kept the earlier offline premise until review showed it was false: `ci.yml` already downloads promtool. The patch check covers everything `vendor/sqlx-core.sha256` did. The manifest's only extra was working without the `.crate`, which CI now always has. And its upstream/patched/added labels were the part offline CI could not check. Removing it also removes `--write-manifest` and its README gate, which a whitespace edit or a deleted manifest got past.

**What this proves, and what it doesn't.**
- **It proves** that `vendor/sqlx-core` is upstream 0.8.6 plus the recorded patches, byte for byte.
- **It doesn't judge the patches.** A patch that trusted the public roots again would pass, and so would a commit that changed both the code and its patch.
- **The control is review.** Review every change under `vendor/sqlx-core.patches/`, where each change to the vendored code is a diff against upstream. `sqlx_tls_verify_ca.rs` and `sqlx_tls_readiness.rs` check what the three changes do.
- **Two files are unchecked:** edits to the README and to `reviewed-advisories.toml`.

The README says the same.

## Tests run

All local. The Python checks and guards ran again on this head, after merging 3.x.x:

- **Vendored source:** `python3 -m unittest -v tests.test_check_vendored_sqlx_core`: 19 passed. I ran it with `SQLX_CORE_UPSTREAM_CRATE` set to a `.crate` freshly downloaded from static.crates.io, as CI sets it, and again with Cargo's cached copy. With the variable naming a missing file, the two real-tree tests fail. The tests cover:
  - the real tree is 0.8.6 plus the 3 patches: 4 of 100 files patched, README.md and reviewed-advisories.toml added;
  - the review's `public_roots()` edit to the real `tls_rustls.rs` fails, and passes only once its `--unrecorded-diff` is saved as a patch;
  - each of these fails: an edited upstream file, a patched file changed beyond its patch, a removed patch, an added source file, an added `build.rs`, `.cargo-ok`, a missing upstream file, a symbolic link, and a `.crate` other than the README's;
  - each of these patches is refused:
    - a hunk at another line, on other context, or with a `+` start that disagrees;
    - an insertion past a file's end, and a no-newline marker that joins two lines, even when the tree matches what a lenient applier makes of them;
    - a patch that creates a file, or touches a file upstream lacks or one outside the crate;
    - timestamps, two paths, short, long or miscounted hunks, text between hunks, a malformed header, or a hunk before any file;
    - no hunks, a file named twice, no final newline, or no file at all;
    - a stray file, an upper-case name, a symlink or a directory in `vendor/sqlx-core.patches/`;
  - a last line without a newline, on either side, round-trips through `--unrecorded-diff`;
  - edits to the README and to `reviewed-advisories.toml` pass. A README that records two `.crate` SHA-256s fails, and so does one that doesn't name a patch (without the hint to record a patch);
  - a `.crate` whose version is not the vendored `Cargo.toml`'s fails, and the error names the version;
  - without `--upstream-crate`, the script checks against Cargo's cached `.crate`, and skips the source check when there is none;
  - `ci.yml` downloads the `.crate` before the check and the Python shard, and passes it to both.
- **CI's step, run locally as written** (with `RUNNER_TEMP` set): it downloaded the `.crate` (SHA-256 `ee6798b1…68dc6`) and the check passed.
- **check-env:** `python3 -m unittest -v tests.test_check_env_public_credentials`: 13 passed. The new relay test fails without the `check-env.sh` line.
- **Startup, through the real binary** (unchanged by the follow-up commit; run on `d3cb5a92`):
  - `cargo test --locked -p qbit-prism-server --test config_cli --no-fail-fast`: 32 passed.
    - `verify_ca_without_a_root_certificate_fails_before_startup`: 10 cases over the three URL settings, covering `sslrootcert` absent or empty, `PGSSLROOTCERT`, `PGSSLMODE`, verify-full and require.
    - `startup_refuses_verify_ca_with_the_message_the_connect_gives`: startup's error equals `PgConnection::connect`'s, against a fake server that answers the SSLRequest with `S` and then sees no further byte.
  - `cargo test --locked -p qbit-prism-server --test public_database_config --no-fail-fast`: 6 passed, through `check-public-database-config` and `public-api`.
  - `cargo test --locked -p qbit-prism-server --lib config::`: 13 passed.
  - With the check disabled, the new verify-ca tests fail.
  - `cargo fmt --all -- --check` passes. `cargo clippy --locked -p qbit-prism-server --all-targets -- -D warnings` passes, apart from the three known `mismatched_lifetime_syntaxes` warnings in vendored sqlx-core.
- **Guards:** `check_vendored_sqlx_core.py --upstream-crate <.crate>`, `check_prism_pool_acquires.py`, `check_gate_env_reads.py`, `check_prism_settings.py`, `check_deleted_test_map.py` and `check_toolchain_pin.py` all pass. `bash -n scripts/check-env.sh` passes, and the workflow parses as YAML.

No new PostgreSQL-gated tests, settings or deleted tests.

## CI

- **Correction to this PR's first body.** CI does run `tests/test_check_vendored_sqlx_core.py`: `run_python_test_shard.py` discovers `tests/test_*.py`, and run 41738227640's shard 2 ran all 18 of the earlier tests. Its upstream test was skipped there because no `.crate` was cached. The `python-tests` job now downloads one.
- **What CI runs.** The lint job's vendored-sqlx-core step runs the source check against the downloaded `.crate`. CI's full suites cover the rest of `qbit-prism-server`.

## Known, and out of scope

- **A whitespace-only `sslrootcert`** passes the startup check. The connect still refuses it.
- **Some `tools.rs` commands skip the startup check.** They read the database URLs directly:
  - `fatal-state show` (`tools.rs:902`)
  - `submission-hold show` (`:1142`)
  - `candidates list` (`:1242`)
  - recover planning (`:1410`)
  - node-identity repersonalise's peer URLs (`:971-976`)

  The connect still refuses each with the same message.
- **`policy-transition`** checks the target configuration with the process's own `PG*` environment. It applies only the `PRISM_` and `QBIT_` settings from its `--to` file, and it can't change `PRISM_DATABASE_URL` anyway.

Item 3 (the release notes rewrite) is #832. Items 4 and 5 are not in this PR.

Refs #825

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

Squashed commits:
af6780d 3.x.x: startup refuses sslmode=verify-ca without a root certificate, and CI checks vendored sqlx-core against upstream's .crate plus recorded patches (#825)
64ee188 Merge remote-tracking branch 'origin/3.x.x' into orca/825-release-and-tls-guards
12b8887 3.x.x: python-tests downloads upstream sqlx-core only in a run that runs the shard (#825)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
djh58 added a commit that referenced this pull request Nov 23, 2026
…ransact-rs/sqlx#4289)

Replaces #919, which was opened against `main`: the test goes to `3.x.x` and reaches `main` with the 3.1.2 promotion.

**This merges after #918, and its new test fails until then.** `3.x.x` does not have the fix yet. #918 brings it, as the merge of `main` (#917). Until #918 lands, "Rust tests" is red here on the two new tests, which is what they are for. Once #918 is in, this branch takes `3.x.x` again and CI is re-run.

## Why

#917 backported [transact-rs/sqlx#4289](transact-rs/sqlx#4289) into the vendored sqlx-core 0.8.6. Its only test is upstream's unit test inside sqlx-core, which CI does not run, so nothing in CI fails if the fix is lost. This adds a regression test that CI runs, next to the ones #4251 and #3861 have.

## The test

`crates/qbit-prism-server/tests/sqlx_pool_num_idle.rs` goes through sqlx's public Postgres pool, the type the server uses, against a local socket that answers only what a pool asks: any startup, and ReadyForQuery for each Sync, which is sqlx's ping. It needs no database and adds no dependency.

It opens the bug's window without a race. The pool's semaphore calls a waiting `acquire()`'s waker from inside `release()`, as it hands over the permit: after the connection is pushed and, in 0.8.6, before `num_idle` is incremented. The tests poll a pending `acquire()` by hand with their own waker, and that waker polls it again where it is called. The waiter then takes the connection at the very point where another worker's acquire could.

- **`a_connection_taken_inside_release_leaves_the_idle_count_at_zero`** reads the pool's idle count at that point. It also checks that the server accepted one connection, so the waiter took the released connection and did not open another.
- **`maintenance_still_reaps_after_a_sweep_during_a_handoff`** holds that window open for three maintenance periods, then leaves a connection idle and expects the maintenance task to close it. The connection is released on a second runtime, so that the hold blocks that runtime's worker and the pool's own runtime keeps its timers.

`vendor/sqlx-core/README.md` names the test file, in the paragraph that lists each change's regression tests.

## Evidence

Run in a scratch crate with this file, sqlx at the repository's features and lock file, and `[patch.crates-io]` pointing at each copy of sqlx-core:

| sqlx-core pool code | idle count inside `release()` | maintenance after the sweep | result |
| --- | --- | --- | --- |
| 0.8.6 as vendored on `3.x.x` today | `18446744073709551615` | the sweep reads `usize::MAX` and never sweeps again; the connection is never closed | both tests fail |
| 0.8.6 ordering, with only #4289's sweep cap | `18446744073709551615` | sweeps on and closes the connection | first fails, second passes |
| with #917's fix | `0` | sweeps on and closes the connection | both pass, 10 runs of 10, 0.8 to 1.0 s |

The second row is the only place the sweep cap is exercised: with the reordering in place the count cannot wrap, so the cap is never reached.

On the unpatched code, a trace of the sweep showed it start with `num_idle=18446744073709551615` and print nothing after. Nothing else on that runtime ran again either: the worker that had been driving its timers and sockets was the one spinning.

Also run: `rustfmt --check` on the file, and `cargo clippy --tests -- -D warnings` in the scratch crate, both clean. On this branch, `python3 scripts/check_vendored_sqlx_core.py --upstream-crate …` passes (upstream 0.8.6 plus the 3 recorded patches, byte for byte) and `tests.test_check_vendored_sqlx_core` passes.

## What this does not cover

- **Not built in this workspace locally.** The host was short of disk, so CI is the first build of the file inside `qbit-prism-server`.
- **When it fails, the second test takes 30 s**, the bound on its wait. A sweep that never ends also keeps one thread of the test binary busy until the binary exits. Both apply to this pull request's CI until #918 lands.
- **The second test's failure depends on timing.** It needs the maintenance task to sweep during a 600 ms hold, at a 200 ms period. A runner stalled for that whole hold would let unfixed code pass it. With the fix it passes whatever the timing, and the first test has no such dependence.
- **The README will conflict with #918's.** Both add text after the same sentence. When this branch takes `3.x.x` after #918, the README's paragraph on the source check also goes back to saying that the regression tests cover every change.

Refs #917, #918, #794.

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

Squashed commits:
4155c9d 3.x.x: a regression test CI runs for the sqlx-core pool num_idle fix (transact-rs/sqlx#4289)
a01a68c Merge 3.x.x into the pool num_idle regression test's branch, now that #918 has landed the fix

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Squashed-from: a01a68c
djh58 added a commit that referenced this pull request Nov 23, 2026
…ransact-rs/sqlx#4289)

Replaces #919, which was opened against `main`: the test goes to `3.x.x` and reaches `main` with the 3.1.2 promotion.

**This merges after #918, and its new test fails until then.** `3.x.x` does not have the fix yet. #918 brings it, as the merge of `main` (#917). Until #918 lands, "Rust tests" is red here on the two new tests, which is what they are for. Once #918 is in, this branch takes `3.x.x` again and CI is re-run.

## Why

#917 backported [transact-rs/sqlx#4289](transact-rs/sqlx#4289) into the vendored sqlx-core 0.8.6. Its only test is upstream's unit test inside sqlx-core, which CI does not run, so nothing in CI fails if the fix is lost. This adds a regression test that CI runs, next to the ones #4251 and #3861 have.

## The test

`crates/qbit-prism-server/tests/sqlx_pool_num_idle.rs` goes through sqlx's public Postgres pool, the type the server uses, against a local socket that answers only what a pool asks: any startup, and ReadyForQuery for each Sync, which is sqlx's ping. It needs no database and adds no dependency.

It opens the bug's window without a race. The pool's semaphore calls a waiting `acquire()`'s waker from inside `release()`, as it hands over the permit: after the connection is pushed and, in 0.8.6, before `num_idle` is incremented. The tests poll a pending `acquire()` by hand with their own waker, and that waker polls it again where it is called. The waiter then takes the connection at the very point where another worker's acquire could.

- **`a_connection_taken_inside_release_leaves_the_idle_count_at_zero`** reads the pool's idle count at that point. It also checks that the server accepted one connection, so the waiter took the released connection and did not open another.
- **`maintenance_still_reaps_after_a_sweep_during_a_handoff`** holds that window open for three maintenance periods, then leaves a connection idle and expects the maintenance task to close it. The connection is released on a second runtime, so that the hold blocks that runtime's worker and the pool's own runtime keeps its timers.

`vendor/sqlx-core/README.md` names the test file, in the paragraph that lists each change's regression tests.

## Evidence

Run in a scratch crate with this file, sqlx at the repository's features and lock file, and `[patch.crates-io]` pointing at each copy of sqlx-core:

| sqlx-core pool code | idle count inside `release()` | maintenance after the sweep | result |
| --- | --- | --- | --- |
| 0.8.6 as vendored on `3.x.x` today | `18446744073709551615` | the sweep reads `usize::MAX` and never sweeps again; the connection is never closed | both tests fail |
| 0.8.6 ordering, with only #4289's sweep cap | `18446744073709551615` | sweeps on and closes the connection | first fails, second passes |
| with #917's fix | `0` | sweeps on and closes the connection | both pass, 10 runs of 10, 0.8 to 1.0 s |

The second row is the only place the sweep cap is exercised: with the reordering in place the count cannot wrap, so the cap is never reached.

On the unpatched code, a trace of the sweep showed it start with `num_idle=18446744073709551615` and print nothing after. Nothing else on that runtime ran again either: the worker that had been driving its timers and sockets was the one spinning.

Also run: `rustfmt --check` on the file, and `cargo clippy --tests -- -D warnings` in the scratch crate, both clean. On this branch, `python3 scripts/check_vendored_sqlx_core.py --upstream-crate …` passes (upstream 0.8.6 plus the 3 recorded patches, byte for byte) and `tests.test_check_vendored_sqlx_core` passes.

## What this does not cover

- **Not built in this workspace locally.** The host was short of disk, so CI is the first build of the file inside `qbit-prism-server`.
- **When it fails, the second test takes 30 s**, the bound on its wait. A sweep that never ends also keeps one thread of the test binary busy until the binary exits. Both apply to this pull request's CI until #918 lands.
- **The second test's failure depends on timing.** It needs the maintenance task to sweep during a 600 ms hold, at a 200 ms period. A runner stalled for that whole hold would let unfixed code pass it. With the fix it passes whatever the timing, and the first test has no such dependence.
- **The README will conflict with #918's.** Both add text after the same sentence. When this branch takes `3.x.x` after #918, the README's paragraph on the source check also goes back to saying that the regression tests cover every change.

Refs #917, #918, #794.

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

Squashed commits:
4155c9d 3.x.x: a regression test CI runs for the sqlx-core pool num_idle fix (transact-rs/sqlx#4289)
a01a68c Merge 3.x.x into the pool num_idle regression test's branch, now that #918 has landed the fix

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Squashed-from: a01a68c
Signed-commit: 6f88fe8
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