Two snapshot create runs of one name within the same second fail on the snapshot ID #270

Closed
opened 2026-10-07 18:00:20 +02:00 by clawbot · 1 comment
Collaborator

The snapshot ID carries a timestamp in whole seconds (internal/snapshot/snapshot.go:118-136), and the row is a plain INSERT (internal/database/snapshots.go:41-48). A second run of the same snapshot name that starts in the same second as the first therefore dies with UNIQUE constraint failed: snapshots.id. The process lock serializes runs, so this needs the first run to finish within that second. A small snapshot to file:// does: vaultik snapshot create x && vaultik snapshot create x reproduces it.

Found by the second-pass audit on next at e161343, by code trace.

Definition of done

  1. Back-to-back snapshot create runs of one name both succeed with distinct snapshot IDs, for example by waiting for the next second before taking the timestamp. Any change to the ID format is reflected in docs/DATAMODEL.md.
  2. A test runs two creates of one name back to back.
  3. make check passes.

Model: fable-5-1 (audit); opus-5-5 (issue)

The snapshot ID carries a timestamp in whole seconds (`internal/snapshot/snapshot.go:118-136`), and the row is a plain `INSERT` (`internal/database/snapshots.go:41-48`). A second run of the same snapshot name that starts in the same second as the first therefore dies with `UNIQUE constraint failed: snapshots.id`. The process lock serializes runs, so this needs the first run to finish within that second. A small snapshot to `file://` does: `vaultik snapshot create x && vaultik snapshot create x` reproduces it. Found by the second-pass audit on `next` at `e161343`, by code trace. ## Definition of done 1. Back-to-back `snapshot create` runs of one name both succeed with distinct snapshot IDs, for example by waiting for the next second before taking the timestamp. Any change to the ID format is reflected in `docs/DATAMODEL.md`. 2. A test runs two creates of one name back to back. 3. `make check` passes. Model: fable-5-1 (audit); opus-5-5 (issue)
clawbot self-assigned this 2026-10-07 18:00:20 +02:00
Author
Collaborator

Fixed in #277. Before creating the snapshot row, the create looks the snapshot ID up in the local index. If a snapshot already has that ID, it waits a second and takes a new timestamp. The ID format is unchanged.

The new test calls the snapshot manager's create twice. A test of two whole backups did not reproduce the failure: under the race detector on a loaded host, one small backup takes over a second.

Model: opus-5-5

Fixed in https://git.eeqj.de/sneak/vaultik/pulls/277. Before creating the snapshot row, the create looks the snapshot ID up in the local index. If a snapshot already has that ID, it waits a second and takes a new timestamp. The ID format is unchanged. The new test calls the snapshot manager's create twice. A test of two whole backups did not reproduce the failure: under the race detector on a loaded host, one small backup takes over a second. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/vaultik#270