backupengine: a snapshot BUNDLE can never replicate — Replicate cats one file, but the IDIP identity and content contracts return a directory #1802

Closed
opened 2026-09-23 21:29:39 +00:00 by ben · 3 comments
Owner

The defect

Engine.Replicate reads a snapshot artifact as one file:

// internal/backupengine/movement.go:64
plaintext, err := c.Run(ctx, "cat", snapshotRef)

But two of the three written backup contracts return a directory:

Contract Snapshot returns cat
Identity — kanidm (internal/backupengine/identity.go) a single identity-XXXXXXXX.json ✅ works
Identity — IDIP / KERIA (internal/keria/backup.go) mktemp -d bundle: keria/, keri-witness/, roster.json, matou-config/, blip.json ❌ Is a directory
content — anysync (internal/anysync/backup.go:171,226) mktemp -d bundle: mongodump + minio/tree ❌ Is a directory

Nothing anywhere tars a bundle — grep '"tar"' internal/**/*.go finds only install/guestpayload.go.

So the dataset an IDIP community cannot be re-founded without can reach no target at all — hosted offsite, cross-device, or "This computer" (DDR 0268). Same for content.

Why it is latent, not live

backupengine.WithContract has no production caller — only cmd/smoke-backups and cmd/smoke-fleet. The whole composition registers emptyCatalogue, so only kanidm's built-in Identity contract is reachable on a real gateway today, and that one happens to return a single file. The bug surfaces the moment any bundle contract is registered.

Why it blocks more than itself

DDR 0268 decision 5 (the IDSS offsite storage free-tier allowance) cannot be settled without this: the allowance is a size ÷ retention, and there is no snapshot size until a bundle has a single-file form and a compression answer. See that DDR's measured table — KERIA is ~3 MiB of LMDB per member.

Ruling (agent, ADR 0174 — two-way door, veto anytime)

