Skip to content

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

Merged
kyle-sexton merged 11 commits into
mainfrom
fix/disk-hygiene-clean-belt-run-scoped
Oct 30, 2026
Merged

kyle-sexton merged 11 commits into
mainfrom
fix/disk-hygiene-clean-belt-run-scoped

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

Closes #6377

Replaces #11250

Hold: a human merges this

#6377 makes this line a done-when item: the change alters when a guard on destructive deletes restricts agents, which protects the host (standing direction §2 counts a host-protecting limit as safety, not friction).

Summary

Carries #11250's change: the /disk-hygiene:clean belt denies only while a clean run is open, tracked by a per-session marker, instead of for the rest of the session. The engine deletes the session's marker clean-runs/<session>.json when the run ends, and deletes any marker past the idle timeout. The guard deletes nothing.

Design notes:

  • The run opens at preview, not at scan: the owner decided this on fix(disk-hygiene): release the clean session belt when no run is open #6377 (D13, option a, "go with a"). D13's wording had scan write the marker, which cannot coexist with the criterion that gh issue list is allowed after an audit-only run reaches its report: nothing the guard or engine sees at scan time tells an audit-only run from one that will execute (plugins/disk-hygiene/skills/clean/SKILL.md:346; the scan subcommand has no execution flag, plugins/disk-hygiene/lib/engine_grammar.py:208-244), and the audit-only end, the step-3 report, makes no engine call. A scan only restarts an open run's idle clock; the belt holds from the preview through apply.
  • A manual-handoff-lane preview ends the run. Each handoff-verify opens it again until the idle timeout, which keeps the belt's ask on the manual lane's PowerShell deletes.

Fix

  • Ended markers stayed on disk (pr-verify): fix(disk-hygiene): release the clean session belt when no run is open #6377 requires that the run-end paths delete the marker and that a marker read past the idle timeout is deleted. The new engine function close_clean_runs does both:

    • after apply or handoff-apply writes the report the marker names;
    • after a preview of the plan the marker names ends in manual-handoff-lane or blocked;
    • on every engine call, for any marker past the idle timeout.

    It removes only regular *.json files in clean-runs/, and leaves other sessions' markers that name a different file. The guard still deletes nothing. The preview's <plan>.run-end.json end file is gone, and the belt now reads only the marker's age.

  • Kill switch vs. belt release (security thread): with disk_hygiene_enabled false and no open run, the release ran before the audit-only verdict, so a PowerShell deletion spelling and a Bash rm fell to the session's own rules. _belt_released now takes the kill switch and never releases while it is off, on both lanes; test_kill_switch_off_denies_deletions_with_no_open_run failed on both lanes before the fix. The safety model, SKILL.md, README and fragment say so.

  • Owner-registry deletion check: close_clean_runs joins the DELETERS set in test_owner_registry.py, next to the temporary-file writers. The test's docstring sanctions that kind of edit: "Widening what a file may do is an edit to the constants above, in review." A new pin, test_the_run_closer_removes_only_clean_run_markers, checks that its only removal is marker.unlink over clean-runs/*.json. A behavior test checks that an aged file elsewhere under the data root, and an aged non-.json file in clean-runs/, both survive. test_no_shipped_file_deletes_names_the_registry_or_reaches_a_lane passes.

  • Security threads (model-writable run end): clean-runs/ is engine-owned state (engine_grammar.ENGINE_OWNED_DIRS), so an engine --output or --report cannot land on a marker. The belt matches only Bash and PowerShell, so a PowerShell command it does not read as a delete could still backdate the marker and end a run early. safety-model.md records this as an accepted residual. A forged end reaches the same state a natural run end gives: the engine gate and the approval token still gate every engine mutation. If the owner wants this closed, the option is a Write|Edit|NotebookEdit matcher that denies writes under clean-runs/.

  • SKILL.md wording thread: the Gotchas bullet, the README and the belt's denial text cover the span from preview to apply.

  • The changelog fragment was generated by scripts/new-changelog-fragment.sh and now names engine-side deletion.

