Protected-path boundary exempts .sandcastle/ runtime artifacts (#272) #275

Closed
matou-build-agent wants to merge 1 commit from agent/issue-272 into main

closes #272

What

Fix the #445 protected-path boundary false-positive that reds every
dev-factory swarm run with a live worker (run 22723, both matrix legs): the
worker's own host-side log .sandcastle/logs/…-worker.log — opened by
sandcastle after the before-snapshot — is always appeared in the
after-snapshot and mis-attributed to the worker, and the rollback then
DELETES it, destroying the incident's own heal-bundle forensics.

How

  • protected-paths-lib.sh: extend PP_EXEMPT_GLOBS_DEFAULT with the runtime
    set .sandcastle/.gitignore already declares never-committed, anchored
    under .sandcastle/
    (logs/, worktrees/, pnpm-store/, nix-store/,
    .state/, .env, top-level + nested __pycache__/) — never a bare
    *logs/*, so a worker cannot hide a machinery edit under an invented
    runtime-looking dir.
  • secrets/ split deliberately: the runtime token files (secrets/*_token,
    rewritten mid-run by a Claude-account failover) are exempt — this also stops
    the live token bytes being blob-copied into two mktemp dirs per run; the
    one TRACKED file secrets/README.md is not a *_token and stays machinery.
  • Harden pp_is_protected: word-split $PP_EXEMPT_GLOBS with pathname
    expansion disabled (set -f, restored), since several default globs match
    files that EXIST in a live run's CWD and would otherwise glob-expand to real
    filenames and silently drop the exemption.

Tests

tests/protected-paths-lib-test.sh +21 → 52 checks (red-first): the worker's
own log is not attributed and survives rollback; a real .sandcastle/run-swarm.sh
edit ALONGSIDE the exempt log still fires and rolls back; a mid-run token
rewrite is not a false changed and token bytes are never blob-copied; the
secrets/README.md + anchoring exemptions resolve correctly; and the
CWD-pathname-expansion guard is proven necessary. Full offline suite green
(the one pre-existing rehearsal-heal-lib-test.sh failure is on main too,
outside this slice).

Blast radius

Root protected-paths-lib.sh only — INERT in the running .sandcastle/
self-copy and every consumer until a human re-vendors + bumps FACTORY_REF
(GOTCHAS 4). Until vendored, every dev-factory run with a live worker reds;
break-glass is PP_ENFORCE=0 in the host's .sandcastle/.env (a human
decision). GOTCHAS 75 added.

Screenshots: none — a shell boundary-lib fix with no visible surface; the behaviour is proven by the offline red-first tests above.

closes #272 ## What Fix the #445 protected-path boundary false-positive that reds **every** dev-factory swarm run with a live worker (run 22723, both matrix legs): the worker's own host-side log `.sandcastle/logs/…-worker.log` — opened by sandcastle *after* the before-snapshot — is always `appeared` in the after-snapshot and mis-attributed to the worker, and the rollback then DELETES it, destroying the incident's own heal-bundle forensics. ## How - `protected-paths-lib.sh`: extend `PP_EXEMPT_GLOBS_DEFAULT` with the runtime set `.sandcastle/.gitignore` already declares never-committed, **anchored under `.sandcastle/`** (`logs/`, `worktrees/`, `pnpm-store/`, `nix-store/`, `.state/`, `.env`, top-level + nested `__pycache__/`) — never a bare `*logs/*`, so a worker cannot hide a machinery edit under an invented runtime-looking dir. - `secrets/` split deliberately: the runtime token files (`secrets/*_token`, rewritten mid-run by a Claude-account failover) are exempt — this also stops the live token bytes being blob-copied into two `mktemp` dirs per run; the one TRACKED file `secrets/README.md` is not a `*_token` and stays machinery. - Harden `pp_is_protected`: word-split `$PP_EXEMPT_GLOBS` with pathname expansion disabled (`set -f`, restored), since several default globs match files that EXIST in a live run's CWD and would otherwise glob-expand to real filenames and silently drop the exemption. ## Tests `tests/protected-paths-lib-test.sh` +21 → 52 checks (red-first): the worker's own log is not attributed and survives rollback; a real `.sandcastle/run-swarm.sh` edit ALONGSIDE the exempt log still fires and rolls back; a mid-run token rewrite is not a false `changed` and token bytes are never blob-copied; the `secrets/README.md` + anchoring exemptions resolve correctly; and the CWD-pathname-expansion guard is proven necessary. Full offline suite green (the one pre-existing `rehearsal-heal-lib-test.sh` failure is on `main` too, outside this slice). ## Blast radius Root `protected-paths-lib.sh` only — **INERT** in the running `.sandcastle/` self-copy and every consumer until a human re-vendors + bumps `FACTORY_REF` (GOTCHAS 4). Until vendored, every dev-factory run with a live worker reds; break-glass is `PP_ENFORCE=0` in the host's `.sandcastle/.env` (a human decision). GOTCHAS 75 added. **Screenshots:** none — a shell boundary-lib fix with no visible surface; the behaviour is proven by the offline red-first tests above.
sandcastle: #272 — protected-path boundary exempts .sandcastle/ runtime artifacts (worker's own log, caches, tokens)
All checks were successful
ci / static (pull_request) Successful in 2m9s
ci / test (pull_request) Successful in 5m3s
5ce509a56f
The #445 outcome boundary fingerprints the whole .sandcastle tree as
machinery, but the tree also holds the pure runtime set .sandcastle/.gitignore
already declares never-committed. The before-snapshot is taken before
sandcastle opens the worker's own host-side log, so .sandcastle/logs/...-worker.log
is always `appeared` after the run and mis-attributed to the worker — every
#445-enforcing run with a live worker red (run 22723, both legs), and the
rollback DELETED the log, eating the heal bundle's forensics.

Key decisions:
- Extend PP_EXEMPT_GLOBS_DEFAULT with the runtime set, ANCHORED under
  .sandcastle/ (logs/, worktrees/, pnpm-store/, nix-store/, .state/, .env,
  top-level + nested __pycache__/) — never a bare */logs/*, so a worker
  cannot hide a machinery edit under an invented runtime-looking dir.
- secrets/ split deliberately: the runtime token files (secrets/*_token,
  rewritten mid-run by a Claude-account failover) are exempt — stops the false
  `changed` violation and stops the live token bytes being blob-copied into two
  mktemp dirs per run; the one TRACKED file secrets/README.md is not a *_token
  and stays machinery (still caught).
- Harden pp_is_protected: word-split $PP_EXEMPT_GLOBS with pathname expansion
  disabled (set -f, restored to the caller's prior state), since several default
  globs match files that EXIST in a live run's CWD and would otherwise
  glob-expand to real filenames and silently drop the exemption.

Files:
- protected-paths-lib.sh — exempt globs + the set -f guard + header docs.
- tests/protected-paths-lib-test.sh — +21 → 52 checks (red-first): worker log
  not attributed and survives rollback; a real run-swarm.sh edit alongside it
  still fires and rolls back; mid-run token rewrite is not a violation and token
  bytes are never blob-copied; README/anchoring exemptions; the CWD glob-expansion
  guard proven necessary.
- docs/gotchas/75-*.md + index row; docs/journal/2026-10-16-272.md; STATUS.md header.

Root only — INERT in the running .sandcastle/ self-copy and every consumer
until a human re-vendors + bumps FACTORY_REF (GOTCHAS 4). Until then every
dev-factory run with a live worker reds; break-glass PP_ENFORCE=0 in the host's
.sandcastle/.env (a human decision). Related: #445, #208, #251.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Factory-Account: d631bd58e1e9
Author
Member
close-report gates passed for #272 — every claim verified; this PR is cleared for merge.
<!-- close-report: gates-passed --> close-report gates passed for #272 — every claim verified; this PR is cleared for merge.
Owner

Superseded, closed unmerged (Ben, 2026-10-17). #272's runtime-artifact exemptions landed through #280 (a4be7db) and #284(a) (14cf51f, cache trees); the wider .env/*_token exemptions this PR's 5ce509a carried are deliberately deferred to #284 (ready-for-human) for Ben's ruling. #272 is closed. Nothing to merge here; #284 is where the remainder is decided.

Superseded, closed unmerged (Ben, 2026-10-17). #272's runtime-artifact exemptions landed through #280 (`a4be7db`) and #284(a) (`14cf51f`, cache trees); the wider `.env`/`*_token` exemptions this PR's `5ce509a` carried are deliberately deferred to #284 (`ready-for-human`) for Ben's ruling. #272 is closed. Nothing to merge here; #284 is where the remainder is decided.
ben closed this pull request 2026-10-17 19:37:47 +00:00
All checks were successful
ci / static (pull_request) Successful in 2m9s
ci / test (pull_request) Successful in 5m3s

Pull request closed

Sign in to join this conversation.
No reviewers
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/dev-factory!275
No description provided.