Repository navigation
Description
worktree-reaper: config is never validated — typo'd deny_* keys and string-typed values silently disarm the denylist, and wrong-shaped config crashes with a raw traceback
infra/worktree-reaper/bin/worktree_reaper.py is the tool that deletes fleet worktrees (git worktree remove + git branch -d) on a timer, gated by the safety rules in its header. Its config — the main config.json and the <state_dir>/config.local.json overlay that install-units.sh uses to denylist the install tree — is merged in load_config (worktree_reaper.py:99–139) with no validation of any kind: no shape check, no known-key check, no type check. main calls it unguarded (:533).
Verified on the laptop at origin/main cb8eee8d68 (script extracted verbatim; probe ~/git/fleet/probe-reaper-config, driving the real load_config and the real binary):
- Typo'd keys are silently accepted, and the denylist silently vanishes. Config
{"deny_path": ["/home/user/git/important"], "quiet_hour": 24}loads OK; the effective config keepsdeny_paths == []and the defaultquiet_hours == 6, plus two stray keys nothing reads. The same holds in the overlay ({"deny_path": [...]}→deny_paths == []). For a deletion tool, a one-character typo in a deny key converts an explicit "never reap this" into no protection at all, with no message anywhere. deny_pathsas a string silently disarms the check.{"deny_paths": "/home/user/git/important"}loads OK and is kept verbatim;is_denied(:221) then iterates the string character by character, deriving 24 nonsense one-character "paths" — the intended path is never denied and nothing complains. (deny_namesas a string similarly turns :229's membership test into a substring test.)- Wrong-shaped config crashes cryptically. A top-level JSON list or string fails with
ValueError: dictionary update sequence element #0 has length 10; 2 is required— a message that never mentions the config file or that an object was expected. A top-level list in the overlay fails withAttributeError: 'list' object has no attribute 'items'(:122–139). - Malformed JSON crashes with a raw traceback. Running the real binary with
--config bad.json(contents{oops) exits 1 with an uncaughtjson.decoder.JSONDecodeErrortraceback frommain→load_config(:533) — noworktree-reaper: cannot load config …style error, and no run record is written to the state dir'sruns/log, so the failure is invisible to the tool's own audit trail. - Type errors pass load and explode mid-run.
{"quiet_hours": "6"}is accepted verbatim; the run only fails later at the quiet gate (:455,now - cfg["quiet_hours"] * 3600) withTypeError: unsupported operand type(s) for -: 'int' and 'str'— after discovery/fetch work has begun, reported (if at all) as a per-tree anomaly rather than a config error.
Why it matters
Every other gate in this tool is written fail-closed (a failed fetch skips the primary, an unscannable /proc is #5740, the kill switch exits 0) — but the config that parameterizes those gates, including the operator's explicit denylist, is trusted blindly. The failure modes above split into the two worst kinds for a destructive tool: silent weakening (cases 1–2: the run proceeds and deletes, minus the protection the operator wrote down) and opaque crashing (cases 3–5: the timer unit fails with a traceback that names neither the file nor the key, and the run-log audit trail has no entry). The overlay case is not hypothetical configuration drift: the overlay is a generated file whose entire purpose is to denylist the install tree.
Distinct from #5946 (the reaper's test suite is run by no workflow — CI wiring) and #5740 (fail-closed when /proc cannot be scanned). Sibling pattern in a different tool: #6388 (deploy validate() crashing on unhashable values instead of reporting them).
Acceptance criteria
load_configvalidates both the main config and the overlay before anything is reaped: top level must be a JSON object; unknown keys are rejected (or at minimum reported loudly by name — rejection preferred, matching the fail-closed posture); the known keys are type-checked (deny_paths/deny_prefixes/deny_names/primaries/generated_dirt_*lists of strings,quiet_hours/max_removalsnumbers,fetcha boolean, path settings strings).- Any config problem — malformed JSON, wrong shape, unknown key, wrong type — aborts the run before discovery/removal with a single clear error naming the file, the key where applicable, and what was expected; exit non-zero; no Python traceback.
- The valid-config behavior is byte-identical: the committed
config.json, theinstall-units.shoverlay merge (deny lists union, scalars override), CLI overrides (--quiet-hours,--max-removals,--no-fetch), and the existing test suite (infra/worktree-reaper/tests/test_worktree_reaper.py, 8 tests) all behave exactly as before. - Regression tests in that suite cover each verified case above: typo'd deny key in config and in overlay,
deny_pathsas a string, top-level list/string in config and overlay, malformed JSON, and stringquiet_hours— each asserting the clean, naming-the-file error.
Activity
developing-today commentedon Nov 5, 2026
CODE-1907
dezren39 commentedon Nov 5, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 5, 2026
🤖 Agent note · handed off
187 remaining items
dezren39 commentedon Nov 11, 2026
🤖 Agent note · triaged (inline, per runbook §1c) — fix proceeding in this same session
load_configininfra/worktree-reaper/bin/worktree_reaper.py(now at bin/, lines 145-183) still performs no validation —cfg.update(json.load(fh))unguarded, overlay merged vialocal.items()unguarded, no known-key or type checks, andmainstill calls it unguarded (line 716). All five failure modes from the issue body stand (typo'd deny keys silently disarm the denylist; string-typed deny_* iterate/substring; wrong-shaped top level crashes cryptically; malformed JSON is a raw traceback; wrong-typed scalars explode mid-run).validate_configpass inload_configfor both files (known keys = DEFAULT_CONFIG keys; per-key types from the defaults; top level must be an object; JSON/read errors wrapped in aConfigErrornaming the file), surface it inmainasworktree-reaper: cannot load config …with a nonzero exit, and add regression tests ininfra/worktree-reaper/tests/test_worktree_reaper.pyfor each invalid case from the issue.dezren39 commentedon Nov 11, 2026
🤖 Agent note · done
load_configvalidates both the config file and the install overlay at load (_load_json_object+validate_configininfra/worktree-reaper/bin/worktree_reaper.py): unknown keys refused (a typo'd deny key can no longer silently disarm the denylist), per-key types enforced fromDEFAULT_CONFIG, top level must be a JSON object, read/JSON errors raise aConfigErrornaming the file, andmainprintsworktree-reaper: cannot load config: …with exit 2 — no traceback, no mid-run explosion. Valid config + overlay merge behavior unchanged.ConfigValidationTestscovering every failure mode in the issue; the real binary was also driven directly on malformed JSON and the typo case (clean error, exit 2).dezren39 commentedon Nov 11, 2026
🤖 Agent note · done (already_done)
_load_json_object+validate_configtoload_configin infra/worktree-reaper/bin/worktree_reaper.py (unknown keys refused, per-key types from DEFAULT_CONFIG, top-level object enforced, file-naming errors) with the regression coverage the acceptance names. This follow-on (created 03:12:05Z) raced that completion.