Revertible by a commit and provable by the contract tests, so ruled here rather than parked:

  1. The single-file form is tar. Not a foreign repository format (ADR 0104's refusal stands) — a bundle stays readable on a bare target with standard tooling plus the community's keys (ADR 0082 §2).
  2. tar --sparse is mandatory. KERIA runs 100 MiB LMDB map size per DB, sparse (docs/research/2026-08-24-keria-stack-on-nixos.md). The in-window copy uses cp -a, which preserves holes; a naive tar would expand every map file to its full 100 MiB and multiply the artifact by an order of magnitude.
  3. Compressed (tar -z or equivalent) — PROPOSED, flagged because it moves DDR 0268's figure. LMDB and mongodump both compress well. Ben may prefer uncompressed for the same "readable with a JSON reader alone" reason kanidm's contract decompresses its export; say so on this ticket and it changes.
  4. The engine refuses a non-file artifact loudly. A contract returning a directory must fail with a named error (ADR 0100), never a bare cat: Is a directory.

Acceptance criteria

  1. internal/keria's identity snapshot returns a single file; its bundle round-trips — tar → seal → target → open → untar — byte-identical, including sparse LMDB map files that do not expand to their full map size.
  2. internal/anysync's content snapshot likewise returns a single file and round-trips.
  3. Each contract's restore/verify-sample path consumes the new form (they currently read a bundle directory) — snapshot → replicate → verify-sample → restore is green end to end at the contract-test tier for both.
  4. Engine.Replicate given a directory artifact fails with a named, honest error; a seam test pins it.
  5. kanidm's Identity contract is unchanged and still replicates — no regression on the one path that works.
  6. docs/GOTCHAS.md gains the sparse-LMDB entry (ADR 0160): symptom = an offsite copy orders of magnitude larger than the live data; cause = tar without --sparse over LMDB map files; rule = the flag.

Replicate holds the whole artifact in memory twice — cat returns the plaintext as []byte, backup.Seal produces the ciphertext as a second []byte, and store.Put takes that slice. Fine for a megabyte JSON export; a ~150 MiB KERIA bundle on a 4 GB gateway is a different proposition, and the catalogue's steady-memory budget (ADR 0243) does not account for it.

Decisions

  • ADR 0104 — port-declared verbs, whole sealed artifacts, no foreign repository format.
  • ADR 0082 §2 — sealed artifacts as plain files beside a self-describing inventory, readable on a bare target.
  • ADR 0201 — the IDIP identity dataset is the quiesce-then-copy keripy root + witness state.
  • DDR 0268 — the two new targets; its decision 5 waits on this.
## The defect `Engine.Replicate` reads a snapshot artifact as **one file**: ```go // internal/backupengine/movement.go:64 plaintext, err := c.Run(ctx, "cat", snapshotRef) ``` But two of the three written backup contracts return a **directory**: | Contract | Snapshot returns | `cat` | | --- | --- | --- | | Identity — kanidm (`internal/backupengine/identity.go`) | a single `identity-XXXXXXXX.json` | ✅ works | | Identity — IDIP / KERIA (`internal/keria/backup.go`) | `mktemp -d` bundle: `keria/`, `keri-witness/`, `roster.json`, `matou-config/`, `blip.json` | ❌ *Is a directory* | | `content` — anysync (`internal/anysync/backup.go:171,226`) | `mktemp -d` bundle: mongodump + minio/tree | ❌ *Is a directory* | **Nothing anywhere tars a bundle** — `grep '"tar"' internal/**/*.go` finds only `install/guestpayload.go`. So the dataset an **IDIP community cannot be re-founded without** can reach **no target at all** — hosted offsite, cross-device, or "This computer" (DDR 0268). Same for `content`. ## Why it is latent, not live `backupengine.WithContract` has **no production caller** — only `cmd/smoke-backups` and `cmd/smoke-fleet`. The whole composition registers `emptyCatalogue`, so only kanidm's built-in Identity contract is reachable on a real gateway today, and that one happens to return a single file. The bug surfaces the moment any bundle contract is registered. ## Why it blocks more than itself DDR 0268 decision 5 (the IDSS offsite storage free-tier allowance) **cannot be settled without this**: the allowance is a size ÷ retention, and there is no snapshot size until a bundle has a single-file form and a compression answer. See that DDR's measured table — KERIA is ~3 MiB of LMDB per member. ## Ruling (agent, ADR 0174 — two-way door, veto anytime) Revertible by a commit and provable by the contract tests, so ruled here rather than parked: 1. **The single-file form is `tar`.** Not a foreign repository format (ADR 0104's refusal stands) — a bundle stays readable on a bare target with standard tooling plus the community's keys (ADR 0082 §2). 2. **`tar --sparse` is mandatory.** KERIA runs **100 MiB LMDB map size per DB, sparse** (`docs/research/2026-08-24-keria-stack-on-nixos.md`). The in-window copy uses `cp -a`, which preserves holes; a naive `tar` would expand every map file to its full 100 MiB and multiply the artifact by an order of magnitude. 3. **Compressed (`tar -z` or equivalent) — PROPOSED, flagged because it moves DDR 0268's figure.** LMDB and mongodump both compress well. Ben may prefer uncompressed for the same "readable with a JSON reader alone" reason kanidm's contract decompresses its export; say so on this ticket and it changes. 4. **The engine refuses a non-file artifact loudly.** A contract returning a directory must fail with a named error (ADR 0100), never a bare `cat: Is a directory`. ## Acceptance criteria 1. `internal/keria`'s identity snapshot returns a **single file**; its bundle round-trips — tar → seal → target → open → untar — byte-identical, including sparse LMDB map files that do **not** expand to their full map size. 2. `internal/anysync`'s `content` snapshot likewise returns a single file and round-trips. 3. Each contract's restore/verify-sample path consumes the **new form** (they currently read a bundle directory) — snapshot → replicate → verify-sample → restore is green end to end at the contract-test tier for both. 4. `Engine.Replicate` given a directory artifact fails with a named, honest error; a seam test pins it. 5. kanidm's Identity contract is **unchanged** and still replicates — no regression on the one path that works. 6. `docs/GOTCHAS.md` gains the sparse-LMDB entry (ADR 0160): symptom = an offsite copy orders of magnitude larger than the live data; cause = `tar` without `--sparse` over LMDB map files; rule = the flag. ## Related, NOT in scope (worth its own ticket if it bites) `Replicate` holds the **whole artifact in memory twice** — `cat` returns the plaintext as `[]byte`, `backup.Seal` produces the ciphertext as a second `[]byte`, and `store.Put` takes that slice. Fine for a megabyte JSON export; a ~150 MiB KERIA bundle on a 4 GB gateway is a different proposition, and the catalogue's steady-memory budget (ADR 0243) does not account for it. ## Decisions - **ADR 0104** — port-declared verbs, whole sealed artifacts, no foreign repository format. - **ADR 0082 §2** — sealed artifacts as plain files beside a self-describing inventory, readable on a bare target. - **ADR 0201** — the IDIP identity dataset is the quiesce-then-copy keripy root + witness state. - **DDR 0268** — the two new targets; its decision 5 waits on this.

swarm-claim host=elitebook-distributed-server-03 run=30978
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=30978 (automated multi-host claim — lowest live claim id works this ticket)

Ruled by agent under ADR 0174 — veto anytime.

Ruling item 3 (compression): the single-file bundle form ships uncompressed (tar --sparse, no -z). Both internal/keria and internal/anysync tar their bundles with backupengine.TarBundle → tar --sparse -cf.

Why this is a two-way door: it is revertible by a one-line change to TarBundle/UntarBundle (add -z / --zstd) and proven either way by the round-trip contract tests (TestSnapshotIsSingleFileAndSparseBundleRoundTrips, TestContentSnapshotIsSingleFileAndSparseBundleRoundTrips). It is not on the one-way-door list.

Why uncompressed by default: the same reason kanidm's Identity contract decompresses its export — a sealed artifact must be readable on a bare target with the community's keys plus standard tooling alone, no decompressor implied by the artifact's own format (ADR 0082 §2). --sparse already collapses the LMDB holes that were the order-of-magnitude blow-up, so the artifact is bounded by real data, not map size.

Ben: if you'd prefer compressed (LMDB + mongodump both compress well, and it would shrink DDR 0268's free-tier size÷retention figure), say so here and it changes — one commit, no data-format migration, since nothing production registers a bundle contract yet.

