Repository navigation
fix(slots): stop a folder or tag delete crashing when a tab closes concurrently - #5933
Conversation
|
👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review. When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically. |
|
👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review. When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically. |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: committing before the sweep, two-pass iteration and the shielded sweep plus audit fix all three harms the description names, and they reuse existing seams ( Notes
[DESIGN-REVIEWED] 648e68d Description read[DESCRIPTION-READ] e7a46050a4290a99a36e8096005e68595eafaf5d388c05ac5d203794607a6e3a 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 |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The new close-in-flight capture, the registry and the slot-name pin protect against a stale id that the base code already says is pruned when the store next loads. Notes
What this change shipsInventory (9 items) — 5 justifiedIntent: Deleting a folder or tag finishes fully and is audited even if a tab closes or the client disconnects mid-delete. FIX.
[FIRST-PRINCIPLES-REVIEWED] 648e68d Description read[DESCRIPTION-READ] 30d9458d2df17f75c312117e677b8e90e73c7b72915c0d9dc13e724a03e1bbab That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
5fcb630 to
3040073
Compare
3040073 to
30431ab
Compare
30431ab to
30b2a43
Compare
|
Not approving for now: the description itself defers the merge-aware-save layer fix to #8361 and states that whether the interim guard/adopt protocol is acceptable is a maintainer decision, which is exactly the kind of unresolved blocker I should not sign off past at 10660 added lines. |
|
A maintainer attempted a conflict-only rebase of this PR onto main What blocks a mechanical rebase:
Once rebased onto current main with the above reconciled, readiness should re-evaluate on the new head. |
PR triage (2026-10-05): REBASE, keep openChecked the full diff at head
|
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
|
First Principles BLOCK on 1344213 (second spelling of
Notes (no reply required, answered for the record):
|
|
GPT 6.1 finding on 1344213 (
|
|
First Principles BLOCK on c900812 (second spelling of the cancellation-drain loop): fixed in e048c3d.
|
iamwhatever
left a comment
There was a problem hiding this comment.
Requesting changes on head e048c3d for missing follow-up issues.
The description's Not a goal section says six items are kept on the fork branch archive/slots-snapshot-full-10-items for separate PRs: restore-time pruning of deleted vocabulary ids, tag-prune reader consolidation, in-flight-delete refusals, parked-slot tag revalidation, a metadata-only sweep persist, and the AST gate families (including the semgrep rule under Pattern harvest). None of these has a GitHub issue. Please open an issue for each item you still plan to do and link them in the description, or drop the promise for any you do not.
The fix itself looks sound. Snapshot-then-await removes the dict-resize crash, the folder delete now commits before it unfiles, the sweep and audit survive a cancellation, and close_in_flight is keyed per registration (snapshot_commit.py#L76). All checks on this head are green.
After the issues are linked, a maintainer still needs to review this PR. It changes delete handlers, the close lifecycle, and a path that re-mints a revoked tag grant on an unproven cancelled commit (chat_tags_vocabulary.py#L703-L728).
AI findings judged non-blocking:
- Design Review note 1: nothing enforces
close_in_flightregistration for future pop paths. Today the only pop-save-restore frames areclose_slotandapi_chat_slots_cleanup, and both are wrapped (slot_lifecycle.py#L534). - Design Review note 2: the store lock is held until a cancelled write finishes. The description declares this, and releasing the lock early is the ordering bug this PR fixes (folder_repository.py#L95-L105).
— crew-pr-reviewer (r133)
|
@iamwhatever Your 2026-10-28 change request (follow-up issues for the "Not a goal" items) is addressed at head e610d2f. The second "Not a goal" bullet in the description now links one issue per item:
This head is a plain rebase onto main with no content change. Every per-file |
iamwhatever
left a comment
There was a problem hiding this comment.
Requesting changes on head ed78a92.
The follow-up issues from my earlier review are linked and match the Not-a-goal items (#26159, #26160, #26161, #26162, #26163, #26164, plus #8361). The snapshot-then-await sweep, commit-first folder delete and per-token close_in_flight look sound, and all checks on this head are green.
Blocker: the unproven-cancel branch of the tag delete re-opens a revoked grant.
When the vocabulary commit is cancelled and never confirmed, the handler restores memory and re-mints the grant it revoked (chat_tags_vocabulary.py#L743-L749, #L723-L732). Because run_to_completion shields the write from the handler's own cancel, "not confirmed" only happens when the write task itself is cancelled (chat_tags_store.py#L130-L140), for example by asyncio.run cancelling every task at gateway shutdown. At that point the to_thread worker may already be running and can still land the deletion in tags.json. The result is a grant row for a tag id that no longer exists in an agent-writable file, which is the stale-open state this handler's docstring rules out (#L655-L670). Before this PR a cancelled write escaped except Exception and the grant stayed revoked.
Smallest fix: on that branch, restore the tag in memory but do not re-mint the grant, leaving the documented "present but closed" state that the owner can re-adopt. Please add a test that cancels the write task directly and asserts no grant row remains.
AI findings judged non-blocking:
- Design Review note 1: cite the load-time
folder_idprune in the spec. A documentation nit with no user-visible effect. - Design Review note 2:
close_in_flightwrapping is enforced only by review. Both current pop-save-restore frames are wrapped, and #26164 tracks the gate (snapshot_commit.py#L98). - First Principles note, item 4: the registry is oversized. The author kept it because removing it reopens the earlier GPT bulk-cleanup finding. It is a note, not a BLOCK.
This PR changes delete handlers, the close lifecycle and tag-grant restoration, so a maintainer still needs to review it even after the fix.
— crew-pr-reviewer (r148)
|
@iamwhatever The blocker from your review of ed78a92 (the unproven-cancel branch of the tag delete re-minting the revoked grant) is fixed at head 3559e76.
The spec citation nit (load-time |
bolichen97
left a comment
There was a problem hiding this comment.
Approving at 4b78ca6. The folder and tag deletes now snapshot the slots before awaiting, include tabs whose close is in flight (close_in_flight), and commit the store write first, so a tab closing or a client disconnecting mid-delete no longer crashes it or skips a tab. On a cancelled, never-confirmed vocabulary commit, the tag comes back in memory with its grant still revoked, present but closed. A failed write still restores the grant, because that write never landed. No regex is added, and all checks pass.
@iamwhatever, could you re-review? Your change request at ed78a92 was that the unproven-cancel branch of the tag delete re-minted the revoked grant. At this head that branch restores the tag without re-minting the grant.
|
HOLD at The blocker from our r148 review is fixed. When the vocabulary commit is cancelled and never confirmed, the tag comes back in memory and the revoked grant stays revoked (chat_tags_vocabulary.py#L743-L751). A failed write still restores the grant, because that write never landed. The new test cancels the write task mid-write, lets the worker land the removal, and checks that no grant row remains. Since Our change request at AI findings judged non-blocking: Design note 1 (only prose enforces — crew-pr-reviewer (r149) |
…ncurrently The sweep awaited a slot save while iterating the live ``_slots`` view, so a concurrent close resized the dict mid-loop; the delete now commits first and sweeps a snapshot.
|
@bolichen97 rebased onto main as |
|
@iamwhatever I re-checked both of your change requests at the current head, 648e68d (a rebase onto main, no content change).
The non-blocking spec citation note is not addressed in this head. |
Problem / Motivation
Goal: Deleting a folder or a tag finishes cleanly, with every tab updated and the delete audited, even when a tab closes or the client disconnects at the same moment.
api_chat_folder_delete(src/kiro_crew/dashboard/chat_folders_routes.py) andapi_chat_tag_delete(src/kiro_crew/dashboard/chat_tags_vocabulary.py) each walk every slot and persist it withawait save_slot_off_loop(...)inside a loop over the livestate._slots.values()view.A tab closing during that await calls
_slots.pop, which resizes the dict mid-iteration and raisesRuntimeError: dictionary changed size during iteration. The sweep aborts part way, so some slots are stripped and the rest still name a folder or tag that no longer exists.Why it matters
The delete is not atomic today. Three ways a user loses state:
asyncio.to_threadhands the vocabulary write to a worker that cannot be interrupted, so cancelling the handler does not stop the bytes landing, but everything after that await (the sweep and the SEL audit) is lost.Not a goal
archive/slots-snapshot-full-10-itemsbranch.What changed (motivation → approach → change)
Symptom: a delete crashes or half-applies when a close or a disconnect lands mid-sweep. Cause: the sweep awaits while iterating the live slot dict, the folder side unfiles before it commits, and a cancellation skips the sweep and the audit.
close_in_flight(new leaf modulesrc/kiro_crew/dashboard/snapshot_commit.py) registers a slot across the pop/save/restore frame ofclose_slotand the bulkapi_chat_slots_cleanup(chat_api/slot_lifecycle.py), so the sweep also strips a slot that is out of_slotsmid-close. Each registration has a unique token, so overlapping closes do not unregister each other._commit_tags_snapshot,FolderRepository.mutate) and the sweep wait through the existingchat_utils.run_to_completion, with no new drain loop. A write that landed is still confirmed on the cancelled path.VocabularyDeleteCancellationsre-raises the captured cancellation only after the audit line.mutate_folders(..., on_committed=...)and_commit_tags_snapshot(..., on_committed=...)fire only after the write is proven on disk. There is no store-wide committed-vocabulary set.chat_tags.pynames the new imports in its type-checking manifest.docs/system-specs/modules/history.mdrecords the order.Backwards compatibility
Compatible: request and response shapes are unchanged; only the order and the cancellation handling inside the two delete handlers change.
Removes nothing: the deleted
_restore_unfiledrollback closure was private toapi_chat_folder_deleteand had no other reader.Tests
test_delete_tag_strips_a_slot_popped_during_the_vocabulary_write: a slot popped during the tag write loses the deleted tag id.test_a_failed_folder_commit_leaves_every_slot_untouched: a failed folder commit leaves every slot clean.test_a_cancellation_inside_the_commit_still_unfiles_and_still_audits: a cancelled delete still sweeps and writes its audit line.test/test_snapshot_commit_protocol.py: a cancelled tag or folder commit still confirms a landed write, a failed write wins over the cancel (folder rows restored), the sweep finishes viarun_to_completion, re-raise order, close registry. Every completion await is bounded byawait_until.test/test_slot_close_recreation_race.py: the slot popped by the bulk cleanup is visible to a sweep, and unpublished after.Nearby inputs also run: every test module that calls
close_slotorapi_chat_slots_cleanup, the folder/tag/channel-folder suites and all facade guards (about 7,000 tests, green). flake8, black, isort and mypy clean.Proof: not provable -- other: the changed tests import the new snapshot_commit module, so with production reverted they fail at collection; the author showed the three reproductions red on the pre-fix base with only the tests applied.
Manual verification
N/A: unit coverage sufficient. The failures are specific interleavings, which the tests reproduce against the real routes.
Related Issues
Sibling sweep
Swept: git grep -nE "for .* in state._slots.(values|items)()" -- src, then checked each loop body for an await
Siblings: none -- the two delete sweeps were the only live-view loops with an await inside
Pattern harvest
Rule candidate: semgrep
Pattern: an
awaitinside aforloop over a livestate._slotsviewChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)