Skip to content

feat(migrations): add atomic checkpoint storage operator - #63

Closed
seonghobae wants to merge 30 commits into
agent/checkpoint-audit-trailfrom
agent/checkpoint-migration-operator
Closed

feat(migrations): add atomic checkpoint storage operator#63
seonghobae wants to merge 30 commits into
agent/checkpoint-audit-trailfrom
agent/checkpoint-migration-operator

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Commercial and acquisition gap

Durable checkpoint and accepted-save audit migrations exist, but existing PostgreSQL volumes had no package-owned operator command that validates both canonical files before database access, serializes concurrent invocations, applies migration 0007 before 0008 in one transaction, rolls both back on failure, and emits bounded machine-readable identity evidence.

Implemented bounded vertical slice

  • adds the explicit opt-in init-checkpoint-storage CLI and public apply_checkpoint_schema_migrations() coordinator;
  • preserves backward-compatible init-db, apply_result_checkpoint_schema(), and apply_result_checkpoint_audit_schema() behavior;
  • bounded-reads each canonical migration with at most 1 MiB plus one oversize-detection byte, rejects empty/oversized/non-UTF-8 inputs, and loads both files before psycopg validation or database connection;
  • identifies only configured 0007_result_stream_checkpoints and 0008_result_checkpoint_audit_events bytes through immutable migration ID, positive bounded byte count, and lowercase SHA-256 descriptors;
  • obtains one fixed two-key transaction-level pg_advisory_xact_lock, executes migration 0007 before 0008 in one PostgreSQL transaction, and issues one explicit commit only after both statements succeed;
  • propagates failure before success output, allowing PostgreSQL to roll back migration 0007 when migration 0008 fails and to release the transaction-level advisory lock automatically;
  • emits one canonical JSON success object containing only schema version, migration IDs, byte counts, and SHA-256 values, excluding DSNs, credentials, SQL bodies, tenants, checkpoint values, provider payloads, audit rows, and raw database errors;
  • proves live PostgreSQL all-or-nothing behavior and observable concurrent waiting on the reviewed advisory lock;
  • makes every required CI job checkout ${{ github.event.pull_request.head.sha || github.sha }} with persist-credentials: false and immediately verify git rev-parse HEAD, preventing required evidence from silently running only on GitHub's synthetic merge ref;
  • retains one permanent read-only-repository live PostgreSQL job for accepted-save audit and migration rollback/serialization verification;
  • updates README, AGENTS, CLAUDE, ARCHITECTURE, CHANGELOG, ADR 0010, operator guidance, doctoring, design, and implementation-plan contracts; and
  • records APA 7 references to NIST SP 800-53 Rev. 5 CM-3/CM-3(2) and PostgreSQL 18 advisory-lock, transaction, and rollback documentation.

SHA-256 is documented only as deterministic byte-identification evidence, not a signature, authenticated provenance statement, remote attestation, publication authority, or release approval. Advisory locking coordinates cooperating package operators only; it is not authorization and does not constrain administrators or unrelated SQL clients.

No temporary or write-capable repair workflow, competing branch writer, generated coverage database, cache, build artifact, migration ledger, downgrade, destructive retained-evidence rollback, version bump, package publication, attestation, OIDC grant, or release is included.

Strict RED → GREEN → refactor evidence

  • Exact stacked base: 2820aa36d8dedf7d89d1b745e5728acf3b913d2b on agent/checkpoint-audit-trail.
  • Public API RED: head 9aedff7a50270a81cd245771dbe7f649a31fe66f; CI 31149845743, Python 3.10 job 92777048403, failed collection because CheckpointSchemaMigration and the coordinator did not exist.
  • Unit GREEN: head c2de384dd5a42a026f1c49d9eeec92c5bff3217f passed the new unit contract before subsequent test-first hardening. It is retained as development evidence only, not final merge evidence.
  • Bounded-read test-first head: 049e6aab513494b114fddfe2e0679dc1ff19e921 introduced the regression that forbids Path.read_bytes() and negative-size reads. Its workflow was superseded before completion and is not counted as an executed pass or failure.
  • Live-workflow test-first head: 6a7ac0125ea67ee60b88d41d3a6a9d56cf8cef75 required both live integration suites. Its workflow was superseded before completion and is not counted as an executed pass or failure.
  • Exact-head CI RED: head 2cb3607a7b9c696c58fa0df72743cd3667822685; CI 31152186361, quality job 92783956312, passed 423 tests then failed the new workflow contract because the required jobs still checked out the pull-request merge ref rather than the exact source head.
  • Exact-head CI GREEN: predecessor head 25e8e493695c227e4510647305574025c0ec58eb; CI 31152516949 proved the exact-head checkout repair across all required jobs before authoritative doctoring was finalized.
  • Current exact head: c213fc549dbf024da43b459df29c0616cd741c96.

Current exact-head evidence

  • Base SHA: 2820aa36d8dedf7d89d1b745e5728acf3b913d2b.
  • CI 31152717191: success on exact head c213fc549dbf024da43b459df29c0616cd741c96. Every required job's exact-source checkout assertion succeeded.
  • Unit matrix: Python 3.10, 3.12, and 3.14 succeeded on the exact head.
  • Quality job 92785563106: success with 658 passed and 8 deselected, Ruff success, 100% public docstrings, 100% production statement coverage, and 100% production branch coverage: 2,514 statements, 628 branches, 0 missed. Lock freshness and wheel/source-distribution build also succeeded.
  • Live PostgreSQL integration: success, including accepted-save audit verification, invalid-second-migration rollback, and concurrent transaction-level advisory-lock waiting/release.
  • Container gate: Compose validation, component image build, and bundled PostgreSQL image build succeeded.
  • Release Acceptance 31152717233, job 92785563352: success on the exact head, with exact-head checkout and reproducible wheel/source-distribution identity verification. This is acceptance evidence only and grants no versioning or publication authority.
  • CodeRabbit commit status: success on the exact head. A review command was rate-limited, but its completed read-only exact-range analysis reported no actionable issue and no generated-artifact or whitespace defect. Rate-limited output and automated status are not independent approval.
  • Unresolved inline review threads: zero at the time of this description update.
  • Formal qualifying independent non-author APPROVED review: absent.
  • OpenCode/Noema received one exact-head review-only request with branch writes, repair workflows, ready-state changes, and merge explicitly prohibited. Their response is not assumed or counted until submitted on the exact head.
  • Branch-protection, organization ruleset, code-scanning, dependency, secret-scanning, and other required-gate surfaces not exposed by the connector are treated as unproven rather than green.
  • No queued, pending, cancelled, skipped-required, absent, stale-head, stale-base, predecessor-head, or synthetic-merge-only result is counted as success.

Dependency and merge boundary

Required order remains:

.github#790 -> pg-llm-batch#53 -> #55 -> #56 -> #57 -> #58 -> #59 -> #60 -> #61 -> #62 -> this PR.

This PR remains intentionally draft. It must not be marked ready or merged until every prerequisite integrates into main, the branch is reconciled onto the actual integrated base without losing predecessor fixes, and fresh integrated exact-head/exact-base quality, branch, docstring, security, dependency, migration, rollback, concurrency, packaging, container, provenance, supply-chain, release-acceptance, branch-protection, and independent-review gates succeed. Unresolved valid findings must be zero and a qualifying independent non-author GitHub APPROVED review is mandatory. Stacked-base and synthetic merge-result evidence is not reusable as final integrated release evidence.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4bcc149f-c0f3-430c-91a8-6221e362d37f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

Review exact source head c213fc549dbf024da43b459df29c0616cd741c96 against exact stacked base 2820aa36d8dedf7d89d1b745e5728acf3b913d2b. Focus on bounded migration reads, load-before-connect behavior, advisory-lock key and transaction semantics, SQL ordering and rollback, body-free CLI evidence, live concurrency determinism, exact-head CI checkout, compatibility, documentation claims, and generated-artifact hygiene. This is review-only; do not mutate the branch, create a repair workflow, mark ready, or merge.

@seonghobae seonghobae left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@opencode-agent @cwl-noema-review

Review-only request for exact source head c213fc549dbf024da43b459df29c0616cd741c96 against exact stacked base 2820aa36d8dedf7d89d1b745e5728acf3b913d2b. Independently verify bounded SQL reads, load-before-connect behavior, fixed transaction-level advisory-lock semantics, exact 0007→0008 order, one-commit/all-or-nothing behavior, live rollback and concurrency determinism, canonical body-free CLI evidence, exact-head CI checkout, standalone/MSA compatibility, documentation claims, and generated-artifact hygiene. Do not mutate the branch, create a repair workflow, mark ready, or merge. Treat the draft stack and missing qualifying independent approval as merge blockers.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

base='2820aa36d8dedf7d89d1b745e5728acf3b913d2b'
head='c213fc549dbf024da43b459df29c0616cd741c96'

git cat-file -e "${base}^{commit}"
git cat-file -e "${head}^{commit}"

printf '%s\n' '=== merge-base ==='
git merge-base "$base" "$head"
printf '%s\n' '=== exact commits ==='
git show -s --format='%H%n%P%n%s' "$base"
git show -s --format='%H%n%P%n%s' "$head"

printf '%s\n' '=== changed files ==='
git diff --name-status "$base" "$head"

printf '%s\n' '=== changed file statistics ==='
git diff --stat "$base" "$head"

printf '%s\n' '=== candidate paths ==='
git diff --name-only "$base" "$head" |
  rg -i '(checkpoint|migration|init|cli|workflow|action|readme|agents|claude|adr|architecture|operator|doctor|changelog|test|sql|toml|yaml|yml)$' || true

Length of output: 3575


🏁 Script executed:

#!/bin/bash
set -euo pipefail

base='2820aa36d8dedf7d89d1b745e5728acf3b913d2b'
head='c213fc549dbf024da43b459df29c0616cd741c96'

printf '%s\n' '=== implementation outline ==='
ast-grep outline pg_llm_batch/checkpoint_migrations.py --items all
ast-grep outline pg_llm_batch/cli.py --items all
ast-grep outline pg_llm_batch/__init__.py --items all

printf '%s\n' '=== implementation and public API diff ==='
git diff --unified=80 "$base" "$head" -- \
  pg_llm_batch/checkpoint_migrations.py \
  pg_llm_batch/cli.py \
  pg_llm_batch/__init__.py

printf '%s\n' '=== SQL and database helper candidates ==='
fd -t f -E .git | rg '(^|/)(0*00[78].*\.sql|.*migration.*\.sql|.*bootstrap.*\.py|.*database.*\.py|.*db.*\.py)$' || true

printf '%s\n' '=== direct test outlines ==='
ast-grep outline tests/test_checkpoint_migration_bounded_reads.py --items all
ast-grep outline tests/test_checkpoint_migration_operator.py --items all
ast-grep outline tests/test_checkpoint_migration_operator_integration.py --items all

printf '%s\n' '=== direct test diffs ==='
git diff --unified=45 "$base" "$head" -- \
  tests/test_checkpoint_migration_bounded_reads.py \
  tests/test_checkpoint_migration_operator.py \
  tests/test_checkpoint_migration_operator_integration.py \
  tests/test_bootstrap_cli.py

printf '%s\n' '=== CI diff ==='
git diff --unified=80 "$base" "$head" -- .github/workflows/ci.yml

Length of output: 58633


🏁 Script executed:

#!/bin/bash
set -euo pipefail

base='2820aa36d8dedf7d89d1b745e5728acf3b913d2b'
head='c213fc549dbf024da43b459df29c0616cd741c96'

printf '%s\n' '=== canonical migrations ==='
cat -n pg_llm_batch/migrations/0007_result_stream_checkpoints.sql
cat -n pg_llm_batch/migrations/0008_result_checkpoint_audit_events.sql

printf '%s\n' '=== rollback migrations ==='
cat -n pg_llm_batch/migrations/rollback/0007_result_stream_checkpoints.sql
cat -n pg_llm_batch/migrations/rollback/0008_result_checkpoint_audit_events.sql

printf '%s\n' '=== CI and compatibility contract diffs ==='
git diff --unified=60 "$base" "$head" -- \
  tests/test_checkpoint_audit_ci_contract.py \
  tests/test_workflow_contracts.py \
  tests/test_checkpoint_migration_operator_documentation.py

printf '%s\n' '=== documentation diffs ==='
git diff --unified=35 "$base" "$head" -- \
  README.md AGENTS.md CLAUDE.md ARCHITECTURE.md CHANGELOG.md \
  docs/adr/0010-atomic-checkpoint-schema-operator.md \
  docs/checkpoint-storage-migrations.md \
  docs/doctoring/checkpoint-migration-operator.md

printf '%s\n' '=== files outside the requested diff that define referenced contracts ==='
ast-grep outline pg_llm_batch/checkpoint_store.py --items all
ast-grep outline pg_llm_batch/checkpoint_audit.py --items all
ast-grep outline pg_llm_batch/db.py --items all
rg -n -C 3 'MIGRATION_PATH|AUDIT_MIGRATION_PATH|def apply_result_checkpoint_schema|def apply_result_checkpoint_audit_schema|def _require_psycopg' \
  pg_llm_batch/checkpoint_store.py pg_llm_batch/checkpoint_audit.py pg_llm_batch/db.py

