Repository navigation
fix: never refile a refused folder move into a deleted folder - #35864
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: this is a small, proportionate fix to the stale-capture-across-await root cause, and every rollback site in the sibling sweep is covered. Notes
[DESIGN-REVIEWED] 1c5cce2 Description read[DESCRIPTION-READ] c0348dfb1c532ebfd08b6081e61a00861c4a509b6a98f485ce4bb016ddc24b1d 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS This fixes a reported defect (#26161) at the cause: every refused-move rollback now checks that the old folder still exists in the same event-loop step that restores it. One note, on spelling. Notes
What this change shipsInventory (6 items) — 6 justifiedIntent: when a folder move is refused, the conversation never goes back into a folder that was deleted while the move was waiting. FIX.
[FIRST-PRINCIPLES-REVIEWED] 1c5cce2 Description read[DESCRIPTION-READ] 0a555c6c6d6f5395fd014cd6c6255b793cbecbf7e61ab5b96f0bd09ae4cf823b That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
|
[operator: bolichen97] The only red on this head, |
A refused folder move, create-time placement, revive filing or cron tab move puts the session back into the folder it captured before an await. A delete of that folder can land inside the await, so the rollback reattached an id that names nothing, and the next save made the dangling placement durable. Each rollback now restores the old folder only while it still exists and leaves the session unfiled otherwise. Closes #26161
|
Rebased: main moved in src/kiro_crew/dashboard/chat_api/slot_create.py, src/kiro_crew/dashboard/chat_folders.py, src/kiro_crew/dashboard/cron_inject.py, src/kiro_crew/dashboard/session_control_parts/session_revive.py, test/test_session_control_revive.py, docs/system-specs/modules/session-control.md, docs/system-specs/modules/learn-cron-dashboard.md since this head went green (2f7e9f2 -> 8301e68); CI re-running. GitHub reported a merge conflict: main rewrote the [operator: bolichen97] |
da7b761 to
1c5cce2
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
I reviewed head 1c5cce2 against the folder delete flow. Every changed rollback (folder move, new chat filed into a folder, revive filing, cron tab placement) checks whether the old folder still exists in the same event loop step that restores it. So whether a concurrent delete lands before or after the rollback, the conversation either goes back into a folder that still exists or is left unfiled. It is never refiled under a deleted id. Successful moves are unchanged, and so are refused moves whose old folder is still there. The three touched test files pass on this head. All six new window tests fail when the source changes are reverted, so they really exercise the fix. Nothing blocks.
Problem / Motivation
Goal: A refused folder move never puts a conversation back into a folder that was deleted while the move was waiting.
A folder move, a new chat filed into a folder, a revived session filed into a folder and a cron tab move all remember the conversation's old folder, then wait (for the store lock, the folder un-hide or the save). If the move is refused, they put the conversation back into that old folder. When the old folder is deleted during the wait, the conversation is put back into a folder that no longer exists, and the next save writes that id to disk.
Why it matters
The user deleted the folder, yet the conversation ends up saved as filed under it: a placement nobody chose, pointing at nothing. The folder delete's own unfile sweep already ran and missed it (the conversation was sitting in the move's target at that moment), so nothing cleans it up later.
Not a goal
What changed (motivation → approach → change)
Symptom: a conversation is saved as filed into a folder the user just deleted. Root cause: each rollback restores the folder id it captured before an await, without asking whether that folder still exists.
Change: every rollback of a refused move restores the old folder only while it is still in the folder list, and otherwise leaves the conversation Unfiled. The check reads the same in-memory list the folder delete removes rows from, in the same event-loop step as the rollback, so a delete either lands first (the folder is gone, the conversation goes Unfiled) or after (its unfile sweep sees the conversation back in the folder and clears it). A delete whose write then fails leaves the conversation Unfiled while the folder stays: the safe side, never a deleted id.
chat_folders.py)chat_api/slot_create.py)session_control_parts/session_revive.py)cron_inject.py)chat_folder_existsThe owning specs state the rule for revive (
docs/system-specs/modules/session-control.md) and for the cron tab (docs/system-specs/modules/learn-cron-dashboard.md).Backwards compatibility
Compatible: only the rollback of an already-refused move changes, and only when the folder it would restore is gone; every other case keeps its current result.
Removes nothing: no key, row, route or function is removed; the rollback writes an empty folder id where it used to write a deleted one.
Tests
Each test deletes the old folder inside the window, refuses the move, and asserts the conversation is left Unfiled:
test/test_folder_store_writer.py:TestPlacementRacesTheStore::test_refused_refile_does_not_restore_a_folder_deleted_in_the_windowand::test_refused_save_does_not_restore_a_folder_deleted_in_the_window(folder move);TestSlotCreateFolderAssignment::test_refused_refile_does_not_restore_a_folder_deleted_in_the_windowand::test_refused_read_does_not_restore_a_folder_deleted_in_the_window(create).test/test_session_control_revive.py::test_a_refused_revive_filing_does_not_restore_a_folder_deleted_in_the_window(revive).test/test_cron_chat_folder.py::TestMovingTheTabAtTheSave::test_a_refused_write_does_not_restore_a_folder_deleted_in_the_window(cron tab).Proof: PROVEN test/test_cron_chat_folder.py::TestMovingTheTabAtTheSave::test_a_refused_write_does_not_restore_a_folder_deleted_in_the_window, test/test_folder_store_writer.py::TestPlacementRacesTheStore::test_refused_refile_does_not_restore_a_folder_deleted_in_the_window, test/test_folder_store_writer.py::TestPlacementRacesTheStore::test_refused_save_does_not_restore_a_folder_deleted_in_the_window, test/test_folder_store_writer.py::TestSlotCreateFolderAssignment::test_refused_refile_does_not_restore_a_folder_deleted_in_the_window, test/test_folder_store_writer.py::TestSlotCreateFolderAssignment::test_refused_read_does_not_restore_a_folder_deleted_in_the_window (head 1c5cce2)
The revive test is the one that fails when the
session_revive.pyhunk alone is reverted (assert 'f0' == ''); the line above lists the ids the proof reporter captured.Determinism: the window is forced by a stub that deletes the folder and then refuses, so no test sleeps or races a real clock. The six tests ran 20 times at
-n0, 10 times at-n 4 --dist loadgroup --max-worker-restart=2besidetest/test_chat_folder_cap.pyandtest/test_chat_folder_delete_if_empty.py, and once in a shuffled order (seed 776953499): all green.Manual verification
On Linux (Ubuntu 24.04, Python 3.12.3), an isolated gateway started from this patch (identical, on main 910f01f) on a throwaway
KIROCREW_HOME, driven through the dashboard API with one chat and two folders A and B:PATCH /api/chat/slots/<key>/folderto B:200 {"ok": true, "folder_id": "<B>"}, and the slot list shows the chat in B.400 {"error": "folder not found"}, and the chat stays in B.DELETE /api/chat/folders/<B>:200 {"ok": true}, and the chat is Unfiled.The race itself, a delete landing inside the move's await, cannot be timed by hand; the six tests above force it through the real handlers on every run.
Real-machine verification
Machine: EC2 m7i.2xlarge, Ubuntu 24.04.5 LTS x86_64, 8 vCPU / 30.8 GiB
Before (main 8301e68, with only this PR's three test files applied):
python3 -m pytest -n0 -p no:cacheprovider -q <the six tests above>->6 failed; each ends on its Unfiled assertion, e.g.AssertionError: assert 'home' == ''(folder move, create),assert 'f0' == ''(revive),assert 'f00dcafe' == ''(cron tab)After (head 1c5cce2): the same command ->
6 passedCleanup: the throwaway base worktree and the gateway's throwaway home were removed and the gateway exited; the host is a reused disposable one with no inbound rules and no key pair, terminated by its idle reaper rather than per PR
Related Issues
Closes #26161
Follow-up from #5933.
Sibling sweep
Swept:
git grep -nE '_folder_changed = (previous|prev|prior|old)' -- src/andgit grep -nE 'folder_id = [a-z_]*(previous|prior|restore|old)' -- src/Sibling: src/kiro_crew/dashboard/chat_folders.py -- changed here
Sibling: src/kiro_crew/dashboard/chat_api/slot_create.py -- changed here
Sibling: src/kiro_crew/dashboard/session_control_parts/session_revive.py:740 -- changed here
Sibling: src/kiro_crew/dashboard/cron_inject.py:554 -- changed here
Sibling: src/kiro_crew/dashboard/workflow_inject.py:284 -- not affected -- it checks the folder exists in the same await-free step that files it
Sibling: src/kiro_crew/dashboard/session_transfer_install.py:660 -- not affected -- it files only after arrival_folder_exists confirms the folder
Sibling: src/kiro_crew/dashboard/session_control_parts/session_create.py:1368 -- not affected -- it files right after the locked existence check, with no await and no rollback
Sibling: src/kiro_crew/dashboard/handlers/cron_runs.py:249 -- not affected -- it restores a closed tab's stored folder only after chat_folder_exists confirms it, in the same await-free step
Pattern harvest
Rule candidate: review-prompt
Pattern: a value captured before an await is restored after it without checking that it still names something that exists.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits