Skip to content

fix(dashboard): stop a cleared chat resuming in the removed directory - #11722

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:split/side-turn-cleared-project
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
rnoack1:split/side-turn-cleared-project

Conversation

@rnoack1

@rnoack1 rnoack1 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

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 read
cwd=slot.project or None. None tells the provider factory "no requirement", which is the
branch 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

  • Changing what a chat that NEVER had a project does. That path still resolves to None and
    keeps the factory's existing behaviour, including the warm pool.
  • Changing how a project is chosen, validated or displayed.

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.py falls back to
_session_map.get_cwd(key) when the caller passes none and a resume sid exists. Clearing a
project emptied slot.project but left that stored value, and the deferred reset keeps the map
entry 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 == "". The
only stale copy was the session map's.

The fix forgets that stored cwd, and nothing else changes.

  • session_map.py adds SessionMap.clear_cwd(key). It removes the entry's cwd and keeps
    its resume sid, so the conversation survives and only the directory is forgotten.
  • session.py adds SessionManager.retract_cwd(key). It calls clear_cwd, and flags a
    live session under the key with cwd_retracted. The deferred reset can stay armed, behind
    attached 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_all at shutdown, and
    commit_provider_switch_replay_sid. Both now write no cwd for a flagged session, so a
    restart 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.py and session_allocation_parts/get_or_create.py carry the
    retraction through an allocation already in flight. A cold start that read the stored
    cwd before the clear has no live session for retract_cwd to flag yet, so it would
    register after the clear, store the old directory, and keep it through shutdown.
    retract_cwd now marks every reservation in flight under the key
    (cwd_retracted_reservations). The session such a reservation registers starts with
    cwd_retracted set, registration stores no cwd for a flagged session, and close_all
    already skips it. A reservation taken after the clear is not marked, and the mark leaves
    with its reservation.
  • session_lifecycle_parts/parked_queue.py allocation_identity passes no cwd for a
    session with cwd_retracted set. A reset that parks queued follow-ups, and a compaction
    restart, rebuild their successor from it; that successor's reservation starts after the
    clear, so it is not marked, and with the old provider.cwd passed in it would store the
    removed directory again. With no cwd it resolves the session default.
  • The Claude sid backfill in get_or_create, which maps a live Claude session whose key
    has no stored sid, writes "" as the cwd for a session with cwd_retracted set, like
    the other writers.
  • dashboard/chat_api/session_relaunch.py calls retract_cwd for the slot's session key when
    the 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 answering
    ok, so the clear is on disk when the user is told it happened; a failed write answers
    500 project_clear_not_saved instead.
  • dashboard/session_directive_apply_slot.py calls it in the set_project directive's clear
    branch, 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".
  • Both clear paths first await SessionManager.aprepare_cwd_clear(), before they change the
    slot. 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_queued and answers not-found if the chat was closed
    and 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
    ok until the write lands.
  • dashboard/chat_turn/session_reset.py calls it again in _consume_pending_reset, just
    before 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_cwd on 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 the
session'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 pooled
child.

Side sessions and reply threads need no drop. Their side: and thread: keys are in
session_parts/policy.py _STATELESS_PREFIXES, so they never resume and never read a stored
cwd, and a thread turn in a cleared chat passes cwd=None like 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.py starts it in default_project_dir of the member's own
workspace, 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_cleared marker on the slot, a resolver every spawn site called, a setter keeping the
two 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_create showed
that 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 cwd in session_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 cwd the same way, so a downgrade
keeps the clear. No new key is written anywhere.

