Skip to content

fix: tighten the windows session-trash removal - #31676

Merged
bolichen97 merged 1 commit into
mainfrom
fix/7566-windows-trash-removal
Nov 7, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/7566-windows-trash-removal

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On Windows, emptying the session trash removes only what is in the trash.

On Windows the session trash is removed with a path-based delete. That delete can be led out of the trash.

Why it matters

The trash holds the user's old sessions, and its folder is writable by the same user, agents included. A delete that leaves the trash can remove files the user never put there.

Not a goal

  • No change to macOS or Linux, which already delete by descriptor.
  • No change to how a batch's manifest is put back or cleaned up.
  • No change to the unlisted-file check or to the manifest ordering on the Windows path.
  • No new refusal, setting or seal.

What changed (motivation → approach → change)

Windows session storage now removes a trash batch with the pinned-directory sweep main already ships and Windows CI already runs. Each folder is held still while it is emptied, and a link inside the batch is removed as a link and never entered.

A cloud-files or dedup folder is still emptied as the folder it is: the pinned-directory helper in src/kiro_crew/platform_compat_links.py can carry its existing links_only choice down the whole tree, and the platform-compat spec says so.

On Windows the helper's file delete checks that the file it opened really sits in the pinned folder, and deletes through that same handle. A folder that became a link in place therefore loses nothing outside. src/kiro_crew/platform_compat.py forwards the two new private helpers, as it does for the module's other names.

A batch's manifest is removed last, only once everything else went, so a batch that will not go keeps its listing.

Everything else stays as it was: the batch is still renamed aside and its identity checked first, the freed bytes are still measured after the attempt, a batch that will not go is still put back and reported as kept. The session storage spec is updated to describe the sweep.

Backwards compatibility

Compatible: the same batches are removed and kept as before; only how the files inside are reached changes.

Removes nothing: the delete reaches the same entries; nothing a user or caller sees is taken away.

Tests

  • A Windows-only test puts a link into a batch while it is being removed. The link's target must keep its file, and the batch must still go.
  • A Windows-path test locks one file in a batch. The batch must keep its manifest and go back under its own name, still listed.
  • A Windows-only test makes every folder answer as a reparse point that is not a link, at the open and in its attributes. The batch must still go.
  • A Windows-only test turns an empty folder in the batch into a link in place, mid-delete. The link's target must keep its file.
  • Two artifact-store tests simulate a locked file at the pinned-directory delete, the one call the store's sweep makes.
  • The containment check, the final-path read and the delete-by-handle are driven through kernel32 stand-ins on every host: a redirect, a case-only difference and an unreadable path are refused, a link is never removed as a folder.
  • Two existing Windows-path tests force a locked file through the sweep.
  • The pinned-only test classes are skipped per class, so the Windows-path tests run on Windows.

Proof: PROVEN test/test_platform_compat_refactor_facade.py::test_every_moved_name_is_defined_by_its_owner_and_read_through_the_facade[kiro_crew.platform_compat_links-_win_check_within], test/test_platform_compat_refactor_facade.py::test_every_moved_name_is_defined_by_its_owner_and_read_through_the_facade[kiro_crew.platform_compat_links-_win_final_path], test/test_platform_compat_refactor_facade.py::test_every_moved_name_is_defined_by_its_owner_and_read_through_the_facade[kiro_crew.platform_compat_links-_win_unlink_within], test/test_platform_compat_refactor_facade.py::test_every_moved_name_is_defined_by_its_owner_and_read_through_the_facade[kiro_crew.platform_compat_links-_WIN_FILE_READ_ATTRIBUTES], test/test_platform_compat_refactor_facade.py::test_every_moved_name_is_forwarded_unless_code_still_here_reads_it (head cb18d11f13b2)

prove.py reverts all production hunks at once, so it reports the first tests that fail. Each Windows test was also run by hand on Windows with its own production change reverted: the swapped-in link, the locked-file manifest, the non-link reparse folder and the in-place link conversion each fail, because a file outside the batch is deleted or the batch cannot go, and each passes with the change. Repeats: the touched files pass 3 runs in a row on Windows, in random order.

Manual verification

N/A — the Windows test drives the real delete against a real junction on NTFS.

Related Issues

Closes #7566

Sibling sweep

Swept: git grep -n "shutil.rmtree" -- src/kiro_crew/session_storage.py src/kiro_crew/session_storage_parts/
Sibling: src/kiro_crew/session_storage_parts/batch_removal.py -- changed here
Sibling: src/kiro_crew/session_storage_parts/pinned_delete.py -- changed here
Sibling: src/kiro_crew/session_storage_parts/crew_staging.py:360 -- tracked in #31901

Pattern harvest

Rule candidate: semgrep
Pattern: a path-based recursive delete of an agent-writable tree where the pinned-directory sweep exists

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 6, 2026 19:06
@bolichen97
bolichen97 requested a review from Zedmor November 6, 2026 19:06
@bolichen97
bolichen97 force-pushed the fix/7566-windows-trash-removal branch from 621fde8 to 9de3bca Compare November 6, 2026 19:06
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 6, 2026
@bolichen97
bolichen97 enabled auto-merge (squash) November 6, 2026 19:13
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Backend Tests (Windows) (2) and Backend Tests (3.12, 2) fail on test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget. It also fails on origin/main 8dbdf04 with this PR's change rebased on top, and this PR touches nothing in that package. Tracked in #31648; fix in #31625. This PR waits for that fix, then rebases.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 8c2351213a4027c0c63962657b7d0fb0011ee1e6 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 8c2351213a4027c0c63962657b7d0fb0011ee1e6 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. One thing to subtract: the new trash sweep is a near-copy of the artifact store's pinned sweep.

Notes

  • Item 1 — duplicate of src/kiro_crew/artifacts_disk.py:602 (_rmtree): _sweep_staged's nested _empty repeats _rmtree's _empty almost line for line. That gives 2 copies of the pinned-directory sweep, counted by grepping def _rmtree|pinned_directory\(. Only three things differ: the keep= skip for the manifest, links_only, and the clean return value. Subtraction: delete the copied recursion from _sweep_staged, keep one _empty in artifacts_disk._rmtree, and pass it the keep name and links_only.
  • Item 4 — framing: the description says "No new refusal, setting or seal". _win_check_within adds one: raise OSError(errno.EXDEV, "the entry is not inside the pinned directory", path), raised even when neither final path can be read. It applies to every Windows PinnedDirectory caller, which includes staging.py, skills_review.py, portability_vetting.py and artifacts_disk.py. Subtraction: drop the refusal for the unreadable pair, or drop the sentence that says there is no new refusal.

What this change ships

Inventory (7 items) — 5 justified

Intent: on Windows, emptying the session trash deletes only what is inside the trash. FIX (#7566).

  1. Windows trash empty and batch removal use a pinned sweep instead of rmtree — duplicate of artifacts_disk._rmtree's recursion
  2. A junction inside a batch is removed as a link and never entered — justified
  3. The manifest is removed last, so a batch with a locked file stays listed — justified
  4. Every Windows PinnedDirectory.unlink/rmdir/child checks the final path and deletes through the open handle — undeclared refusal for an unreadable final path
  5. pinned_directory(links_only=...) is passed down the chain — justified
  6. The handle is closed when open_osfhandle fails — rides along
  7. Pinned-only tests are skipped per class, so the coarse-path tests run on Windows — justified

[FIRST-PRINCIPLES-REVIEWED] 8c23512

Description read

[DESCRIPTION-READ] fff43ad0df52cd895d6559db3d995aa69c29577d8e007077191d39af7dd72e10

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 8c2351213a4027c0c63962657b7d0fb0011ee1e6 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the fix removes the path-based delete itself, using the pinned-directory sweep that main already ships, and Windows CI runs the new tests.

Notes

  • The PinnedDirectory.unlink/rmdir/child changes for Windows (delete through the handle, plus _win_check_within) also change behaviour for every other Windows caller: artifacts_disk._rmtree, staging.py, skills_review.py, portability_vetting.py, session_transfer_staging.py and session_staging_sweep.py. The ## Backwards compatibility section only mentions trash batches. A line saying these callers now hit the new EXDEV refusal would make the wider reach visible to anyone reading the PR.

[DESIGN-REVIEWED] 8c23512

Description read

[DESCRIPTION-READ] d67e1dfdef42cc42deca7dd2e55c6c4479ffce6ba4d15082431b2207ade0a3b8

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 8c2351213a4027c0c63962657b7d0fb0011ee1e6 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 8c23512

Verdict parsed from the review's SHA-scoped output markers for commit 8c2351213a4027c0c63962657b7d0fb0011ee1e6.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 8c2351213a4027c0c63962657b7d0fb0011ee1e6 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 8c2351213a4027c0c63962657b7d0fb0011ee1e6 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 8c23512

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 8c2351213a4027c0c63962657b7d0fb0011ee1e6 false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 force-pushed the fix/7566-windows-trash-removal branch from 9de3bca to a4ac5a0 Compare November 6, 2026 20:15
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • Cloud-backed trash directories cannot be emptied span=d285b8d2e602

fixed in a4ac5a0: the Windows trash sweep pins with links_only=True, carried down the whole PinnedDirectory chain, so a cloud-files or dedup directory is swept as the directory it is.
A symlink or junction is still refused at every level: win_fd_is_link checks the name-surrogate bit on the opened handle and fails closed.
Test: TestTheCoarsePlatform::test_a_directory_that_is_a_non_link_reparse_point_is_still_removed fails without links_only and passes with it.
self-added: yes
mechanism: links_only on PinnedDirectory, used only by the session-trash sweep

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Backend Tests (3.12, 7) fails on test/test_pull_request_target_allowlist.py::test_only_the_allowed_workflows_use_pull_request_target (sensitive-change-review.yml). It fails on origin/main 39717a0 too, and this PR touches no workflow. Tracked in #31771. This PR waits for that fix, then rebases.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/7566-windows-trash-removal branch from a4ac5a0 to 0d40168 Compare November 6, 2026 21:52
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/7566-windows-trash-removal branch from 0d40168 to a603bf9 Compare November 6, 2026 23:18
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • Directory pins still allow in-place junction replacement span=d285b8d2e602

fixed in a603bf9: on Windows PinnedDirectory.unlink, rmdir and child open the entry itself, require the kernel final path of that handle to be a direct child of the pinned directory's final path (exact compare, DOS then NT namespace), and delete through the same handle.
Denying FILE_SHARE_WRITE, as suggested, does not close it: a probe on Windows set a mount point on a pinned empty directory through a FILE_WRITE_ATTRIBUTES-only handle, which no share mode refuses.
Test: TestTheCoarsePlatform::test_an_empty_pinned_directory_turned_into_a_junction_deletes_nothing_outside converts the pinned dir in place mid-sweep; it deletes the outside file without the fix and nothing with it.
self-added: no
mechanism: final-path containment check plus delete-by-handle in the shared Windows PinnedDirectory

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 6, 2026
@bolichen97
bolichen97 force-pushed the fix/7566-windows-trash-removal branch from a603bf9 to ed83327 Compare November 7, 2026 00:09
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97]

  • Non-link reparse directories cannot be removed span=d2e4b9be9922

fixed in ed83327: _win_unlink_within classifies a reparse entry as a link only when win_fd_is_link reads a name-surrogate tag on the opened handle, so a cloud-files or dedup directory the links_only sweep entered is removed as a real directory; containment and delete-by-handle are unchanged.
Test: TestTheCoarsePlatform::test_a_directory_that_is_a_non_link_reparse_point_is_still_removed now tags every directory's attributes as a reparse point; it fails with ENOTDIR on a603bf9 and passes on ed83327.
self-added: yes
mechanism: links_only plus final-path containment in the shared Windows PinnedDirectory
resolution: narrowed - kept both mechanisms (retrospective: removing either reopens a verified defect); classification now follows the handle's name-surrogate tag

@bolichen97
bolichen97 force-pushed the fix/7566-windows-trash-removal branch from 5243e95 to 21b7d26 Compare November 7, 2026 05:50
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in docs/system-specs/common/platform-compat.md, src/kiro_crew/platform_compat.py and test/test_platform_compat_refactor_facade.py since this head went green (e4611c5 -> 480d162); CI re-running.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Nov 7, 2026
@bolichen97
bolichen97 force-pushed the fix/7566-windows-trash-removal branch from 21b7d26 to dfe4439 Compare November 7, 2026 07:21
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/session_storage_parts/batch_removal.py since this head went green (480d162 -> b65af1a); CI re-running.

[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Nov 7, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Backend Tests (Windows) (2) and Backend Tests (3.12, 2) fail on test/test_security_gate_liveness.py::test_the_package_stays_within_its_line_budget (package grew to 34855 lines). This PR touches nothing in the security package; the budget is main's. Fix in #32183. This PR waits for it, then rebases.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 7, 2026
On Windows, emptying the session trash removes only what is in the trash.

Closes #7566
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in test/test_security_gate_liveness.py (line-budget fix) since this head's CI ran (b65af1a -> f58c3cf); CI re-running. Rebase only: same patch (git range-diff identical), no rule changed. Local gate and local GPT and Opus reviews passed on the rebased tree.

[operator: bolichen97]

@bolichen97
bolichen97 force-pushed the fix/7566-windows-trash-removal branch from dfe4439 to 8c23512 Compare November 7, 2026 13:23
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 7, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved: PR Readiness passed on 8c23512, and all five review lanes (Opus 5.5, GPT 6.1, Design, UX, First Principles) report no blocking finding on this head. No conflict and no open change request.

@bolichen97
bolichen97 merged commit 614b0eb into main Nov 7, 2026
99 checks passed
@bolichen97
bolichen97 deleted the fix/7566-windows-trash-removal branch November 7, 2026 19:47
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 7, 2026
buluoray pushed a commit that referenced this pull request Nov 8, 2026
On Windows, emptying the session trash removes only what is in the trash.

Closes #7566

(cherry picked from commit 614b0eb)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows session-trash removal and manifest recovery have no descriptor-bound path

2 participants