pp_snapshot silently truncates on a failed blob cp — a truncated before-snapshot false-attributes real machinery as "appeared" (follow-up to #320) #321

Closed
opened 2026-10-30 19:08:07 +00:00 by matou-build-agent · 4 comments

Context

Follow-up to #320 (the go-cache/npm-cache leak fix). #320 exempted the caches and made the snapshot dirs self-reaping, but left pp_snapshot's per-blob cp … 2>/dev/null || true untouched — a distinct soundness concern surfaced while triaging the matou-app-side report (matou-app#766, item 3, flagged "Consider").

Symptom / risk

In protected-paths-lib.sh, every blob copy in pp_snapshot is cp "$f" "$snap/blobs/$key" 2>/dev/null || true, and both snapshot callers in verify-lib.sh wrap pp_snapshot in 2>/dev/null || true. So a failed blob copy (e.g. a /tmp space/quota wall) silently truncates the snapshot: the path gets an index line but no blobs/<key>.

A truncated before-snapshot is the dangerous case. In pp_attributed, a machinery file present after the run but absent from the before-index reads as appeared → pp_enforce deletes it and reds the run as a #445 violation. So a truncated before-snapshot can roll back real machinery no worker touched. The #320 cache-exemption makes the snapshots tiny (a write wall is now far less likely), but the silent-unsoundness shape remains.

Suggested direction (needs TDD)

Not a naive flip of || true to fail-loud — a transient cp failure reddening every run is its own hazard. Prefer: pp_snapshot counts blob-copy failures and exposes them; verify_protected_paths degrades safely when the before-snapshot was truncated (skip rollback / no-op the boundary, log loud) rather than false-attribute every unwritten path as appeared. Decide whether a truncated snapshot hard-fails or degrades-to-unenforced.

Routed here (not matou-app) because protected-paths-lib.sh / verify-lib.sh are factory-vendored (ADR 0180) — the fix lands at the root here and re-vendors to consumers.

## Context Follow-up to #320 (the go-cache/npm-cache leak fix). #320 exempted the caches and made the snapshot dirs self-reaping, but left `pp_snapshot`'s per-blob `cp … 2>/dev/null || true` untouched — a distinct soundness concern surfaced while triaging the matou-app-side report (matou-app#766, item 3, flagged "Consider"). ## Symptom / risk In `protected-paths-lib.sh`, every blob copy in `pp_snapshot` is `cp "$f" "$snap/blobs/$key" 2>/dev/null || true`, and both snapshot callers in `verify-lib.sh` wrap `pp_snapshot` in `2>/dev/null || true`. So a failed blob copy (e.g. a `/tmp` space/quota wall) silently **truncates** the snapshot: the path gets an `index` line but no `blobs/<key>`. A truncated **before**-snapshot is the dangerous case. In `pp_attributed`, a machinery file present after the run but absent from the before-index reads as `appeared` → `pp_enforce` deletes it and reds the run as a #445 violation. So a truncated before-snapshot can **roll back real machinery** no worker touched. The #320 cache-exemption makes the snapshots tiny (a write wall is now far less likely), but the silent-unsoundness shape remains. ## Suggested direction (needs TDD) Not a naive flip of `|| true` to fail-loud — a transient `cp` failure reddening every run is its own hazard. Prefer: `pp_snapshot` **counts** blob-copy failures and exposes them; `verify_protected_paths` **degrades safely** when the before-snapshot was truncated (skip rollback / no-op the boundary, log loud) rather than false-attribute every unwritten path as `appeared`. Decide whether a truncated snapshot hard-fails or degrades-to-unenforced. Routed here (not matou-app) because `protected-paths-lib.sh` / `verify-lib.sh` are factory-vendored (ADR 0180) — the fix lands at the root here and re-vendors to consumers.
Author
Member

swarm-claim host=bens-mac-04 run=25440
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=bens-mac-04 run=25440 (automated multi-host claim — lowest live claim id works this ticket)
Author
Member

Ruled by agent under ADR 0174 — veto anytime.

Decision on the hard-fail vs degrade-to-unenforced fork: a truncated/unsound protected-path snapshot degrades the boundary to unenforced for that one run (loud), it does not hard-fail/RED the run.

Why this is a two-way door: hard-failing on a transient cp/disk wall would RED an otherwise-good run (the ticket flags this as its own hazard), while a false appeared rollback is the worse outcome — it deletes real machinery no worker touched. Degrading is a revertible, test-proven fail-OPEN on a detected I/O fault, logged loud, for one run only — not a durable posture change: git-fence stays the backstop and the next run re-enforces. So it is revertible and provable, not the security-posture widening ADR 0174 reserves for a human.

What proves it: verify-lib-test.sh — a before-snapshot truncated under a failing cp makes verify_protected_paths return 0 with no rollback of a planted machinery edit, VERIFY_PP_VIOLATION unset, no rescue push, and a loud stderr + Mattermost DEGRADED + a protected-path-degraded swarm.db event.

Also folding in #320's correction: the blob cp … || true alone does not flip a path to appeared (the index digest line is written regardless); the genuine truncation is an aborted/partial index write under disk pressure, for which blob-copy failures are the detectable canary. Fix counts/exposes them via a blob_failures completion marker and pp_snapshot_sound.

Ruled by agent under ADR 0174 — veto anytime. **Decision on the hard-fail vs degrade-to-unenforced fork:** a truncated/unsound protected-path snapshot **degrades the boundary to unenforced for that one run (loud)**, it does not hard-fail/RED the run. **Why this is a two-way door:** hard-failing on a transient `cp`/disk wall would RED an otherwise-good run (the ticket flags this as its own hazard), while a false `appeared` rollback is the worse outcome — it deletes real machinery no worker touched. Degrading is a revertible, test-proven fail-OPEN on a **detected** I/O fault, logged loud, for one run only — not a durable posture change: `git-fence` stays the backstop and the next run re-enforces. So it is revertible and provable, not the security-posture widening ADR 0174 reserves for a human. **What proves it:** `verify-lib-test.sh` — a before-snapshot truncated under a failing `cp` makes `verify_protected_paths` return 0 with no rollback of a planted machinery edit, `VERIFY_PP_VIOLATION` unset, no rescue push, and a loud stderr + Mattermost `DEGRADED` + a `protected-path-degraded` swarm.db event. Also folding in #320's correction: the blob `cp … || true` alone does not flip a path to `appeared` (the `index` digest line is written regardless); the genuine truncation is an aborted/partial `index` write under disk pressure, for which blob-copy failures are the detectable canary. Fix counts/exposes them via a `blob_failures` completion marker and `pp_snapshot_sound`.
Author
Member

⏩ independent reviewer for #321 — verdict unauthenticated

review JSON
{
  "verdict": "unauthenticated",
  "findings": []
}
:fast_forward: **independent reviewer** for #321 — verdict `unauthenticated` <details><summary>review JSON</summary> ```json { "verdict": "unauthenticated", "findings": [] } ``` </details>
Author
Member

close-report for #321 — status success

✅ close-report gates passed — every claim verified against the pushed worker branch sandcastle/worker/20261030-141035-c3d689 (pre-land — the host promotes it to main only after its post-run verify, #193/#283); issue closed.

envelope
{
  "issue": 321,
  "status": "success",
  "commits": [
    "5b42a83d93c539c074fc34d9a870942b3c39e3ad"
  ],
  "changed_files": [
    "protected-paths-lib.sh",
    "verify-lib.sh",
    "tests/protected-paths-lib-test.sh",
    "tests/verify-lib-test.sh",
    "docs/journal/2026-10-30-321-pp-snapshot-truncation-degrade.md"
  ],
  "tests": [
    {
      "command": "bash tests/protected-paths-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/verify-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/run-swarm-stages-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh",
      "exit_code": 0
    }
  ],
  "criteria": {
    "pp_snapshot counts blob-copy failures and exposes them": "protected-paths-lib.sh pp_snapshot now counts each failed blob cp and writes the count to a `blob_failures` marker (written last, so it doubles as a completion sentinel); accessors pp_blob_failures/pp_snapshot_sound. Proven by tests/protected-paths-lib-test.sh (failing-cp shim: non-zero return, counted failures, index line NOT dropped, absent marker not sound).",
    "verify_protected_paths degrades safely on a truncated snapshot (skip rollback / no-op the boundary, log loud) rather than false-attribute": "verify-lib.sh: verify_pp_snapshot sets VERIFY_PP_BEFORE_TRUNCATED when the before-snapshot is not sound; verify_protected_paths no-ops the boundary (rc 0, no rollback, VERIFY_PP_VIOLATION unset, no rescue push), logs loud to stderr, records a protected-path-degraded swarm.db event, and warns Mattermost. Proven by tests/verify-lib-test.sh (truncated before-snapshot degrades; planted machinery edit NOT rolled back).",
    "Decide whether a truncated snapshot hard-fails or degrades-to-unenforced": "Ruled degrade-to-unenforced (loud, one run) under ADR 0174 as a revertible, test-proven fail-OPEN on a detected I/O fault, not a posture change — ruling posted to the issue (comment 66321) and recorded in docs/journal/2026-10-30-321-pp-snapshot-truncation-degrade.md."
  },
  "summary": "A truncated/unsound protected-path snapshot now degrades the #445 boundary to unenforced (loud) instead of false-attributing untouched machinery as `appeared` and rolling it back; pp_snapshot counts and exposes blob-copy failures via a completion marker.",
  "reason": "",
  "blockers": [],
  "no_code_change": ""
}
**close-report** for #321 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against the pushed worker branch `sandcastle/worker/20261030-141035-c3d689` (pre-land — the host promotes it to `main` only after its post-run verify, #193/#283); issue closed. <details><summary>envelope</summary> ```json { "issue": 321, "status": "success", "commits": [ "5b42a83d93c539c074fc34d9a870942b3c39e3ad" ], "changed_files": [ "protected-paths-lib.sh", "verify-lib.sh", "tests/protected-paths-lib-test.sh", "tests/verify-lib-test.sh", "docs/journal/2026-10-30-321-pp-snapshot-truncation-degrade.md" ], "tests": [ { "command": "bash tests/protected-paths-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/verify-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/run-swarm-stages-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/vendor-manifest-coverage-test.sh", "exit_code": 0 } ], "criteria": { "pp_snapshot counts blob-copy failures and exposes them": "protected-paths-lib.sh pp_snapshot now counts each failed blob cp and writes the count to a `blob_failures` marker (written last, so it doubles as a completion sentinel); accessors pp_blob_failures/pp_snapshot_sound. Proven by tests/protected-paths-lib-test.sh (failing-cp shim: non-zero return, counted failures, index line NOT dropped, absent marker not sound).", "verify_protected_paths degrades safely on a truncated snapshot (skip rollback / no-op the boundary, log loud) rather than false-attribute": "verify-lib.sh: verify_pp_snapshot sets VERIFY_PP_BEFORE_TRUNCATED when the before-snapshot is not sound; verify_protected_paths no-ops the boundary (rc 0, no rollback, VERIFY_PP_VIOLATION unset, no rescue push), logs loud to stderr, records a protected-path-degraded swarm.db event, and warns Mattermost. Proven by tests/verify-lib-test.sh (truncated before-snapshot degrades; planted machinery edit NOT rolled back).", "Decide whether a truncated snapshot hard-fails or degrades-to-unenforced": "Ruled degrade-to-unenforced (loud, one run) under ADR 0174 as a revertible, test-proven fail-OPEN on a detected I/O fault, not a posture change — ruling posted to the issue (comment 66321) and recorded in docs/journal/2026-10-30-321-pp-snapshot-truncation-degrade.md." }, "summary": "A truncated/unsound protected-path snapshot now degrades the #445 boundary to unenforced (loud) instead of false-attributing untouched machinery as `appeared` and rolling it back; pp_snapshot counts and exposes blob-copy failures via a completion marker.", "reason": "", "blockers": [], "no_code_change": "" } ``` </details>
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
Matou/dev-factory#321
No description provided.