printf '%s\n' '=== generated-artifact and ignore hygiene ==='
git diff --check "$base" "$head"
git diff --name-only "$base" "$head" | rg -i '(^|/)(dist|build|__pycache__|\.pytest_cache|coverage|htmlcov|.*\.(pyc|pyo|whl|tar\.gz|zip|egg-info))($|/)' || true
git status --short

Length of output: 89577


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '=== declared psycopg dependency ==='
rg -n -C 2 'psycopg' pyproject.toml uv.lock

printf '%s\n' '=== transaction-context usage in repository ==='
rg -n -C 4 'with psycopg\.connect\(|\.commit\(\)' pg_llm_batch tests

Length of output: 54709


🤖 web_search executed:

Official psycopg 3 documentation: Does with psycopg.connect(...) as conn:automatically commit when the context block exits normally? What happens ifconn.commit() was already called inside that block?

Length of output: 10862


@seonghobae I completed the read-only review of exact head c213fc549dbf024da43b459df29c0616cd741c96 against base 2820aa36d8dedf7d89d1b745e5728acf3b913d2b.

I found no actionable issue in the requested scope.

Verified items:

  • Both canonical SQL files use bounded binary reads of 1 MiB plus one detection byte.
  • The operator loads and validates both files before psycopg validation or database connection.
  • The operator uses fixed two-key pg_advisory_xact_lock values in one transaction.
  • The operator executes 0007_result_stream_checkpoints before 0008_result_checkpoint_audit_events.
  • The operator commits only after both migration statements succeed.
  • A second-migration failure exits before the explicit commit. PostgreSQL then rolls back the transaction and releases the transaction-level lock.
  • Psycopg 3.3.4 commits a connection-context transaction only when it remains open. The explicit connection.commit() leaves no pending transaction for the context exit to commit.
  • CLI success output contains only schema version, migration IDs, byte counts, and SHA-256 values.
  • The live tests verify rollback and observable waiting on the advisory lock.
  • All four CI jobs check out ${{ github.event.pull_request.head.sha || github.sha }} and verify the checked-out HEAD.
  • init-db and the independent migration helpers remain available.
  • Documentation states the operator boundary and limitations consistently.
  • The range has no generated build, cache, coverage, bytecode, wheel, archive, or egg-info artifacts. git diff --check reported no whitespace errors.

I did not execute repository code. This result is a static source review of the requested range.

⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor Author

Current exact-head/base audit after dependency-order ancestry reconciliation:

  • source head: f7f187c261f74d5b96022a17e7670d8db5db9f2c
  • exact stacked base: ba2c102476f834c2c25750de8ede146e391d4c74
  • ancestry: 55 ahead / 0 behind
  • tree identity check: prior feature head 9a66d79b5de6cfd2fdfc51c4794335c1043fe0ab → current head is ahead-only with files=[]; reconciliation changed ancestry only and used non-force fast-forwards after no-file candidate comparisons
  • CI 31166616117: completed / success on this exact source head; every required job verified the exact source SHA, Python 3.10/3.12/3.14 passed, coverage/docstrings/lint/package passed, container builds passed, and live checkpoint storage/audit migration integration passed
  • Release Acceptance 31166616107: completed / success on this exact source head
  • CodeRabbit commit status: success
  • unresolved inline review threads: 0; no qualifying independent non-author APPROVED review exists

Older c213..., 9a66..., predecessor-base, and synthetic merge evidence is stale/supporting evidence only. Branch-protection, ruleset, code-scanning/security, and any required surfaces unavailable through the connector remain unproven, so this draft is not merge-authorized.

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #80. Live revalidation shows #80 is open/mergeable at exact head 3cac073cc791b78fafa0005b820e0206fe168a63 on replacement predecessor #79 exact head e99c99b081cd5d85f67faf1a0f46944110efbef3. #80 has the same 21-file migration-operator delta and identical aggregate additions/deletions (2045/19) as this PR, its PR patch matches the replayed feature delta, and fresh exact-head CI 31286065261 plus Release Acceptance 31286065264 both completed successfully. This PR remains on superseded #62 history, so keeping it open would preserve a competing integration path. No checks, reviews, or approvals from this PR transfer to #80.

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