Export publish does not fsync the export directory, so a power loss can drop the latest Forgets from the export #93

Open
opened 2026-11-16 05:03:30 +00:00 by svc-agent-writer · 0 comments

export_tombstones (src/messages_mind_mcp/tombstones.py:179-210) publishes the export with os.replace(tmp, dest) (:199) and then commits export_pending = 0 in the Tombstone store (:200-201). Nothing calls fsync on the export directory after the rename, and nothing calls fsync on the temp file before it.

Failure

  1. A Forget writes the Tombstone row and sets export_pending.
  2. The export writes the temp file, renames it over dest, and commits export_pending = 0. SQLite syncs that commit to the Tombstone store.
  3. Power is lost before the directory entry for the rename reaches the disk.
  4. After the restart, dest is the previous export. It is complete and valid, but it lacks the Forget from step 1. export_pending is 0, so no pass writes the export again.
  5. The export stays behind until a later Forget writes it. If the volume is lost in that gap, a Rebuild from the export brings the Forgotten message back.

ADR 0006 treats Tombstones as the erasure guard, so this is a Forget-durability gap.

Fix direction

  • fsync the temp file before os.replace, and fsync the export directory after it, before export_pending is cleared.
  • A failed fsync must leave export_pending set, so the next pass writes the export again.
  • Test with a spy on os.fsync and on the directory open, in the order file, rename, directory, commit. Linux CI runs Python 3.12 on python:3.12-slim-bookworm.
  • Check whether the restore (restore_tombstones, os.link at tombstones.py:284) needs the same directory fsync.

Out of scope

#92 states this limit in SECURITY only, because it has no src/ edit.


Filed under: #92 architect gate (spec note 20), from the PR #91 security review.

`export_tombstones` (`src/messages_mind_mcp/tombstones.py:179-210`) publishes the export with `os.replace(tmp, dest)` (`:199`) and then commits `export_pending = 0` in the Tombstone store (`:200-201`). Nothing calls `fsync` on the export directory after the rename, and nothing calls `fsync` on the temp file before it. ## Failure 1. A Forget writes the Tombstone row and sets `export_pending`. 2. The export writes the temp file, renames it over `dest`, and commits `export_pending = 0`. SQLite syncs that commit to the Tombstone store. 3. Power is lost before the directory entry for the rename reaches the disk. 4. After the restart, `dest` is the previous export. It is complete and valid, but it lacks the Forget from step 1. `export_pending` is 0, so no pass writes the export again. 5. The export stays behind until a later Forget writes it. If the volume is lost in that gap, a Rebuild from the export brings the Forgotten message back. ADR 0006 treats Tombstones as the erasure guard, so this is a Forget-durability gap. ## Fix direction - `fsync` the temp file before `os.replace`, and `fsync` the export directory after it, before `export_pending` is cleared. - A failed `fsync` must leave `export_pending` set, so the next pass writes the export again. - Test with a spy on `os.fsync` and on the directory open, in the order file, rename, directory, commit. Linux CI runs Python 3.12 on `python:3.12-slim-bookworm`. - Check whether the restore (`restore_tombstones`, `os.link` at `tombstones.py:284`) needs the same directory `fsync`. ## Out of scope #92 states this limit in SECURITY only, because it has no `src/` edit. --- Filed under: #92 architect gate (spec note 20), from the PR #91 security review.
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#93
No description provided.