Repository navigation
fix(scratch): a resume never remounts a scratch directory another session tree recorded - #37836
jeeshofone wants to merge 1 commit into
Conversation
d79aabc to
c8d0d30
Compare
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS No blocker. Every item comes from the reported cross-tree mount and its three mount sites. The in-memory double-fault mark machinery is the one part with no harm of its own. Notes
What this change shipsInventory (8 items) — 7 justifiedIntent: after a restart, a resumed chat never mounts a scratch directory that another session tree's chat also recorded. FIX.
[FIRST-PRINCIPLES-REVIEWED] 0ae2424 Description read[DESCRIPTION-READ] 1b2589d6ef092e87cc8a6ec5e7b24148e9e88a7de8df0d557b9fe4e548093a4c That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change targets a real cross-tree isolation leak at the resume seam, and the readers of the renamed setter and the Notes
[DESIGN-REVIEWED] 0ae2424 Description read[DESCRIPTION-READ] a6db5af34e8c78486a73469f130f3e7ea6eb3bf6f856afc491db3ad1f913a993 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 (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
c8d0d30 to
e817475
Compare
|
Replies to the review lanes on c8d0d30. Both findings are fixed on e817475. Design Review: a dedicated subagent reads as a foreign tree. Fixed. A key's tree root now comes from its recorded lineage ( GPT 6.1 Review: retire contaminated directory bindings atomically. Fixed as suggested. |
e817475 to
cecf5dc
Compare
|
Backend Tests shard 7 on e817475: both facade guards were ours and are fixed on cecf5dc, with no guard edits.
E2E (stub ACP backend, offline) on e817475 was the |
cecf5dc to
c761cc0
Compare
|
GPT 6.1 Review on cecf5dc (unseeded lineage retires a lead's own directory): fixed on c761cc0.
Opus's non-blocking notes on the same head:
|
c761cc0 to
59f8b9c
Compare
|
GPT 6.1 Review on c761cc0 ("Unavailable lineage bypasses scratch isolation"): fixed on 59f8b9c. This is the fail-closed option for the fenced F1, with no deletion: when isolation cannot be shown, the directory is not shared.
|
59f8b9c to
7bd838a
Compare
|
GPT 6.1 Review on 59f8b9c (F1, a chat left as the only binding on a refused directory rejoins it): fixed on 7bd838a. The fix fails closed and deletes nothing.
|
Security Scope Review (fork) — 🔴 BLOCK (blocking)Which legitimate operations does the per-platform reports could not be folded Scope-Verdict: PASS Reason: The only deny-side tightening is in the file-tool path gate, which the shell classifier does not adjudicate. It adds TIGHTENING: the scratch-root protected-file check in ADJUDICATED: 13 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: The diff compares a casefolded basename and
UNADJUDICATED:
[SCOPE-REVIEWED] 7bd838a |
7bd838a to
2b86ef4
Compare
8287d86 to
609da92
Compare
|
Local review rounds 13 to 15 since 8287d86. The head is now 609da92, rebased on origin/main 4aec9c9. Round 13, Opus B1: a chat's own subagent with a pruned run record quarantined the chat's directory. The gateway now records each subagent's spawn parent beside its binding in
Round 14, Opus B2: a
The parent keeps exactly the verified flag it carries on its own.
Round 15, GPT B1: a stale or malformed parent claim could hide an owner. 238106c6f0 re-read the recorded parent after a failed placement and ignored the reason. A live record naming another parent, a cycle, too many hops, or a parent row on a channel key could therefore collapse
Round 15, Opus B1: a nested subagent of a channel chat (two hops down) still quarantines. Declined under this PR's convergence cap. It fails closed, it is pinned by Round 15, Opus N3 (docstring): fixed. Opus N2 (a parent row on a non-subagent key) is covered by the GPT B1 fix. Opus N1, and the carried r24 N1 and N2, are not blocking and are left as they are. |
609da92 to
593f61c
Compare
|
First Principles review on 609da92: the blocker and note 6 are fixed on 593f61c; note 3 is declined. Blocker: two readers for one tree walk. Only one reader is installed now, the placement reader.
Note 6: Note 3: replace the quarantine mark with GPT (fork lane) on 609da92: a Slack thread whose subagent was spawned before this change has no parent row, so the resumed thread lost its directory. Fixed. This also covers nested channel subagents.
|
593f61c to
115fcd0
Compare
|
GPT 6.1 Review on 593f61c: F1 is fixed on 115fcd0. F1 (fenced): at the size cap, the fallback persisted a rebinding without the held quarantine mark. Fixed where it happened, in In your sequence, Two writes still land at the cap: removing a held directory's last binding ( Why refuse rather than write a compact mark: this module is the index's only writer, and refusing keeps it the single place that decides what is persisted. A compact mark would add a second row format that every reader and the strict mark parser would have to accept. It would also still need room the index may not have. Pins:
First Principles: that lane ended "review incomplete" on 593f61c. Its job will be re-run on this head once its other checks finish. |
115fcd0 to
118c0b4
Compare
|
GPT 6.1 Review on 115fcd0: F1 is fixed on 118c0b4. F1 (fenced): a successful retirement erased the ownership evidence. Your chain, and where each step is now refused:
The mark stays through later registrations. It clears only when every marked owner resolves to one tree ( Pins (
Local GPT lane B1 on the round-18 fix: a respawn remounted a marked directory. When B's process crashes or respawns,
|
118c0b4 to
f6d1129
Compare
|
Opus 5.5 Review and GPT 6.1 Review on 118c0b4: the blocking finding both raised is fixed on f6d1129. Both lanes: the quarantine check ran on the event loop.
Pins:
Not taken this round:
|
…sion tree recorded An index written while unrelated session trees shared one process binds all of their keys to that process's directory, and the resume path handed it back as shared_scratch on every restart, so the trees kept reading each other's staged files. A resume now checks every key recorded on its tree against its own session-tree root; on a mismatch every key on the directory is retired and the resume starts in a fresh one. Fixes kirodotdev#37817
f6d1129 to
0ae2424
Compare
|
Rebased onto current main. The head is now 0ae2424, with no change to what this PR does.
|
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 25% chance that this change introduces a defect, above the 12% limit for approving on its own. The PR fixes the reported leak: a resumed chat no longer remounts a scratch directory that a chat of another session tree recorded. One helper checks ownership on both resume paths. Where ownership cannot be settled, it quarantines the directory with a mark row inside the existing masked .trees.json (fails closed), and when owners resolve to two trees it retires every binding in one write. Spawns made on a parent's behalf (run_turn, get_subagent_runtime) and ACP respawns also refuse a marked directory. Every writer of .trees.json now carries the mark row forward, readers that only want bindings skip the new rows, the renamed tree-placement reader has no stale references, and chat runtime sharing gets the same roots as on main. Same-tree cases still rejoin their directory: a chat alone, a chat with its own subagent, a channel or cron chat with its subagents, and a lead with live workers. Every new behaviour has tests and all backend shards passed. The remaining gaps are low-severity and fail closed (staged files stay on disk), so none blocks the merge. Tier: 2, held for a person: 23 files, more than 20. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
|
This changes behaviour users already rely on, so it needs a design sign-off from a maintainer before it can merge. A maintainer will post the decision here. To propose a design, follow the request-for-change process in CONTRIBUTING.md (docs/request-for-change/). Review result on this head: no blocking defect found. Both resume sites in Optional:
|
Problem / Motivation
Goal: after a gateway restart, a resumed chat never mounts a scratch directory that a chat of another session tree also recorded.
Three unrelated dashboard chats that once shared one process each resumed into their own process after a restart, but all three processes mounted the same
$KIROCREW_SCRATCHdirectory, so each tree could read and write what the others staged there.Why it matters
Scratch directories hold staged files (uploads, generated artefacts, intermediate output). A cross-tree mount breaks the isolation between unrelated chats, and because the binding is re-created on every restart it never heals.
Not a goal
What changed (motivation → approach → change)
Symptom: unrelated trees mount one recorded directory after every restart. Cause, confirmed (the filer's inference was right): both resume paths in
session_allocation_parts/get_or_create.py(the hidden-cwd check and theshared_scratchbinding) hand backagent_scratch_trees.recorded_tree(key)as is. The index maps a key to a directory name only, and nothing compares that directory with the session tree, so rows written while unrelated trees shared a process keep binding them together.Change: one helper,
_recorded_tree_of_own_session_tree, used by both resume paths. It reads every key recorded on the directory (agent_scratch_trees.keys_on_tree: live bindings, the fallback snapshot and the disk index) and resolves each key's session-tree root through its recorded lineage (_known_tree_root). A dashboard chat is placed by the gateway's slot reader, the same root #37466 places runtimes by; a chat the reader cannot place is its own root, because startup restores only open tabs and rebuilds other slots on demand. Asubagent:key is placed through theparent_sessionof its run record, since it runs in its parent's directory. Owners are placed by live slots and run records first, so a chat and its own dedicated subagent rejoin without the persisted lineage, as on main. Only when those roots disagree does the resume load the persisted lineage off the event loop (projection().ensure_seeded()). If the crew log is off or the lineage is not settled, the directory is neither handed back nor retired: it is quarantined with every key that owns it (agent_scratch_trees.quarantine_tree, a mark row inside the existing tree index.trees.json, which main already refuses to agents and host tools on both roots), and the resume starts in fresh scratch. A mark row that cannot be read refuses. A mark that cannot be written is held in memory for this process and goes out with the next index write that fits under the size cap; entries for reclaimed directories are pruned. A mark is cleared only when every owner in it was among the owners the resume checked; a mark past 256 owners is written as an overflow and is never cleared. Retirement and a failed write's mark run as one shielded unit. The check lives in the newsrc/kiro_crew/session_allocation_parts/scratch_ownership.py(owned by thesrc/kiro_crew/session_allocation.pyfacade), reading placements throughshare_tree_placement_of(src/kiro_crew/agent_sdk/chat_runtime_sharing.py), the only installed tree reader. A marked directory is refused on every later resume, across restarts and however many keys are still bound, until a settled lineage resolves all its marked keys: to one tree clears the mark and rejoins, to two retires every binding. The other sessions' bindings stay, the resuming session's own binding moves to its fresh directory, and the old directory stays on disk for the sweep. Otherwise the directory is refused only when its keys resolve to two different known roots. Thenabandon_tree_allretires every binding and marks the directory with its owners in one index write, and the resume starts fresh; the mark refuses it to later keys,parent_work_scratch_dir(session_allocation_parts/companions.py) and a respawn insrc/kiro_crew/acp/launch.pynever mount a marked directory.Backwards compatibility
The mark, not plain retirement, is kept on purpose: a directory held because one owner was briefly unplaceable (a pruned subagent later placed through its recorded parent) clears and rejoins once every marked owner resolves. Abandoning it would turn every transient ambiguity into permanent fresh scratch.
Known behaviour: with the crew log off, a multi-key directory is not shared until the lineage settles, and its quarantine persists across binding changes and restarts; each resume starts in fresh scratch. The other sessions' bindings stay, the resuming session's own binding moves to its fresh directory, and the old directory stays on disk for the sweep.
Known gaps: a quarantine mark that cannot be written does not survive a restart, but while it is held the index refuses any rewrite that takes an owner off that directory while another stays, so its owners still quarantine it after a restart (
TestAHeldMarkAtTheSizeCap); that needs a double fault (the lineage is unavailable and the tree index itself refuses the write), the mark still holds in memory for the running gateway, the failure is logged at error level naming the directory, and the next refusal tries the write again. A tree index corrupted by a writer outside this module loses its marks the same way it loses its bindings. A downgrade to a build without this change drops the mark row the next time it rewrites the index. A session key equal to the mark row's reserved name makes the row unparseable, which refuses every recorded directory. Nothing tells the user why a refused chat's staged files are no longer in its scratch directory; that notice is a follow-up.Compatible: members of one session tree keep rejoining their recorded directory; only a directory recorded across trees is refused.
Reader: src/kiro_crew/session_allocation_parts/get_or_create.py:_get_or_create_impl -- chat|subagent|cron -- a refused directory reads as "no recorded tree", the path main already takes when a tree is gone | test_unrelated_trees_recording_one_directory_resume_into_their_own
Reader: src/kiro_crew/agent_scratch_trees.py:recorded_tree -- chat -- retired rows read back as None, as after any abandon_tree | test_members_of_one_tree_recording_one_directory_still_rejoin_it
Tests
test_unrelated_trees_recording_one_directory_resume_into_their_own: three keys of three trees recording one directory each resume with no shared directory bound.test_members_of_one_tree_recording_one_directory_still_rejoin_it: a worker of the lead's tree still rejoins the recorded directory.test_a_chat_rejoins_the_directory_its_dedicated_subagent_also_recorded: with the gateway's real slot reader, a chat plus itssubagent:key on one directory still rebinds the chat.test_a_co_owner_that_cannot_be_placed_quarantines_an_unmarked_directoryand the recorded-parent pins (test_a_chat_keeps_its_directory_after_its_own_subagents_record_is_pruned,TestChannelAndCronParents): an unplaceable owner never drops out; a subagent takes a channel or cron parent's identity only along its run-record chain, or the parent row the gateway records at spawn (src/kiro_crew/subagent_manager/run_turn.py) once a record is pruned, through current owners only (test_a_thread_from_before_parent_rows_keeps_its_directory,test_a_nested_subagent_of_a_channel_chat).test_two_chats_with_no_live_slot_on_one_directory_are_refused: two chats whose slots are not restored yet are two trees, and the directory is refused.test_two_slot_chats_of_different_trees_on_one_directory_are_refused: two live chats of different trees are refused and every binding is retired.test_two_unrelated_resumes_at_once_neither_mounts_their_shared_directoryandtest_a_resume_racing_the_refusal_of_its_directory_does_not_mount_it: concurrent resumes, and a resume retired between its two reads, never mount the directory.test_an_unseeded_lineage_retires_nothing_and_does_not_hand_the_directory_back: an unsettled lineage keeps the other bindings and gives the resume fresh scratch.test_with_the_crew_log_off_two_unrelated_chats_never_share_a_directory: with the crew log off, neither of two unrelated chats is handed their shared directory.test_a_settled_lineage_of_two_trees_still_retires_the_directory: a settled lineage of two trees still retires it.test_a_chat_left_alone_on_a_refused_directory_does_not_rejoin_it: A is refused and moves away, then B, the only binding left, is still refused.test_a_quarantine_mark_survives_a_fresh_process: the mark is read back from disk.test_a_mark_that_cannot_be_written_still_refuses_the_chat_left_alone: a failed mark write still refuses in this process.test_a_failed_retirement_write_survives_a_restart_without_mounting: a failed index write keeps the mark in memory, the next refusal writes it, and after a restart the owner gets fresh scratch with the files untouched.docs/system-specs/modules/subagent.mdand the scratch tree index section ofdocs/system-specs/modules/security.mddescribe the ownership check and the quarantine row.test/test_scratch_tree_quarantine.py; the resume pins stay intest/test_subagent_scratch_tree_index.py.test_an_unusable_index_refuses_rather_than_reading_as_no_marksandtest_a_mark_writer_carries_another_directorys_held_mark: an unusable index refuses, and any index write carries other directories' held marks.test_an_unpersisted_mark_keeps_a_bounded_owner_set_and_refuses_past_it,test_an_overflow_mark_is_never_clearedandtest_a_retirement_writes_an_overflow_held_only_in_memory: the overflow mark is durable and sticky.test_a_mark_that_gained_owners_after_the_check_is_kept: a clear never drops an owner nobody checked.test_two_chats_with_an_unverified_creator_never_share_a_directory,test_a_forged_saved_creator_under_a_settled_lineage_never_merges_two_chats,test_two_chats_opened_by_one_cron_job_stay_distinct_ownersandtest_chats_whose_recorded_root_slot_is_gone_are_quarantined: a placement is verified only when no hop rests on an unchecked claim and the root is a live slot (src/kiro_crew/crew_mode.pyshare_tree_placement, read throughsrc/kiro_crew/dashboard/state_parts/dashboard_state.pyandsrc/kiro_crew/acp/chat_runtime_sharing.py).test_a_marked_owner_that_can_no_longer_be_placed_keeps_the_directory_refused: a marked owner that can no longer be placed keeps the directory refused.test_a_held_mark_goes_out_with_the_next_successful_index_write,test_a_removal_too_large_with_held_marks_still_lands_and_stays_readableandtest_a_retirement_too_large_with_held_owners_keeps_the_index_readable: held marks and the size cap.test_memory_holds_unpersisted_marks_only_for_live_directoriesandtest_an_unpersisted_mark_is_pruned_once_its_directory_is_reclaimed: memory holds marks only for live directories.test_with_the_crew_log_off_a_chat_and_its_own_subagent_rejoin_after_a_restart: no lineage is needed when live slots and run records agree.test_with_the_crew_log_off_a_chat_with_no_live_slot_still_refuses: a chat with no live slot still needs the lineage.test_a_cancelled_retirement_with_a_failed_write_still_leaves_the_mark: a resume cancelled during a failed retirement write still leaves the mark, and after a restart the remaining owner is refused.test_a_quarantine_mark_in_the_scratch_index_survives_an_artifact_write(test/test_artifacts.py): a default-root artifact read and write of the index is refused and the mark survives.src/kiro_crew/builtin_skills/kirocrew-dev/writing-tests/SKILL.mdname the placement reader.test_an_index_written_by_main_reads_as_beforeandtest_a_mark_row_this_module_did_not_write_refuses: index compatibility.test_a_settled_lineage_of_one_tree_clears_the_mark_and_rejoinsandtest_a_settled_lineage_of_two_trees_retires_a_marked_directory: how a mark is cleared.test_a_refused_directory_is_retired_for_every_key_in_one_write: one index write, other keys untouched.Proof: PROVEN test/test_dashboard_state_process_hooks.py::test_the_hooks_answer_through_a_live_state, test/test_dashboard_state_process_hooks.py::test_a_dropped_state_is_collected_and_the_hooks_answer_unwired, test/test_host_isolation_floor_restores.py::TestBootWiredGlobalsGoBack::test_a_state_built_in_the_cycle_leaves_the_inherited_values, test/test_subagent_scratch_tree_index.py::TestAResumedKeyRejoinsItsTree::test_unrelated_trees_recording_one_directory_resume_into_their_own, test/test_subagent_scratch_tree_index.py::TestAResumedKeyRejoinsItsTree::test_a_settled_lineage_of_two_trees_still_retires_the_directory (head f6d1129)
Allocation, scratch, runtime-sharing, artifacts, flake-ratchet and facade-guard suites on main ceb593c: 1090 passed, 1 skipped.
Manual verification
N/A — unit coverage sufficient: the defect is in index-to-binding resolution, which the resume tests drive end to end through
SessionManager.get_or_create.Related Issues
Fixes #37817
Related: #37826 (fixes the sibling #37816 by sharing a chat runtime by session tree; this PR is the scratch-side fix it scopes out)
Sibling sweep
Swept: git grep -n "recorded_tree" -- src/
Sibling: src/kiro_crew/session_allocation_parts/get_or_create.py -- changed here
Sibling: src/kiro_crew/providers/chat_share.py -- not affected -- only reads the shared_scratch the resume path already chose
Pattern harvest
Not generalizable: the tree index is the only per-key binding that outlives a process and is reused across sessions.
Checklist