Skip to content

worktree-reaper: config is never validated — typo'd deny_* keys and string-typed values silently disarm the denylist, wrong-shaped config crashes with a raw traceback #6394

Closed

Description

@dezren39

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):

  1. 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 keeps deny_paths == [] and the default quiet_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.
  2. deny_paths as 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_names as a string similarly turns :229's membership test into a substring test.)
  3. 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 with AttributeError: 'list' object has no attribute 'items' (:122–139).
  4. Malformed JSON crashes with a raw traceback. Running the real binary with --config bad.json (contents {oops) exits 1 with an uncaught json.decoder.JSONDecodeError traceback from main → load_config (:533) — no worktree-reaper: cannot load config … style error, and no run record is written to the state dir's runs/ log, so the failure is invisible to the tool's own audit trail.
  5. 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) with TypeError: 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_config validates 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_removals numbers, fetch a 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, the install-units.sh overlay 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_paths as a string, top-level list/string in config and overlay, malformed JSON, and string quiet_hours — each asserting the clean, naming-the-file error.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    on Nov 5, 2026
  2. developing-today commented on Nov 5, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (new-issue-creator-code-b, Lane B)
    • Session / ID: cron new-issue-creator-code-b run 2026-11-05 16:50 CST
    • Found via: filed this run
    • Task: Filed after verifying on the laptop at origin/main cb8eee8 (probe ~/git/fleet/probe-reaper-config, real load_config + real binary): typo'd deny_path/quiet_hour keys silently accepted with the denylist dropped in both config and overlay; deny_paths as a string iterated per-character by is_denied; top-level list/string and malformed JSON crash with raw tracebacks (real binary exit 1); string quiet_hours accepted at load then TypeErrors at the quiet gate.
    • Expectation: effort s — triage confirms the reject-vs-warn shape for unknown keys and routes load-time config validation plus regression tests.
    • Links: probe ~/git/fleet/probe-reaper-config (laptop); distinct from ci(worktree-reaper): test_worktree_reaper.py is run by no workflow — the destructive reap gates are verified nowhere #5946 (CI wiring) and worktree-reaper: fail closed when /proc cannot be scanned before removal #5740 (/proc fail-closed)
  4. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor
  5. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    work/assignedQueue worker lifecycle state
    and removed on Nov 5, 2026
  6. 187 remaining items

  7. added
    queue/claimedQueue worker lifecycle state
    and removed
    task/triageQueue packet kind: verify, reproduce, and route this item
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 11, 2026
  8. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged (inline, per runbook §1c) — fix proceeding in this same session

    • Agent: queue worker (repo-worker-code), lane code-w
    • Session / ID: task 10809
    • Found via: queue claim
    • Verdict: REAL AND CURRENT. Fresh verification 2026-11-11 at current main: load_config in infra/worktree-reaper/bin/worktree_reaper.py (now at bin/, lines 145-183) still performs no validation — cfg.update(json.load(fh)) unguarded, overlay merged via local.items() unguarded, no known-key or type checks, and main still 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).
    • Work kind: task/small-fix (the packet's own scope: load-time validation + regression tests). Priority: priority/normal (retained). Effort: effort/s. Kind: kind/bug (retained).
    • First concrete step: add a validate_config pass in load_config for both files (known keys = DEFAULT_CONFIG keys; per-key types from the defaults; top level must be an object; JSON/read errors wrapped in a ConfigError naming the file), surface it in main as worktree-reaper: cannot load config … with a nonzero exit, and add regression tests in infra/worktree-reaper/tests/test_worktree_reaper.py for each invalid case from the issue.
    • Acceptance check: each invalid case in the issue yields the clean naming-the-file error (no traceback, no silent disarm); valid config + overlay merge behavior unchanged (existing suite green).
    • Links: task 10809 · issue worktree-reaper: config is never validated — typo'd deny_* keys and string-typed values silently disarm the denylist, wrong-shaped config crashes with a raw traceback #6394
  9. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

  10. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (already_done)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/worktree-reaperinfra/worktree-reapereffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions