Deletion follow-ups from the #13 reviews: Forget guards, lock codes and documents #60

Open
opened 2026-11-15 00:10:42 +00:00 by svc-agent-writer · 0 comments

The correctness review and the security review of PR #59 at c2f08bb found no blocker. This issue holds their should-fix findings, their test gaps, and the notes from the three rework rounds that the merge did not fix. Each finding below was reproduced on synthetic data unless it says "reasoned".

Forget guards (security first)

  1. A stale Mirror keeps a Forgotten message readable until the next Reconcile. Only _reconcile checks the held rows against the Tombstones (sync.py:431-433). A normal pass does not. Case: sync, copy the Mirror, forget, put the copy back, sync --once; the api reader still returns the message. A forget that answers wal=busy and then loses its -wal ends the same way. Fix: check the held guids against the Tombstones at each writer open, or at the start of each pass. SECURITY.md states the window until then.
  2. The Tombstone store has no integrity protection. It is plain SQLite, and salt_check is readable in it (tombstones.py:89-125). Anyone who can write the volume can delete its rows or put back a stale copy, without the store key. Reconcile then fetches the Forgotten message again. The marker refuses a 0-byte file only. When the export file is present, the merge repairs this; otherwise nothing detects it. Fix: hold a Tombstone count, or a digest of the digest set, in the encrypted Mirror's sync_state, and refuse a Tombstone store that holds fewer. At least, SECURITY.md states that the Tombstone store has no integrity protection.
  3. A missing or older export is not written again until the next Forget. The export is written only when export_pending is "1" (sync.py:679-684). Case: delete the export; it stays absent through 4 passes. Put an older copy back; it keeps 1 of 2 digests. A Rebuild from that file after a lost volume then brings back the later Forgets. Fix: when the export is absent, or lacks a digest that the live store holds, set export_pending and write it.
  4. reply_to can keep a Forgotten guid. Case: forget writes the Tombstone and its Mirror transaction fails (store-unavailable), then the owner deletes the message before the next forget or Reconcile. Recently Deleted and the hard-deletion scan remove the row with a plain remove_row, so reply_to keeps the guid. Reconcile looks only at held guids (sync.py:430-435, 543-549, 564-567). forget again answers unknown-message, so the README remedy fails. Fix: in Reconcile, clear each reply_to whose salted hash a Tombstone matches; or give the Tombstone check precedence in the two deletion paths.
  5. A transient failure turns a 0.1.0 Mirror into a permanent stop. When _open_tombstones raises tombstones-unreadable, the handler opens the Mirror with _open_mirror only to record failed_at (sync.py:709-715). _open_mirror also writes the DELETION_SLICE marker. Case: a 0.1.0 Mirror with no marker and no Tombstone file, and the create fails once. Every later sync then stops with tombstones-missing (exit 2). A 0-byte legacy file whose initialisation fails once ends the same way. Fix: use store.open_writer in that handler.

Codes and the sync loop

  1. A busy Tombstone lock reads as an invalid export and stops the loop. merge_export runs BEGIN IMMEDIATE on the live store every pass, even with no new rows, and maps every error to tombstones-export-invalid (tombstones.py:250-262, sync.py:703). That is a setup code (exit 2), so sync_loop returns. Case: a lock held for 7 s; sync --once exits 2 after 5.2 s, and forget prints the same code. A partly written export file also makes a running loop exit after one pass. Fix: map a lock to a code that the loop retries; skip the write transaction when there are no new rows; keep tombstones-salt-mismatch for a salt mismatch in the export. Correct the README row: it says "Does not start", but the loop also exits mid-run, and it tells the operator to move a valid export aside.
  2. forget can create a Tombstone store beside an unmarked Mirror (sync.py:385). Rework round 1 item 2 says forget passes create=False. Harmless today; make it match.
  3. The export-path rules in config.py:266-292 run for every verb. A shared config whose export directory is not mounted for api stops api with config-validation. The shipped Compose and Kubernetes configs set no export path. Decide whether the rule runs only for the verbs that write the export.

Documents

  1. README.md:130, the interrupted row for forget: Ctrl-C after the Tombstone commit leaves the message in the Mirror and readable. Say what the store-unavailable row says: the Tombstone may be written, so run forget again; otherwise the next Reconcile removes the message.
  2. SECURITY.md:43 and README.md:110 say that "a second mount of the same directory is refused". This holds only for a mount that keeps the device and inode, such as a Linux bind mount. An NFS, SMB or FUSE mount of the same directory has another st_dev and passes (reasoned, not run). "Place it on another volume" is advice; the code does not compare st_dev. The word "atomically" for the export does not mean durable.
  3. config.example.toml:18 still names the -wal, -shm and -journal rule that round 3 removed.
  4. docs/install-single-host.md has no steps for the export path, forget and sync --rebuild (from the dispatch report; the file was outside the write set).

Test gaps (mutations that survive)

  1. _open_mirror no longer marks an existing Mirror (sync.py:341-343). Every test passes. On an upgraded 0.1.0 Mirror, forget and then a lost Tombstone file: the real code stops with tombstones-missing, the mutant exits 0 and the Forgotten message comes back. This is the main gap.
  2. merge_export without _verify_export (tombstones.py:259). No test gives a well-formed export with another salt, an extra object or a damaged page to the pass merge or the forget merge.
  3. The export-time recheck with mirror_path=None (sync.py:402). The tests put both stores in one directory.
  4. merge_export without setting export_pending (low impact).

Carried from the rework rounds

  1. A Reconcile fetch that gets a short page (new_rows(row_id-1, limit=1) with no row and more=true).
  2. No fsync of the export directory around os.replace.
  3. Reconcile can delete a Chat that a concurrent pass added with no message yet (transient; the next pass adds it again).
  4. Notes, no change required unless triage decides otherwise:
    • forget m007 is accepted as m7.
    • KEY_FILE_VERBS only describes the code.
    • A filesystem without hard links fails closed.
    • An export that fails on every pass stops every pass (documented).
    • A crash between os.link and unlink in _open_mirror leaves .mirror.db.<uuid>.tmp, a second hard link to the live Mirror.
    • Whoever holds the readable salt_check can plant valid junk digests in an export. They are merged for good and match no message.
    • A symlinked export parent can be swapped between the directory check and os.replace (tombstones.py:198-199). That needs write access to the live directory already.

Filed under: operator word "I grant authority to merge T4 through 21:00 aedt" sha256:cec4dd4fecbd