Tests

  • test_cleared_project_drops_stored_cwd.py (new) drives the real SessionManager allocator
    with only the provider faked:
    • a chat cleared over HTTP, and one cleared by the directive, does not resume in the removed
      directory, and keeps its conversation sid;
    • the clear survives a restart of the session manager, including a restart while the old
      session is still live because the deferred reset has not landed;
    • a provider-switch replay commit after the clear stores the sid but not the old directory;
    • a cold start paused inside provider startup, then the clear, then shutdown and a
      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;
    • a reservation taken after the clear keeps the cwd it was given;
    • the Claude sid backfill does not store a cleared session's directory;
    • a directive clear drops a project set while it waited on the map;
    • a reset successor built from allocation_identity of a cleared session neither binds nor
      stores the removed directory; with the previous allocation_identity it stores it again;
    • with the debounced map write held off, a clear over HTTP and by the directive is already
      on disk when it is acknowledged, and a clear whose write fails is not acknowledged;
    • a retried clear, whose project is already empty, is not acknowledged while the write
      still fails, and succeeds with the cwd off disk once it lands;
    • after a failed map load, a clear re-reads the file first and drops its stored cwd, and
      while the file stays unreadable the clear is refused and the slot keeps its project;
    • a slot replaced under the same name during that preparation gets a not-found answer, and
      neither it nor the detached slot loses its project; on the previous head the route
      answered 200;
    • the pending reset retracts the cwd again before resetting, and leaves a chosen project's
      cwd alone;
    • a model-only reset on a chat with no project keeps the stored cwd;
    • clear_cwd keeps the sid and saves only when it dropped something;
    • a cleared chat's reply thread does not resume a stale stored cwd for its thread: key.
  • test_session_capabilities.py pins that an enrolled member started with no cwd binds its
    workspace's default_project_dir, through the real capability service and allocator.
  • test_session_map_bindings.py and test_session_bindings.py register clear_cwd,
    retract_cwd and aprepare_cwd_clear in the frozen SessionMap and SessionManager member inventories,
    test_session_allocation_bindings.py registers retract_reservation_cwds, and
    test_state_parts_facade.py adds the slot's _pending_reset_clears_cwd default.
  • test_mcp_core_set_project.py gives its fake state a sessions, which the directive's clear
    now reaches, and it, test_chat_slot_project.py and test_alias_slot_shared_project.py
    give their mock sessions an awaitable aflush and aprepare_cwd_clear.
  • test_alias_slot_shared_project.py pins that a clear marks every alias, that a joining
    alias 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 paths
put 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.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 18, 2026
@dwu96

dwu96 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

👋 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
@dwu96

dwu96 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

👋 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.

@dwu96

dwu96 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

👋 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.

@dwu96

dwu96 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

👋 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.

@rnoack1
rnoack1 marked this pull request as ready for review September 18, 2026 10:49
@rnoack1
rnoack1 requested review from a team and pepmach September 18, 2026 10:49
@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 Sep 18, 2026
@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 0b62026d7516d3623cdf513862a1545fcf776711 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • The spec now says "any code that writes a live session's provider.cwd back into the map … must write "" for a session with cwd_retracted set". That rule only holds by convention, across four writers plus allocation_identity. If someone adds a fifth writer and forgets the check, the removed directory comes back with no warning. A cheaper fix is to apply the check once, inside the SessionMap method these writers all call (or in one helper they share). A pin test that lists every writer would also catch it.
  • The only stored-cwd reader outside the patch is teams/renderer.py:_upload_root. It reads Teams keys, and an empty cwd makes it fail closed, so this change does not affect it.

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 0b62026d7516d3623cdf513862a1545fcf776711 via the fork AI-review pipeline — 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 root cause is confirmed on base: get_or_create.py:746-750 restores the stored cwd when a resume names none. One mechanism handles a case another item already covers.

Notes

  • Item 7 — duplicate of item 3: the description says "A cold start already in flight at the clear registers with the old directory… this second call removes it". Item 3 already covers that case: "the session such a reservation registers starts with cwd_retracted set, registration stores no cwd". On base, every cold start adds its reservation token at get_or_create.py:413, before the cwd read at line 748. _get_or_create_impl has 1 caller, and it always passes _reservation=token. Subtraction: delete the retract in _consume_pending_reset and the _pending_reset_clears_cwd slot field, along with its init_session_fields default, its bind_transcript inheritance and the clears_cwd kwarg on arm_project_reset.

What this change ships

Inventory (7 items) — 6 justified

Intent: 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.

  1. Clearing a project forgets the stored resume directory, and the next turn starts in the session default — justified
  2. A session still live at the clear no longer writes the removed directory back at shutdown, at replay commit or in the Claude sid backfill — justified
  3. A cold start already in flight at the clear registers without storing the old directory — justified
  4. Reset and compaction successors of a cleared session start in the default directory — justified
  5. The clear is refused (HTTP 500 project_clear_not_saved, or an Error: reply to the directive) when the session map can't be read or saved — justified
  6. The HTTP clear answers 404 when the chat was replaced while the map was being prepared — justified
  7. A second retract when the deferred reset lands, through a new slot flag set on every alias — duplicate of item 3 (reservation marking already covers it)

[FIRST-PRINCIPLES-REVIEWED] 0b62026

Description read

