Protected-paths enforcement: tree-fingerprint diff around swarm workers, rollback + loud fail #445

Closed
opened 2026-08-11 22:16:04 +00:00 by ben · 2 comments
Owner

Context

Learning L3 of docs/research/2026-08-11-software-factory-learnings.md: git-fence blocks specific commands by name (a
blocklist), but nothing stops a worker from editing the machinery that judges
its work — .sandcastle/ scripts, .forgejo/ workflows, git admin dirs. #239
(in-sandbox git worktree repair corrupting shared .git/worktrees) and the
93c6afb regression were both this class. SSSF enforces a boundary on
outcomes: fingerprint the tree before/after the agent, attribute every
appeared/vanished/changed path to it, roll back unauthorized changes, fail the
phase loudly. Comparing change-sets (not watching writes) also catches
git checkout reverts.

What to build

In the swarm harness, around each worker run:

  1. Before the worker starts: snapshot the change-set
    (git status --porcelain + HEAD sha; include .forgejo/ and
    .sandcastle/ explicitly).
  2. After the worker finishes (including any retry/correction sends):
    snapshot again and diff the two.
  3. Any change the worker introduced under the protected set —
    .sandcastle/, .forgejo/, .git/ admin paths (hooks, worktrees,
    config) — is rolled back (tracked: git checkout --; untracked: delete)
    and the run FAILS loudly naming every path and what happened to it.
  4. Paths already dirty before the worker ran are left untouched — another
    session's uncommitted work must never be collateral (shared-worktree
    hazard).
  5. git-fence stays as defence-in-depth; it is no longer the boundary.

Caveat — the escape path (REQUIRED, ruled by Ben 2026-08-11)

A worker will sometimes be right that the machinery needs changing. When a
swarm worker, in the course of any ticket, identifies an improvement or bug
fix required in a protected path, it must NOT edit the protected path.
Instead it must:

  1. File a separate Forgejo issue describing the needed machinery change —
    symptom, proposed fix, and the ticket it was working when it found it;
  2. Label that issue ready-for-human (the human-requirement label) — a
    human rules on machinery changes before any agent touches them;
  3. Continue its original ticket without the machinery change if possible,
    or report blocked in its close report naming the filed issue.

This escape path must be spelled out in the worker prompt so the worker
routes instead of improvising, and the enforcement failure message must
point to it ("protected path — file a ready-for-human issue instead").

Acceptance criteria

  • Fingerprint snapshot/diff/rollback library in .sandcastle/ with tests
    under .sandcastle/tests/ (fixture: worker writes into .sandcastle/,
    run rolls it back and fails naming the path)
  • Revert-detection fixture: a protected file modified-then-reverted by the
    worker is attributed and reported
  • Pre-existing dirty paths are provably untouched by rollback (fixture)
  • Worker prompt carries the escape path verbatim (separate issue +
    ready-for-human label)
  • Enforcement failure message names the escape path
  • Healer's own "never edits itself" rule unchanged; healer evidence dirs
    exempted from the protected set (they are runtime, not machinery)

References

  • docs/research/2026-08-11-software-factory-learnings.md (L3)
  • SSSF adw_modules/permissions.py + references/config.md
    ("writes and protected_files") in disler/super-simple-software-factory
  • #239, GOTCHAS §16–17 for the incident class
## Context Learning L3 of `docs/research/2026-08-11-software-factory-learnings.md`: `git-fence` blocks specific commands by name (a blocklist), but nothing stops a worker from editing the machinery that judges its work — `.sandcastle/` scripts, `.forgejo/` workflows, git admin dirs. #239 (in-sandbox `git worktree repair` corrupting shared `.git/worktrees`) and the 93c6afb regression were both this class. SSSF enforces a boundary on **outcomes**: fingerprint the tree before/after the agent, attribute every appeared/vanished/changed path to it, roll back unauthorized changes, fail the phase loudly. Comparing change-sets (not watching writes) also catches `git checkout` reverts. ## What to build In the swarm harness, around each worker run: 1. **Before** the worker starts: snapshot the change-set (`git status --porcelain` + HEAD sha; include `.forgejo/` and `.sandcastle/` explicitly). 2. **After** the worker finishes (including any retry/correction sends): snapshot again and diff the two. 3. Any change the worker **introduced** under the protected set — `.sandcastle/`, `.forgejo/`, `.git/` admin paths (hooks, worktrees, config) — is rolled back (tracked: `git checkout --`; untracked: delete) and the run FAILS loudly naming every path and what happened to it. 4. Paths already dirty **before** the worker ran are left untouched — another session's uncommitted work must never be collateral (shared-worktree hazard). 5. `git-fence` stays as defence-in-depth; it is no longer the boundary. ## Caveat — the escape path (REQUIRED, ruled by Ben 2026-08-11) A worker will sometimes be *right* that the machinery needs changing. When a swarm worker, in the course of any ticket, identifies an improvement or bug fix required in a protected path, it must NOT edit the protected path. Instead it must: 1. **File a separate Forgejo issue** describing the needed machinery change — symptom, proposed fix, and the ticket it was working when it found it; 2. **Label that issue `ready-for-human`** (the human-requirement label) — a human rules on machinery changes before any agent touches them; 3. Continue its original ticket without the machinery change if possible, or report `blocked` in its close report naming the filed issue. This escape path must be spelled out in the worker prompt so the worker routes instead of improvising, and the enforcement failure message must point to it ("protected path — file a ready-for-human issue instead"). ## Acceptance criteria - [ ] Fingerprint snapshot/diff/rollback library in `.sandcastle/` with tests under `.sandcastle/tests/` (fixture: worker writes into `.sandcastle/`, run rolls it back and fails naming the path) - [ ] Revert-detection fixture: a protected file modified-then-reverted by the worker is attributed and reported - [ ] Pre-existing dirty paths are provably untouched by rollback (fixture) - [ ] Worker prompt carries the escape path verbatim (separate issue + `ready-for-human` label) - [ ] Enforcement failure message names the escape path - [ ] Healer's own "never edits itself" rule unchanged; healer evidence dirs exempted from the protected set (they are runtime, not machinery) ## References - `docs/research/2026-08-11-software-factory-learnings.md` (L3) - SSSF `adw_modules/permissions.py` + `references/config.md` ("writes and protected_files") in `disler/super-simple-software-factory` - #239, GOTCHAS §16–17 for the incident class
Author
Owner

