Repository navigation
fix(dashboard): stop a cleared chat resuming in the removed directory - #11722
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. |
3 similar comments
|
👋 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. |
|
👋 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. The fix removes the stale stored cwd at the source, and the reader I checked outside the patch fails closed. Notes
[DESIGN-REVIEWED] 0b62026 Description read[DESCRIPTION-READ] 45b1490b1a323ca9ff6b45e2ef1f7e188ccefa042599409745ed3c14c95b4bcd 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, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The root cause is confirmed on base: Notes
What this change shipsInventory (7 items) — 6 justifiedIntent: when a user clears a chat's project, the chat's later turns, including after a restart, run in the session's default directory and not the removed one. FIX.
[FIRST-PRINCIPLES-REVIEWED] 0b62026 Description read[DESCRIPTION-READ] eb79e72f0f27f5a13ad6eadba2c9d7f58b5450590908ba3db0f5ca740fdbe4da That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
794242c to
9baef54
Compare
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days. I reviewed the blockers but they require your input:
Three further blockers are mechanical and I can fold them into a drive-to-green pass once the above is settled — flagging them now so they are not a surprise:
When you've addressed these, the pipeline will re-assess on its next cycle. |
d312b02 to
5f72e5f
Compare
|
PR triage (2026-10-05): REBASE + MERGE-DISCUSSION
|
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
|
Rebased, as asked. Head is now Your other three items are unanswered here on purpose. The merge-order question against the sibling PRs is a maintainer call, not mine to settle. |
|
Hold. Dropping the session map's stored cwd while keeping the resume sid is a sound, small fix, and CI is green. Two current-head AI items have no reply, and the overlap with sibling PRs is unsettled. What would clear this:
Reviewed head: 879a8ba — crew-pr-reviewer (r118) |
bolichen97
left a comment
There was a problem hiding this comment.
Blocking race: a cold start can capture the old project before clear, register after clear, and persist that old path during shutdown. The next start can then reopen the directory the user removed.
Required fix: carry retraction state through in-flight allocation. Make registration and shutdown honor it. Add the paused-cold-start, clear, shutdown, and restart regression test.
|
@bolichen97 Fixed at The race you described is real. On What changed:
Regression test: |
|
Hold at The fix is sound: What would clear this:
— crew-pr-reviewer (r124) |
bolichen97
left a comment
There was a problem hiding this comment.
[operator: bolichen97] My earlier change request is addressed on f2602dd. Approving to clear it; other open gates on this PR still apply.
|
HOLD at f2602dd. The fix is sound: What still blocks, and what clears each:
No PR code was run locally. — crew-pr-reviewer (r126) |
|
HOLD at f2602dd. The fix is sound. What holds it: a maintainer still has to decide how this lands relative to #11910 and #11813. Both target the same bug and are still open, and this PR carries AI findings judged non-blocking
— crew-pr-reviewer (r132) |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Thanks for this fix. It removes the stale stored directory at its source, and the real-manager tests cover the paused cold start and the failed-load cases well. One item in the new test needs a change before merge.
test/test_cleared_project_drops_stored_cwd.py:381: intest_a_cold_start_paused_across_the_clear_does_not_survive_a_restart, the test holds thestarttask insidepaused_startuntil it callsresume.set(). It then awaits that task with a bareawait startand no bound. Suppose a later change makes registration stall after the resume. The await then hangs until pytest-timeout kills the xdist worker. On Windows that loses the whole shard run, and the test does not fail by name. The repo's determinism rule requires every await the test itself unblocks to be bounded. Smallest fix:await await_until(start, what="the paused cold start to register").await_untilis already imported and used two lines above.
Optional:
session_allocation_parts/get_or_create.py:603-612: the Claude sid backfill writessession.provider.cwdwithout checkingcwd_retracted. The new session.md rule lists three writers, and this is a fourth. The branch looks unreachable on current builds. Could you either gate it ("" if session.cwd_retracted else ...) or say in session.md why it cannot fire?dashboard/session_directive_apply_slot.py:42: the directive readsold_projectbefore theaprepare_cwd_clearawait. The HTTP route re-reads it after the same await. Moving the read below the await would make the two paths match.- #11813 fixes the same bug and is still open. Please close it as superseded by this PR, as asked earlier.
A resume that states no cwd restored the one stored in the session map, so clearing a chat's project now drops that stored cwd and keeps the conversation.
|
Fixed at
5,076 tests pass across the 80 affected test files. On #11813, I have passed that to the PR author, since closing it is their call. |
bolichen97
left a comment
There was a problem hiding this comment.
Approving at 0b62026. I compared it with 40313fc, the head KiroCrewCaptain reviewed. The required point and both optional points are done:
test_a_cold_start_paused_across_the_clear_does_not_survive_a_restartnow runsawait await_until(start, what="the paused cold start to register")in place of the bareawait start, so a stalled registration fails the test by name and does not hang the worker.- The Claude sid backfill in get_or_create.py now writes
"" if session.cwd_retracted else session.provider.cwd, and session.md lists it as the fourth writer. The new testtest_the_claude_sid_backfill_does_not_store_a_cleared_sessions_directorycovers it. - session_directive_apply_slot.py now reads
old_projectafter theaprepare_cwd_clearawait, the same as the HTTP route.test_the_directive_clear_reads_the_project_after_preparing_the_mappins it.
The rest of the commit matches what was reviewed before. It adds no regex. Every check that shows as cancelled has a newer passing run on this head.
@KiroCrewCaptain, could you re-review? Your point is fixed.
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approving at 0b62026. I compared it with 40313fc, the head of my earlier review. All three earlier items are resolved:
- Fixed (required):
test_a_cold_start_paused_across_the_clear_does_not_survive_a_restartnow runsawait await_until(start, what="the paused cold start to register")at line 423, so a stalled registration fails by name. - Fixed (optional): the Claude sid backfill at
get_or_create.py:612writes"" if session.cwd_retracted else session.provider.cwd, and session.md lists it as the fourth writer. - Fixed (optional):
session_directive_apply_slot.pyreadsold_projectagain after theaprepare_cwd_clearawait, as the HTTP route does.
Other checks on this head: PR Readiness is green. Every session map writer that stores a cwd honours the retraction, and the reservation mark is discarded with the reservation. Both clear paths answer ok only after the map write lands. Done well: the fix drops the stale cwd where it is stored and keeps the resume sid. The tests drive the real SessionManager, the real route and the real directive, with only the provider faked.
Optional:
dashboard/handlers/session_environments.py:733and:845clear_pending_reset_history_keybut leave_pending_reset_clears_cwdset. A later model-only reset could then retract the stored cwd. Clear the flag along with the key, or put both behind one helper.- No test checks the
clears_cwdargument at either arm site (session_directive_apply_slot.py:54,chat_api/session_relaunch.py:848). In the http and directive cases oftest_a_cleared_chat_does_not_resume_in_the_removed_directory, assertingslot._pending_reset_clears_cwd is Truewould cover it. - The
## Backwards compatibilityReader line forapp_agent_binding.py:_app_agent_start_dirsnames a function that does not exist on any ref. The other two Reader lines already cover every stored cwd reader, so this line can go.
Problem / Motivation
Goal: a turn in a chat whose project the user cleared runs in the session's own default directory, not the directory that was removed.
Clearing a chat's project emptied
slot.project, and the spawn sites readcwd=slot.project or None.Nonetells the provider factory "no requirement", which is thebranch that RESTORES a stored or inherited directory, so the turn landed back in the
directory the user had just removed with nothing to signal it. Relative writes then resumed
into the former project. A cleared state also did not survive a restart, because nothing on
disk distinguished "never had a project" from "had one and it was removed".
Why it matters
A turn that spawns in the cleared directory does not fail. It succeeds, against the tree the
user just removed, and its answer looks authoritative: nothing in the result says the
directory was not the one the chat was scoped to. Reads come from the wrong tree and relative
writes land in it.
It reaches every turn surface in a cleared chat, not one: the side turn, the main chat turn
and the eager prefetch spawn all read the same collapsed field. And because the cleared state
did not persist, a restart silently re-bound the removed directory even for a chat the user
had cleared deliberately.
Not a goal
Noneandkeeps the factory's existing behaviour, including the warm pool.
What changed (motivation → approach → change)
Root cause, measured on base. A resume that states no cwd restores the cwd stored in the
session map:
session_allocation_parts/get_or_create.pyfalls back to_session_map.get_cwd(key)when the caller passes none and a resume sid exists. Clearing aproject emptied
slot.projectbut left that stored value, and the deferred reset keeps the mapentry so the conversation can resume. So the next turn, and every turn after a restart, resumed
in the removed directory. The slot side already persisted the clear on base: after a full save,
a forced empty-window save and an unforced save, the restored slot reads
project == "". Theonly stale copy was the session map's.
The fix forgets that stored cwd, and nothing else changes.
session_map.pyaddsSessionMap.clear_cwd(key). It removes the entry'scwdand keepsits resume sid, so the conversation survives and only the directory is forgotten.
session.pyaddsSessionManager.retract_cwd(key). It callsclear_cwd, and flags alive session under the key with
cwd_retracted. The deferred reset can stay armed, behindattached sub-agents or a busy session, and that live session is still bound to the removed
directory. Two writers store a live session's cwd:
close_allat shutdown, andcommit_provider_switch_replay_sid. Both now write no cwd for a flagged session, so arestart before the reset lands does not bring the directory back. The reset's successor is
a new session, unflagged, and stores its own cwd as usual.
session_allocation.pyandsession_allocation_parts/get_or_create.pycarry theretraction through an allocation already in flight. A cold start that read the stored
cwd before the clear has no live session for
retract_cwdto flag yet, so it wouldregister after the clear, store the old directory, and keep it through shutdown.
retract_cwdnow marks every reservation in flight under the key(
cwd_retracted_reservations). The session such a reservation registers starts withcwd_retractedset, registration stores no cwd for a flagged session, andclose_allalready skips it. A reservation taken after the clear is not marked, and the mark leaves
with its reservation.
session_lifecycle_parts/parked_queue.pyallocation_identitypasses no cwd for asession with
cwd_retractedset. A reset that parks queued follow-ups, and a compactionrestart, rebuild their successor from it; that successor's reservation starts after the
clear, so it is not marked, and with the old
provider.cwdpassed in it would store theremoved directory again. With no cwd it resolves the session default.
get_or_create, which maps a live Claude session whose keyhas no stored sid, writes
""as the cwd for a session withcwd_retractedset, likethe other writers.
dashboard/chat_api/session_relaunch.pycallsretract_cwdfor the slot's session key whenthe HTTP route empties a project that was set, after the existing 409 check, so a request
rejected for a rebound session drops nothing. It then awaits
aflush()before answeringok, so the clear is on disk when the user is told it happened; a failed write answers500
project_clear_not_savedinstead.dashboard/session_directive_apply_slot.pycalls it in theset_projectdirective's clearbranch, on the same condition that already arms the deferred reset. It reads the slot's
old project after preparing the map, as the HTTP route does, and awaits
aflush()the same way: a failed write returns an
Error:reply instead of "Project cleared".SessionManager.aprepare_cwd_clear(), before they change theslot. After a failed map load the map holds none of the file's entries, so a clear would
drop nothing and the next save would adopt the old cwd from the file. The method retries
that read and lands any write still owed, and raises when either fails, so the clear is
refused and the slot keeps its project. That call can yield, so the HTTP route then
re-checks with
_slot_replaced_while_queuedand answers not-found if the chat was closedand resumed under the same name meanwhile, before it touches either slot. Both paths also await
aflush()on every clear,not only when the project changed, so retrying a clear whose save failed is not answered
okuntil the write lands.dashboard/chat_turn/session_reset.pycalls it again in_consume_pending_reset, justbefore the reset, when the slot still has no project and the queued reset is a project
clear's. A cold start already in flight at the clear registers with the old directory and
writes it back to the map; this second call removes it and flags that session before the
reset recreates it. A model switch arms the same pending reset, so the clear paths also set
_pending_reset_clears_cwdon the slot, and a model-only reset keeps the stored directory.Alias slots share one session, so the clear paths set it through
transcript_binding.arm_project_reset(..., clears_cwd=True), which marks every live alias,and an alias that joins while the reset is pending inherits the mark.
The spawn sites are unchanged: the side turn, the main turn and the eager spawn still pass
cwd=slot.project or None. With nothing stored, a resume in a cleared chat binds thesession's own default directory. A resume also bypasses the warm pool
(
pool_decision = "bypass_resume"), so a cleared chat with a conversation never draws a pooledchild.
Side sessions and reply threads need no drop. Their
side:andthread:keys are insession_parts/policy.py_STATELESS_PREFIXES, so they never resume and never read a storedcwd, and a thread turn in a cleared chat passes
cwd=Nonelike the main turn.An enrolled crew member gets the same treatment as a member chat that never had a project:
with no cwd,
session_capabilities.pystarts it indefault_project_dirof the member's ownworkspace, so a clear moves it there rather than into a per-session directory.
Why this and not the earlier design. An earlier revision added a persisted
project_clearedmarker on the slot, a resolver every spawn site called, a setter keeping thetwo consistent, and identity-gated rollbacks of the marker in the agent switch, the workspace
switch and the project 409, across 18 files. Review asked whether dropping the map's cwd was
enough on its own. A base reproduction through the real
SessionManager.get_or_createshowedthat it is: with the stored cwd dropped and the sid kept, a cleared chat binds the session
default on the next turn, after a reset, and after a restart. So the marker and everything that
existed to keep it consistent were removed. This version is 24 files, most of them a few lines.
Backwards compatibility
Compatible: a session map written before this change is read exactly as before. An entry
whose cwd was never dropped still resumes in its stored directory.
The change removes one value, a cleared chat's stored
cwdinsession_map.json. Its readers:Reader: src/kiro_crew/session_allocation_parts/get_or_create.py:_get_or_create_impl -- chat -- the intended effect; an empty stored cwd binds the session default, test_a_cleared_chat_does_not_resume_in_the_removed_directory
Reader: src/kiro_crew/dashboard/chat_turn/app_agent_binding.py:_app_agent_start_dirs -- app -- an empty stored value is one of four candidates beside the pool cwd and the session default, so the check still runs against the session default
Reader: src/kiro_crew/teams/renderer.py:_persisted_upload_root -- chat -- reads a Teams session key, which no dashboard clear writes, so its value is untouched
An older build reading a new map: it reads a missing
cwdthe same way, so a downgradekeeps the clear. No new key is written anywhere.
Tests
test_cleared_project_drops_stored_cwd.py(new) drives the realSessionManagerallocatorwith only the provider faked:
directory, and keeps its conversation sid;
session is still live because the deferred reset has not landed;
restart: the paused start registers with no stored cwd and the restarted chat does not
resume in the removed directory. On the previous head this test fails, with the old
directory stored at registration;
allocation_identityof a cleared session neither binds norstores the removed directory; with the previous
allocation_identityit stores it again;on disk when it is acknowledged, and a clear whose write fails is not acknowledged;
still fails, and succeeds with the cwd off disk once it lands;
while the file stays unreadable the clear is refused and the slot keeps its project;
neither it nor the detached slot loses its project; on the previous head the route
answered 200;
cwd alone;
clear_cwdkeeps the sid and saves only when it dropped something;thread:key.test_session_capabilities.pypins that an enrolled member started with no cwd binds itsworkspace's
default_project_dir, through the real capability service and allocator.test_session_map_bindings.pyandtest_session_bindings.pyregisterclear_cwd,retract_cwdandaprepare_cwd_clearin the frozenSessionMapandSessionManagermember inventories,test_session_allocation_bindings.pyregistersretract_reservation_cwds, andtest_state_parts_facade.pyadds the slot's_pending_reset_clears_cwddefault.test_mcp_core_set_project.pygives its fake state asessions, which the directive's clearnow reaches, and it,
test_chat_slot_project.pyandtest_alias_slot_shared_project.pygive their mock sessions an awaitable
aflushandaprepare_cwd_clear.test_alias_slot_shared_project.pypins that a clear marks every alias, that a joiningalias inherits the mark, and that a later project change drops it on all of them.
Mutation control: each of the three call sites, the live-session flag, the shutdown guard,
the replay-commit guard and the clear-only condition was removed in turn, and each made its own
test fail; restoring each file byte-identically returned 10 passed. For the in-flight
path, removing the reservation mark, the registration flag, the registration map guard, the
shutdown guard or the mark's removal each fails the paused-cold-start test, and restoring
returns it to passing. Removing either clear path's
aflush()fails that path's on-disk test. With both clear pathsput back to the previous head, all six cases of the retry, failed-load and unreadable-map tests
fail. Marking only the
calling slot, or dropping the joiner's inheritance, fails the alias test. Removing
thread:from the stateless prefixes makes
the thread test bind the removed directory, and changing the member default fails the member
test.
Manual verification
N/A: unit coverage is sufficient. The end-to-end tests run the real allocator, the real HTTP
route and the real directive, and each guard carries a mutation control.
Pattern harvest
Not generalizable: the defect is one stored value that outlived the field it was copied from,
and the fix is to drop it where that field is cleared and stop the live session, or one
still starting, writing it back.