Skip to content

3.x.x: keep the PostgreSQL CI shards' database on a tmpfs, give their ledgers a 60 s statement timeout, and log slow statements - #677

Merged
RobertClarke merged 8 commits into
3.x.xfrom
ci/pg-contract-statement-timeouts
Oct 5, 2026
Merged

RobertClarke merged 8 commits into
3.x.xfrom
ci/pg-contract-statement-timeouts

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Why

The Rust PRISM PostgreSQL and multi-instance contracts shards keep failing pull requests in tests those PRs did not touch, with canceling statement due to statement timeout.

Failure counts (CI workflow):

The four flakes:

Test Run What timed out
authorization_rpc::authorization_fallback_requires_a_definitive_address_result 37358318061 (#659) the migration's catalog fingerprint query
candidate_window_switch::as_issued_snapshot_preparation_runs_off_the_runtime_on_both_write_paths 37359680165 (#661) and 37359707612 (#663) writing a 300,000-recipient balance snapshot
b275_persistence_measure::persistence_and_exact_rows_precede_three_second_stub_release 37358577355 (#662) a statement during the persistence measurement

What the probe showed. A probe on this branch ran all four shards on 2 vCPU, on 2 vCPU with the data directory on tmpfs, and on 4 vCPU, logging every statement over 1 s:

  • With deliberate lock waits and sleeps excluded, the heaviest statements take 1–4 s on a quiet runner. The fingerprint query takes 1.1–1.9 s.
  • iowait is about 1% and steal under 0.4%.

So the 15 s ledger timeout only breaks when the runner has a slow spell, roughly 5x or worse.

Evidence of a busy host disk in the failing jobs. The two shard-2 failures (authorization_rpc and b275) had the slowest end-of-job disk syncs of all 129 recent shard jobs: 17 s and 10 s, against a 7.4 s maximum for jobs that passed, which had more data to flush. Each shard also writes Cargo's build output (bursts up to 400 MB/s) to the same disk that holds PostgreSQL's WAL.

What

  • tmpfs for the PostgreSQL service's data directory.
    • fsync, full_page_writes and synchronous_commit stay on. The ledger refuses a server without the first two, and the fixtures check all three.
    • A flush no longer waits on the runner's disk.
    • Memory, measured: the container peaks at about 0.8 GB, and the runner never had less than 3.5 GB available. The tmpfs is capped at 4 GB.
  • PRISM_DATABASE_STATEMENT_TIMEOUT_MS=60000 for the ledgers the tests open.
    • The production default stays 15 s.
    • Tests of timeout behaviour already set their own values (audited: SET statement_timeout / set_config in the fixtures, jsonb_ceiling_gate, the cutover rehearsal and migration-lifecycle extra env, and the load harness's explicit 15 s for the frontends it launches).
    • authorization_rpc now passes the variable to its env-cleared child, a re-run of its own test binary.
    • candidate_dispatch_probe restores the configured timeout after its 100 ms check, instead of a literal 15s.
  • Slow-statement and lock-wait logging in the service (log_min_duration_statement=1s, log_lock_waits=on, log_parameter_max_length=64). The runner prints this log when the job ends, so the next statement to go slow names itself.
  • Throughput floor: CI_MIN_SHARES_PER_SEC stays 250, as its comment asks to re-derive when the service changes.
  • Docs: docs/prism-integration-test-gate.md describes the CI database.

The temporary probe workflow that produced these numbers (runs 37366251758 and 37369158766) was removed in d66a8d5, so the squash-merge does not carry it.

Validation

Every CI run of the four PostgreSQL shards with this change:

Run Head Result
37369196133 39b68b2 green
37370812752 cdc8134 green after one rerun of shard 3, which failed on the unrelated settlement-lock flake in qbit-prism-load --test faults (#686)
37375243887 4746766 (empty commit) green
37377221495 18c4235 green
37379268725 40b3561 shards 0, 1 and 3 green; shard 2 failed share_append_throughput_floor at 132 shares/s in a runner stall (the job linked the test binary 2.9x slower than the run before; #683)
37382237266 917d964 green (throughput back to a slowest level of 1,166 shares/s)

Review: two /code-review high passes, with the outcomes in the PR comments (6002459080 and 6003867188), and Codex, which had no findings after the probe was removed.

Follow-ups

Not changed

  • Shard count and runner size. On the tmpfs runs the shards took 14–25 min, against a 45 min cap.
  • Per-binary test concurrency.
  • Production defaults, and every assertion.

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

RobertClarke and others added 2 commits October 5, 2026 15:52
…d I/O

Runs the prism-native-postgres shards on 2 vCPU (as today), on 2 vCPU with
the service's data directory on tmpfs, and on 4 vCPU, and records every
statement over 1 s, auto_explain plans over 3 s, CPU steal and iowait, and
the database's size. Removed before the branch merges.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… ledgers a 60 s statement timeout, and log slow statements

The PostgreSQL shards failed 4 of 19 CI runs on 2026-10-05 with
'canceling statement due to statement timeout' in tests their pull
requests did not touch: a migration's catalog fingerprint
(authorization_rpc) and a 300,000-recipient balance snapshot
(candidate_window_switch), among others. On a quiet 2 vCPU runner those
statements take 1 to 4 s; the failing jobs also had the slowest
end-of-job disk syncs of the last 129 shard jobs, a busy host disk.

- The service's data directory is a tmpfs, so commits no longer wait on
  the runner's disk; fsync, full_page_writes and synchronous_commit stay
  on, as the ledger and the fixtures require.
- The job sets PRISM_DATABASE_STATEMENT_TIMEOUT_MS=60000 for the ledgers
  the tests open; production keeps 15 s. authorization_rpc passes it to
  its env-cleared child.
- The service logs statements over 1 s and lock waits, which the runner
  prints at the end of the job.

The temporary probe workflow now runs the shards under a busy disk, with
the data directory on disk and on tmpfs.

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

chatgpt-codex-connector Bot commented Oct 5, 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-05T22:25:34.885116Z 917d964 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.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 39b68b2b03

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/pg-ci-probe.yml Resolved
- Configure the service's logging in one psql call, and never fail a
  shard over that diagnostics step.
- Say that the tmpfs covers the service only, and that spawned servers and
  operator tools keep the production statement timeout.
- candidate_dispatch_probe restores the timeout the ledger configured
  instead of assuming 15 s.

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

Copy link
Copy Markdown
Member Author

Ran a high-effort code review on this branch. It made eight findings, now handled in cdc8134.

Fixed:

  • The logging set-up is now one docker exec … psql with one -c per setting. It is continue-on-error, so a diagnostics step can never fail a shard.
  • The ci.yml comment and the doc now say the tmpfs covers the service only. The disposable clusters that tests start from PRISM_TEST_PG_BIN_DIR stay on disk.
  • candidate_dispatch_probe used to restore a hard-coded 15s after its 100 ms check. It now reads the configured timeout first and restores that, so it holds whatever CI sets.

Kept, deliberately:

The open follow-ups (children at 15 s if one of them flakes, the disposable clusters on disk, and the 1–2 s planning cost of the migration fingerprint query) will go into a tracking issue.

RobertClarke and others added 3 commits October 5, 2026 17:20
CI_MIN_SHARES_PER_SEC's comment asks for a re-derivation when the
PostgreSQL service changes. In four runs on the tmpfs service, the
slowest level was 1,084, 1,056 and 1,103 shares/s in the
prism-native-postgres job (runs 37369196133, 37370812752 and
37375243887), and 702 in the probe's tmpfs leg, which also loaded
auto_explain. That is the range the disk runs showed, so the floor stays
at 250.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The throughput floor's note claimed the tmpfs runs fell in the disk
runs' range. They don't. The fourth CI run on the tmpfs (37377221495)
had a slowest level of 670 shares/s, and the probe's tmpfs leg 702, both
below the disk calibration's 847. The note now gives all five levels. It
says 250 is about 37% of the slowest, and that it stays rather than
dropping to the rule's 200.

The docs and the ci.yml comment now name the one spawned process that
gets the CI statement timeout: authorization_rpc forwards it to the
re-run of its own test binary.

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

Copy link
Copy Markdown
Member Author

Ran a second high-effort code review, at 18c4235. It made six findings: two are fixed in 40b3561, and four are kept.

Fixed:

  • The throughput floor's note claimed the tmpfs runs fell in the disk runs' range. They don't. Run 37377221495 (this PR, at 18c4235) had a slowest level of 670 shares/s, and the probe's tmpfs leg 702, both below the disk calibration's 847.
    • The note now gives all five tmpfs levels: 1,084, 1,056, 1,103 and 670 in the job, and 702 in the probe.
    • It says 250 is about 37% of the slowest, and that it stays rather than dropping to the 30% rule's 200, since no run has come within 2.5x of it.
  • The docs and the ci.yml comment didn't mention authorization_rpc. They now say it forwards the setting to the re-run of its own test binary, the one spawned process that gets the CI value.

Kept:

  • Spawned servers and tools still run at 15 s. These are signing-transition, policy-transition, candidates recover, the cutover rehearsal's migrate, and the servers in candidate_storm_restart, stratum_restart_bind, fatal_state and public_replica.
  • CI no longer holds in-process statements to the production 15 s.
    • That timeout never measured production: the fixtures' data is tiny next to a production ledger, and on these runners it mostly failed PRs during slow spells.
    • Where a test means to check the default it still does: the cutover rehearsal runs migrate at 15 s, and every spawned server and tool keeps it.
    • The service log names every statement over 1 s, and the follow-ups issue proposes a warning for anything past 15 s that isn't a test-held lock wait.
  • Slow-statement logging could print whole migration scripts into the job log. Measured on this PR's tmpfs runs:
    • the largest service log is 1.8 MB, of which the duration: and lock-wait entries are about 3 KB;
    • the rest is PostgreSQL's default log_min_error_statement, the full text of statements that tests fail on purpose;
    • the runner printed that before this PR too: a pre-PR shard job (run 37358318061) printed a 190 KB service log with 187 STATEMENT lines and no duration: lines.
  • tmpfs exhaustion. Same as the first review.
    • The container peaked at 0.8 GB, data and WAL included.
    • The runner kept at least 3.5 GB available, and it also has 11 GB of swap.
    • The 4 GB cap bounds a runaway, and a PANIC would name ENOSPC in the service log the runner prints.

…issue

Run 37379268725, at 40b3561, failed share_append_throughput_floor at 132
shares/s on the tmpfs service, so the note's "no run has come within
2.5x" no longer held. The runner itself stalled: the same job linked the
test binary 2.5 to 2.9 times slower than the two runs before it, and the
service log shows no slow statement or checkpoint during the
measurement. The disk service had failed the same way five times
between 2026-09-29 and 2026-10-01, once with almost the same levels.
#683 tracks the flake. The floor stays at 250, because a floor low
enough to pass such a stall would miss the collapse it exists for.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant