Skip to content

fix(disk-hygiene): engine gate denies the plugin's own test file via substring marker match #1611

Closed

Description

@kyle-sexton

Summary

The disk-hygiene destructive_guard.py engine gate denies Bash invocations of the plugin's own test file, test_hygiene.py, because the engine marker is matched as a bare substring. _ENGINE_MARKER = "hygiene.py" is a substring of test_hygiene.py, so a different file trips the gate.

Found incidentally while babysitting #1588 — the exact command the Codex reviewer recommended in its review comment there is denied by this plugin's own hook.

Reproduction

Verified on this machine with disk-hygiene 0.9.7 installed and enabled.

Denied (marker-bearing path + an interpreter token parses as an engine invocation):

cd <repo> && python3 -m unittest -v plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py
Disk-hygiene fails closed: Bash is restricted to exact bundled scan, preview, handoff-verify,
and apply invocations using the hook's absolute Python interpreter "...python.exe". Bare
python/python3 commands are denied because shell functions and aliases can replace them.

Allowed (dotted-module form carries no .py, so the marker is absent and the gate defers):

cd <repo>/plugins/disk-hygiene/skills/clean/scripts && python3 -m unittest test_hygiene.GuardTests.<method>

Both invoke the same tests. The only difference is whether the literal string hygiene.py appears in the command.

Why the existing mitigation does not catch this

_engine_gate_relevant's docstring states that a word resolving to an existing file other than the bundled hygiene.py "is not this engine and defers", implemented via os.path.samefile(word, bundled). That check cannot help here:

  • samefile resolves the word relative to the hook process's working directory, which is not the user's shell CWD, so a repo-relative path like plugins/disk-hygiene/.../test_hygiene.py does not resolve and raises OSError.
  • _samefile returns False on OSError, and an unresolvable marker-bearing word deliberately "stays in play" — so the gate proceeds, classify_exact_engine_command cannot match a unittest invocation, and the command is denied.

Impact

Bounded but real, and it is a dogfooding defect: in any consumer session with disk-hygiene enabled, a contributor (human or agent) cannot run this plugin's test suite through Bash using the natural file-path form. The dotted-module form is an undocumented workaround. It also means the gate's substring match will deny unrelated third-party files whose names merely end in hygiene.py (e.g. a consumer's own test_hygiene.py) whenever the path cannot be resolved from the hook's CWD.

No security weakening — this is over-blocking, which is the correct direction for a fail-closed guard to err. The cost is usability and contributor friction, not exposure.

Suggested direction (not prescriptive)

Match the marker on a filename boundary rather than as a bare substring: treat a word as marker-bearing only when its Path(word).name casefolds to exactly hygiene.py, instead of testing _ENGINE_MARKER in lowered over the whole command string. That keeps every current gating shape (including python3 -B .../hygiene.py and linked aliases invoked by path) while letting test_hygiene.py — a genuinely different filename — defer without depending on CWD-sensitive samefile resolution.

Worth confirming against the gate's own test suite before changing anything; the substring form may be load-bearing for a copy-evasion case I have not identified.

Activity

  1. added
    needs-triage
    on Jul 26, 2026
  2. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Triage: verified

    Reproduced live in this session against origin/main, with disk-hygiene enabled and the plugin-level engine gate active:

    • Invoking the plugin's own test module through Bash by relative file path, from the scripts directory, is denied with the guard's "Bash is restricted to exact bundled scan, preview, handoff-verify, and apply invocations" message.
    • The same tests invoked in dotted-module form (no .py suffix anywhere in the command) run to completion — 86 tests, OK (skipped=2).
    • The only difference between the two commands is whether the literal engine-marker string appears in the command text.
    • Incidental second reproduction: an ordinary git show … | grep inspection command was denied for the same reason, purely because a marker-suffixed filename appeared in it.

    The reported mitigation analysis holds. The "provably a DIFFERENT existing file" escape resolves the word against the hook process's working directory, not the user's shell CWD, so a path that is valid in the user's shell does not resolve for the hook; an unresolvable marker-bearing word deliberately stays in play, the gate proceeds, the exact-invocation classifier cannot match a unittest command, and the belt denies.

    Also checked: no bundled gate test asserts that a filename merely containing the marker must gate. Every existing gate test uses the exact engine filename (bare, absolute, wrapper-launched, compound-payload) or the same-file identity path. The reporter's own caution — "the substring form may be load-bearing for a copy-evasion case I have not identified" — did not survive that check.

    Category: bug (over-blocking usability defect in a fail-closed guard; no security weakening in the reported direction).

    Agent Brief

    Type: Bug
    Summary: The plugin-level engine gate treats the engine's filename marker as a bare substring, so a genuinely different file whose name merely ends with that marker is routed into the fail-closed belt and denied.

    Current behavior:
    Marker relevance is decided by a substring test over the whole command string and, in the compound/unparsable branches, over individual tokens. A filename such as the plugin's own test module contains the engine marker as a suffix, so it is treated as marker-bearing. The differencing escape hatch depends on resolving the word to an existing file from the hook's working directory; when that resolution fails the word stays in play and the command is denied. Contributors must use an undocumented dotted-module workaround to run this plugin's test suite through Bash. Third-party files whose names end with the same marker are denied the same way whenever they cannot be resolved from the hook's CWD.

    Desired behavior:
    A word is marker-bearing only when its filename component equals the engine marker exactly (casefolded). A different filename that merely ends with the marker is not the engine and defers, with no dependence on CWD-sensitive path resolution. Every shape that gates today continues to gate.

    Key interfaces:

    • _engine_gate_relevant() — the relevance predicate; its whole-command early bailout, its unparsable/compound token branches, and its literal-word loop must all agree on one boundary-aware marker test.
    • _ENGINE_MARKER — the marker constant; its comparison semantics change from substring-containment to filename-component equality.
    • _script_path_key() / _same_file_as_bundled() — the identity path; it must remain the mechanism that catches a link to the bundled engine under any other name, including a marker-suffixed one.
    • classify_exact_engine_command() — unchanged; it stays the authority once the gate decides a command is relevant.

    Acceptance criteria:

    • Invoking the plugin's own test module through Bash by a relative or absolute file path succeeds, from a working directory that differs from the hook process's.
    • Every currently-gated shape still gates: a bare marker word as the command; an interpreter with options before the script; an absolute engine path under any launcher; known launcher wrappers (including ones with option operands); quoted compound payloads whose first token is the engine or an interpreter; and a hard link or symlink to the bundled engine under a different name.
    • Mere mentions of the engine filename (diff, grep, echo, PowerShell pattern search) still defer.
    • New regression tests cover both directions: a differently-named file whose name ends with the marker defers, and a link to the bundled engine carrying a marker-suffixed name still gates by identity.
    • The full bundled disk-hygiene test suite passes.
    • The relevance predicate's docstring is updated to describe boundary matching rather than substring matching.

    Out of scope:

    • The copy-evasion residual class (a byte copy is a different file and is explicitly an accepted residual).
    • The skill-scoped belt mode's deny-by-default Bash posture.
    • The PowerShell deletion-spelling rules.
    • The kill-switch and data-root authority checks themselves.

    Labels applied

    Bug (native issue type), priority: medium, agent-ready, status: ready; priority: needs-triage cleared. Reporter did not self-label a severity; impact is contributor friction, not exposure, so the assessed default tier applies. The automated label is retained.

    Role-label resolution warning: this repository's .work-item-tracker.json carries no config.role_labels entry, so the canonical roles fell back to their documented defaults (agent-ready / needs-human). Both strings exist as labels in this repository, so the fallback is correct here — but it is a fallback, not a binding.

  3. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Decision defaulted: match the engine marker on a filename boundary (filename component equals the marker, casefolded) rather than as a bare substring — veto before merge.

    Grounding: triage verification found no bundled gate test that depends on substring-only matching — every existing gate test uses the exact engine filename or the same-file identity path — and link/alias coverage survives the change, because a marker-suffixed link to the bundled engine falls through to the marker-absent scan, which identity-checks every separator-carrying word. That closes the reporter's own open question ("the substring form may be load-bearing for a copy-evasion case I have not identified").

    The maintainer-vetoable alternative: keep the substring form and special-case the plugin's own test module. Reversible, but narrower — it leaves every third-party filename ending in the same marker over-blocked whenever it cannot be resolved from the hook's working directory.

    Flagged for veto rather than shipped silently because it relaxes the matching of a fail-closed guard. The direction of the relaxation is over-blocking → correctly-scoped blocking, and the identity path is unchanged, but a security-posture edit in a kill-switch guard deserves a maintainer's eyes before merge.

  4. added
    agent-ready
    status: ready
    and removed
    needs-triage
    on Jul 26, 2026
  5. added theissue type on Jul 26, 2026
  6. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Admission gate: carries agent-ready but no work-class: label and no body-recorded class trailer — unclassified → fail-closed human-gated per the work-loop lane's admission table (a role label alone is not classification evidence). Routed to human-gated; not dispatched. (Recurring pattern, tracked at #1288.)

  7. added
    needs-human
    and removed
    agent-ready
    on Jul 26, 2026
  8. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    🤖 Released by autonomous babysit lane (fable-autopilot) at session wind-down. Not fixed. Parked for a successor.

    PR #1625 carries the work: do-not-merge applied, HEAD b401bd08, all four commits pushed, CI green, one review thread left unresolved because the finding it records is genuinely unaddressed.

    Codex reviewed six times and found five real defects; four were fail-opens the change itself introduced. Four are fixed with reproduction evidence in their threads. Two remain, and both are regressions this branch introduced, so neither is legitimately deferrable — each must be fixed or the branch reverted:

    I earlier deferred both under a fix-round cap. That cap was retracted as contradicting org policy — round count is never a stopping criterion — so that reasoning is withdrawn and recorded as withdrawn on the PR.

    The substantive question for a successor is not "handle trailing dots". All five defects share one root: the change makes the filename authoritative, and there turned out to be many ways to spell a filename; each fix passed a differential matrix before the next spelling appeared. The direction recorded in the PR's final thread — make identity authoritative (basename matches or the token resolves to the bundled engine) — is a hypothesis, not a tested result. Reverting is an equally legitimate outcome.

    main is unchanged and still carries the original over-gate this issue reports.

  9. kyle-sexton commented on Jul 27, 2026

    @kyle-sexton
    MemberAuthor

    🤖 Agent-authored (autonomous babysit lane orchestrator, wind-down disposition). PR #1625 is parked (do-not-merge, escalated) after its author's pre-committed stop rule fired: four self-introduced fail-opens across six review rounds, terminal one being the Windows trailing-dot normalization bypass (verified: os.path.samefile('hygiene.py.', 'hygiene.py') is True on Win32).

    Orchestrator disposition, concurring with the author's recommendation: re-scope to the identity-based predicate (basename equality OR token resolves to the bundled engine — identity is ground truth; subsumes spelling variants without enumeration), implemented from a FRESH context (the enumerative-verification blind spot is documented on the PR), run through the full adversarial review chain with the six threads of preserved evidence as its test corpus. An independent plugin-quality audit of this session separately confirmed the root cause is unfixed at origin/main and the false-positive class reproduces live — the two findings converge on the same re-scope.

    Incidental live reproduction while posting this very comment: the gate blocked a gh issue comment invocation because the comment body mentioned the engine filename and a bare interpreter name — argument-string matching gating a tracker write. Recorded in the audit packet as fresh evidence for the false-positive class.

    Do not merge #1625 as-is (live fail-open on the fleet's primary platform). Related: #1640 (over-gate on legal path characters).

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

    needs-humanstatus: ready

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions