Skip to content

fix(disk-hygiene): engine gate defers simple readers that only quote the engine name - #8117

Merged
kyle-sexton merged 5 commits into
mainfrom
work-resolve-issue/issue-6242-39105884948-1
Oct 18, 2026
Merged

kyle-sexton merged 5 commits into
mainfrom
work-resolve-issue/issue-6242-39105884948-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #6242

Hold: a human merges this

Summary

Opened by the work-resolve-issue lane. The run's own summary:

The disk-hygiene engine gate now blanks quoted string data for one simple command on a closed reader allowlist (cat, head, tail, wc, grep, rg without --pre, git show/log/diff/grep without -c/-O, gh issue/pr), so gh issue create --title '...hygiene.py...' is no longer denied. Identity is checked on the command as written before blanking; pipelines, awk, sed and expansions stay gated. Hold: a human merges this.

Not verified

  • The 6 lsof-related tests fail in this sandbox; not confirmed on a clean baseline run, left to the PR's CI
  • Red-first run before the fix was not captured separately; the old gh test expectation was inverted instead
  • Merge hold: the PR body needs the line 'Hold: a human merges this' (owner ratification); the lane's merge-hold step adds it

Fix

  • plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py: new _bash_without_string_data and option check; _engine_gate_relevant uses it on Bash; docstring names the gh alias residual
  • plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py: stay-quiet cases and fail-closed cases (pipeline, awk/sed, $ in double quotes, exec options, resolving engine path); moved two gh cases out of the denial-naming test
  • .changes/disk-hygiene/work-issue-6242-7d2e4b1a.md: patch fragment

Verification

The run reports:

Left out: the items under Not verified.

Related

#6242

…the engine name

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 0772effdd23dc676c8e73f19db5347d424b84101: 0 finding(s), 0 as inline comments.

No security findings in the incremental change since c233623.

The change has three parts:

  • Changelog fragment (.changes/disk-hygiene/work-issue-6242-7d2e4b1a.md): one added sentence saying a quoted word that links to the engine under any name now gates on both shells.
  • Docstring (destructive_guard.py): a paragraph added to _engine_gate_relevant. No executable code changed.
  • Tests (test_hygiene.py): a new git grep -nc'…' case in the keeps-gating list, and a new test, test_engine_gate_quoted_marker_free_link_gates_a_reader. It hard-links the engine under cleanup and @@, and checks the gate returns false before the link exists and true after, for both Bash and PowerShell.

I read the current _engine_gate_relevant to check that the documented behavior is real. Before it blanks string data, it identity-checks every whitespace token and every _literal_shell_words word with os.path.samefile. It does this on the command as written, so a quoted link to the engine under any name still gates. The new tests exercise that existing path, and the docstring now matches it. The guard gets no weaker, and the diff adds no new bypass, injection or trust-boundary surface.

This diff deletes, narrows or softens no standing instruction, so the instruction-surface lens found nothing to check.

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 0772effdd23dc676c8e73f19db5347d424b84101: 0 finding(s), 0 as inline comments.

No findings on the incremental change since c233623 (changelog line, docstring paragraph, two test additions).

I read the code and did not run the tests. Both attempts to run pytest needed approval and were not granted, so the new tests are unexecuted by me.

  • git grep -nc'…' stay-gated case (test_hygiene.py): the case gates as intended. _bash_without_string_data strips quotes before reading options, so -ncpython3… contains c. _bash_reader_option_runs_program flags it, the function returns None, and the command is classified as written (destructive_guard.py:906-928).
  • test_engine_gate_quoted_marker_free_link_gates_a_reader: this covers the branch it names. The marker-free identity scan at destructive_guard.py:1079-1091 runs on the command as written, for Bash and PowerShell alike. It sees cleanup and @@ as whole words, and a hard link to the engine makes _samefile true. The assertFalse before the link is sound. The engine directory holds no cleanup or @@, and the temp directory is a fresh cwd. _hard_link_or_skip skips rather than copies when links are refused.
  • Docstring and changelog: both match the code at destructive_guard.py:1068-1092.
  • Closing issue fix(disk-hygiene): engine gate denies commands that only mention the engine file name #6242 criteria: the stay-quiet gh issue create case, the pipeline, non-allowlist reader, $ in double quotes and resolving-path cases were covered in the earlier reviewed range. This increment adds a further fail-closed case and does not weaken any of them.
  • Unread or unverifiable: the PR body's "6 lsof failures" and test counts are author-claimed and I did not verify them.

…nking

A symlink to the engine under a name without the marker, written in
quotes, was blanked to `_` and never identity-checked. Run the same
all-tokens _samefile/_in_engine_dir scan over the command as written
before blanking.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 1 of 3 on edf16c6.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 2 of 3 on edf16c6.

@melodic-automation-lanes melodic-automation-lanes Bot added the needs-human Human-in-the-loop required; autonomous sessions must not resolve items carrying this. label Oct 18, 2026
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane stopped on this pull request and needs a person: a review finding is uncertain or deferred, so a person decides it.

  • Reason: feedback-uncertain
  • Resume key: edf16c644a4f950a2c5957423e1866638720e4b6 (the head the lane stopped on)

To resume, deal with the reason above, remove the needs-human label (and do-not-merge, if set), then dispatch the pr-unblock workflow with pr-number=8117 and activity=address-feedback:

gh workflow run pr-unblock.yml -R melodic-software/claude-code-plugins -f pr-number=8117 -f activity=address-feedback

@kyle-sexton

Copy link
Copy Markdown
Member

This was generated by AI: an independent fresh-context review requested by the owner in an attended backlog-shaping session on 2026-10-18. The owner merges this PR after the findings are fixed.

Review: PR #8117 (fix(disk-hygiene): engine gate defers simple readers that only quote the engine name)

PR: #8117 (head edf16c6)
Source issue: #6242 (Decision recorded + Agent Brief, 2026-10-18)

Criteria read: REVIEW.md, AGENTS.md Code Review Rules, .claude/rules/pr-body-contract.md, issue #6242 decision and Agent Brief, PR inline review threads.

Verdict: FIX

The design matches the decision and I found no way for an engine invocation to get past the gate. The head commit still fails its own acceptance test and breaks PowerShell behavior already on main. CI is red, and the fix is one line.

Findings

IMPORTANT (blocking): the new pre-blank identity scan gates every quoted bare engine name and breaks the PowerShell rule already on main

  • File: plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py:1079-1087 (the _names_engine(candidate) at line 1081)
  • The scan pr-unblock added in edf16c6, in reply to the claude-review thread at line 1064, runs _names_engine. That function joins each relative token to the engine directory (_in_engine_dir), so the bare token hygiene.py inside any quoted string resolves to the bundled engine and gates. The scan is unconditional for PowerShell (allow_backslash or data_free != command), so it also undoes the PowerShell string-data deferral that main already ships.
  • Effect: 7 of the 9 stay-quiet subtests fail, including the issue case gh issue create --title 'x' --body 'run python3 hygiene.py scan'. Only mentions next to a parenthesis, like (only hygiene.py), still defer. Four existing tests also regress: test_powershell_engine_name_in_string_data_defers, test_powershell_bare_name_mentions_defer_but_engine_identity_denies, test_engine_gate_defers_mere_mentions_of_the_engine and test_engine_gate_marker_free_split_keeps_verdict_parity. That makes 16 failures in CI test-python, test-bash (hygiene.test.sh) and test-windows-secrets. I reproduced all 16 locally on the head.
  • The error makes the gate stricter, not looser, so nothing slips past it.
  • Fix: read identity only as written in this pre-blank scan. Change line 1081 to _samefile(candidate). A path that resolves from the working directory, including a quoted marker-free link, still gates. A bare mention no longer resolves against the engine directory. Verified on a scratch copy: all 73 engine_gate/powershell/string_data/mere_mentions tests pass after this one change.
  • Confidence: high

IMPORTANT: the quoted marker-free link scan has no test (review thread still open)

  • File: plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py, beside test_engine_gate_bare_link_outside_engine_dir_gates (around line 11775)
  • The claude-review thread at destructive_guard.py:1079 is right: removing the scan fails nothing. pr-unblock marked it UNCERTAIN and escalated it to a person. The edf16c6 fix was never run, and that is how the defect above shipped.
  • Fix: in a temp working directory, hard-link the engine to cleanup with _hard_link_or_skip. Assert that _engine_gate_relevant("gh issue create --title x 'cleanup'", "Bash") is True. Add a counterpart with no link that asserts False. Also add one PowerShell case if the scan stays shared, or see the scope finding below.
  • Confidence: high

SUGGESTION: the fail-closed tests passed at head for the wrong reason

  • File: plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py, test_engine_gate_keeps_gating_what_the_string_data_rule_does_not_cover (new test, after line 10803)
  • At head, every case holding a bare hygiene.py token gates through the defect above. So the --pre, --hostname-bin, -O and -c guards are not what these assertions test. I disabled the rg branch of _bash_reader_option_runs_program and the test stayed green. With the line-1081 fix in place, the same mutant fails 3 subtests, so the tests become meaningful once the fix lands.
  • Fix: after the fix, disable each remaining guard in turn and confirm a subtest fails: the git -c/-O cluster check, the --open prefix check, the whole-command backslash reject, and the $/backtick check in double quotes.
  • Confidence: high

