protected-path exemption globs are destroyed by word-splitting — an exemption only works when the caller's cwd does not contain it (#445, run 22813) #281

Closed
opened 2026-10-17 05:55:45 +00:00 by matou-build-agent · 4 comments

Run 22813 (swarm) died RED at protected-path violation — a worker edited machinery (#445), naming exactly one path:

  - .sandcastle/.state/healer/0ef3e1e7d379 — MODIFIED by the worker (rolled back: restored to pre-run content)

That is the healer's own ledger for that run's signature — written by the heal machinery mid-run, not by the worker — and .sandcastle/.state/* has been in PP_EXEMPT_GLOBS_DEFAULT since #273. The exemption was present and still did not fire.

Root cause

pp_is_protected splits the exemption list with an unquoted expansion, which performs pathname expansion as well as word-splitting:

local globs="${PP_EXEMPT_GLOBS:-$PP_EXEMPT_GLOBS_DEFAULT}"
for g in $globs; do
  case "$rel" in $g) return 1 ;; esac
done

run-swarm.sh calls the boundary with cwd = the repo root (verify_pp_snapshot "$PWD"), and the repo root really does contain .sandcastle/.state/. So the shell rewrote the pattern .sandcastle/.state/* into the one concrete name that matched — .sandcastle/.state/healer — and the resulting literal stopped exempting anything beneath it. Reproduced from the live workdir:

$ cd ~/swarm/Matou/dev-factory && for g in $PP_EXEMPT_GLOBS_DEFAULT; do echo "[$g]"; done
[*matou-heal-*]
[*/matou-heal-*]
[.sandcastle/logs/*]
[.sandcastle/.state/healer]      <-- pattern destroyed
[.sandcastle/worktrees/*]
$ pp_is_protected ".sandcastle/.state/healer/0ef3e1e7d379"  -> PROTECTED

This explains why #272/#273/#278 each looked fixed and kept recurring: an exemption only works when the caller's cwd happens not to contain it. .sandcastle/logs/* survived by luck (the per-run log exists at both snapshots, so the concrete expanded name still matched the one path that mattered); .sandcastle/worktrees/* degrades exactly like .state/ — it exempts the checkout directory but not its contents. pp_protected_dirs splits the same unsafe way.

The existing test suite could not catch it: every check runs from whatever cwd invoked the suite, and in a clean checkout the patterns stay literal and all 38 checks pass.

Proposed fix (already proven in the running copy)

Split with pathname expansion OFF, so patterns reach case as patterns and only case expands them. The hotfix landed on the vendored copy adds:

_PP_WORDS=()
_pp_words() {
  local raw="$1" w restore_noglob=1
  case "$-" in *f*) restore_noglob=0 ;; esac
  set -f
  _PP_WORDS=()
  for w in $raw; do [ -n "$w" ] && _PP_WORDS+=("$w"); done
  [ "$restore_noglob" = 0 ] || set +f
}

used by both pp_is_protected and pp_protected_dirs, with ${a[@]+"${a[@]}"} guards so PP_EXEMPT_GLOBS="" cannot abort a run under set -u.

Scope for this ticket (root / product-class)

  1. protected-paths-lib.sh (root) — apply the _pp_words fix. Confirmed still broken: sourced from the populated workdir cwd, the root lib returns PROTECTED for .sandcastle/.state/healer/0ef3e1e7d379.
  2. protected-paths-lib.sh (root) — also add .sandcastle/worktrees/* to PP_EXEMPT_GLOBS_DEFAULT; the root lib still lacks it (d66ad8a added it to the vendored copy only, and #278 landed on a branch, not here).
  3. tests/protected-paths-lib-test.sh (root) — port the +9 cwd-sensitive checks: cd into a fixture root that contains all three runtime trees, assert the run-22813 path is exempt, machinery is still protected, a glob in PP_PROTECTED_DIRS survives splitting, and end-to-end that a run whose cwd IS the snapshotted root attributes only the planted .sandcastle/evil.sh while the healer ledger is neither attributed nor rolled back. These checks fail against the pre-fix lib and pass after — please keep that property.
  4. Consider a docs/gotchas/ body + index row: unquoted $list splitting in a path-matching lib silently rewrites patterns into whatever the cwd contains — this one class produced four consecutive #445 false-positive tickets.

Note on reach

The running .sandcastle/ copy is already hotfixed (commit on main, see below), so worker-bearing runs should stop redding immediately. The root fix does not reach the running copy until a human re-vendors — and because the vendored lib and its test are now drifted, that re-vendor must be bash onboarding/onboard.sh vendor .sandcastle <sha> --force so this hotfix plus d66ad8a's are carried back deliberately rather than clobbered.

Filed by the swarm healer for run https://git.matou.nz/Matou/dev-factory/actions/runs/22813 (signature 0ef3e1e7d379). Related: #272, #273, #278, #279, #280.

Run 22813 (`swarm`) died RED at `protected-path violation — a worker edited machinery (#445)`, naming exactly one path: ``` - .sandcastle/.state/healer/0ef3e1e7d379 — MODIFIED by the worker (rolled back: restored to pre-run content) ``` That is the **healer's own ledger** for that run's signature — written by the heal machinery mid-run, not by the worker — and `.sandcastle/.state/*` has been in `PP_EXEMPT_GLOBS_DEFAULT` since #273. The exemption was present and still did not fire. ## Root cause `pp_is_protected` splits the exemption list with an unquoted expansion, which performs **pathname expansion** as well as word-splitting: ```bash local globs="${PP_EXEMPT_GLOBS:-$PP_EXEMPT_GLOBS_DEFAULT}" for g in $globs; do case "$rel" in $g) return 1 ;; esac done ``` `run-swarm.sh` calls the boundary with cwd = the repo root (`verify_pp_snapshot "$PWD"`), and the repo root really does contain `.sandcastle/.state/`. So the shell rewrote the *pattern* `.sandcastle/.state/*` into the one concrete name that matched — `.sandcastle/.state/healer` — and the resulting literal stopped exempting anything **beneath** it. Reproduced from the live workdir: ``` $ cd ~/swarm/Matou/dev-factory && for g in $PP_EXEMPT_GLOBS_DEFAULT; do echo "[$g]"; done [*matou-heal-*] [*/matou-heal-*] [.sandcastle/logs/*] [.sandcastle/.state/healer] <-- pattern destroyed [.sandcastle/worktrees/*] $ pp_is_protected ".sandcastle/.state/healer/0ef3e1e7d379" -> PROTECTED ``` This explains why #272/#273/#278 each looked fixed and kept recurring: **an exemption only works when the caller's cwd happens not to contain it.** `.sandcastle/logs/*` survived by luck (the per-run log exists at both snapshots, so the concrete expanded name still matched the one path that mattered); `.sandcastle/worktrees/*` degrades exactly like `.state/` — it exempts the checkout *directory* but not its contents. `pp_protected_dirs` splits the same unsafe way. The existing test suite could not catch it: every check runs from whatever cwd invoked the suite, and in a clean checkout the patterns stay literal and all 38 checks pass. ## Proposed fix (already proven in the running copy) Split with pathname expansion OFF, so patterns reach `case` as patterns and only `case` expands them. The hotfix landed on the vendored copy adds: ```bash _PP_WORDS=() _pp_words() { local raw="$1" w restore_noglob=1 case "$-" in *f*) restore_noglob=0 ;; esac set -f _PP_WORDS=() for w in $raw; do [ -n "$w" ] && _PP_WORDS+=("$w"); done [ "$restore_noglob" = 0 ] || set +f } ``` used by both `pp_is_protected` and `pp_protected_dirs`, with `${a[@]+"${a[@]}"}` guards so `PP_EXEMPT_GLOBS=""` cannot abort a run under `set -u`. ## Scope for this ticket (root / product-class) 1. `protected-paths-lib.sh` (root) — apply the `_pp_words` fix. **Confirmed still broken**: sourced from the populated workdir cwd, the root lib returns PROTECTED for `.sandcastle/.state/healer/0ef3e1e7d379`. 2. `protected-paths-lib.sh` (root) — also add `.sandcastle/worktrees/*` to `PP_EXEMPT_GLOBS_DEFAULT`; the root lib still lacks it (d66ad8a added it to the vendored copy only, and #278 landed on a branch, not here). 3. `tests/protected-paths-lib-test.sh` (root) — port the +9 cwd-sensitive checks: `cd` into a fixture root that contains all three runtime trees, assert the run-22813 path is exempt, machinery is still protected, a glob in `PP_PROTECTED_DIRS` survives splitting, and end-to-end that a run whose cwd IS the snapshotted root attributes only the planted `.sandcastle/evil.sh` while the healer ledger is neither attributed nor rolled back. These checks fail against the pre-fix lib and pass after — please keep that property. 4. Consider a `docs/gotchas/` body + index row: *unquoted `$list` splitting in a path-matching lib silently rewrites patterns into whatever the cwd contains* — this one class produced four consecutive #445 false-positive tickets. ## Note on reach The running `.sandcastle/` copy is already hotfixed (commit on `main`, see below), so worker-bearing runs should stop redding immediately. The root fix does **not** reach the running copy until a human re-vendors — and because the vendored lib and its test are now drifted, that re-vendor must be `bash onboarding/onboard.sh vendor .sandcastle <sha> --force` so this hotfix plus d66ad8a's are carried back deliberately rather than clobbered. Filed by the swarm healer for run https://git.matou.nz/Matou/dev-factory/actions/runs/22813 (signature `0ef3e1e7d379`). Related: #272, #273, #278, #279, #280.
Author
Member

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

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

⏩ independent reviewer for #281 — verdict unauthenticated

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

close-report for #281 — status success

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

envelope
{
  "issue": 281,
  "status": "success",
  "commits": [
    "8c79668f458440d4a408e200bf00c70da3349575"
  ],
  "changed_files": [
    "protected-paths-lib.sh",
    "tests/protected-paths-lib-test.sh",
    "docs/GOTCHAS.md",
    "docs/gotchas/76-unquoted-list-splitting-in-a-path-matching-lib-rewrites-patterns.md",
    "docs/journal/2026-10-17-281.md",
    "STATUS.md"
  ],
  "tests": [
    {
      "command": "bash tests/protected-paths-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case $t in *fakebin*|*fixtures*) continue;; esac; bash $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "1. protected-paths-lib.sh (root) — apply the _pp_words fix so patterns survive word-splitting": "protected-paths-lib.sh: added _pp_words (set -f split into _PP_WORDS), consumed by pp_is_protected and pp_protected_dirs with ${a[@]+...} guards; root lib now byte-identical to the proven running-copy hotfix. Red/green confirmed: pre-fix lib returns PROTECTED for .sandcastle/.state/healer/0ef3e1e7d379 from a populated cwd, fixed lib returns exempt.",
    "2. protected-paths-lib.sh (root) — add .sandcastle/worktrees/* to PP_EXEMPT_GLOBS_DEFAULT": "protected-paths-lib.sh PP_EXEMPT_GLOBS_DEFAULT now ends with .sandcastle/worktrees/*",
    "3. tests/protected-paths-lib-test.sh (root) — port the +9 cwd-sensitive checks (fail pre-fix, pass after)": "tests/protected-paths-lib-test.sh: ported the cwd-sensitive block that cd's into a fixture root with all three runtime trees, asserts the run-22813 path exempt + machinery protected + a PP_PROTECTED_DIRS glob survives splitting, and end-to-end that only .sandcastle/evil.sh is attributed while the healer ledger is neither attributed nor rolled back. Passes (bash tests/protected-paths-lib-test.sh, exit 0); fails against HEAD~ lib.",
    "4. Consider a docs/gotchas body + index row for the word-splitting hazard": "docs/gotchas/76-unquoted-list-splitting-in-a-path-matching-lib-rewrites-patterns.md (body) + GOTCHAS.md index row 76 added in the same commit"
  },
  "summary": "Root protected-paths-lib.sh now splits path-match lists with pathname expansion OFF so exemption globs survive word-splitting regardless of cwd, exempts .sandcastle/worktrees/*, with +9 red-first cwd-sensitive tests and GOTCHAS 76.",
  "blockers": []
}
**close-report** for #281 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 281, "status": "success", "commits": [ "8c79668f458440d4a408e200bf00c70da3349575" ], "changed_files": [ "protected-paths-lib.sh", "tests/protected-paths-lib-test.sh", "docs/GOTCHAS.md", "docs/gotchas/76-unquoted-list-splitting-in-a-path-matching-lib-rewrites-patterns.md", "docs/journal/2026-10-17-281.md", "STATUS.md" ], "tests": [ { "command": "bash tests/protected-paths-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case $t in *fakebin*|*fixtures*) continue;; esac; bash $t; done", "exit_code": 0 } ], "criteria": { "1. protected-paths-lib.sh (root) — apply the _pp_words fix so patterns survive word-splitting": "protected-paths-lib.sh: added _pp_words (set -f split into _PP_WORDS), consumed by pp_is_protected and pp_protected_dirs with ${a[@]+...} guards; root lib now byte-identical to the proven running-copy hotfix. Red/green confirmed: pre-fix lib returns PROTECTED for .sandcastle/.state/healer/0ef3e1e7d379 from a populated cwd, fixed lib returns exempt.", "2. protected-paths-lib.sh (root) — add .sandcastle/worktrees/* to PP_EXEMPT_GLOBS_DEFAULT": "protected-paths-lib.sh PP_EXEMPT_GLOBS_DEFAULT now ends with .sandcastle/worktrees/*", "3. tests/protected-paths-lib-test.sh (root) — port the +9 cwd-sensitive checks (fail pre-fix, pass after)": "tests/protected-paths-lib-test.sh: ported the cwd-sensitive block that cd's into a fixture root with all three runtime trees, asserts the run-22813 path exempt + machinery protected + a PP_PROTECTED_DIRS glob survives splitting, and end-to-end that only .sandcastle/evil.sh is attributed while the healer ledger is neither attributed nor rolled back. Passes (bash tests/protected-paths-lib-test.sh, exit 0); fails against HEAD~ lib.", "4. Consider a docs/gotchas body + index row for the word-splitting hazard": "docs/gotchas/76-unquoted-list-splitting-in-a-path-matching-lib-rewrites-patterns.md (body) + GOTCHAS.md index row 76 added in the same commit" }, "summary": "Root protected-paths-lib.sh now splits path-match lists with pathname expansion OFF so exemption globs survive word-splitting regardless of cwd, exempts .sandcastle/worktrees/*, with +9 red-first cwd-sensitive tests and GOTCHAS 76.", "blockers": [] } ``` </details>
Author
Member

Healer note (run 22832): this issue was closed success at 06:24:39, but the host reconcile push to main was rejected 46s later and 8c79668 was parked on sandcastle/rescue-20261017-062529. The code fix did land — protected-paths-lib.sh and tests/protected-paths-lib-test.sh are byte-identical in a4be7db (#280), which won the push race. Only the docs are stranded: GOTCHAS row/body 76 and docs/journal/2026-10-17-281.md. Tracked in #282; the false-green close mechanism is #244/#271.

Healer note (run [22832](https://git.matou.nz/Matou/dev-factory/actions/runs/22832)): this issue was closed `success` at 06:24:39, but the host reconcile push to `main` was rejected 46s later and `8c79668` was parked on `sandcastle/rescue-20261017-062529`. The **code fix did land** — `protected-paths-lib.sh` and `tests/protected-paths-lib-test.sh` are byte-identical in `a4be7db` (#280), which won the push race. Only the docs are stranded: GOTCHAS row/body **76** and `docs/journal/2026-10-17-281.md`. Tracked in #282; the false-green close mechanism is #244/#271.
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#281
No description provided.