Skip to content

fix(disk-hygiene): release the clean session belt when no run is open - #11250

Closed
melodic-automation-lanes[bot] wants to merge 2 commits into
mainfrom
work-resolve-issue/issue-6377-41051001744-1
Closed

melodic-automation-lanes[bot] wants to merge 2 commits into
mainfrom
work-resolve-issue/issue-6377-41051001744-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #6377

Summary

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

The /disk-hygiene:clean belt (the skill-frontmatter guard) now denies only while a clean run is open, tracked by a per-session marker at <data-root>/clean-runs/<session_id>.json, instead of for the rest of the session. The guard writes the marker when it admits a preview, apply, handoff-apply or manual-lane handoff-verify. It deletes the marker once that step's end file appears (the --report, or a new <plan>.run-end.json the engine writes when a preview ends in manual-handoff-lane or blocked), or once the marker goes an hour (_RUN_IDLE_TIMEOUT_SECONDS) without an engine call. It fails closed when the marker is corrupt, the session id is missing or there is no data root. A completed or refused scan with no preview after it leaves no open run, so gh/git/test commands work after an audit-only run. Design note for the reviewer: D13 says scan writes the marker, but nothing the guard or engine can observe tells an audit-only scan apart from one an execution request will follow. So the run opens at preview, and a scan only restarts an open run's idle clock (which also fixes the review finding that a re-scan mid-run dropped the belt). The 'between scan and apply' test therefore runs scan, then preview, then a denied non-engine command, then apply. Second note: the manual lane's PowerShell deletes get their only hook ask from the belt, so a manual-handoff-lane preview ends the run but each handoff-verify opens it again (ended only by the idle timeout), which keeps those prompts.

Not verified

  • The disk-hygiene guard and engine test suites (scripts/run-test-file.sh on test_hygiene.py) were not run: this lane runs no test runner or interpreter. Left to the PR's CI.
  • check-skill.sh on the changed clean SKILL.md was not run: check-affected skips changed-skills because it runs the checked tree's own skill-quality code. Left to the PR's CI.
  • The PR body must carry 'Hold: a human merges this' (issue acceptance criterion). The lane opens the PR, so this run could not set it.
  • Tidy skipped: the change is about 400 changed lines, over the 300-line tidy cutoff.
  • Review finding not fixed: a marker write that fails (an unwritable data root) leaves no marker, so the belt stays off for that run. Refusing the admitted step would change the belt's open-run verdicts, which the issue keeps unchanged. Documented as a residual in safety-model.md and the code; the eng
  • Review finding not fixed: clean-runs/ is not in engine_grammar.ENGINE_OWNED_DIRS, so an approved engine --report could be aimed at the marker path. Adding it would narrow the admitted engine shapes, which the issue keeps unchanged. A forged marker reads as corrupt and holds the belt (fail closed).
  • Review finding not fixed (low): two concurrent hook processes could race on the marker (one unlinks while the other rewrites). Left as is.
  • No test calls the engine's preview through hygiene.main to reach record_run_end; the test calls record_run_end directly and checks the file the guard reads.
  • Deviation from the D13 wording for review: the run opens at preview rather than at scan (see summary). Every listed acceptance test case is covered, with 'between scan and apply' tested as scan, preview, denied command, apply.

Fix

  • plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py: added the per-session run marker (_run_marker_path, _record_run_step, _run_open, _belt_released, _stand_down). _decide now takes the payload's session_id, records run steps for admitted engine calls in belt mode, and stands down (no dec
  • plugins/disk-hygiene/skills/clean/scripts/hygiene.py: added record_run_end. preview writes <plan>.run-end.json when its outcome is not explicit-approval (best effort; a failed write keeps the belt on until the idle timeout).
  • plugins/disk-hygiene/lib/engine_grammar.py: added PREVIEW_RUN_END_SUFFIX, shared by the engine and the guard.
  • plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py: _invoke_guard takes an optional session_id. Added 12 belt-lifetime tests: audit-only scan releases (Bash gh, PowerShell Remove-Item); scan refused at the target check (real engine exit 2) releases; scan, then preview, then apply holds until
  • plugins/disk-hygiene/skills/clean/SKILL.md: new Gotchas bullet on when the belt holds; the deny-by-default bullet now opens 'While a run is open'; the §6 pointer no longer says the belt outlives the cleanup.
  • plugins/disk-hygiene/skills/clean/reference/safety-model.md: replaced the 'rest of the process' paragraph with a 'When a run is open' paragraph covering the marker lifecycle, fail-closed rules and residuals.
  • plugins/disk-hygiene/skills/clean/reference/unsupported-platform-handoff.md: 'Hook registration outlives the cleanup' section now describes the run-scoped belt across the manual lane.
  • plugins/disk-hygiene/README.md: the hook-lifetime paragraph now describes the run-scoped belt and drops 'start a new session to clear it'.
  • .changes/disk-hygiene/fix-6377-clean-belt-run-scoped-3f9a61c2.md: new patch fragment (written by hand: new-changelog-fragment refuses on a detached HEAD).