The correctness review and the security review of PR #59 at `c2f08bb` found no blocker. This issue holds their should-fix findings, their test gaps, and the notes from the three rework rounds that the merge did not fix. Each finding below was reproduced on synthetic data unless it says "reasoned". ## Forget guards (security first) 1. **A stale Mirror keeps a Forgotten message readable until the next Reconcile.** Only `_reconcile` checks the held rows against the Tombstones (`sync.py:431-433`). A normal pass does not. Case: sync, copy the Mirror, `forget`, put the copy back, `sync --once`; the api reader still returns the message. A `forget` that answers `wal=busy` and then loses its `-wal` ends the same way. Fix: check the held guids against the Tombstones at each writer open, or at the start of each pass. `SECURITY.md` states the window until then. 2. **The Tombstone store has no integrity protection.** It is plain SQLite, and `salt_check` is readable in it (`tombstones.py:89-125`). Anyone who can write the volume can delete its rows or put back a stale copy, without the store key. Reconcile then fetches the Forgotten message again. The marker refuses a 0-byte file only. When the export file is present, the merge repairs this; otherwise nothing detects it. Fix: hold a Tombstone count, or a digest of the digest set, in the encrypted Mirror's `sync_state`, and refuse a Tombstone store that holds fewer. At least, `SECURITY.md` states that the Tombstone store has no integrity protection. 3. **A missing or older export is not written again until the next Forget.** The export is written only when `export_pending` is `"1"` (`sync.py:679-684`). Case: delete the export; it stays absent through 4 passes. Put an older copy back; it keeps 1 of 2 digests. A Rebuild from that file after a lost volume then brings back the later Forgets. Fix: when the export is absent, or lacks a digest that the live store holds, set `export_pending` and write it. 4. **`reply_to` can keep a Forgotten guid.** Case: `forget` writes the Tombstone and its Mirror transaction fails (`store-unavailable`), then the owner deletes the message before the next `forget` or Reconcile. Recently Deleted and the hard-deletion scan remove the row with a plain `remove_row`, so `reply_to` keeps the guid. Reconcile looks only at held guids (`sync.py:430-435`, `543-549`, `564-567`). `forget` again answers `unknown-message`, so the README remedy fails. Fix: in Reconcile, clear each `reply_to` whose salted hash a Tombstone matches; or give the Tombstone check precedence in the two deletion paths. 5. **A transient failure turns a 0.1.0 Mirror into a permanent stop.** When `_open_tombstones` raises `tombstones-unreadable`, the handler opens the Mirror with `_open_mirror` only to record `failed_at` (`sync.py:709-715`). `_open_mirror` also writes the `DELETION_SLICE` marker. Case: a 0.1.0 Mirror with no marker and no Tombstone file, and the create fails once. Every later `sync` then stops with `tombstones-missing` (exit 2). A 0-byte legacy file whose initialisation fails once ends the same way. Fix: use `store.open_writer` in that handler. ## Codes and the sync loop 6. **A busy Tombstone lock reads as an invalid export and stops the loop.** `merge_export` runs `BEGIN IMMEDIATE` on the live store every pass, even with no new rows, and maps every error to `tombstones-export-invalid` (`tombstones.py:250-262`, `sync.py:703`). That is a setup code (exit 2), so `sync_loop` returns. Case: a lock held for 7 s; `sync --once` exits 2 after 5.2 s, and `forget` prints the same code. A partly written export file also makes a running loop exit after one pass. Fix: map a lock to a code that the loop retries; skip the write transaction when there are no new rows; keep `tombstones-salt-mismatch` for a salt mismatch in the export. Correct the README row: it says "Does not start", but the loop also exits mid-run, and it tells the operator to move a valid export aside. 7. `forget` can create a Tombstone store beside an unmarked Mirror (`sync.py:385`). Rework round 1 item 2 says `forget` passes `create=False`. Harmless today; make it match. 8. The export-path rules in `config.py:266-292` run for every verb. A shared config whose export directory is not mounted for `api` stops `api` with `config-validation`. The shipped Compose and Kubernetes configs set no export path. Decide whether the rule runs only for the verbs that write the export. ## Documents 9. README.md:130, the `interrupted` row for `forget`: Ctrl-C after the Tombstone commit leaves the message in the Mirror and readable. Say what the `store-unavailable` row says: the Tombstone may be written, so run `forget` again; otherwise the next Reconcile removes the message. 10. SECURITY.md:43 and README.md:110 say that "a second mount of the same directory is refused". This holds only for a mount that keeps the device and inode, such as a Linux bind mount. An NFS, SMB or FUSE mount of the same directory has another `st_dev` and passes (reasoned, not run). "Place it on another volume" is advice; the code does not compare `st_dev`. The word "atomically" for the export does not mean durable. 11. `config.example.toml:18` still names the `-wal`, `-shm` and `-journal` rule that round 3 removed. 12. `docs/install-single-host.md` has no steps for the export path, `forget` and `sync --rebuild` (from the dispatch report; the file was outside the write set). ## Test gaps (mutations that survive) 13. `_open_mirror` no longer marks an existing Mirror (`sync.py:341-343`). Every test passes. On an upgraded 0.1.0 Mirror, `forget` and then a lost Tombstone file: the real code stops with `tombstones-missing`, the mutant exits 0 and the Forgotten message comes back. This is the main gap. 14. `merge_export` without `_verify_export` (`tombstones.py:259`). No test gives a well-formed export with another salt, an extra object or a damaged page to the pass merge or the `forget` merge. 15. The export-time recheck with `mirror_path=None` (`sync.py:402`). The tests put both stores in one directory. 16. `merge_export` without setting `export_pending` (low impact). ## Carried from the rework rounds 17. A Reconcile fetch that gets a short page (`new_rows(row_id-1, limit=1)` with no row and `more=true`). 18. No fsync of the export directory around `os.replace`. 19. Reconcile can delete a Chat that a concurrent pass added with no message yet (transient; the next pass adds it again). 20. Notes, no change required unless triage decides otherwise: - `forget m007` is accepted as `m7`. - `KEY_FILE_VERBS` only describes the code. - A filesystem without hard links fails closed. - An export that fails on every pass stops every pass (documented). - A crash between `os.link` and `unlink` in `_open_mirror` leaves `.mirror.db.<uuid>.tmp`, a second hard link to the live Mirror. - Whoever holds the readable `salt_check` can plant valid junk digests in an export. They are merged for good and match no message. - A symlinked export parent can be swapped between the directory check and `os.replace` (`tombstones.py:198-199`). That needs write access to the live directory already. --- Filed under: operator word "I grant authority to merge T4 through 21:00 aedt" sha256:cec4dd4fecbd
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/messages-mind-mcp#60
No description provided.