Skip to content

fix: never refile a refused folder move into a deleted folder - #35864

Merged
bolichen97 merged 1 commit into
mainfrom
fix/26161-refuse-deleted-folder-revert
Nov 19, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/26161-refuse-deleted-folder-revert

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

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

  • No change to a move that succeeds, or to a refused move whose old folder still exists: it goes back there exactly as before.
  • No new refusal, error code or status: each path refuses in the same cases it does today.
  • The check on the move's target folder is unchanged; it already refuses a deleted target.

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.

Path Rollback that changed
Moving a chat to a folder (chat_folders.py) the refused move, and the refused save
Creating a chat in a folder (chat_api/slot_create.py) the locked existence read, and the folder un-hide
Reviving a session into a folder (session_control_parts/session_revive.py) the refused filing
Filing or moving a cron job's tab (cron_inject.py) the save that did not commit, through the module's existing chat_folder_exists

The 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_window and ::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_window and ::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.py hunk 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=2 beside test/test_chat_folder_cap.py and test/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>/folder to B: 200 {"ok": true, "folder_id": "<B>"}, and the slot list shows the chat in B.
  • The same call to a folder id that does not exist: 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 passed
Cleanup: 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/ and git 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

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • 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 12, 2026 14:59
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 1c5cce20b2e9bb4aa832eb4df24dc45b4ec19d28 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 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

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

  • The same any(f["id"] == x for f in state._folders) else "" check is now copied in five places across four modules, while cron_inject.chat_folder_exists already does this job. A shared "restore-or-unfile" helper in a folder-store owner would give the next rollback site one thing to call, so a sixth copy doesn't drift from the others.

[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 .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 12, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 1c5cce20b2e9bb4aa832eb4df24dc45b4ec19d28 — 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

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

  • Item 1–4 — second spelling of chat_folder_exists (src/kiro_crew/dashboard/cron_inject.py:405): the diff adds 5 more inline any(f["id"] == previous… for f in state._folders) checks. Grepping that pattern in src/ finds 9 at head, 4 of them on base. Item 5 already calls the named helper. Subtraction: replace the 5 added inline expressions with one existence check moved somewhere the chat-folder modules can import it from, and keep the single spelling.

What this change ships

Inventory (6 items) — 6 justified

Intent: when a folder move is refused, the conversation never goes back into a folder that was deleted while the move was waiting. FIX.

  1. A refused drag/move of a chat to a folder leaves it Unfiled if its old folder was deleted meanwhile — justified
  2. A move whose save is refused follows the same rule — justified
  3. A new chat filed into a folder: a refused read or folder un-hide lands Unfiled instead of in a deleted folder — justified
  4. A revived session whose filing is refused lands Unfiled if its own folder is gone — justified
  5. A cron job's tab, when the placement write doesn't commit, lands Unfiled if the folder to restore is gone — justified
  6. Revive and cron-tab specs state the new rollback rule — justified

[FIRST-PRINCIPLES-REVIEWED] 1c5cce2

Description read

[DESCRIPTION-READ] 0a555c6c6d6f5395fd014cd6c6255b793cbecbf7e61ab5b96f0bd09ae4cf823b

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 1c5cce20b2e9bb4aa832eb4df24dc45b4ec19d28 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 1c5cce2

Verdict parsed from the review's SHA-scoped output markers for commit 1c5cce20b2e9bb4aa832eb4df24dc45b4ec19d28.

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

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 1c5cce20b2e9bb4aa832eb4df24dc45b4ec19d28 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 1c5cce2

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 12, 2026 15:19
@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 12, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] The only red on this head, Backend Tests (3.12, 7) (with the Coverage Gate and PR Readiness that wait on it), is test/test_denied_commands_security_cost.py::TestSelfModuleIndexIsLinear::test_the_scan_is_linear_not_quadratic missing its 0.5s wall-clock bound. The same test is red on main too (push run https://github.com/kirodotdev/KiroCrew/actions/runs/43312884216/job/131530201808). This PR does not touch that test or the code it times. It is tracked as flaky in #28212, and #28293 fixes it. This PR waits for that fix and needs no change of its own.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 18, 2026
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
@bolichen97

Copy link
Copy Markdown
Contributor Author

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 learn-cron-dashboard.md sentence this PR edits (a cron tab's filing now restores the folder a closed tab was filed in, #38848). The rebase keeps main's wording and adds this PR's rule to it: a refused filing or move lands unfiled when the folder it would restore is gone. Every code and test hunk applied unchanged. The rebase also picks up #28293, which fixes the timing flake in test_the_scan_is_linear_not_quadratic that was the only red on the old head.

[operator: bolichen97]

@bolichen97
bolichen97 force-pushed the fix/26161-refuse-deleted-folder-revert branch from da7b761 to 1c5cce2 Compare November 19, 2026 19:16
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention labels Nov 19, 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.

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.

@bolichen97
bolichen97 merged commit a5e83da into main Nov 19, 2026
97 of 100 checks passed
@bolichen97
bolichen97 deleted the fix/26161-refuse-deleted-folder-revert branch November 19, 2026 20:50
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 19, 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.

Refuse a move or placement that targets a folder deleted mid-flight

2 participants