[DESCRIPTION-READ] eb79e72f0f27f5a13ad6eadba2c9d7f58b5450590908ba3db0f5ca740fdbe4da

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 Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 0b62026d7516d3623cdf513862a1545fcf776711 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 0b62026

@github-actions

github-actions Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 0b62026d7516d3623cdf513862a1545fcf776711 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 0b62026

@dwu96 dwu96 added the needs-pr-triage PR scanner: awaiting automated triage label Sep 22, 2026
@rnoack1
rnoack1 force-pushed the split/side-turn-cleared-project branch from 794242c to 9baef54 Compare September 22, 2026 05:04
@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 Sep 22, 2026
@NicholasRBowers NicholasRBowers added needs-author-decision PR blocked on author input and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 22, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been inactive for 7+ days. I reviewed the blockers but they require your input:

  • Merge order for the split series. Design Review BLOCKs on 9baef54 because nothing in production ever sets project_cleared: both clear paths (dashboard/session_directive_apply.py:1010 and the chat_handlers.py project commits) still write only slot.project = "", so claim_cwd returns self.project or None — byte-identical to the old slot.project or None. GPT 5.6 and First Principles reach the same conclusion. Their stated clearing condition is either "a production setter exists — the one-line flag at the clear site in this diff" or "the sibling merged first", and fix(dashboard): never resurrect a cleared project directory #11910 (split/slot-project-claim, "never resurrect a cleared project directory") plus fix(session): bind a cleared project to the default workspace #11813 (split/session-allocation-core, "bind a cleared project to the default workspace") appear to carry exactly that write side and the allocation enforcement. Folding the setter into this PR would cross your own split boundary; landing the siblings first would contradict this PR's claim of "no merge-order dependency". That choice is yours, and I will not pick it for you.
  • The description's independence claim. The body states these files are "carried identically with the sibling unit … so this PR builds and tests on its own with no merge-order dependency." Three lanes found the behaviour inert without the siblings. Whichever path you take above, the description needs to match it.
  • default_workspace_dir ships with zero callers. First Principles Item 5 proposes a subtraction: defer it to the sibling PR that consumes it. Keep or drop?

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:

  • Opus 4.8 BLOCKING, and it is a real import break: config/loader.py:537 renames _session_work_dir to session_default_cwd with no alias, but apps/builtins/auto_improvement/spine/crew_runner.py:11 still does from kiro_crew.config.loader import _session_work_dir (used at line 182), reached via the lazy import at backend/crew.py:147. Running an auto-improvement crew assignment raises ImportError. This is also what reds Backend Lint & Type Check (3.12) and every Backend Tests shard, including the namespace-sandbox one.
  • PR Hygiene fails because a fix PR must carry a ## Pattern harvest section.
  • test/test_pending_boundary_consumer_semantics.py::test_running_and_turn_running_slot_readers_are_enumerated needs the new reader enumerated.

When you've addressed these, the pipeline will re-assess on its next cycle.

@rnoack1
rnoack1 force-pushed the split/side-turn-cleared-project branch 2 times, most recently from d312b02 to 5f72e5f Compare September 22, 2026 09:03
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 22, 2026
@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 Sep 24, 2026

Copy link
Copy Markdown
Contributor

PR triage (2026-10-05): REBASE + MERGE-DISCUSSION

  • Stale: merge base cbe6d6a0 is 1146 commits behind origin/main (cc7e7989), and GitHub reports the PR as dirty. Please rebase.
  • Not superseded: origin/main still has project: str | None = slot.project or None at dashboard/handlers/side.py:418. None of CWD_CLEARED, claim_cwd, project_cleared or session_default_cwd exist on main yet.
  • Overlap with open PRs fix(dashboard): never resurrect a cleared project directory #11910, fix(session): bind a cleared project to the default workspace #11813, fix(dashboard): keep a deferred project reset on the key its slot runs on #11831 and fix(chat): keep a deferred reset armed when its arm never settles #11983. All four are confirmed PRs, and all are open. Each one adds its own copy of CWD_CLEARED/resolved_cwd in config/paths.py, the _ChatSlot.project_cleared/claim_cwd pair in dashboard/state.py, project_cleared in history.py meta keys, and the _session_work_dir → session_default_cwd rename (loader.py, cli_server.py, slack/gateway.py, crew_runner.py). These PRs aim at different things, so none of them is a duplicate of another. They will conflict on those shared files, though, and on each other's tests (test_chat_slot_project.py). Please agree which PR lands the shared paths.py/state.py/history.py layer first, then rebase the others onto it. The "no merge-order dependency" line in the description does not hold once a sibling lands.
  • Existing blockers stand. The GPT 5.6 and Opus 5 findings on chat_runner.py:11676-11706 are still open. On the last _rebind iteration, a mismatch releases the lease and consumes the teardown, and then the turn falls through to reproject_claimed_session with the torn-down client. I am not filing a duplicate request-changes review for that.

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 0b62026d7516d3623cdf513862a1545fcf776711 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@rnoack1

