Skip to content

3.x.x: a go-live gate that checks every self-check fact but legacy audit completeness while import-audits runs (#734) - #736

Merged
RobertClarke merged 3 commits into
3.x.xfrom
RobertClarke/legacy-import-admission-gate
Oct 6, 2026
Merged

RobertClarke merged 3 commits into
3.x.xfrom
RobertClarke/legacy-import-admission-gate

Conversation

@RobertClarke

@RobertClarke RobertClarke commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Why

Nothing on the serving path reads a legacy audit row's canonical bytes: shares, settlement, payouts and readiness never do. So frontends can admit traffic before import-audits finishes storing them. Union's history is about 618 GB of canonical bytes, about 3 h of import.

In production, though, self-check stops at audit completeness, and skips its other checks, until the import is done (#734). That leaves no go-live gate for those hours.

What

scripts/prism_legacy_import_admission_gate.sh checks every other fact self-check checks (self_check() and self_check_local() in tools.rs). Run it on each frontend host with that frontend's environment.

self-check fact The gate
Config::from_env, the pool fee settling dust (#525), block-submission warnings qbit-prism-server check-config, which runs all three plus every settings loader
live-instance census (fails only on a failed read; warns when HA is unknown or fewer than 2 are live) the same read, classified live/stale/inactive/unknown as live_instances() does, with the same warnings
submission hold (report only) submission-hold show (report only)
audit completeness (0/0 in production) legacy rows without bytes reported as pending, together with whether an import-audits session is visible; an incomplete native row (no bytes, and no object body or no snapshot) fails
carry-forward integrity: mismatch and drift both 0 qbit_carry_forward_integrity_report()
durability: fsync, full_page_writes, synchronous_commit not off the same pg_settings read
offer standby (#529), on when the name is set and PRISM_OFFER_STANDBY_FLUSH_WAIT_MS ≠ 0: role readable, exactly one standby, flushing the same rule, and the same pg_stat_replication read
healthcheck(), plus the tool coordinator's start and refresh_once() qbit-prism-server healthcheck, the same function. It passes only once the serving frontend has passed the same startup gates and published work on the observed tip
highdiff floor probe, on for a nonblank PRISM_STRATUM_HIGHDIFF_PORT the same rule, and the same username fallbacks; subscribe and authorize; within 15 s, the first set_difficulty must be a positive finite number ≥ PRISM_STRATUM_HIGHDIFF_MIN_DIFF

Every query runs read-only. psql gets the database URL without its password, which it reads from PGPASSWORD, so no credential appears in a command line or in the output. The script exits 0 only when every check passes.

The migration guide gains a paragraph on the gate. It also notes that, until a legacy row is imported, /public/v1/artifacts/<sha> answers 500 for an audit whose 2.x body can't be read on that host (#735), and the block's audit view answers 404.

Tests

tests/test_prism_legacy_import_admission_gate.py joins CI's Python shards through discovery.

  • 22 hermetic tests, using a fake qbit-prism-server and a fake psql that logs its command line:
    • every pass and fail path, including a failed query for each read;
    • legacy rows reported as pending, and the import-session report;
    • the HA warnings;
    • a zero flush wait turning the standby check off, and a bind without a port leaving highdiff off;
    • each username fallback;
    • the password absent from every psql command line and present in PGPASSWORD, and the token absent from the output;
    • the probe against a fake Stratum listener: the floor, refused difficulties and errors, and its 15 s deadline.
  • A gated real-schema test, which runs when PRISM_TEST_DATABASE_URL and PRISM_ADMISSION_GATE_SERVER_BIN are set:
    • it migrates a fresh database with qbit-prism-server migrate, inserts heartbeats and legacy and native audit rows, and runs the gate with the real psql;
    • it expects a PASS with 2 legacy rows pending (and the census and import-session reports), then a FAIL on 2 incomplete native rows;
    • it passed locally against PostgreSQL 16.
  • ShellCheck and bash -n are clean.

Refs #734, #735

🤖 Generated with Claude Code

…dit completeness while import-audits runs (#734)

Nothing on the serving path reads a legacy row's canonical bytes, so a
frontend can admit traffic before import-audits finishes storing them. In
production, though, self-check stops at audit completeness and skips its
other checks until the import is done (#734). That leaves no go-live gate
for the hours the import takes.

scripts/prism_legacy_import_admission_gate.sh checks every other fact
self-check checks, from the frontend's own environment on each host:
- check-config: the configuration, the pool fee settling dust and the
  block-submission warnings;
- the heartbeat census, and the submission hold, which is reported only;
- carry-forward integrity, durability and the offer standby, with
  self-check's own SQL;
- the frontend's healthcheck, which also stands for self-check's
  one-shot refresh;
- the highdiff floor probe.
It reports legacy rows without stored bytes as pending, and fails on a
native audit that self-check would count as incomplete. Every query runs
read-only, and it never prints the DSN or the token.

The tests run the script with a fake qbit-prism-server and a fake psql,
covering every pass and fail path, the highdiff probe against a fake
listener, and the DSN and token staying out of the output. A gated test
migrates a fresh database with qbit-prism-server and runs the gate's SQL
against it with the real psql. The migration guide notes the gate, and
the 500 that /public/v1/artifacts/<sha> gives for rows not yet imported
(#735).

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

chatgpt-codex-connector Bot commented Oct 6, 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-06T21:42:32.172682Z 1c569d0 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: ecdb9b5013

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

…and keep the database password off command lines

Review found that the first version of the gate disagreed with self-check
in several places:
- It probed highdiff when only PRISM_STRATUM_HIGHDIFF_BIND was set, but
  StratumConfig::highdiff_config() turns highdiff on only for a nonblank
  port.
- It checked the offer standby whenever the application name was set,
  but config::offer_standby() turns the wait off when
  PRISM_OFFER_STANDBY_FLUSH_WAIT_MS is 0, and trims the name.
- It looked up the probe's username under the wrong variable names.
  self-check uses PRISM_USERNAME_FALLBACK_ADDRESS (or the built-in
  test-network address), then PRISM_POOL_FEE_ADDRESS.
- Its probe had no overall deadline, and it accepted difficulties and
  errors that probe_first_difficulty refuses.
- psql received the full database URL, password included, on its
  command line.

The gate now follows each of those rules. psql gets the URL without its
password, and reads the password from PGPASSWORD. The probe gives up
after 15 s in total, and refuses a difficulty that is not a positive
finite number, as well as any non-null error. The census classifies
heartbeats as live_instances() does, and prints self-check's HA warnings.
While legacy rows are pending, the gate reports whether an import-audits
session can be seen, and warns when none can.

The tests cover each change:
- the password is absent from every psql command line and present in
  PGPASSWORD;
- a zero flush wait, and a bind without a port;
- each username fallback;
- the probe's refusals and its deadline;
- the HA warnings, and the import session.
The gated test also checks the census against heartbeats in a migrated
schema.

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

@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: 6bb2798337

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

…s the probe's username and bind verbatim as self-check does

Bash reads a number with a leading zero as octal. So a valid
PRISM_HEALTH_REFRESH_SECONDS such as 08 or 09, which Rust parses as
decimal, aborted the gate before it printed a verdict. It's now read
in base 10.

self-check reads PRISM_SELF_CHECK_ADDRESS, PRISM_USERNAME_FALLBACK_ADDRESS
and PRISM_POOL_FEE_ADDRESS through config::optional. A blank value counts
as unset, and a set value is used verbatim. It reads
PRISM_STRATUM_BIND through config::value, where only an unset variable
takes the default. The gate trimmed these values, so it could authorize
an address that self-check sends padded and the listener refuses. It now
passes them through unchanged.

The tests cover a refresh interval of 09, a padded probe address and
blank addresses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@RobertClarke
RobertClarke merged commit 25eac8d into 3.x.x Oct 6, 2026
40 checks passed
@RobertClarke
RobertClarke deleted the RobertClarke/legacy-import-admission-gate branch October 6, 2026 22:36
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]>
kiwidream added a commit that referenced this pull request Oct 28, 2026
…s is in progress (#734) (#808)

In production, self-check returned at audit completeness before its local
checks, so for the ~3 h of a union-scale import-audits it reported nothing
else and could not gate a deployment. #736's admission gate script was the
workaround.

- self-check runs every local check before the completeness verdict, so the
  report is always complete. A production refusal is returned after them, as
  #525's pool-fee refusal is. When the local checks fail too, their error is
  printed on its own ERROR line, so neither failure hides the other.
- audit_completeness() also counts the missing rows by kind, in the same
  snapshot: pending_legacy_rows (no bytes and no share snapshot, the rows the
  importer selects) and incomplete_native_rows (a snapshot reference, but no
  metadata body or no snapshot row; no import repairs these). Together they
  make up missing_canonical_bytes. import-audits prints both.
- self-check's audit_completeness gains a status. It is complete when nothing
  is missing. It is legacy_import_pending only when the operator declares the
  import for that run with PRISM_SELF_CHECK_LEGACY_IMPORT_PENDING=1 and no
  native row is incomplete; the rows are then reported, with a WARNING, and
  are not a failure. Otherwise it is incomplete, and production fails as
  before: on native rows first, since import-audits doesn't repair them, and
  otherwise on the legacy rows, with a hint naming the declaration. An
  unreadable count stays null and fails. An unparsable declaration fails
  before anything is read.
- The setting is read only by self-check, once. It is not part of the
  frontend Config, because it applies to one run and a frontend never needs
  it. It is in native-settings.txt, and `make prism-self-check` passes it into
  the container with `exec -e` only when it is set.
- Docs: docs/prism-rust-migration.md (the #734 paragraph and the rehearsal
  row), the crate README, the deleted-test map, and the admission gate
  script's header, which still serves builds through 3.1.0.

Tests (PostgreSQL-gated, new ones listed in test/prism-gated-tests.txt):
- tests/audit_completeness.rs:
  - self_check_runs_every_local_check_while_a_legacy_import_is_pending:
    production self-check against the fake node, with a pending legacy row.
    Declared, the status is legacy_import_pending. Undeclared, it fails on
    the audits. Both report health, carry-forward integrity and durability,
    and reach the readiness probe of a frontend the test doesn't run.
  - self_check_reports_missing_audits_before_rpc_and_enforces_production now
    runs lab and production, each declared and undeclared. An undeclared
    pending import still fails production. Every case reaches the local
    checks (the RPC failure). An unparsable declaration fails.
  - self_check_fails_on_an_incomplete_native_row_even_with_a_declared_import:
    a native row lacking its body, beside a pending legacy row, fails
    production either way.
  - The counts test checks the legacy/native split and its sum.
- The exact-JSON assertions in self_check_cli.rs, cutover_rehearsal.rs,
  live_migration_lifecycle.rs and import_audits_settlement_lock.rs include
  the new fields.
- tests/test_makefile_lifecycle.py: the make target passes the declaration
  only when it is set.

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