SUGGESTION: the new identity scan widens PowerShell behavior beyond the brief

  • File: plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py:1064 and 1075-1087
  • The brief and the changelog fragment cover Bash only, but this block also runs for PowerShell. After the line-1081 fix it is only stricter on PowerShell: a quoted link that resolves to the engine gates. That is defensible, but neither the docstring (lines 967-981) nor .changes/disk-hygiene/work-issue-6242-7d2e4b1a.md mentions it.
  • Fix: limit the block to Bash (if not allow_backslash), or say in the PowerShell paragraph of the docstring and in the fragment that both shells get the check.
  • Confidence: medium (advisory)

SUGGESTION: the PR body misreports verification

  • The PR body says the 6 failures are lsof sandbox failures, and the Verification section reports a run from before edf16c6. The real head fails 16 gate tests, and the head commit was never executed.
  • Fix: after the fix, update the Not verified and Verification sections with the CI run on the new head.
  • Confidence: high

Can a destructive command slip past the gate?

No bypass found. What I checked:

  • _bash_without_string_data (destructive_guard.py:849-929) rejects $, backtick, backslash, #, ;, &, |, <, >, parentheses, braces, CR and LF outside quotes. That excludes pipelines, lists, subshells, command and process substitution, here-strings, $'...' and $"..." quoting, and escape-parity tricks. Any backslash in the command rejects it, so quote pairing cannot be misread.
  • A quoted or partly quoted command word is rejected (c'a't becomes c_ and 'cat' hits the leading-quote check). A VAR=value prefix or a path-qualified command word is not on the allowlist.
  • Global options before a git or gh subcommand (git -c ..., gh -R ...) fail the subcommand check. Quote-stripped option reads catch rg '--pre'. The git -O cluster and --open-files-in-pager prefix abbreviations are caught.
  • None of cat, head, tail, wc, grep, git show/log/diff/grep (without -c/-O) or gh issue/pr runs an argument string. In engine-gate mode, a command the gate does not consider relevant defers entirely (destructive_guard.py:3018-3023), so this mode never gated non-engine destructive commands such as rm. The PR adds no new exposure there.
  • Residuals that are not new: a user shell alias or function named after an allowlisted reader in the Bash tool shell snapshot (the same class affects every existing deferral). The gh alias residual is documented in the docstring as the brief requires.

Decision match and scope

  • Matches the decision and the brief: one simple command, the closed allowlist with the rg/git exclusions, only safe literals blanked, awk and sed classified as written, pipelines still fail closed, identity checked before blanking, the gh alias residual named in the docstring, and a fragment present. Pulling _names_engine out as a helper is a small shared refactor and acceptable.
  • Not met: the acceptance case is still denied (finding 1), and the "red before the fix" evidence was not captured. The two moved cases in test_engine_gate_denial_names_the_payload_word_it_gated show the old behavior.

CI and review lanes

  • Red: ci-status, ci-lanes (lane 3 of 10), test-python, test-bash and test-windows-secrets, all from the 16 gate-test failures.
  • Review lanes: claude-review and claude-security-review both passed on edf16c6. The security review had 0 findings. claude-review had 2 inline findings. One was "fixed" without being run, and that fix caused finding 1. The other is open and escalated to a person (pr-unblock report-escalation, feedback-uncertain).
  • The body holds "Hold: a human merges this", as the brief requires.

Coverage: all changed files reviewed.

@kyle-sexton kyle-sexton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generated by AI: independent review requested by the owner in an attended backlog-shaping session on 2026-10-18. Each finding is its own thread so the PR-fix lane can address it. The owner merges this PR after the fixes.

File-level notes:

  • plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py: SUGGESTION: the PR body misreports verification (the body is not a file, so this sits on the test file it describes). It says the 6 failures are lsof sandbox failures, and its Verification section reports a run from before edf16c6. At this head 16 engine-gate tests fail, and the head commit was never executed.

Fix: after the destructive_guard.py:1081 fix, update the Not verified and Verification sections with the CI run on the new head.

The pre-blank scan used _names_engine, which joins bare tokens to the
engine directory, so any quoted `hygiene.py` mention gated and the
PowerShell string-data deferral regressed. Check _samefile instead: a
path resolving from the working directory still gates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kyle-sexton and others added 2 commits October 18, 2026 06:55
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ells

Add a test that a quoted word naming a hard link to the engine gates a
gh reader on Bash and PowerShell, with a stay-quiet case before the link
exists. The `@@` name owns no marker token, so only the whole-word scan
sees it and removing that scan now fails the test. Add a `git grep -nc`
case so the `-c` half of the git option check has a failing subtest.

State in the gate docstring and the changelog fragment that the scan
runs for both shells.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kyle-sexton kyle-sexton removed the needs-human Human-in-the-loop required; autonomous sessions must not resolve items carrying this. label Oct 18, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 18, 2026
Merged via the queue into main with commit 3e9be5d Oct 18, 2026
51 of 52 checks passed
@kyle-sexton
kyle-sexton deleted the work-resolve-issue/issue-6242-39105884948-1 branch October 18, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(disk-hygiene): engine gate denies commands that only mention the engine file name

1 participant