Skip to content

retention: make backup and restore disposition-aware - #246

Merged
TusanHomichi merged 3 commits into
mainfrom
issue-213-disposition-aware-recovery
Nov 20, 2026
Merged

TusanHomichi merged 3 commits into
mainfrom
issue-213-disposition-aware-recovery

Conversation

@TusanHomichi

@TusanHomichi TusanHomichi commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Primary Issue

Closes #213
Refs #64, #44

Problem And Outcome

Before confirmed disposition execution (#214) can be enabled, backups, off-server copies, and restore must enforce the ADR 0030 recovery protocol so lawfully disposed records cannot be silently resurrected by restoring an older snapshot or republished off the server by backup copy catch-up, while missing, stale, corrupt, or unreachable recovery evidence fails closed.

This PR implements the canonical installation-scoped recovery ledger (data/instance/disposition-ledger.json, mirrored to CONSOLEBOOK_BACKUP_COPY_DIR), makes backup, backup_copy, restore, and read-only doctor disposition-aware, adds forward migration 0019_evaluation_record_id_floor.sql so new records can never reuse disposed or ledger-reserved IDs (moving installation_export to format_version: 4 while preserving v1–v3 verification), and adds typed recovery health states and durable disposition_run progress interfaces for #214. No destruction endpoint is exposed in this PR.

Changes

  • Durable recovery ledger (src/disposition_recovery/ledger.rs, src/data_dir.rs)
    • Defines consolebook-disposition-ledger format_version: 1 in canonical JSON with "authenticity": "self_consistency_only" and strict root/entry allowlists carrying only opaque IDs, sorted SHA-256 content hashes, UTC disposed_at, and bounded policy_authority (zero narratives, ratings, acknowledgments, display names, or free-form reasons).
    • Fails closed on corrupt JSON, non-canonical encoding, unknown format versions, disallowed fields, false authenticity claims, out-of-order entries, or installation-ID mismatches.
    • Persists atomically (temp + sync_all + rename + file/dir fsync), reads live DB state through WAL-aware storage::open_diagnostic (and finished snapshots through storage::open_snapshot), merges deterministically across sources, mirrors safely to off-server copy directories, and inspects snapshots by both evaluation_record.id and evaluation_version.content_hash.
  • Monotonic record-ID floor (0019_evaluation_record_id_floor.sql, evaluation_drafts.rs, summaries.rs, installation_export v4) (persisted schema & constraints)
    • Adds forward migration 0019_evaluation_record_id_floor.sql with singleton monotonic table evaluation_record_id_floor (id CHECK (id = 1), last_reserved_id CHECK (last_reserved_id >= 0)), no-delete and monotonic-update triggers, an AFTER INSERT ON disposition_event trigger advancing last_reserved_id, and an AFTER INSERT ON evaluation_record trigger refusing reuse of any ID <= last_reserved_id or present in disposition_event.
    • Routes both evaluation_drafts::create and summaries::create through one shared allocate_record_id(&mut tx) allocator inside storage::write_tx, and advances evaluation_record_id_floor from the merged recovery ledger during restore.
    • Bumps installation_export to format_version: 4 (48 carried tables), pins its specification fingerprint and tests/fixtures/installation-export-v4.zip, and keeps v1, v2, and v3 golden archives verifying untouched.
  • Typed recovery states & durable progress interfaces (src/disposition_recovery/progress.rs)
    • Exposes durable disposition_run read and monotonic transition helpers (list_all_runs, list_incomplete_runs, record_step_failure, advance_to_copy_cleanup_pending, mark_run_completed), read-only enumerate_controlled_artifacts covering scheduled/manual, pre-migration, pre-restore (.db and .damaged), .partial/.tmp, data/exports/, and off-server copy directories, plus explicit EXTERNAL_COPIES_NON_GUARANTEE text so Consolebook never claims external copies were deleted.
    • Exposes read-only inspect_recovery_health surfaced by doctor and /api/backups/status (with matching TypeScript types in web/src/lib/api/installation.ts).
  • Disposition-aware restore, backup, backup_copy, and read-only doctor
    • restore (RestoreOptions, CLI --backup-copy-dir and --disposition-ledger) consults local ledger, copy-dir mirror, explicit ledger, and WAL-aware live DB before touching the database; fails closed on corrupt, mismatched, missing-required, stale local, or unreachable copy-dir evidence; refuses any snapshot containing disposed record IDs or content hashes; persists collected recovery evidence to data/instance/disposition-ledger.json before promoting the restored database; advances evaluation_record_id_floor after opening the restored DB; prints an explicit honest warning when restoring onto a clean host with no ledger available; and fails closed on externally encrypted blobs with ADR 0027 storage-layer decryption guidance.
    • backup::run, backup::run_after_restore, backup::before_migrating, backup_copy::copy_snapshot, backup_copy::copy_snapshot_with_data_dir, and backup_copy::catch_up verify snapshot DB disposition coverage against the local ledger, refuse snapshots contradicting recovery evidence, refuse stale/corrupt ledgers, recognize ledger-only copy-directory ownership, and mirror clean recovery ledgers off-server.
    • doctor adds a strictly read-only disposition recovery check reporting incomplete runs and corrupt/stale ledgers as failures and unreachable/lagging copy mirrors as warnings without modifying any file or database state.

Correction Ladder

Rung 1 & Rung 2: persisted monotonic record-ID floor and triggers (0019_evaluation_record_id_floor.sql), canonical allowlist ledger verifier and fail-closed snapshot inspection in one owning module (disposition_recovery), wired into every backup/copy/restore/doctor/draft-creation path, with process-level CLI and integration drills (tests/disposition_recovery/).

Verification

All recovery drill evidence is from automated local process-level tests with invented agencies, people, schedules, and records — separate from real-host deployment verification and hosted CI. Local cargo xtask proof receipt for the latest head (661297a60194) is posted in comments once completed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-20T20:58:36.043526Z 661297a 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.

@fieldmouseworks-steward fieldmouseworks-steward Bot added the waiting: review Its reviewers, or a Claude job judging it, are looking at this head label Nov 20, 2026

@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: e077c8fc8f

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

@TusanHomichi

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: c44d04aca5

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

@TusanHomichi

Copy link
Copy Markdown
Member Author

Updated local proof receipt — passed (c44d04aca514544d69746f2269df1f930e5c86a5)

  • Candidate: c44d04aca514544d69746f2269df1f930e5c86a5 tree 3b99bec160905032cc8c319887c6addbadf1e06f; unchanged during run: true
  • Scope: local (local run; hosted pr-gate results are separate evidence, linked not copied)
  • Command: cargo xtask proof in /data/dev/src/consolebook
  • Started 2026-11-20T20:37:18Z, finished 2026-11-20T20:46:20Z, 542.3s
  • Browser suite: 74 expected, 0 unexpected, 0 flaky, 0 skipped; report sha256 5d3f84d8643a7f24c604680890c8c55a76bb0769d6a2201b6775f0a66e88a515
  • Receipt: .proof/20261120T203718Z-c44d04aca514/receipt.json sha256 2f0ddcea55cca549c879c29c3d9fa2d0d0588494e4d9e68bfa17c63a4b75c270
  • All 7 steps exited 0.

@TusanHomichi

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 661297a601

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

@TusanHomichi

Copy link
Copy Markdown
Member Author

Local proof receipt — passed (661297a601942490c81c49a631fd53b732801889)

  • Candidate: 661297a601942490c81c49a631fd53b732801889 tree 98d6a965536691da7431fda8eebb8e45e429c60c; unchanged during run: true
  • Scope: local (local run; hosted pr-gate results are separate evidence, linked not copied)
  • Command: cargo xtask proof in /data/dev/src/consolebook
  • Started 2026-11-20T20:55:36Z, finished 2026-11-20T21:05:35Z, 598.3s
  • Browser suite: 74 expected, 0 unexpected, 0 flaky, 0 skipped; report sha256 ab962af979c0967ee102017708bb1e22a5e36f2aa35e3eb9e477d9ad53eccd1f
  • Receipt: .proof/20261120T205536Z-661297a60194/receipt.json sha256 b22e4e234714eee0ba048b33f343c64af268cb09442c3b7cd2e11ed2e192891e
  • All 7 steps exited 0.

@TusanHomichi
TusanHomichi merged commit 9e47768 into main Nov 20, 2026
25 of 26 checks passed
@TusanHomichi
TusanHomichi deleted the issue-213-disposition-aware-recovery branch November 20, 2026 21:06
@fieldmouseworks-steward fieldmouseworks-steward Bot removed the waiting: review Its reviewers, or a Claude job judging it, are looking at this head label Nov 20, 2026
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.

retention: make backup and restore disposition-aware

1 participant