Verification

Run locally on head f22bda0 through scripts/run-test-file.sh:

  • test_owner_registry.py: 25 passed.

  • owner_registry.test.sh: 25 tests OK.

  • test_hygiene.py: 757 passed, 3 skipped, 1065 subtests passed.

  • hygiene.test.sh: 760 tests OK, 3 skipped.

  • Red before the fix: the new and changed tests failed on the pre-fix engine (7 failed, 5 passed), as did the new owner-registry pin (1 failed, 24 passed). The failures were:

    • test_belt_holds_between_scan_and_apply_until_the_report_lands
    • test_handoff_apply_completion_ends_the_run
    • test_terminal_preview_outcome_ends_the_run (manual-handoff-lane and blocked)
    • test_engine_call_after_the_report_does_not_reopen_the_run
    • test_run_end_deletes_only_the_marker_of_the_run_it_ends
    • test_engine_deletes_a_marker_past_the_idle_timeout

    Each asserted that the marker file is gone after the engine step. All pass after the fix.

  • check-skill.sh plugins/disk-hygiene/skills: 4 passed, 0 failed.

  • scripts/check-changelog-fragments.sh --check: all fragments valid.

  • run-ruff.sh check on the changed Python files: all checks passed.

Related

🤖 Generated with Claude Code

melodic-automation-lanes Bot and others added 5 commits October 30, 2026 12:17
Lane-Activity: work-resolve-issue/resolve-issue
…uard

The owner-registry scan allows deletion only in the engine's lanes, and the
belt's marker.unlink() in destructive_guard.py broke it (check-skills,
test-bash, test-python). An ended marker now stays on disk and reads as no
run; the next step that opens a run overwrites it. A scan refreshes the
idle clock only of an open run, so a timed-out or corrupt marker is not
revived.

clean-runs/ joins ENGINE_OWNED_DIRS, so no engine --output or --report can
land on a marker. The safety model records the residual that a file write
the belt does not see can end a run early. SKILL.md, README.md and the
denial text restore the preview-to-apply span.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 30, 2026 16:10
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T16:13:12.378575Z 53719ed Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Incremental review of d28dbd6, which changes safety-model.md, destructive_guard.py and test_hygiene.py. I found no defects.

What changed. _record_run_step now leaves a handoff-verify's manual-lane marker alone when a later preview, apply or handoff-apply is admitted. It only refreshes the marker's mtime. Before, those calls overwrote the marker with an ends_with file name. When that step ended in manual-handoff-lane, blocked, or a written report, the engine deleted the marker and dropped the belt's ask on the lane's PowerShell deletes.

What I checked, by reading the code. I did not run the tests.

  • close_clean_runs in hygiene.py (lines 484-488) only closes a marker early when the recorded ends_with is a string equal to the ended file. A verify's marker records None, so no engine step can end it early. Only the idle timeout does. This matches the new tests and the doc text.
  • _manual_lane_open fails closed. An unreadable open marker counts as a manual lane, so the marker is kept and only refreshed.
  • A verify after a preview still overwrites the marker with ends_with: None, which is intended. A preview, apply or handoff-apply over a preview-opened run still rewrites the marker with its own end file, as before.
  • _run_open and _manual_lane_open both stat the marker with a small race window. The failure mode is the fail-closed one, so it is harmless.
  • The new tests use helpers that exist (_engine_preview, _engine_handoff_apply, _engine_words, _age_run_marker, _run_marker). They cover both terminal preview outcomes and handoff-apply, and they assert the marker file survives and PowerShell Remove-Item still gets ask.
  • The safety-model.md edit matches the guard behaviour. The "Accepted residual" heading is narrowed to "outside the engine", which is accurate.

The guard comment block above _RUN_MARKER_DIRNAME still says the engine deletes the marker when a preview ends in manual-handoff-lane or blocked. It doesn't note the verify exception. This is a minor wording gap and I did not count it as a finding.

No trusted-path files are in this incremental change. No cost or critical-security hold applies.

@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 53719ed6ad4369ecb74637ac74506a069ee26d58; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

No security issues found in the incremental change (since 0f03ee0). I read .claude-lane/incremental.diff and the surrounding _record_run_step and _run_open code in destructive_guard.py. I did not read the engine's marker-deletion code or run the new tests.

  • What changed: a preview, apply or handoff-apply admitted while a handoff-verify run is open now only touches the marker's mtime (destructive_guard.py:2684-2689). Before, it overwrote the marker with an ends_with end file. The engine then deleted the marker when that file was written, which dropped the ask on the manual lane's PowerShell deletes. A new helper, _manual_lane_open, tells the two cases apart.
  • Direction of the change: it only keeps the belt closed longer, so it narrows nothing. An unreadable or malformed open marker is treated as a manual lane and stays open (destructive_guard.py:2711-2712), so a read failure keeps the ask and doesn't drop it.
  • Residual cost: repeated engine calls can keep the lane held past the idle timeout. Because the held state means more prompts, not fewer, this is a usability effect and not a path to an impact.
  • Engine gate: the engine gate and approval token are untouched, and the diff opens no new delete path.
  • Docs and tests: the safety-model.md edits match the code. The two new tests cover a terminal preview (manual-handoff-lane and blocked) and a handoff-apply after a verify.

Manifest fields: not touched. No spend beyond prepaid or subscription usage. No hold.

critical-findings: 0

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

The pr-verify verifier failed head 79568f59dded6ce89e485be0d2535b66de88e25a. What it wrote, as data:

What it wrote (37 lines)
Summary: This fails #6377 because the PR departs from the owner's D13 design without sign-off. D13
  has `scan` open the run. Here only a `preview` (or a mutation or `handoff-verify`) opens it. So
  the belt is off for the whole stretch after a scan and before a preview. In that stretch any
  non-engine Bash or PowerShell command passes, including deletes. That breaks the done-when item
  "between scan and apply, a non-engine Bash command is still denied" and weakens a guard on
  destructive deletes beyond what the spec asks. The PR body raises this as a design note for the
  owner, but no owner decision on the issue accepts it. Several other parts look sound: the
  session-id fail-closed path, the corrupt-marker handling, the run-end deletion by the engine, the
  changelog fragment, the denial text, the PowerShell gh-body test and the Hold line.
- plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py:251-265 (`_record_run_step`): an
  admitted `scan` only refreshes a run that is already open, so after a scan and before any preview
  `_run_open` is False. `_belt_released` then lets every non-engine Bash and PowerShell command
  through, `rm` and `Remove-Item` included. D13 and the Agent Brief say scan, the first engine call
  of a run, writes the marker. Fix: have an admitted `scan` open the marker. Then close it in the
  engine when the scan is refused at the target check (exit 2) and at the audit-only terminal
  outcome. Alternatively, get the change from preview-opens to scan-opens decided by the owner on
  #6377 before this merges.
- plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py
  (`test_belt_holds_between_scan_and_apply_until_the_report_lands`): the name says the belt holds
  between scan and apply, but the test opens the run with a preview, so it never checks the
  scan-to-preview stretch. Add an assertion that `gh issue list` (or `rm x`) is denied right after
  `_scan()` with no preview yet. That assertion fails on this head.
- plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py:278-294 (`_run_open`): the guard
  reads a marker that is past the idle timeout but never deletes it. Only the engine's next call
  deletes it (`close_clean_runs`). The 2026-10-27 decision says a marker past the timeout 'is
  removed when read'. If removal on the engine's next call is the intended fix for the shipped-file
  deletion check, record that in the issue or the PR. Otherwise, add a deletion path that the
  deleter checks allow.
- plugins/disk-hygiene/skills/clean/scripts/hygiene.py:441-443: a preview with outcome
  `explicit-approval` keeps the run open. In an audit-only flow, where the user never asks for
  execution after an approvable preview, the belt then holds for the full hour instead of ending at
  the audit-only terminal outcome the spec lists. Close the run at the audit-only report, or
  document this case and test it.
- plugins/disk-hygiene/skills/clean/reference/safety-model.md: the new accepted residual says a
  session can backdate or forge its own marker, or an end file, and so end its run early. That is a
  new trade-off in a host-protecting guard, and a human should confirm it at merge, which the PR's
  Hold line already requires.

This pull request leaves the merge queue, and ci-status holds it out while it carries pr-verify-failed. A pr-verify pass at a new commit removes the label.

@github-actions github-actions Bot added the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Oct 30, 2026
kyle-sexton and others added 2 commits October 30, 2026 12:39
…he run ends

The guard left an ended marker on disk, which the #6377 criteria rule out:
the run-end paths delete clean-runs/<session>.json, and a marker past the
idle timeout is deleted. The engine now does both in close_clean_runs:
after apply or handoff-apply writes the report the marker names, after a
preview of the marker's plan ends in manual-handoff-lane or blocked, and on
every engine call for any marker past the idle timeout. It removes only
regular *.json files in clean-runs/; the guard still deletes nothing.

close_clean_runs joins the owner-registry DELETERS set beside the temporary
file writers, with a pin that it removes only clean-runs markers. The
preview's <plan>.run-end.json end file is gone, and the belt reads only the
marker's age.

Refs: #6377

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot removed the pr-verify-failed pr-verify failed this head; a pass at a new commit, or after a trusted body edit, removes it. label Oct 30, 2026
…en run

With disk_hygiene_enabled false and no open run, the belt release ran
before the audit-only verdict was used, so a PowerShell deletion spelling
the kill switch denies, and a Bash rm, fell through to the session's own
permission rules. _belt_released now takes the kill switch and never
releases while it is off, on both lanes. The safety model, SKILL.md,
README and changelog fragment say so.

Refs: #6377

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 f22bda0d2c1718eeaba5c7594894682ccd487cdc; the summary is in this lane's pull request comment.

claude-lane: claude-review

kyle-sexton and others added 2 commits October 30, 2026 14:36
…no run

"Audit-only" names the disk_hygiene_enabled=false mode, but the
changelog fragment's headline, the README belt paragraph, the safety
model and a guard comment also used it for a scan with no preview. The
fragment now says the fix covers a scan-only /disk-hygiene:clean with
execution enabled, and states plainly that with the kill switch off the
belt keeps denying gh, git and test commands for the rest of the
session.

Refs: #6377

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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 0f03ee05b84be48a02941d9e179dba576dcda91b; the summary is in this lane's pull request comment.

claude-lane: claude-review

A handoff-verify opens the manual lane with no end file, so only the idle
timeout ends it. An allowed preview admitted afterwards rewrote the
marker with its --plan as the end file, and when that preview ended in
manual-handoff-lane or blocked the engine deleted the marker. The belt
then stood down and a PowerShell Remove-Item ran with no ask, with no
backdating involved. An apply or handoff-apply report closed it the same
way.

While a verify-opened run is open, the guard now only restarts its idle
clock for a preview, apply or handoff-apply and never records an end
file, so only the timeout ends the lane. An unreadable open marker counts
as a verify's. New tests cover a terminal preview and a handoff-apply
after a verify; both fail on the old guard. The safety model's run and
residual paragraphs say so.

Refs: #6377

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KeBVgcHpe4YpFuL5b24Ft2
@kyle-sexton
kyle-sexton added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 0ef5740 Oct 30, 2026
43 checks passed
@kyle-sexton
kyle-sexton deleted the fix/disk-hygiene-clean-belt-run-scoped branch October 30, 2026 21:51
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): release the clean session belt when no run is open

1 participant