Repository navigation
fix(session): don't start a chat in an earlier process's scratch dir - #31391
Conversation
UX Review (Opus 5.5) — ✅ PASS (a BLOCK with no Trigger and no Outcome does not block)UX-level review of UX-Verdict: PASS cannot evaluate: missing a screenshot of the new chat notice. The PR adds a message that appears in the chat after a restart, and no image shows it, so the blind read was not performed. Evidence gaps
Notes
[UX-REVIEWED] f02f92d Description read[DESCRIPTION-READ] 93d971c2c6be6c433ad7b2f3e2ade4677b2ed22e6369f0023c9ad86fe223f3e9 That sha256 names everything this verdict read: the PR description, plus the 3 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 The fix targets the mechanism (#31319, tests that fail on base). The only open point is a note: three of the added pieces exist only because the chat keeps its dead folder stored. Notes
What this change shipsInventory (7 items) — 5 justifiedIntent: after a gateway restart, a dashboard chat whose folder was an earlier run's scratch folder starts and answers instead of failing every turn. FIX.
[FIRST-PRINCIPLES-REVIEWED] f02f92d Description read[DESCRIPTION-READ] 2408f44b547dd101e74eb4aaa571119aab8ca0a5fd6f218e4c57fbf8488d1612 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. The scratch-folder check that resume already runs now also covers the dashboard chat's explicit cwd. Only callers that opt in get the fallback, and the stored folder is never rewritten. Notes
[DESIGN-REVIEWED] f02f92d Description read[DESCRIPTION-READ] d4d6c4672deaf0ac144b7b6db7991cb54bc989f85ecb2b425dc4d31cb7d09ee9 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 |
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: |
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: |
9765db0 to
d1c2c67
Compare
d1c2c67 to
b1d350b
Compare
b1d350b to
0cea3c4
Compare
|
span=26cc9b6e03a3
|
|
span=d5d66fca2778
|
|
span=2df48fba51e4
|
0cea3c4 to
ae3996f
Compare
|
span=4803882cd425
|
|
span=2a19189fa717
|
ae3996f to
427783c
Compare
|
resolution: removed -- the folder-saving step ( Head 427783c drops the step that rewrote the chat's stored folder, which every blocking finding on b1d350b and 0cea3c4 sat in (GPT 26cc9b6e03a3, d5d66fca2778, 4803882cd425; Opus 2df48fba51e4). The chat's stored folder is now never changed:
With nothing writing |
427783c to
4d3e5fb
Compare
9e4bb06 to
161e9e6
Compare
|
span=2a19189fa717
|
161e9e6 to
83c9c34
Compare
|
span=0bbdc6f6edee
|
A chat whose project was set to a folder in its $KIROCREW_SCRATCH breaks after a gateway restart. The new process gets a fresh scratch tree and the sandbox hides the old one (on Linux an empty tmpfs over the scratch root), so the chat's folder does not exist for it. Every MCP server the session starts there fails with "spawn ... ENOENT", even for binaries that exist, and every retry hits the same wall. The resume path already skipped such a folder when it came from the session map. The dashboard passes the chat's project as an explicit cwd, which skipped that check. Run the same check on an explicit cwd too and start in the default folder instead. The chat's stored folder is never changed. A translated startup notice says the folder was not reopened, at most once per chat per gateway run (in memory), and the turn describes the folder the session actually runs in.
83c9c34 to
f02f92d
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Approving f02f92d. I read the product hunks in get_or_create.py, turn_admission.py, turn_spec_hooks.py, eager_spawn.py, the chat slot files and ErrorCard.tsx.
- A dashboard chat whose stored project is an earlier process's hidden scratch folder now starts in the default folder instead of in a folder the sandbox hides, where every MCP server would fail to spawn. Only callers that opt in (
fallback_hidden_cwd=True, the chat turn and its prefetch) fall back; any other caller keeps its explicit cwd, so it still fails loudly rather than running somewhere else. - The chat says so once per chat per gateway run (
HIDDEN_SCRATCH_CWD_NOTICE, shown through the existing error card), and a notice the start already left is not overwritten. The new string is in every locale. - The turn's project follows the folder the session really runs in, and the session hold is released if that await is cancelled.
- Native Windows applies no scratch mask, so the cwd is kept there as before.
This turns a broken start into a working one with a notice; it adds no refusal. No new regex. All checks pass on this head (97 ok, 0 red, 0 pending), and no human has an open change request. Auto-merge was already enabled by the author, so I left it as is.
#31391 brought the native-Windows rule into _stored_cwd_is_hidden_scratch (Windows masks no scratch tree, so a resumed chat keeps its stored scratch cwd) but no test pins the Windows branch. Add one: with IS_WINDOWS set and sandbox mode auto, a resume keeps the stored scratch cwd. Removing the branch fails it.
Partial backport of #31391 (main 4023e84) to the 0.12 line. Carried: - get_or_create.py: native Windows keeps a scratch cwd, because no scratch-root mask applies there (a Kiro spawn is delegated to Kiro's own sandbox). This is the Windows branch the GPT review asked for. - get_or_create.py: a caller that opts in (fallback_hidden_cwd) and names an earlier process's hidden scratch tree as its own cwd starts in the default directory instead. - turn_admission.py and eager_spawn.py: the dashboard chat opts in with fallback_hidden_cwd=True. - test_session_get_or_create.py: #31391's tests, without the notice assertions, plus a Windows test adapted from main's test_hidden_scratch_notice.py. Left out: the chat start notice (_note_skipped_hidden_cwd and HIDDEN_SCRATCH_CWD_NOTICE), _fallback_turn_project in turn_spec_hooks.py, the ErrorCard and i18n strings, and test_hidden_scratch_notice.py. The notice surface (startup_notice) comes from #25347, which is not on 0.12. The fallback is kept on 0.12 for #31319: without it every MCP server in that chat fails with ENOENT and the chat is dead, and the hidden folder is unreachable from the process anyway. With no chat notice on 0.12, the existing WARNING log line names the hidden folder and says the session starts in the default directory. (cherry picked from commit 4023e84, partial)
#31391 brought the native-Windows rule into _stored_cwd_is_hidden_scratch (Windows masks no scratch tree, so a resumed chat keeps its stored scratch cwd) but no test pins the Windows branch. Add one: with IS_WINDOWS set and sandbox mode auto, a resume keeps the stored scratch cwd. Removing the branch fails it.
#31391 brought the native-Windows rule into _stored_cwd_is_hidden_scratch (Windows masks no scratch tree, so a resumed chat keeps its stored scratch cwd) but no test pins the Windows branch. Add one: with IS_WINDOWS set and sandbox mode auto, a resume keeps the stored scratch cwd. Removing the branch fails it.
Partial backport of #31391 (main 4023e84) to the 0.12 line. Carried: - get_or_create.py: native Windows keeps a scratch cwd, because no scratch-root mask applies there (a Kiro spawn is delegated to Kiro's own sandbox). This is the Windows branch the GPT review asked for. - get_or_create.py: a caller that opts in (fallback_hidden_cwd) and names an earlier process's hidden scratch tree as its own cwd starts in the default directory instead. - turn_admission.py and eager_spawn.py: the dashboard chat opts in with fallback_hidden_cwd=True. - test_session_get_or_create.py: #31391's tests, without the notice assertions, plus a Windows test adapted from main's test_hidden_scratch_notice.py. Left out: the chat start notice (_note_skipped_hidden_cwd and HIDDEN_SCRATCH_CWD_NOTICE), _fallback_turn_project in turn_spec_hooks.py, the ErrorCard and i18n strings, and test_hidden_scratch_notice.py. The notice surface (startup_notice) comes from #25347, which is not on 0.12. The fallback is kept on 0.12 for #31319: without it every MCP server in that chat fails with ENOENT and the chat is dead, and the hidden folder is unreachable from the process anyway. With no chat notice on 0.12, the existing WARNING log line names the hidden folder and says the session starts in the default directory. (cherry picked from commit 4023e84, partial)
…ws (#30910) #31391 brought the native-Windows rule into _stored_cwd_is_hidden_scratch (Windows masks no scratch tree, so a resumed chat keeps its stored scratch cwd) but no test pins the Windows branch. Add one: with IS_WINDOWS set and sandbox mode auto, a resume keeps the stored scratch cwd. Removing the branch fails it.
Problem / Motivation
Goal: A dashboard chat whose folder was in an earlier run's temporary scratch folder starts and answers after a gateway restart, instead of failing every turn with
KAS managed MCP initialization failed: ... spawn ... ENOENT.After a restart, one chat fails on every turn and every background start. Every MCP server fails with
spawn <path> ENOENT, even ones whose binary exists. Other chats on the same gateway work. Switching that chat's folder back to the normal workspace makes it work again, and the conversation is kept (#31319).Why it matters
The chat is stuck until the user finds the folder switch by hand, and the error points at the interpreter path, so users chase an install problem that does not exist. Agents are told to put clones and worktrees in
$KIROCREW_SCRATCHand toset_projectinto them, so any chat that did this breaks at the next restart.Not a goal
What changed (motivation → approach → change)
spawn ... ENOENT.spawnwith a missingcwdreportsENOENTnaming the command. fix(session): don't resume in an earlier process's hidden scratch dir #30129 already skips such a folder when a resume reads it from the session map, but the dashboard passes the chat's folder as an explicitcwd, which bypassed that check (src/kiro_crew/session_allocation_parts/get_or_create.py, theeffective_cwdblock).fallback_hidden_cwd=True: the dashboard chat's turn claim (src/kiro_crew/dashboard/chat_turn/turn_admission.py) and its eager start (src/kiro_crew/dashboard/chat_turn/eager_spawn.py), which show the notice. Any other caller, such as a sub-agent continuing in a recorded cwd, keeps its cwd, so its start fails loudly instead of running in another repository. When it fires, this start runs in the default folder and the provider carries astartup_notice. The chat's stored folder is never changed. Native Windows masks no scratch tree, so there the check keeps the cwd, with the same one-line predicate change as fix(session): keep a resumed scratch cwd on native windows #30910 (identical hunk, so either merge order is clean).src/kiro_crew/dashboard/state_parts/chat_slot.py,src/kiro_crew/dashboard/state_parts/slot_session.py, read in_surface_startup_noticeinsrc/kiro_crew/dashboard/chat_turn/turn_spec_hooks.py). Other start notices are never held back. The text is translated:website/src/pages/chat/ErrorCard.tsxmaps thehidden_scratch_cwd_skippedkind topages.chat.errorCard.hidden_scratch_folder, in all 12 locales underwebsite/src/i18n/locales/, as the two cloud-session notices are; the English wire text stays the channel fallback._fallback_turn_project, called fromsrc/kiro_crew/dashboard/chat_turn/turn_admission.pyafter the claim); the session is released if that read is cancelled, as the reprojection just above it already does).docs/system-specs/modules/session.mdsays the check covers both cwds, that the stored folder is never changed, and how the notice is limited.builder-security checked: the change only picks a working folder for a child process inside the existing sandbox. It adds no listener, route, bind, auth change or exposure.
Backwards compatibility
Compatible: only a cwd inside the scratch root, outside the spawn's shared tree, with the sandbox on, is dropped for that start. Such a cwd already failed every MCP start.
Removes nothing: the chat's stored folder is never changed; the user can pick another folder at any time.
Tests
test/test_session_get_or_create.py::TestGetOrCreatePoolClaim::test_a_given_cwd_in_an_earlier_process_scratch_is_skipped_with_a_notice: an explicit cwd in an old scratch tree starts with no cwd and leaves the notice; an explicit cwd outside the scratch root, or inside the shared tree, is kept with no notice.test/test_hidden_scratch_notice.py::test_the_notice_shows_once_per_chat_and_never_hides_another_notice: two starts of one chat show one notice, another chat shows its own, and a cloud notice after them still shows.test/test_hidden_scratch_notice.py::test_the_turn_describes_the_folder_the_session_runs_in: a turn whose stored folder is old scratch describes the session's folder; any other folder, even a missing one, is kept.test/test_hidden_scratch_notice.py::test_native_windows_keeps_a_chat_scratch_folder: on native Windows a chat's scratch folder is kept and the turn describes it.test/test_hidden_scratch_notice.py::test_a_turn_cancelled_while_reading_its_folder_releases_the_session: a turn cancelled during the folder read hands the session back.website/src/test/ErrorCard.test.tsx: the notice kind renders the catalog sentence, not the wire text.Proof: not provable -- other: prove.py reverts the notice constant with the hunks, so the test errors at import. Mutating by hand: disabling the cwd check fails 2 tests, dropping the notice call fails 1, disabling the once-per-run flag fails the notice test, and keeping the stored folder in the turn fails the turn-folder test. Dropping the native-Windows check fails the Windows test. Ignoring the opt-in fails the explicit-cwd test. Dropping the release on cancel fails the cancellation test.
Ran:
test/test_hidden_scratch_notice.py,test/test_session_get_or_create.py,test/test_eager_spawn.py,test/test_kiro_cloud_sandbox_notice.py,test/test_chat_runner_composition_contract.py,test/test_chat_runner_turn_plumbing.py,test/test_no_config_dir_in_async.py(single process). black, flake8, isort and mypy clean on the touched files. Frontend:tsc -p tsconfig.app.jsonclean;vitest run src/test/ErrorCard.test.tsx src/i18n/1267 passed;i18n:checkdiff-scoped checks all PASS (itskey-refsstep could not run locally: the worktree'stypescriptpackage failed to resolve).Manual verification
N/A — not reproduced against a live gateway restart; the unit test covers the cwd choice and the notice, and the sandbox mask that hides the old tree is existing behaviour.
Screenshots / video
Why no screenshot: the error card's layout is unchanged; for one notice kind it now shows the catalog sentence instead of the English wire text, which
ErrorCard.test.tsxpins.Related Issues
Closes #31319
Related: #30129 (same check for a resumed cwd), #30910 (same check on native Windows), #30062 (keep the scratch tree across a resume).
Sibling sweep
Swept: git grep -n "_stored_cwd_is_hidden_scratch|shared_scratch" -- src/kiro_crew/session_allocation_parts src/kiro_crew/subagent_manager
Sibling: src/kiro_crew/subagent_manager/run_turn.py -- not affected -- a sub-agent passes its parent's tree as shared_scratch, which the check keeps
Pattern harvest
Not generalizable: the session start is the one place that picks a child's cwd from caller or session-map state, and both now pass through the same check.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)