rnoack1 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Rebased, as asked.

Head is now 52bd85a6f0: a single commit whose parent is the upstream main tip it was rebased onto, and GitHub reports the PR mergeable. The description has also been rewritten to describe the current diff rather than an earlier revision.

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.

@iamwhatever

Copy link
Copy Markdown
Contributor

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:

  1. Post a disposition for the GPT 6.1 finding at session.py#L1052. A Slack allocation in flight at the clear is not registered yet, so retract_cwd misses it, and a restart can bring the removed directory back. Adjudication downgraded it, but it needs an answer.
  2. Answer the Design Review note. Either add the "every live-session cwd writer must check cwd_retracted" rule to docs/system-specs/modules/session.md, or say why it should not go there.
  3. A maintainer decides how this lands relative to fix(dashboard): never resurrect a cleared project directory #11910 and fix(session): bind a cleared project to the default workspace #11813, which target the same bug and are still open (needs-author-decision).

Reviewed head: 879a8ba

— crew-pr-reviewer (r118)

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

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.

@rnoack1

rnoack1 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@bolichen97 Fixed at 9ba80c8e2c.

The race you described is real. On 879a8bad01, a cold start that read the stored cwd before the clear registered after it and stored the removed directory again. The new test failed there with the old path stored.

What changed:

  • SessionManager.retract_cwd now also marks every allocation in flight for the key (SessionAllocationService.retract_reservation_cwds).
  • In _get_or_create_impl, a session registered from a marked allocation starts with cwd_retracted set, and registration stores no cwd for it.
  • close_all already skips a flagged session, so shutdown does not write it back either.
  • An allocation that starts after the clear is not marked, so it keeps the cwd it was given.

Regression test: test_a_cold_start_paused_across_the_clear_does_not_survive_a_restart in test/test_cleared_project_drops_stored_cwd.py. It pauses a cold start inside provider startup, clears the project, resumes the start, shuts down and restarts. The restarted chat does not resume in the removed directory. Removing the mark, the registration flag, the registration cwd guard, the shutdown guard, or the mark's cleanup each makes it fail.

@iamwhatever

Copy link
Copy Markdown
Contributor

Hold at f2602dd286fa16de155b7692f41b81478f16c475.

The fix is sound: retract_cwd drops the stored cwd, marks allocations already in flight, and every writer of a live session's cwd now honours cwd_retracted (session.py#L1045-L1055). Our r118 items 1 and 2 are addressed, and CI is green.

