Skip to content

3.x.x: let the import admission gate run its integrity report on a hot standby, or skip it, under statement and lock timeouts (#738) - #740

Merged
RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/gate-integrity-off-primary
Oct 7, 2026
Merged

RobertClarke merged 2 commits into
3.x.xfrom
RobertClarke/gate-integrity-off-primary

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Summary

Check 5 of scripts/prism_legacy_import_admission_gate.sh (#736) ran qbit_carry_forward_integrity_report() on the writer, with no statement timeout. At production size the report takes about a minute (57–65 s on a 65.99M-share ledger). A snapshot held that long on a primary with live miners bloats the cluster row every share updates, and slows the share append's ORDER_LOCK (#738). So the gate has the same "below about 200 shares/s" limit as self-check. This PR lets the report run elsewhere, and bounds every query.

Running the report on a standby: PRISM_INTEGRITY_REPORT_DATABASE_URL runs check 5 on a hot standby. The gate refuses the URL when the standby:

  • is not in recovery;
  • is not a replica of this writer's database on its timeline: pg_control_system().system_identifier and current_database() are compared on both connections. The writer's timeline, from pg_walfile_name(pg_current_wal_lsn()), must equal the standby's: its WAL receiver's received_tli when the role may read it, else its last restartpoint's (Codex P1);
  • has hot_standby_feedback on, so its report would hold back the writer anyway;
  • serves a writer that waits for standby apply (synchronous_commit = remote_apply with synchronous standbys), where a pause stalls every commit;
  • is stale: its last replayed transaction is older than PRISM_INTEGRITY_REPORT_MAX_AGE_SECONDS (default 300). The live frontends' heartbeats keep the writer committing. The age is clamped at 0 against clock skew. WAL positions are recorded but never used to call a standby fresh: across timelines they aren't comparable.

It records both WAL positions, and warns unless pg_get_wal_replay_pause_state() is paused, or both max_standby_streaming_delay and max_standby_archive_delay are -1. A blank URL counts as unset. An unusable max age exits 2, like an unusable URL.

Skipping: PRISM_GATE_INTEGRITY=skip skips check 5 with a WARN and says so on the final line. It also says when a configured standby URL is therefore unused. Any other value fails.

Timeouts (the gate's own; the frontends' 15 s PRISM_DATABASE_STATEMENT_TIMEOUT_MS is too short for the report, #737):

  • every query: statement_timeout 15 s and lock_timeout 5 s (self-check bounds its completeness sample at 5 s);
  • the report: 120 s on the writer, 600 s on a standby.
  • A failed check names a statement timeout, a lock timeout or a recovery conflict. It never echoes psql's stderr, which can name the host.

Credentials: the standby's password reaches psql through a subshell's environment, never argv. A standby URL without a password doesn't borrow the writer's.

Docs: docs/prism-rust-migration.md gives the same guidance as the script header.

CI: the Python shards already discover the hermetic tests. The real-schema tests, which never ran in CI, now run in PostgreSQL shard 3, and there PRISM_TEST_REQUIRE_INTEGRATION=1 turns a missing input into a failure instead of a skip. That's how the recovery probe's CASE WHEN pg_is_in_recovery() guard against pg_get_wal_replay_pause_state() gets exercised on a real primary.

Tooling only: no runtime code and no repin. The pinned gate changes sha256 (from e1e1caee…), so the runbooks must pin the new bytes after merge.

Review

Two /code-review high passes before pushing. They found 20 items; 18 are fixed here:

  • the feedback, identity, staleness, remote_apply and pause-state checks;
  • the timeouts, the blank URL and the max-age validation;
  • the CI coverage and require-integration;
  • the comments.

Declined:

Codex: the P1 on lineage (a divergent-timeline standby) is fixed in 42d34367.

Testing

  • python3 -m unittest tests.test_prism_legacy_import_admission_gate: 35 hermetic tests pass. New ones cover:
    • the standby route, with credentials kept out of argv;
    • unfit standbys: a primary, another cluster or database, another timeline, feedback on, stale, nothing replayed, remote_apply;
    • a blank URL, and max-age validation;
    • the pause states and the -1 delays;
    • skip, and skip with an unused URL;
    • the per-query timeouts;
    • named cancellation causes, with no host leak.
  • Real-schema tests on PostgreSQL 16.10: a private cluster and a database qbit-prism-server migrate created: 2/2 pass, including a primary refused as the integrity standby.
  • A divergent timeline on real clusters: a primary with two standbys; promote one to be the writer (timeline 2) and point the gate at the other (still on timeline 1). The gate fails with "the integrity standby is on timeline 00000001 but the writer is on 00000002".
  • End to end against a real streaming hot standby (PG 16.10), with the gate pointed at the standby:
    • replay running: the INFO with both LSNs, a WARN, and PASS on the standby;
    • pg_wal_replay_pause(): no WARN, PASS;
    • hot_standby_feedback = on: FAIL.
  • bash -n. ShellCheck isn't available on this host.

🤖 Generated with Claude Code

…t standby, or skip it, under statement and lock timeouts (#738)

The gate's check 5 ran qbit_carry_forward_integrity_report() on the
writer with no statement timeout. At production size the report takes
about a minute, and a snapshot held that long on a primary with live
miners piles up dead versions of the cluster row every share updates,
which slows the share append's lock (#738).

PRISM_INTEGRITY_REPORT_DATABASE_URL now runs the report on a hot standby
instead. The gate refuses that URL when it is not in recovery, is not a
replica of this writer's database (system identifier and database name),
has hot_standby_feedback on, replicates a writer that waits for apply,
or is stale: behind the writer and its last replayed transaction older
than PRISM_INTEGRITY_REPORT_MAX_AGE_SECONDS (default 300). It records
both WAL positions and warns unless replay is paused or both conflict
delays are -1. PRISM_GATE_INTEGRITY=skip skips the check with a WARN.

Every query now runs with a 15 s statement timeout and a 5 s lock
timeout. The report gets 120 s on the writer and 600 s on a standby. A
failed check names a statement timeout, lock timeout or recovery
conflict without echoing psql's stderr, which can name the host. The
standby's credential reaches psql through a subshell's environment, and
a blank URL counts as unset.

The Python shards already ran the gate's hermetic tests. Its real-schema
tests now run in PostgreSQL shard 3, where a missing input fails them as
it fails the gated Rust tests.

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

chatgpt-codex-connector Bot commented Oct 7, 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-07T15:50:56.276832Z 42d3436 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.

@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: 427bf7c5cd

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

…caught-up shortcut (Codex on #740)

After a failover a standby left on the old timeline keeps the writer's
system identifier and database name, and its replay position can even
compare as ahead of the new writer's. So positions are no longer used
to call a standby fresh. The last replayed transaction's age always
applies, since the live frontends' heartbeats keep the writer
committing. The standby's timeline, from its WAL receiver when this
role may read it and otherwise from its last restartpoint, must equal
the writer's, taken from its current WAL file name.

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

Copy link
Copy Markdown
Member Author

@codex review

@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: 42d3436733

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

@RobertClarke
RobertClarke merged commit 5d677a3 into 3.x.x Oct 7, 2026
39 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/gate-integrity-off-primary branch October 7, 2026 16:05
RobertClarke added a commit that referenced this pull request Oct 8, 2026
Set VERSION and [workspace.package].version to 3.0.0-rc.5: rc.4 plus
#737's fixes in #742 (fatal-state clear accepts a tip that only grew,
takes --timeout-seconds, and runs the integrity report under its own
statement timeout) and #744 (migration 026: the report computes each
set once); the deferred share-hash backfill in #743 and #746 (migrate
--defer-share-hashes, then the throttled backfill-share-hashes after
go-live); #745 (migrate --offline-indexes, which composes with
--defer-share-hashes); the cutover tooling merged after rc.4's tag
(#728, #732, #736, #740); and #747, a test-only fix for #724. Both
Cargo.lock files move only their workspace-member entries.

doc/release-notes-3.0.0-rc.5.md, dated 2026-10-08, covers:
- the changes, with the report's estimated 57 to 29 s since 026, the
  migrate --defer-share-hashes command measured on the pair at
  5 min 06 s (539d6c9, before #745), backfill-share-hashes' throttle,
  record of 2 and safe rerun, the evidence scripts' changes, and the
  offline index builds' estimated gain;
- upgrading: migrate is needed again (a binary-only upgrade refuses
  "missing migration(s) 26", and this export refuses a database without
  026), the cutover's migrate step with both flags, and finishing the
  backfill after go-live under #738's snapshot rule, with self-check
  only at low share rates. Rolling back to rc.4 at fence 2 goes only by
  finishing the backfill first or from the pre-migrate backup or
  physical copy, and each rc.4 refusal is quoted where it applies: a
  start meets the cursor first and says to run migrate, which rc.4's
  migrate refuses. The rules still in force: #737's statement timeout
  for rc.4's tools, 026 or not, #738's snapshot rule, and fatal-state
  clear --timeout-seconds, whose bound ends before the commit;
- the same evidence set as rc.4's, with each PR's merge SHA, the pair's
  serving evidence carried, and the rehearsal's full measurements left
  to the cutover's go/no-go record;
- the known issues: rc.4's, minus #737's F1, F2, F4 and F5, plus
  #737's open part, #738 (its fix planned for rc.6), #739, #741, #731
  and #734, with #582 closed and #712 and #724 updated.

docs/prism-rust-migration.md now says how earlier candidates refuse a
database at fence 2: a start with the backfill's own refusal, whose
advice to run migrate holds only for this release, and their migrate,
or a start with PRISM_POSTGRES_INIT_SCHEMA=1, with the fence. The
development-line notes name 3.0.0-rc.5, and they and the 3.0.0 notes
link all five candidates' notes.

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