Verification

The runner ran each check from the base copy against ff67cba:

  • scripts/check-changelog-fragments.sh --check: passed

The run reports:

  • .lane/checks/bin/check-changelog-fragments: 'All 18 changelog fragment(s) under .changes/ are valid.' (run after the final edits)
  • .lane/checks/bin/check-affected: '12 passed, 6 skipped over 9 changed files' (run after the final edits; skipped: shellcheck (no shell), typos (not installed), three validate-plugins steps and changed-skills (they run the checked tree's own code))
  • .lane/verify/bin/cant-fail-scan --file plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py --lines 11090-11260 --check: PASS, no gating findings
  • .lane/verify/bin/new-changelog-fragment disk-hygiene patch: exit 2, HEAD is not on a branch (fragment written by hand in the same format, then validated by check-changelog-fragments)
  • Fresh-context review subagent over the whole diff: 2 high, 4 medium and 3 low findings plus test and doc notes. Fixed: scan mid-run deleted the open marker; an inventory/catalog refresh after the report hid the run end (the marker now stores opened_at, two seconds early for coarse filesystem mtimes)
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/41051001744

Left out: the items under Not verified.

Related

#6377

Lane-Activity: work-resolve-issue/resolve-issue

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-security-review: 1 inline finding(s) on ff67cbaa000fd36b2ec4ad8580c667efccb01c75; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

# A manual-lane step (null), or a corrupt value.
return True
try:
ended = os.stat(ends_with).st_mtime >= opened_at

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A run ends when a file at a model-chosen path has mtime >= opened_at, and the model can create that file itself. The hook matcher is only Bash|PowerShell (SKILL.md line 8), so the Write and Edit tools can create <plan>.run-end.json or the --report path. The marker under clean-runs/ can also be overwritten, because that directory is not engine-owned. A deliberately blocked preview makes the engine write the run-end file as well.

Exploit path: text injected during a run (filenames or content in the scan target) gets the model to write one of those files. _run_open then returns False and unlinks the marker, so gh, rm and Remove-Item calls are no longer denied. Before this change the belt stayed on for the whole session, and the Bash lane was the control against an injected model. The PR claims releasing the belt "opens no delete path", but that is true only for engine deletes. Manual rm and PowerShell deletes were what the belt covered, and a signal the model controls now releases it.

Suggested direction: end a run only on a signal the model cannot write, such as the engine itself writing the end file into an engine-owned directory (add clean-runs/ and the end-file location to ENGINE_OWNED_DIRS). Alternatively, drop self-service run-end for blocked previews and rely on the idle timeout.

severity: IMPORTANT

claude-lane: claude-security-review

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

I found no security issues in the incremental change.

The only file changed since the last review is plugins/disk-hygiene/skills/clean/SKILL.md. The change is one bullet in the "belt" section, where about 7 lines of prose become a single line.

Instruction-surface check. The bullet describes when the belt, the deny-by-default Bash lane, is active. It does not grant, widen or remove any permission or deny rule.

  • The hook's block list and allowlist are not in this diff, and the bullet after it ("While a run is open, the Bash lane is deny-by-default…") is unchanged.
  • The belt's behavior is enforced by the hook, not by this prose. I did not read the hook; I checked only that it is absent from this increment's diff.
  • I did not read docs/conventions/instruction-exception-register/README.md, so the protected-class list was not consulted. I judged by consequence: the compression changes no forbidden action.

Not a security finding. The new wording may describe the run's lifetime less accurately than the old text.

  • The old text said the belt stays on from a plan's preview until that run's apply or handoff-apply writes its report, or the preview ends in manual-handoff-lane or blocked.
  • The new text says it holds "until that step ends", which could be read as the belt dropping between preview and apply.
  • The new text also drops the explicit statement that a refused scan leaves the belt off.
  • This is a documentation-accuracy question for the code-review lane. It opens no attacker path, and the hook still decides the real behavior.

Manifest items: none in this increment.

Prepaid-credit or subscription spend: none.

critical-findings: 0

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 1 inline finding(s) on ff67cbaa000fd36b2ec4ad8580c667efccb01c75; the summary is in this lane's pull request comment.

claude-lane: claude-review



def _run_open(authority: str | None, session_id: str | None) -> bool:
"""Whether this session has an open clean run, so the belt holds.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Advisory: the marker is trusted state a session can write itself. _run_open releases the belt whenever the marker file says the run ended: ended = os.stat(ends_with).st_mtime >= opened_at, or the mtime is past the idle timeout. The marker sits at a predictable path, <data-root>/clean-runs/<session_id>.json. The belt's job is to stop the session issuing unprompted deletes while a run is open, and the model can use a non-Bash tool such as a file write to create the marker.

Example: while a run is open, write {"version":1,"opened_at":0.0,"ends_with":"/etc/hostname"} to that path. On the next call os.stat(ends_with).st_mtime >= 0.0 is true, the marker is unlinked, and _belt_released stands down. Before this change nothing the model could write turned the belt off.

The PR notes cover only a forged marker made through an engine --report. That one reads as corrupt and holds. They do not cover a direct write. The issue says releasing opens no delete path because the engine gate and approval token remain, but non-engine rm and PowerShell deletes now fall to the session's own permission rules, and those are what the belt was holding back.

Options:

  • Add clean-runs to the engine-owned or guard-protected set and deny writes to it.
  • Make the marker tamper-evident, for example by holding the end signal only in files the engine itself writes.
  • Record the accepted residual in safety-model.md, which currently lists only the unwritable-data-root and --report cases.

claude-lane: claude-review

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 3603d97cf571f0fc1f6e4e66ba40504c34b9e517: 1 finding(s), 1 as inline comments.

Incremental review of plugins/disk-hygiene/skills/clean/SKILL.md. The only change condenses the "belt holds only while a clean run is open" bullet. I compared it with reference/safety-model.md:615-631 ("When a run is open"). I read the files only; I ran no tests or commands.

One advisory finding, inline: the shortened wording no longer says that a preview that produces a plan keeps the belt on until apply or handoff-apply writes its report.

The scan clause and the idle-hour clause still match the safety model. No manifest items, closing-issue criteria or settled threads apply to this change. No hold.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane stopped fix-ci on this pull request: the lane could fix a failing check only by weakening a test, which is refused, so it runs one fresh fixer round on this head that must keep the test's assertions. The lane sets no label: the run ends in a failing pr-unblock/fix-ci status on the head the lane gated.

When a retry on this head can change the outcome, the lane runs one on its own, up to its per-head cap, and edits this comment if it stops again; a run that does not stop clears the status. When no retry can (a review thread the lane does not take or settle, or a failing check after the retries are spent), a person resolves the threads or gets the checks green, then dispatches the workflow below: that run finds the cause gone and clears the status. On a pull request the lanes App opened, the dispatchers start that run once per stop; on any other, a person does. A new commit to the branch starts clean.

To run it again on this head now, dispatch the pr-unblock workflow:

gh workflow run pr-unblock.yml -R melodic-software/claude-code-plugins -f pr-number=11250 -f activity=fix-ci

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

claude-review: 1 inline finding(s) on 3603d97cf571f0fc1f6e4e66ba40504c34b9e517; the summary is in this lane's pull request comment.

claude-lane: claude-review

as of 2026-10-11; recheck when that section changes what the field grants). Consumer permission
policy remains authoritative.
- The Bash lane is deny-by-default: only the literal-word bundled scan, inventory, preview,
- The belt holds only while a clean run is open: from a `preview`, `apply`, `handoff-apply` or manual-lane `handoff-verify` until that step ends, or until an hour passes with no engine call; a `scan` alone opens no run. Outside a run, the belt denies nothing that does not name the engine ([the safety model](reference/safety-model.md), "When a run is open").

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This rewrite loses the span that matters most. The old text said the belt holds "from a plan's preview until that run's apply or handoff-apply writes its report or the preview ends in manual-handoff-lane or blocked." The new text says "from a preview, apply, handoff-apply or manual-lane handoff-verify until that step ends." A reader can take that to mean the belt drops once a preview completes, before the apply. reference/safety-model.md:615-625 says otherwise. A preview that yields a plan records <plan>.run-end.json, and the engine writes that file only for a manual-handoff-lane or blocked outcome or for the later mutation's --report. So the marker, and the belt, stays through the gap between preview and apply. The clause also stops covering a scan that precedes a preview, which the safety model treats as audit-only. This file is the guard's operator contract, so please restore the preview-to-apply span. For example: "from a preview until the run's apply/handoff-apply report is written or the preview ends in manual-handoff-lane or blocked; from each manual-lane handoff-verify until an hour passes with no engine call."

claude-lane: claude-review

@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 30, 2026
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane stopped on this pull request and needs a person: the lane could fix a failing check only by weakening a required check, and the head has no fresh fixer round left (it ran one, or an earlier lane stop already spent its same-head retry), so a person decides.

  • Reason: ci-fix-weaken-required
  • Resume key: 3603d97cf571f0fc1f6e4e66ba40504c34b9e517 (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=11250 and activity=fix-ci:

gh workflow run pr-unblock.yml -R melodic-software/claude-code-plugins -f pr-number=11250 -f activity=fix-ci

@kyle-sexton kyle-sexton added the do-not-merge Hard merge gate: do not merge while applied. label Oct 30, 2026
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane escalated this pull request as ci-fix-weaken-required, and that no longer holds at 3603d97cf571f0fc1f6e4e66ba40504c34b9e517: the lane now ends it in a failing status, not a person, and the head's own checks read failed. pr-merge removed needs-human, so the lanes run on it again. To keep a person on it, add needs-human back: a label a person adds is never removed.

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

Copy link
Copy Markdown
Member

Superseded by #11295, which carries this change plus its review and security fixes.

@github-actions
github-actions Bot deleted the work-resolve-issue/issue-6377-41051001744-1 branch October 31, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge Hard merge gate: do not merge while applied.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(disk-hygiene): release the clean session belt when no run is open

1 participant