Skip to content

verdict: name what a stopped run leaves in a typed standing_run field - #708

Merged
Kiran01bm merged 3 commits into
mainfrom
kiran01bm/pd137-standing-run-typed-field
Dec 4, 2026
Merged

Kiran01bm merged 3 commits into
mainfrom
kiran01bm/pd137-standing-run-typed-field

Conversation

@Kiran01bm

@Kiran01bm Kiran01bm commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

A refusal that meets a stopped copy-and-swap run now carries standing_run, a typed field naming what that run left on the database.

Why

Copy-and-swap changes a table by building a new copy of it (the shadow table) and keeping it in step with the original, through either a replication slot or a write fence (a trigger that blocks writes). A stopped run leaves those behind, and a slot keeps the server's WAL from being recycled until the run finishes or is discarded. pg-sprite described them only in the refusal's sentence, so a tool around migrate --json that wanted to warn "a replication slot is holding WAL" had to parse prose.

What

  • New pkg/verdict/standing_run.go: standing_run has shadow (quoted), hold (slot or write-fence), slot and publication (only under hold: slot), and phase. It is omitted when nothing stands.
  • Filled once in copySwapRunVerdict from the *schemachange.StandingRunError, so every copy-and-swap-refused cause that carries one has it: cutover-schema-drift, cutover-fidelity-drift, copy-conversion-drift, resume-source-changed, resume-slot-held, resume-slot-backlog, and a resume-row-mismatch whose row matches the shadow. migrate --desired gets it through the same function.
  • An unknown hold kind is ErrInvariantViolation, not a guessed value.
  • No version bump. The verdict has no format_version, and the recent lock_holder and partitioned_index_fault additions bumped nothing.
  • The field is what the checkpoint row records, not a catalog reading: a run whose fence was dropped by hand still reads hold: write-fence, and writes_blocked: false says no fence stands.
  • Docs: schemabot-integration.md says the field is the row's record, how a migrate.Run host and a schemachange.Runner host each read it, and which keys match pg-sprite discard --json. The resume-source-changed example in cli-output-examples.md shows the terminal text and the --json with the field. ST-2 and ST-5 in docs/invariants.md name the field and its tests.
  • Tests:
    • Unit tests for the slot and write-fence forms, a recorded fence that no longer stands, and every cause.
    • Two CLI integration tests read the field from a real stopped run's migrate --json.
    • The live cutover-drift test asserts it too.
    • All of these fail without the change.

Before / after

A live retype of orders stopped in verifying; someone then added a column to orders by hand, and the next run is refused.

input: pg-sprite migrate --alter "ALTER TABLE orders ALTER COLUMN qty TYPE bigint" --json

Before
  reason   ──▶ copy-and-swap-refused, cause resume-source-changed
  detail   ──▶ "... the shadow "_pgsprite_..._new", the replication slot
                pgsprite_a725d037 and its publication stand ..."
  a wrapper──▶ must parse this sentence to know a slot holds WAL

After
  reason   ──▶ copy-and-swap-refused, cause resume-source-changed
  detail   ──▶ same sentence
  standing_run ──▶ { "shadow": "\"public\".\"_pgsprite_..._new\"",
                     "hold": "slot", "slot": "pgsprite_a725d037",
                     "publication": "\"pgsprite_a725d037\"",
                     "phase": "verifying" }
  a wrapper──▶ reads hold == "slot" and warns

A wrapper that warns about a standing slot or write fence had to parse
the refusal's detail sentence.
@Kiran01bm
Kiran01bm marked this pull request as ready for review December 3, 2026 02:15
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-03T02:15:55.114131Z
We couldn’t complete this review. Comment @codex review to try again.
4aa0a56 Draft marked ready
ℹ️ 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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@aparajon

aparajon commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

🤖 Review 1/2 (correctness) of 4aa0a56: 0 blocking, 2 non-blocking.

Inspected the whole change at 4aa0a56b4e6f3eec410078b719c85edcec61e0d4: the new type in pkg/verdict/standing_run.go, the one production hook in copySwapRunVerdict and its mapper standingRunField, the library side it reads (schemachange.StandingRunError, withStandingRun and standing_test.go at the same head), the docs, and every new test. CI at the time of posting: 16 checks green, including the PostgreSQL 14 to 17 legs, test (PostgreSQL 18, schemachange), unit tests with the docs guards, lint, build and the smoke test; test (PostgreSQL 18, other packages) failed on its first run (and with it the all-green gate) on a container-reaper failure in a package this PR does not touch (finding 2), and has since been rerun by someone else and is in progress. In that failed run internal/cli, pkg/migrate and pkg/verdict (the three packages this PR changes tests in) all report ok.

The change adds a pointer field standing_run (omitempty) to the verdict and fills it in one place, from the *schemachange.StandingRunError a refusal already carries beside it, so the sentence in detail and the typed field are read from the same value. The mapping is exhaustive on the library's two holds (replication-slot becomes slot, write-fence stays) and an unknown hold is executor.ErrInvariantViolation rather than a guessed token, so a hold added to the library without a mapping fails loudly. The field is additive: absent on every verdict that does not name a stopped run, no existing key changes, and it is documented for hosts in schemabot-integration.md#L653-L674 and in the copy-and-swap-refused rows of both tables. The JSON keys are pinned by TestStandingRunJSONKeys, and two integration tests read the field from a real stopped run's migrate --json.

Invariants (docs/invariants.md): the change upholds ST-5 (the cutover gate's cutover-schema-drift and cutover-fidelity-drift refusal that wraps a StandingRunError, #L1661-L1663) and ST-2's resume guard (resume-source-changed and resume-row-mismatch wrapping one, #L1344-L1348): every refusal still refuses and leaves the same row, shadow and hold, and the new field is read-only output. It touches nothing in RF-7 and RF-8 (the field is not part of the refusal proof). Nothing is weakened or moved.

Non-blocking

  1. standing_run is the checkpoint row's record, not a catalog reading, but the docs' first sentence reads as if it were. schemabot-integration.md#L655-L656 says a wrapper can use the field to warn "that a replication slot retains WAL, or that the source refuses writes". The hold is derived from the row alone (standingRun in standing.go: a row that names a slot is slot, any other row is write-fence), so hold: write-fence is set for a blocked-writes run whose fence was dropped or disabled by hand. That is the holdRowOnly branch (copy_swap.go#L727-L731), where the same verdict carries writes_blocked: false and a detail saying the table takes writes. The docs do say at #L666-L667 that the catalog answer is writes_blocked, not hold, but a host that reads only the first sentence and the field would warn "writes are refused" on a table that takes writes. The slot half has the same shape: the name comes from the row, not from pg_replication_slots, so a slot dropped by hand still reads as hold: slot (the detail makes the same statement today, so this is parity with the prose, not a regression). Move the writes_blocked caveat into the first sentence ("warn that the run recorded a write fence; writes_blocked says whether it stands") and say once that slot and publication are what the row records. Reasoned from the code, not run.

  2. The first run of test (PostgreSQL 18, other packages) failed on a Docker reaper failure in pkg/dbconn, not on this change. The one failing test is TestConnectReplicationAsksForWarningsThroughPgBouncer, which stops creating its pooler network: reaper: from container "203cf8f9": wait for reaper 203cf8f9: unexpected container status "removing", from internal/testutil/pgbouncer.go:85 via pkg/dbconn/replication_integration_test.go:123, 3.15 s in; the leg's other packages, including pkg/migrate and internal/cli, ran and passed. The PR touches nothing under pkg/dbconn or internal/testutil, and the PostgreSQL 14 to 17 legs pass. Nothing for the author to change; the leg is being rerun (not by me), and all-green blocks the merge until it passes.

Verified

  • Read the whole diff against the library side: withStandingRun wraps a StandingRunError for exactly cutover-schema-drift, cutover-fidelity-drift, copy-conversion-drift, resume-slot-held and resume-slot-backlog (TestWithStandingRunNamesWhatAStoppedRunLeaves pins that list), and resume-source-changed and a resume-row-mismatch over the derived shadow wrap one at the row check; the doc's list of six causes plus the conditional resume-row-mismatch matches. resume-slot-foreign and resume-shadow-gone wrap none, so the field is absent, as documented.
  • Walked the control flow in copySwapRunVerdict: the mode-mismatch refusal returns before the new block (it carries no standing run, which matches the docs' exclusions); the new block runs before the cause switch, so resume-source-changed still finds its StandingRunError for its detail, and an unknown hold fails before any detail is built. WritesBlocked and the hold note are set after, unchanged.
  • Additivity: one omitempty pointer, no key renamed or retyped, slot and publication omitted under write-fence (TestStandingRunJSONKeys pins both shapes and the round trip, and TestStandingRunJSONOmittedWithoutAStoppedRun pins absence). The docs-example guard (TestCLIOutputExamplesMatchPipelineOutput, 26 blocks) passed in the green legs.
  • Did not run a test: the CLI and live-drift tests start a PostgreSQL container. The PostgreSQL 14 to 17 and schemachange legs at this head passed them, and the internal/cli and pkg/migrate packages passed in the red leg.
  • Mutation table (by reading; the PR reports its tests fail without the change):
Mutant Caught by
v.StandingRun = field deleted TestCopySwapRunVerdict subtests (slot, write fence, every cause), the two CLI tests, the live drift test, the docs example guard
HoldReplicationSlot mapped to write-fence or the reverse the slot and write-fence subtests and both CLI tests
Publication left unquoted, or Slot quoted TestCopySwapRunVerdict live subtest, TestMigrateJSONNamesTheSlotAStoppedLiveRunLeaves
unknown-hold default branch returns a verdict instead of an error the hold of unknown kind subtest
omitempty dropped from slot or publication TestStandingRunJSONKeys (write-fence case)
Phase.String() replaced by another spelling the CLI tests and the docs example guard ("verifying")

This review was generated by Claude Code (claude-sonnet-5-5).

@aparajon

aparajon commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

🤖 Review 2/2 (OSS adoption and integration) of 4aa0a56: 0 blocking, 4 non-blocking.

Read the change from two seats: a host that wraps pg-sprite migrate --json (or reads the Go verdict) and wants to warn an operator that a stopped run is holding WAL or fencing writes, and a downstream importer that already consumes discard --json and the library's StandingRunError. The field is additive (one omitempty pointer, no existing key touched), it is documented for hosts in the copy-and-swap-refused row and the paragraph after it (schemabot-integration.md#L653-L674), and the doc says honestly that the verdict has no format version, so a host that must tell "no run stands" from "an older binary" records the binary's version. That is the right contract; the findings below are about how well the surface reads next to its neighbors.

Non-blocking

  1. The docs send a Go adapter to errors.As for a verdict that comes with no error. #L659-L661 says the listed refusals are "exactly the refusals that wrap a *schemachange.StandingRunError, from which a Go adapter reads the same facts with errors.As". That holds for a host that drives schemachange.Runner directly. A host that calls migrate.Run gets a refused verdict with a nil error (the copy-and-swap-refused row in the table above it says "The error is nil"), because copySwapRunVerdict consumes the wrapped error and returns the verdict. For that host the typed read is v.StandingRun, and nothing in the paragraph says so. One clause fixes it: "a migrate.Run host reads Verdict.StandingRun; a schemachange.Runner host reads the same facts with errors.As on the returned error".

  2. The field spells the same facts differently from discard --json, which a host reads right after. The next thing an operator does with a standing_run is run pg-sprite discard, and a wrapper will pair the two reports. standing_run.shadow is the quoted, schema-qualified name ("public"."_pgsprite_..._new"), the discard report's shadow is the bare name in the table's schema (discard.go, discardReport); standing_run.publication is quoted, the discard report's publication is bare; the hold is a string token here (slot, write-fence) and a write_fence boolean plus slot/publication names there; and the Go library's own constants are HoldReplicationSlot (replication-slot) and HoldWriteFence, so the same hold has the spelling slot on the verdict and replication-slot on StandingRunError. The doc explains each spelling on its own (and ties phase to row_phase), so nothing is wrong; but a host matching a standing run to its discard report has to unquote on one side. A sentence in the paragraph saying which fields match the discard report as they are (slot, phase) and which differ in quoting (shadow, publication) would save each adopter finding that out. Whether to quote at all is a judgment call: quoting makes DROP TABLE and DROP PUBLICATION copy-ready, which is a fair reason, and the field is new enough to keep it.

  3. The invariants registry names the library error but not the verdict field it now rides on. ST-5 (docs/invariants.md#L1661-L1663) and ST-2's resume guard (#L1344-L1348) both say the refusal wraps a StandingRunError "naming the shadow, the fence or slot and publication, and the checkpoint row it leaves", and cite their enforcing tests. A reader following those entries to learn what a front door can report will not find that the same facts now reach the verdict as standing_run. A short clause on each ("which migrate also carries on the verdict as standing_run") plus the new CLI test names in the enforcing list keeps the registry true to what is checked. The change upholds both entries and needs no wording change to either rule.

  4. The resume-source-changed example in cli-output-examples.md is now JSON only, so the page no longer shows what the operator sees. The section "Refused: the table changed under a stopped copy-and-swap run (resume-source-changed)" switched its block from the text rendering to a --json capture (the docs guard now counts 26 captured outputs), and the new prose around it explains the field. The text form of this refusal, which is what a person at a terminal reads, is gone from the page. Keeping the text block beside the JSON one (the guard only pins blocks that start $ pg-sprite ... --json, so a text block would not disturb it) would show both audiences their form.

What reads well for adopters

  • The PR body's before and after shows the one concrete wrapper change (parse a sentence versus read hold == "slot"), run through the same input, and the docs carry a captured --json example whose bytes the docs guard recomputes, so the example cannot drift from the code.
  • omitempty on slot and publication means a write-fence run names neither, not empty strings, and the key test pins both shapes; a host's if standing_run.slot check is therefore meaningful.
  • An unknown hold is a typed ErrInvariantViolation, not a guessed token, so a library version that adds a hold cannot silently put a wrong string in front of a host.
  • The PR is one new type, one fill site and its docs, with no flag, option or version bump to learn, which is the right size for a field a host adopts by ignoring or reading.

This review was generated by Claude Code (claude-sonnet-5-5).

@aparajon aparajon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 Stamping with comments: 0 blocking, 6 non-blocking (see the review comments above).

This stamp was left by Claude Code (claude-sonnet-5-5).

@JashLal

JashLal commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

🤖 Local review of 4aa0a56b4e6f3eec410078b719c85edcec61e0d4 across all 12 changed files.

P2 — Pin the recorded-fence case without a live fence. The new write-fence integration test covers a live fence. Add a verdict case for holdRowOnly that asserts standing_run.hold remains write-fence and writes_blocked is false. That would make the checkpoint-versus-catalog distinction raised above part of the tested contract. The GitHub rerun of PostgreSQL 18 and the all-green check now pass. Current verdict branch

This was a static review. I did not run tests locally. GitHub reports 18 passing checks on this head. BuilderBot's result was unavailable, and I couldn't verify unresolved inline threads. CI summary

@JashLal JashLal left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 Approved by Codex on Jash behalf after reviewing 4aa0a56. See the review comment for findings and verification limits; approval does not resolve those findings.

A host reading only the field could warn that writes are refused on a
table whose recorded fence was dropped by hand. The docs now lead with
that, say how each kind of host reads the field and how it pairs with
the discard report, and a unit test pins hold write-fence beside
writes_blocked false.
@Kiran01bm

Copy link
Copy Markdown
Collaborator Author

🤖 Adversarial review response — created by Kiran's code review agent (Amp, claude-opus-5-5) — pull/708, follow-up commit

All six findings are fixed in the follow-up commit: the docs now say standing_run is the checkpoint row's record, a unit test pins that record against writes_blocked: false, and the host docs, registry and example page are filled out.

# Finding Status Explanation
C1-F1 The docs' first sentence reads standing_run as a catalog reading, so a host could warn "writes are refused" on a table that takes writes fixed The paragraph now opens with "the run recorded a replication slot … or a write fence", then says the field is what the row records: writes_blocked says whether the fence stands, and a slot or publication dropped by hand is still named.
C3-F1 No test pins a recorded fence with no fence standing (holdRowOnly) fixed New TestCopySwapRunVerdict subtest: a write-fence refusal under holdRowOnly carries hold: write-fence with writes_blocked false.
C2-F1 The docs send a migrate.Run host to errors.As, but its refused verdict comes with a nil error fixed Now says a migrate.Run host reads Verdict.StandingRun and a schemachange.Runner host uses errors.As on the returned error.
C2-F3 ST-2 and ST-5 name StandingRunError but not the verdict field fixed Both entries add "which migrate also carries on the verdict as standing_run", with the two CLI tests (ST-2) and the live cutover-drift test (ST-5).
C2-F2 Field spellings differ from pg-sprite discard --json, which a host reads right after fixed One sentence: slot and phase match the discard report's slot and row_phase; shadow and publication are quoted here and bare there, so a wrapper pairing the two unquotes them. Quoting stays, so DROP TABLE and DROP PUBLICATION take the names as they are.
C2-F4 The resume-source-changed example lost its terminal text form fixed The text block is back above the --json one; the docs guard matches only --json blocks, so its count is unchanged.

No action: C1-F2 (the PostgreSQL 18 leg's container-reaper failure in pkg/dbconn; its rerun and all-green passed), both comments' "Verified" and "What reads well for adopters" sections, and both approvals (6162611533, 6173114047).

Source: block/pg-sprite#708, review comments 7365377275, 7365378468 and 7383600924, and reviews 6162611533 and 6173114047 at head 4aa0a56b; fixes in the follow-up commit

@Kiran01bm
Kiran01bm enabled auto-merge (squash) December 4, 2026 12:26
@Kiran01bm
Kiran01bm merged commit f2a9c41 into main Dec 4, 2026
18 checks passed
@Kiran01bm
Kiran01bm deleted the kiran01bm/pd137-standing-run-typed-field branch December 4, 2026 12:39
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.

3 participants