Scrub forgotten data and migrate SQLite stores to schema 7 #63

Merged
Collaborator

Summary

Forget now erases the forgotten Person's values from the store's database file, purges their addresses from the legacy pending checkpoint, and deletes derived Organisations that only they used (ADR 0003 Amendment 1, rules 1, 2, 4 and 5).

 open_writer
   journal_mode=WAL, foreign_keys=ON, busy_timeout=5000
+  secure_delete=ON
   BEGIN IMMEDIATE
     run MIGRATIONS[version:]          # each sets its own user_version; still 6
   COMMIT
+  if version < 7
+    VACUUM                            # outside the transaction; scrubs pages freed before secure_delete
+    user_version = 7                  # only after VACUUM succeeds; a failure leaves 6 and the next open retries
 forget(person)
   write Tombstones and audit row
   for each email Handle
     delete mail_pending / mail_support / mail_staged rows
+  drop the addresses from every legacy `pending` checkpoint in source_state
+  orgs = the Person's derived organisation fields + their relations.target_org_id
   delete Person (cascades Handles, fields, their own Relations)
+  for each org in orgs
+    delete it when it is derived (has org_domains), no other Person relates to it,
+    and it has no asserted field (org_aliases)

No application checkpoint and no per-Forget VACUUM in production code. Litestream owns checkpointing. The legacy fetch-failure race in run_pass is out of scope (#59). Restore-safe Tombstones stay with #55.

Evidence

  • Before: after Forget, C08 checked raw bytes for signature and subject text only; the forgotten address stayed in free pages, the legacy checkpoint kept it, and test_identity.py asserted the orphaned Organisation remained.
  • After:
    • test_writer_migrates_v6_store_to_v7_scrubbing_freed_pages: a schema-6 store written with explicit secure_delete=OFF migrates to 7, and a marker present in the file before the migration is gone after it.
    • test_c08_concurrent_forget_suppresses_staged_queued_late_and_replayed: after a test-run wal_checkpoint(TRUNCATE), the forgotten address bytes are absent from the db file.
    • test_forget_purges_legacy_pending_checkpoint[True|False]: the decoded checkpoint holds none of the forgotten addresses.
    • test_forget_removes_only_orphaned_derived_organisations: the orphan goes; one shared by a Handle of another Person, one another Person relates to, and one with an alias all stay.
    • Filtered run: 32 passed. make check: 387 passed, 5 skipped, 4 deselected.

Merge Danger

Door: one-way

Schema 7 is a forward migration. Older binaries refuse a schema-7 store, so a rollback needs a pre-migration backup. Forget deletes are irreversible by design.

Blast Radius: store

The first writer open after deploy runs one VACUUM over the whole live database, under Litestream replication.

Post-deploy checklist (operator)

The one-time VACUUM was not measured on a production-sized store (architect ruling: a post-deploy check, not a merge gate). After the first deploy:

  • peoplemind check --config /etc/peoplemind/config.toml prints store=ok schema=7.
  • The Litestream logs show no new-generation or replication error around the migration.
  • Record the time from writer start to /healthz/sync ok, against the db file size.
  • make test-integration (container deployment tests, including the schema=7 restore check) runs on a container-capable host; integrate did not run it.

Closes #54

🤖 Generated with Claude Code
Co-Authored-By: gpt-6.1-sol noreply@openai.com

## Summary Forget now erases the forgotten Person's values from the store's database file, purges their addresses from the legacy pending checkpoint, and deletes derived Organisations that only they used (ADR 0003 Amendment 1, rules 1, 2, 4 and 5). ```diff open_writer journal_mode=WAL, foreign_keys=ON, busy_timeout=5000 + secure_delete=ON BEGIN IMMEDIATE run MIGRATIONS[version:] # each sets its own user_version; still 6 COMMIT + if version < 7 + VACUUM # outside the transaction; scrubs pages freed before secure_delete + user_version = 7 # only after VACUUM succeeds; a failure leaves 6 and the next open retries ``` ```diff forget(person) write Tombstones and audit row for each email Handle delete mail_pending / mail_support / mail_staged rows + drop the addresses from every legacy `pending` checkpoint in source_state + orgs = the Person's derived organisation fields + their relations.target_org_id delete Person (cascades Handles, fields, their own Relations) + for each org in orgs + delete it when it is derived (has org_domains), no other Person relates to it, + and it has no asserted field (org_aliases) ``` No application checkpoint and no per-Forget `VACUUM` in production code. Litestream owns checkpointing. The legacy fetch-failure race in `run_pass` is out of scope (#59). Restore-safe Tombstones stay with #55. ## Evidence - **Before:** after Forget, C08 checked raw bytes for signature and subject text only; the forgotten address stayed in free pages, the legacy checkpoint kept it, and `test_identity.py` asserted the orphaned Organisation remained. - **After:** - `test_writer_migrates_v6_store_to_v7_scrubbing_freed_pages`: a schema-6 store written with explicit `secure_delete=OFF` migrates to 7, and a marker present in the file before the migration is gone after it. - `test_c08_concurrent_forget_suppresses_staged_queued_late_and_replayed`: after a test-run `wal_checkpoint(TRUNCATE)`, the forgotten address bytes are absent from the db file. - `test_forget_purges_legacy_pending_checkpoint[True|False]`: the decoded checkpoint holds none of the forgotten addresses. - `test_forget_removes_only_orphaned_derived_organisations`: the orphan goes; one shared by a Handle of another Person, one another Person relates to, and one with an alias all stay. - Filtered run: 32 passed. `make check`: 387 passed, 5 skipped, 4 deselected. ## Merge Danger **Door:** one-way Schema 7 is a forward migration. Older binaries refuse a schema-7 store, so a rollback needs a pre-migration backup. Forget deletes are irreversible by design. **Blast Radius:** store The first writer open after deploy runs one `VACUUM` over the whole live database, under Litestream replication. ## Post-deploy checklist (operator) The one-time `VACUUM` was not measured on a production-sized store (architect ruling: a post-deploy check, not a merge gate). After the first deploy: - [ ] `peoplemind check --config /etc/peoplemind/config.toml` prints `store=ok schema=7`. - [ ] The Litestream logs show no new-generation or replication error around the migration. - [ ] Record the time from writer start to `/healthz/sync` ok, against the db file size. - [ ] `make test-integration` (container deployment tests, including the `schema=7` restore check) runs on a container-capable host; integrate did not run it. Closes #54 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: gpt-6.1-sol <noreply@openai.com>
Scrub forgotten data and migrate SQLite stores to schema 7
All checks were successful
ci/woodpecker/pr/validation Pipeline was successful
52f552ea0f
Enable secure_delete on writer connections and run a one-time VACUUM outside the migration transaction before recording schema 7. Preserve the six transactional migrations.

Purge forgotten addresses from legacy pending checkpoints and delete orphaned derived Organisations while retaining shared, related and aliased Organisations. Update schema expectations and document physical erasure, backup retention and pending restore-safe Tombstones.

Validation: 32 filtered tests passed; make check passed with 387 passed, 5 skipped and 4 deselected. The pristine baseline had no failures. Source distribution and wheel builds succeeded.

Closes #54
Co-Authored-By: gpt-6.1-sol <noreply@openai.com>
svc-svd-writer deleted branch feat/svd-dev-people-mind-mcp-54-forget-scrub-the-database-fil-e6d768fb 2026-11-04 01:07:54 +00:00
Sign in to join this conversation.
No description provided.