Skip to content

fix(appearances): finish a pack delete a held file interrupted - #33703

Merged
bolichen97 merged 1 commit into
mainfrom
fix/32171-appearance-pack-delete-retry
Nov 11, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/32171-appearance-pack-delete-retry

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Deleting a custom appearance pack on Windows finishes even when another program briefly holds one of its files open.

On Windows, AppearanceStore.delete_pack removed the pack folder with a bare shutil.rmtree. A file held open by an editor, an indexer or an antivirus scan raises PermissionError (WinError 32), so the delete stopped partway: part of the pack was gone, the rest stayed on disk, and the dashboard answered 404 pack_not_found.

Why it matters

A user who deletes a pack while another program glances at one of its files gets a half-deleted pack and a "no such appearance pack" error, and has to delete it again by hand. Both the crew appearance library and Crew Companion's gallery delete through this store.

Not a goal

What changed (motivation → approach → change)

A pack delete on Windows now waits out a briefly held file instead of failing at the first one. A file held for longer still fails the delete, but the pack stays in the gallery, so deleting it again finishes the job. Linux and macOS delete an open file, so they behave as before.

The cause was the bare shutil.rmtree in delete_pack. The delete now goes through platform_compat.remove_with_retry, the helper the meeting delete uses (#32190). It retries a sharing violation (winerror 32/33) for about three seconds, then raises an error naming the held file.

Where How the pack folder is removed
shutil.rmtree.avoids_symlink_attacks is false (Windows) each entry through remove_with_retry, the manifest last whatever its letter case (MANIFEST.JSON is the same file there), then the folder; the gallery lists only packs that have a manifest
everywhere else (Linux, macOS) one remove_with_retry call on the folder, which is the same shutil.rmtree as before and removes through the folder it opened

The link refusal and the containment check still run first, and any failure is still logged and answered False. The helper table in docs/system-specs/common/platform-compat.md names the pack delete among its callers.

Backwards compatibility

Compatible: every delete that succeeds today succeeds the same way. On Windows a sharing violation is retried for up to about three seconds per held entry before the same False answer, and the dashboard's config lock, which the delete runs under, is held for that wait. Every other error, and every error on Linux and macOS, fails at once as before; there the delete is the same single shutil.rmtree call as today.

Removes nothing: the same folder is deleted after the same link and containment checks.

Tests

  • test/test_appearance_packs_store.py::TestPathSafety::test_deleting_a_pack_waits_out_a_file_held_open_briefly: unlinking idle.svg raises WinError 32 once, then succeeds; the delete returns True and the folder is gone.
  • test_a_hold_past_the_retry_keeps_the_pack_listed_to_delete_again (same file): working.svg, which Windows lists after manifest.json, stays held on every attempt; the delete returns False, the pack is still listed, and a second delete after the hold ends returns True.
  • test_a_hold_past_the_retry_keeps_a_case_variant_manifest (same file): the manifest is named MANIFEST.JSON and the folder is listed in Windows order (case-insensitive, so it comes before working.svg); with working.svg held, the delete returns False and MANIFEST.JSON is still on disk.
  • All three set shutil.rmtree.avoids_symlink_attacks to false so they run the Windows path on Linux; remove_with_retry keys on winerror, not on the OS. The Windows backend lane runs them natively.
  • test_a_pack_swapped_for_a_symlink_mid_delete_deletes_nothing_outside (same file, skipped where rmtree walks by path): the pack folder is replaced by a link to another folder after the delete starts; nothing in that other folder is removed and the delete returns False.
  • Determinism: test/test_appearance_packs_store.py run 10 times, each in a fresh shuffled order, 42 of 42 every run; the four delete tests above 20 times at -n0 and 10 times at -n 4 beside two sibling appearance-pack test files, green every run.

Proof: PROVEN test/test_appearance_packs_store.py::TestPathSafety::test_deleting_a_pack_waits_out_a_file_held_open_briefly, test/test_appearance_packs_store.py::TestPathSafety::test_a_hold_past_the_retry_keeps_the_pack_listed_to_delete_again, test/test_appearance_packs_store.py::TestPathSafety::test_a_hold_past_the_retry_keeps_a_case_variant_manifest (head 2d417f6)

Manual verification

N/A — the behaviour is Windows-only and the unit test forces the exact winerror the helper reads; not run on a Windows host.

Screenshots / video

N/A — backend-only change; no frontend file is touched.

Related Issues

Part of #32171

Sibling sweep

Swept: git grep -nE "shutil.rmtree(" -- src/kiro_crew/appearance_packs, plus the sites #32171 lists
Sibling: src/kiro_crew/appearance_packs/store.py:307 -- not affected -- the other rmtree calls in this file (307, 637-708) remove the store's own .tmp-* staging and .old.* backup folders, which no user program has open
Sibling: src/kiro_crew/apps/builtins/code_review_sage/sage_lib/store.py:883 -- tracked in #32171
Sibling: src/kiro_crew/apps/builtins/code_review_sage/sage_lib/learning.py:225 -- tracked in #32171

Pattern harvest

Rule candidate: review-prompt
Pattern: a user-initiated delete of a folder the user can open in other programs calls shutil.rmtree instead of platform_compat.remove_with_retry

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 9, 2026 05:03
@bolichen97
bolichen97 requested a review from Zedmor November 9, 2026 05:03
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 2d417f68720e719600caa71e8bd1459ae5dec1c4 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 9, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 2d417f68720e719600caa71e8bd1459ae5dec1c4 — 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. The fix reuses the existing platform_compat.remove_with_retry, so it is not a second spelling. The manifest-last order fixes the cause, the half-deleted pack that drops out of the gallery, the same way meetings delete_meeting does.

Not checked: whether a real Windows hold on a pack file behaves as the faked winerror 32 does; the description says no Windows host was used.

What this change ships

Inventory (6 items) — 5 justified

Intent: delete a custom appearance pack on Windows even when another program briefly holds one of its files open. This is a FIX.

  1. On Windows, deleting a pack waits up to about 3 s for a held file instead of failing at the first one. — justified
  2. On Windows, the pack's manifest is deleted last, so a pack a long hold interrupts stays in the gallery and a second delete can finish it. — justified
  3. On Windows, the dashboard's config lock stays held during that wait, up to about 3 s for each held file. — justified
  4. A failed delete now logs which file was held and a hint to close the program using it. — justified
  5. The platform-compat helper table lists the appearance pack delete among its callers. — justified
  6. A POSIX-only test checks that a pack swapped for a symlink mid-delete removes nothing outside the pack. — rides along (test only, no new surface)

[FIRST-PRINCIPLES-REVIEWED] 2d417f6

Description read

[DESCRIPTION-READ] c2d3ce20dac6d3454034394ef8f3fc7a1cd6655c8704c51b358d6811d24ac20f

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 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks. The delete runs in a worker thread, so the retry can sleep. Keeping the manifest until last means a half-finished delete still shows in the gallery, and the Windows branch is covered by tests forced to run on Linux and by the Windows CI lane.

Notes

[DESIGN-REVIEWED] 2d417f6

Description read

[DESCRIPTION-READ] d29e8277f349a2d8a04992dcc479001648100fde47c7b6abcbcb473656d48208

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 9, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 2d417f68720e719600caa71e8bd1459ae5dec1c4 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 2d417f6

Verdict parsed from the review's SHA-scoped output markers for commit 2d417f68720e719600caa71e8bd1459ae5dec1c4.

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

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 2d417f68720e719600caa71e8bd1459ae5dec1c4 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2d417f6

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 9, 2026 05:14
@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 9, 2026
buluoray
buluoray previously approved these changes Nov 9, 2026

@buluoray buluoray 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.

Approving. delete_pack replaces a bare shutil.rmtree with platform_compat.remove_with_retry per child, manifest.json last, so a briefly held Windows file no longer half-deletes a pack (appearance_packs/store.py:543-549, platform_compat_files.py:620-664). Link refusal and containment checks are unchanged and run first; both new tests turn red under mutation.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in src/kiro_crew/appearance_packs/store.py, docs/system-specs/common/platform-compat.md and test/test_pid_reader_ratchet.py since this head's CI ran (2caa69b -> fd5d9ef); CI re-running. The Static Ratchet Gate red on the old head was main's own (test_owner_marked_sites_match_the_recorded_count, fixed on main by #33695), and the arm64 desktop build died on a 504 from the download host.

The new head also keeps Linux and macOS on the single shutil.rmtree call they used before; the entry-by-entry walk now runs only where shutil.rmtree.avoids_symlink_attacks is false (Windows). One added test covers it; the body is regenerated.

[operator: bolichen97]

@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 10, 2026
buluoray
buluoray previously approved these changes Nov 10, 2026

@buluoray buluoray 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.

Approve on 99382f7. Since the approved 6eff28e, the per-entry, manifest-last walk runs only where shutil.rmtree walks by path (Windows: if not shutil.rmtree.avoids_symlink_attacks). POSIX keeps the single fd-based rmtree, and a new test pins that a pack swapped for a symlink mid-delete removes nothing outside the pack. Tests 41/41, both guards turn a named test red under mutation. The GPT lane is red on a hand-placed MANIFEST.JSON edge case (low harm, one-token fix); the author needs to fix it or file an override before merge. Decisive lines: src/kiro_crew/appearance_packs/store.py:543-550, src/kiro_crew/platform_compat_files.py:640-648, test/test_appearance_packs_store.py (test_a_pack_swapped_for_a_symlink_mid_delete_deletes_nothing_outside)

On Windows, deleting a custom appearance pack while another program
held one of its files open (an editor, an indexer, an antivirus scan)
failed with WinError 32 and left a half-deleted pack behind. The delete
now goes through platform_compat.remove_with_retry, which waits out the
sharing violation for about three seconds, the same helper the meeting
delete uses since #32190.

Where shutil.rmtree walks a folder by path (Windows), the pack's
entries are removed one at a time with manifest.json last, so a hold
that outlasts the wait leaves the pack listed and a second delete
finishes it. Everywhere else the delete stays one shutil.rmtree call,
which removes through the folder it opened. The platform-compat helper
table names the pack delete among its callers.

Part of #32171
@bolichen97
bolichen97 force-pushed the fix/32171-appearance-pack-delete-retry branch from 99382f7 to 2d417f6 Compare November 11, 2026 06:11
@bolichen97

bolichen97 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: the Windows per-entry walk that keeps the manifest last; its name check now folds case

  • span=cb279efbd8d2 Preserve case-variant manifests until other files are deleted

fixed in 2d417f6: the walk compares child.name.casefold() with "manifest.json", so MANIFEST.JSON and any other case variant is skipped and goes only with the folder.
test_a_hold_past_the_retry_keeps_a_case_variant_manifest names the manifest MANIFEST.JSON, lists the folder in Windows order and holds working.svg: red on 99382f7 (manifest removed), green here.

[operator: bolichen97]

@buluoray buluoray 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.

Approve on 2d417f6. Since the APPROVE on 99382f7, the only change is the fix for the GPT finding. The manifest-last skip now compares child.name.casefold(), so a MANIFEST.JSON also stays until last on Windows. A new test pins this, and reverting the casefold turns that test red. Tests pass 42/42, and every AI lane, including GPT and Sensitive Change Review, is green on this head. Decisive lines: src/kiro_crew/appearance_packs/store.py:548, test/test_appearance_packs_store.py:195-225 (test_a_hold_past_the_retry_keeps_a_case_variant_manifest)

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 11, 2026
@bolichen97
bolichen97 merged commit 4dd6b6b into main Nov 11, 2026
98 of 100 checks passed
@bolichen97
bolichen97 deleted the fix/32171-appearance-pack-delete-retry branch November 11, 2026 07:18
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 11, 2026
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.

2 participants