swarm-claim host=matou-dev-server-01 run=4824
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=4824 (automated multi-host claim — lowest live claim id works this ticket)
Author
Owner

Landed in e57b0e2 on main.

What shipped (all acceptance criteria):

  • .sandcastle/protected-paths-lib.sh — the fingerprint snapshot/diff/rollback library (SSSF permissions.py model). pp_snapshot fingerprints every file under .sandcastle/+.forgejo/ by sha256 of its working-tree bytes (plus a blob copy for restore); pp_attributed diffs before/after change-sets naming every protected path that appeared/vanished/changed (change-set comparison catches a git checkout revert); pp_rollback restores each to its pre-run content (created→deleted, changed/deleted→restored); pp_enforce composes them and fails loud naming each path AND the escape path.
  • .sandcastle/tests/protected-paths-lib-test.sh — 27 checks: create rolled-back-and-named (fixture: worker writes into .sandcastle/), revert attributed with pre-run content restored, pre-existing dirty protected+non-protected paths provably untouched by rollback, exempt runtime not attributed.
  • Worker prompt (prompt.md rule 9) carries the escape path verbatim (file a separate ready-for-human issue, do not edit the machinery).
  • Enforcement failure banner names the escape path ("file a ready-for-human issue instead").
  • Healer evidence dirs exempt (PP_EXEMPT_GLOBS default *matou-heal-*); the healer’s own "never edits itself" rails are unchanged.

Wiring: run-swarm.sh snapshots before/after the sandcastle run and enforces behind PP_ENFORCE (default OFF). Rationale: the ordinary swarm still runs machinery tickets directly today (this very commit is one), so a live rollback would revert legitimate work — the flip to PP_ENFORCE=1 is a one-line cutover once machinery is routed through the human-gated escape path. git-fence stays as defence-in-depth.

.git/ admin is declared protected (pp_is_protected returns true) but deliberately not fingerprinted by default — the host churns .git/ under normal git ops; that dir stays git-fence’s job.

Follow-ups (noted in STATUS.md): cross-repo manifest propagation to matou-app; the PP_ENFORCE=1 cutover.

Landed in `e57b0e2` on `main`. **What shipped (all acceptance criteria):** - `.sandcastle/protected-paths-lib.sh` — the fingerprint snapshot/diff/rollback library (SSSF `permissions.py` model). `pp_snapshot` fingerprints every file under `.sandcastle/`+`.forgejo/` by sha256 of its working-tree bytes (plus a blob copy for restore); `pp_attributed` diffs before/after change-sets naming every protected path that appeared/vanished/changed (change-set comparison catches a `git checkout` revert); `pp_rollback` restores each to its pre-run content (created→deleted, changed/deleted→restored); `pp_enforce` composes them and fails loud naming each path AND the escape path. - `.sandcastle/tests/protected-paths-lib-test.sh` — 27 checks: **create** rolled-back-and-named (fixture: worker writes into `.sandcastle/`), **revert** attributed with pre-run content restored, **pre-existing dirty** protected+non-protected paths provably untouched by rollback, exempt runtime not attributed. - Worker prompt (`prompt.md` rule 9) carries the escape path verbatim (file a separate `ready-for-human` issue, do not edit the machinery). - Enforcement failure banner names the escape path ("file a ready-for-human issue instead"). - Healer evidence dirs exempt (`PP_EXEMPT_GLOBS` default `*matou-heal-*`); the healer’s own "never edits itself" rails are unchanged. **Wiring:** `run-swarm.sh` snapshots before/after the sandcastle run and enforces behind `PP_ENFORCE` (default OFF). Rationale: the ordinary swarm still runs machinery tickets directly today (this very commit is one), so a live rollback would revert legitimate work — the flip to `PP_ENFORCE=1` is a one-line cutover once machinery is routed through the human-gated escape path. `git-fence` stays as defence-in-depth. **`.git/` admin** is *declared* protected (`pp_is_protected` returns true) but deliberately not fingerprinted by default — the host churns `.git/` under normal git ops; that dir stays git-fence’s job. **Follow-ups (noted in STATUS.md):** cross-repo manifest propagation to matou-app; the `PP_ENFORCE=1` cutover.
ben closed this issue 2026-08-12 00:16:04 +00:00
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/idss#445
No description provided.