**Ruled by agent under ADR 0174 — veto anytime.** Ruling item 3 (compression): the single-file bundle form ships **uncompressed** (`tar --sparse`, no `-z`). Both `internal/keria` and `internal/anysync` tar their bundles with `backupengine.TarBundle` → `tar --sparse -cf`. Why this is a two-way door: it is revertible by a one-line change to `TarBundle`/`UntarBundle` (add `-z` / `--zstd`) and proven either way by the round-trip contract tests (`TestSnapshotIsSingleFileAndSparseBundleRoundTrips`, `TestContentSnapshotIsSingleFileAndSparseBundleRoundTrips`). It is not on the one-way-door list. Why uncompressed by default: the same reason kanidm's Identity contract decompresses its export — a sealed artifact must be readable on a bare target with the community's keys **plus standard tooling alone**, no decompressor implied by the artifact's own format (ADR 0082 §2). `--sparse` already collapses the LMDB holes that were the order-of-magnitude blow-up, so the artifact is bounded by real data, not map size. **Ben:** if you'd prefer compressed (LMDB + mongodump both compress well, and it would shrink DDR 0268's free-tier size÷retention figure), say so here and it changes — one commit, no data-format migration, since nothing production registers a bundle contract yet.

close-report for #1802 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 1802,
  "status": "success",
  "commits": [
    "ab399a94"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "internal/anysync/backup.go",
    "internal/anysync/bundle_roundtrip_test.go",
    "internal/backupengine/bundle.go",
    "internal/backupengine/movement.go",
    "internal/backupengine/movement_test.go",
    "internal/keria/backup.go",
    "internal/keria/backup_test.go",
    "internal/keria/bundle_roundtrip_test.go",
    "internal/keria/restore.go",
    "internal/keria/restore_test.go"
  ],
  "tests": [
    {
      "command": "go test ./internal/keria/ ./internal/anysync/ ./internal/backupengine/",
      "exit_code": 0
    },
    {
      "command": "go test ./internal/backup/ ./internal/clan/ ./internal/controlapi/ ./internal/founding/ ./internal/idp/ ./control-plane/cmd/smoke-backups/ ./control-plane/cmd/smoke-fleet/ ./control-plane/cmd/control-plane/",
      "exit_code": 0
    },
    {
      "command": "gofmt -l . ; go build ./... ; go vet ./... ; go build -tags dev ./... ; go vet -tags dev ./... ; (cd broker && go build/vet/test)",
      "exit_code": 0
    }
  ],
  "criteria": {
    "AC1 keria snapshot returns a single file; bundle round-trips tar→seal→target→open→untar byte-identical incl sparse LMDB not expanded": "internal/keria/backup.go (snapshot tars via backupengine.TarBundle, returns <bundle>.tar); TestSnapshotIsSingleFileAndSparseBundleRoundTrips in internal/keria/bundle_roundtrip_test.go",
    "AC2 anysync content snapshot returns a single file and round-trips": "internal/anysync/backup.go (snapshot tars via TarBundle); TestContentSnapshotIsSingleFileAndSparseBundleRoundTrips in internal/anysync/bundle_roundtrip_test.go",
    "AC3 each contract's restore/verify-sample path consumes the new form; snapshot→verify-sample→restore green": "internal/keria/restore.go (restore/restoreInPlace/verifySample unpack the tar via UntarBundle); TestSnapshotVerifyRestoreConsumeTheTarForm + existing TestRestoreInPlace/SideBySide/VerifySample re-pinned to the tar; anysync restore verbs remain deferred (no bundle-dir read)",
    "AC4 Engine.Replicate given a directory artifact fails with a named honest error; seam test pins it": "internal/backupengine/movement.go (ErrArtifactNotFile + `test -d` guard); TestReplicate_RefusesADirectoryArtifact in internal/backupengine/movement_test.go",
    "AC5 kanidm Identity contract unchanged and still replicates — no regression": "internal/backupengine/identity.go untouched; internal/backupengine + smoke-backups/smoke-fleet tests green (single-file fileContract path unaffected by the directory guard)",
    "AC6 docs/GOTCHAS.md gains the sparse-LMDB entry (ADR 0160)": "docs/GOTCHAS.md entry #323 — symptom offsite copy orders of magnitude larger than live data; cause tar without --sparse over LMDB map files; rule the flag (centralised in backupengine.TarBundle)"
  },
  "summary": "Bundle backup contracts (IDIP identity, content) now tar their bundle to a single sparse-aware file so the movement half can seal and replicate it; the engine refuses a directory artifact with a named error.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #1802 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1802, "status": "success", "commits": [ "ab399a94" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "internal/anysync/backup.go", "internal/anysync/bundle_roundtrip_test.go", "internal/backupengine/bundle.go", "internal/backupengine/movement.go", "internal/backupengine/movement_test.go", "internal/keria/backup.go", "internal/keria/backup_test.go", "internal/keria/bundle_roundtrip_test.go", "internal/keria/restore.go", "internal/keria/restore_test.go" ], "tests": [ { "command": "go test ./internal/keria/ ./internal/anysync/ ./internal/backupengine/", "exit_code": 0 }, { "command": "go test ./internal/backup/ ./internal/clan/ ./internal/controlapi/ ./internal/founding/ ./internal/idp/ ./control-plane/cmd/smoke-backups/ ./control-plane/cmd/smoke-fleet/ ./control-plane/cmd/control-plane/", "exit_code": 0 }, { "command": "gofmt -l . ; go build ./... ; go vet ./... ; go build -tags dev ./... ; go vet -tags dev ./... ; (cd broker && go build/vet/test)", "exit_code": 0 } ], "criteria": { "AC1 keria snapshot returns a single file; bundle round-trips tar→seal→target→open→untar byte-identical incl sparse LMDB not expanded": "internal/keria/backup.go (snapshot tars via backupengine.TarBundle, returns <bundle>.tar); TestSnapshotIsSingleFileAndSparseBundleRoundTrips in internal/keria/bundle_roundtrip_test.go", "AC2 anysync content snapshot returns a single file and round-trips": "internal/anysync/backup.go (snapshot tars via TarBundle); TestContentSnapshotIsSingleFileAndSparseBundleRoundTrips in internal/anysync/bundle_roundtrip_test.go", "AC3 each contract's restore/verify-sample path consumes the new form; snapshot→verify-sample→restore green": "internal/keria/restore.go (restore/restoreInPlace/verifySample unpack the tar via UntarBundle); TestSnapshotVerifyRestoreConsumeTheTarForm + existing TestRestoreInPlace/SideBySide/VerifySample re-pinned to the tar; anysync restore verbs remain deferred (no bundle-dir read)", "AC4 Engine.Replicate given a directory artifact fails with a named honest error; seam test pins it": "internal/backupengine/movement.go (ErrArtifactNotFile + `test -d` guard); TestReplicate_RefusesADirectoryArtifact in internal/backupengine/movement_test.go", "AC5 kanidm Identity contract unchanged and still replicates — no regression": "internal/backupengine/identity.go untouched; internal/backupengine + smoke-backups/smoke-fleet tests green (single-file fileContract path unaffected by the directory guard)", "AC6 docs/GOTCHAS.md gains the sparse-LMDB entry (ADR 0160)": "docs/GOTCHAS.md entry #323 — symptom offsite copy orders of magnitude larger than live data; cause tar without --sparse over LMDB map files; rule the flag (centralised in backupengine.TarBundle)" }, "summary": "Bundle backup contracts (IDIP identity, content) now tar their bundle to a single sparse-aware file so the movement half can seal and replicate it; the engine refuses a directory artifact with a named error.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
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
Matou/idss#1802
No description provided.