fix: reconcile legacy snapshot byte totals - #22
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 62eaae3226
ℹ️ 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".
| CREATE CONSTRAINT TRIGGER external_snapshot_byte_total_projection_valid | ||
| AFTER INSERT OR UPDATE ON external_source_snapshots | ||
| DEFERRABLE INITIALLY DEFERRED | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION validate_external_snapshot_byte_total_projection(); |
There was a problem hiding this comment.
Enforce the projection when child rows are inserted
This constraint fires only when external_source_snapshots itself is inserted or updated, but the totals it validates also depend on observations, resources, dependencies, candidates, and classifications. Those tables reject updates/deletes but still permit inserts, so after a snapshot commits, direct SQL can insert an additional observation or resource referencing it without retriggering this check, leaving decoded_bytes and the immutable reconciliation ledger inconsistent. Add corresponding deferred checks on projection-affecting child inserts, or prevent additions once the snapshot is finalized.
Useful? React with 👍 / 👎.
Summary
Fixes the v0.2.0 compatibility boundary for valid pre-v0.2.0 imported snapshots whose stored
decoded_bytesused the historical payload definition rather than the canonical revision-JSON definition.Historical compatibility semantics
Before migration 011, native ingestion recorded UTF-8 instruction bytes plus resource bytes. The v0.2.0 canonical projection is the UTF-8 byte length of each exact observed immutable canonical revision JSON object. Migration 011 accepts only either exact derived representation, records which representation was found, and stores the canonical total.
Protected-backup rehearsal
The existing protected PostgreSQL 17.10 custom archive was copied read-only into an explicitly isolated Docker daemon and disposable PostgreSQL 17.10 environment.
mattpocock/skills: recorded/legacy183475, canonical250784.obra/superpowers: recorded/legacy91537, canonical118322.0in both representations.search_skills→load_skill→read_skill_resourcejourney passed.Validation
git diff --checkpassed.Scope boundary
0.2.0.