What would clear this:

  1. @bolichen97's CHANGES_REQUESTED review is still active. The author's reply says it is fixed at 9ba80c8e2c; it needs a re-review or dismissal.
  2. Post a disposition for the downgraded GPT 6.1 finding: a retried clear after a failed save skips aflush() because slot.project is already empty (session_directive_apply_slot.py#L42-L59).
  3. A maintainer still needs to decide how this lands relative to fix(dashboard): never resurrect a cleared project directory #11910 and fix(session): bind a cleared project to the default workspace #11813, which are open (needs-author-decision).

— crew-pr-reviewer (r124)

bolichen97
bolichen97 previously approved these changes Oct 25, 2026

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

[operator: bolichen97] My earlier change request is addressed on f2602dd. Approving to clear it; other open gates on this PR still apply.

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at f2602dd.

The fix is sound: retract_cwd drops the stored cwd, marks allocations already in flight, and registration and shutdown honour cwd_retracted (session.py#L1045-L1055). bolichen97 has approved this head, so their change request is cleared. CI is green.

What still blocks, and what clears each:

  1. The downgraded GPT 6.1 finding still has no disposition. When the save fails, the reply tells the user to "Clear it again", but a second clear finds slot.project already empty, skips aflush() and answers "Project cleared" (session_directive_apply_slot.py#L44-L59). Either await the save on a repeated clear, or change the reply and post a disposition explaining why the later debounced save is enough.
  2. A maintainer decides how this lands relative to fix(dashboard): never resurrect a cleared project directory #11910 and fix(session): bind a cleared project to the default workspace #11813, which target the same bug and are still open (needs-author-decision).

No PR code was run locally.

— crew-pr-reviewer (r126)

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at f2602dd.

The fix is sound. retract_cwd forgets the stored cwd, keeps the resume sid, and marks the live session and any allocation in flight so no writer stores the removed directory again (session.py#L1045-L1055). bolichen97's change request is cleared by their approval, and CI is green on this head.

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 needs-author-decision. That decision, or closing the overlapping PRs, would clear the hold.

AI findings judged non-blocking

  • GPT 6.1 F1 (already downgraded): a retried clear after a failed save skips aflush(). A failed flush calls _restore_dirty, so the clear stays owed and the next save or shutdown aclose writes it (session_map_store.py#L284-L292, #L338-L359).
  • Design: two state carriers, and a single writer helper. This is a design suggestion. Every current writer honours cwd_retracted, and the rule is in the session spec (session.md).
  • Design: does the picker show the new 500? chatSlotProject parses with j(), which throws ApiError on a non-2xx response (chatSlotSettings.ts#L102-L103).

— crew-pr-reviewer (r132)

@bolichen97

Copy link
Copy Markdown
Contributor

Maintainer decision: this PR, #11722, is the fix for the cleared-project directory bug. #11910 is already closed. @rnoack1, could you close #11813 as superseded by this one? We will not close it ourselves.

I'll review this head again once the AI lanes and CI finish on df1f0f6.

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

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.

  1. test/test_cleared_project_drops_stored_cwd.py:381: in test_a_cold_start_paused_across_the_clear_does_not_survive_a_restart, the test holds the start task inside paused_start until it calls resume.set(). It then awaits that task with a bare await start and 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_until is already imported and used two lines above.

Optional:

  • session_allocation_parts/get_or_create.py:603-612: the Claude sid backfill writes session.provider.cwd without checking cwd_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 reads old_project before the aprepare_cwd_clear await. 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.
@rnoack1

rnoack1 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed at 0b62026d75.

  1. test/test_cleared_project_drops_stored_cwd.py:423 (line 381 on the reviewed head) now reads await await_until(start, what="the paused cold start to register"). No bare await start is left in the file.
  2. The Claude sid backfill in session_allocation_parts/get_or_create.py:612 now writes "" if session.cwd_retracted else session.provider.cwd. The session.md rule lists it as a fourth writer. New test test_the_claude_sid_backfill_does_not_store_a_cleared_sessions_directory drives it through the real manager, and it fails on 40313fc363.
  3. session_directive_apply_slot.py reads old_project after the aprepare_cwd_clear await, at line 49, as the HTTP route does. New test test_the_directive_clear_reads_the_project_after_preparing_the_map sets a project during that await, and it fails on 40313fc363.

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 bolichen97 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 at 0b62026. I compared it with 40313fc, the head KiroCrewCaptain reviewed. The required point and both optional points are done:

  1. test_a_cold_start_paused_across_the_clear_does_not_survive_a_restart now runs await await_until(start, what="the paused cold start to register") in place of the bare await start, so a stalled registration fails the test by name and does not hang the worker.
  2. 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 test test_the_claude_sid_backfill_does_not_store_a_cleared_sessions_directory covers it.
  3. session_directive_apply_slot.py now reads old_project after the aprepare_cwd_clear await, the same as the HTTP route. test_the_directive_clear_reads_the_project_after_preparing_the_map pins 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 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.

Approving at 0b62026. I compared it with 40313fc, the head of my earlier review. All three earlier items are resolved:

  1. Fixed (required): test_a_cold_start_paused_across_the_clear_does_not_survive_a_restart now runs await await_until(start, what="the paused cold start to register") at line 423, so a stalled registration fails by name.
  2. Fixed (optional): the Claude sid backfill at get_or_create.py:612 writes "" if session.cwd_retracted else session.provider.cwd, and session.md lists it as the fourth writer.
  3. Fixed (optional): session_directive_apply_slot.py reads old_project again after the aprepare_cwd_clear await, 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:733 and :845 clear _pending_reset_history_key but leave _pending_reset_clears_cwd set. 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_cwd argument at either arm site (session_directive_apply_slot.py:54, chat_api/session_relaunch.py:848). In the http and directive cases of test_a_cleared_chat_does_not_resume_in_the_removed_directory, asserting slot._pending_reset_clears_cwd is True would cover it.
  • The ## Backwards compatibility Reader line for app_agent_binding.py:_app_agent_start_dirs names 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants