Repository navigation
fix(acp): share a chat runtime by session tree, not by recorded scratch directory - #37826
Conversation
|
Remaining
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. One rider is stricter than the fix needs: when the old scratch directory has no owner marker, or a garbled one, the session falls back to founding its own process, so the tree splits again in a case the sweep already handles safely. Notes
What this change shipsInventory (7 items) — 6 justifiedIntent: after a gateway restart, a team lead and its resumed workers run on one KAS process again (sharing preview on) — FIX.
[FIRST-PRINCIPLES-REVIEWED] a410db8 Description read[DESCRIPTION-READ] f8076b985fe629d45752ab0d10bf7045a855d405186194b79941ccab29ffb023 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the key now matches the tree it is meant to share, the change only applies while the sharing preview is on, and a revert undoes it. Notes
[DESIGN-REVIEWED] a410db8 Description read[DESCRIPTION-READ] 9ef5755ec96bc3e7a87e4a3d1d512cbf76ac4528abd301b9b6f00f095bcacefd 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 — ✅ human override acceptedReviewed Human judgment by @chenmingwei23 overrides the Opus 5.5 finding for [OPUS-OVERRIDE] a410db8 Verdict recorded from an authorized human decision for commit False positive or not applicable? A repository writer can comment: |
|
target=first-principles span=b2fcff6b2afe needs-a-decision
|
|
/ai-review override first-principles d7d9193 owner-decision: #37826 (comment) The owner ruled that the scratch directory is retired as a sharing input and only session lineage decides placement; a resumed worker's previously staged scratch files are not mounted after it joins its tree's process. |
Human judgment recorded@chenmingwei23 recorded a owner-decision release (class
This decision applies only to this commit. A new push requires a new judgment. |
d7d9193 to
78b1207
Compare
|
Re the Opus and GPT 6.1 finding on On a join whose recorded directory differs from the one the joined process mounts, The old directory now lives exactly as long as the tree's process. Once that process exits it is swept by the existing rules (a directory holding a git repository is quarantined for 14 days first), the same lifetime as any other scratch directory. This is intentional; the sweep itself is unchanged. Test: |
78b1207 to
6e8893e
Compare
|
Findings on
|
6e8893e to
524a8ec
Compare
|
GPT and Opus finding on
Test: |
…ch directory A resumed chat binds the scratch directory it was recorded in, and the chat runtime sharing key carried that directory. Sessions of one tree that had run on separate processes recorded one directory each, so after a gateway restart they never matched again and the tree stayed split on every restart. shared_scratch leaves ChatRuntimeKey: sessions of one tree share by tree_root. A joiner runs in the directory the process it joins mounts, which the start path already records. The restart-only join on a matching tree (_join_own_tree, RuntimeOwnership.join_on_tree) and the founder's published key (_published_key_for, acquire's published_key) existed only to work around the keyed directory and are removed. A joiner's earlier recorded directory is not mounted, and its owner is a process that exited with the gateway, so the sweep would reclaim it an hour after the join. ChatSharePlacement.place holds that directory for the sweep's grace window before the acquisition (agent_scratch.shared_scratch_window, as a spawn holds a tree it mounts) and, right after a join and before any session setup, adds the joined process to its owner marker (agent_scratch.adopt_owner) with a WARNING naming the session and the directory: it stays on disk while the tree's process runs and is then swept by the ordinary rules. Unless the marker then reads back naming the joined process (an unowned tree answers "recorded" without a write; "unwritable", "stale", "refused" and "garbled" keep nothing), the join is given up and the session founds its own process, which mounts the directory. A failure or cancellation in that step releases the joiner's lease before it propagates. Closes #37816
524a8ec to
a410db8
Compare
|
Findings on
|
|
Owner decision (Mingwei), on head a410db8: accept option A for the Opus finding at chat_share.py:271. Sharing is decided by session-tree lineage only; the scratch dir is being retired as a sharing input. A resumed worker joins its tree's process even when its recorded scratch dir differs. That dir is not mounted after the join; it is kept alive as long as the shared process (adopt_owner) and then follows the normal sweep rules. Files staged there before a gateway restart are not reachable after the join and are removed once the shared process exits. This is an accepted risk; it only affects chats that were running before a restart. The alternative (keep each worker on its own process when its old dir has files) was rejected because it leaves most restarted trees split. |
|
/ai-review override fable a410db8 owner-decision: #37826 (comment) resumed worker joins by tree; old scratch dir not mounted, retained until the shared process exits |
Human judgment recorded@chenmingwei23 recorded a owner-decision release (class
This decision applies only to this commit. A new push requires a new judgment. |
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 20% chance that this change introduces a defect, above the 12% limit for approving on its own. Approve. Dropping shared_scratch from ChatRuntimeKey lets resumed sessions of one tree share one process again; tree_root stays keyed, so sharing can't cross trees. The removed helpers (join_on_tree, published_key, _join_own_tree, _published_key_for) have no other callers. After a join, place() holds the old recorded directory, adds the joined process to its owner marker and reads it back. If that fails, the session releases its lease and takes its own process, which mounts the directory; the lead's process and lease are untouched and a cancellation also releases the lease. Tests cover each part. The start path then saves the joined process's directory for the next restart (acp_runtime_start.py:1431, get_or_create.py:1661). Only dashboard chats can share, so subagents and companions that inherit a parent's directory never use this path. The one real trade-off, staged files becoming unreachable after a join, was an owner decision recorded for this commit. 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 |
bolichen97
left a comment
There was a problem hiding this comment.
Approving head a410db8607.
Cross-tree isolation holds. ChatRuntimeKey still keys tree_root and member_id/memory_store, so dropping shared_scratch only widens the key inside one tree. A session whose lineage cannot be read is its own root (share_tree_root_of falls back to the session key; ChatSharePlacement uses tree_root or session_key), so it fails closed to a private process. Every fallback in _keep_unmounted_scratch goes through _place_alone, which sets a unique root and joinable = False.
What the old key guarded. Keying the recorded scratch dir kept a resumed worker on a process that mounts its own old directory, so its staged files stayed reachable. That is the trade-off this PR gives up on purpose (owner decision recorded in the thread). The directory is held for the sweep's grace window before acquisition and adopted by the joined process before session setup, and the join is dropped unless the owner marker reads back naming that pid. So files are not deleted early. Isolation between trees never depended on this field: tree_root already separated them.
Preview off is unchanged: share is None, so place is never called. No new regex in product code.
Tests run locally on this head: the touched files plus the claude, goose and deepseek sharing suites, test_acp_harness_contract.py, test_runtime_ownership*.py and test_subagent_shared_scratch.py: 872 passed. I also added a throwaway probe (not pushed): two different trees that recorded the SAME scratch directory never share, and a session with an unreadable root plus a matching scratch dir stays on its own process. Both passed.
🟡 Non-blocking: _names_owner in providers/chat_share.py calls the private agent_scratch._read_owner_pids. A small public reader in agent_scratch would keep the sweep's read rule in one owner if it ever changes.
AI-assisted, sent by Bolin Review bot
…Key (#37945) #37615 added test_claude_leaves_each_per_session_field_out_of_the_key with shared_scratch=None in the ChatRuntimeKey.build call. #37826, cut before #37615 landed, removed that keyword-only parameter, so on main the test's five cases raise TypeError and red every backend run. Drop the keyword from the test's base arguments. The key no longer carries the scratch directory at all, which is what #37826 intended. Co-authored-by: Bolin Chen <bolichen@amazon.com>
The memory spec described record-list filters (applies, source, status, never_recalled), a status-widened refresh and the unforget and set_tier bulk operations. None of them is in the records or bulk handlers on main; they belong to the open #37498. The config spec named SessionAllocation, whose class is SessionAllocationService. The runtime-ownership paragraph on a restart rejoin is dropped, since #37826 removed join_on_tree and _join_own_tree.
The memory spec described record-list filters (applies, source, status, never_recalled), a status-widened refresh and the unforget and set_tier bulk operations. None of them is in the records or bulk handlers on main; they belong to the open #37498. The config spec named SessionAllocation, whose class is SessionAllocationService. The runtime-ownership paragraph on a restart rejoin is dropped, since #37826 removed join_on_tree and _join_own_tree.
* docs: align 40 docs with main after the week of 2026-11-14 Weekly docs-vs-code check of the 304 non-merge commits between b81cf5a and 5abc52b. Fixes stale owners, renamed classes, changed defaults and flags, adds rows for CLI subcommands, config keys and preview names that had none, and moves three RFC status lines to match what merged. * docs: drop unbuilt memory record filters and fix a class name The memory spec described record-list filters (applies, source, status, never_recalled), a status-widened refresh and the unforget and set_tier bulk operations. None of them is in the records or bulk handlers on main; they belong to the open #37498. The config spec named SessionAllocation, whose class is SessionAllocationService. The runtime-ownership paragraph on a restart rejoin is dropped, since #37826 removed join_on_tree and _join_own_tree. --------- Co-authored-by: zejiangg <zejiangg@amazon.com>
Problem / Motivation
Goal: with ACP runtime sharing on, a team lead and the workers it opened run on one KAS process again after a gateway restart, as #37466 intends for one session tree.
After a gateway restart, the lead and its resumed workers founded separate KAS processes, grouped exactly as they had been before the restart. Only workers created after the restart joined the lead.
Why it matters
Each KAS process costs hundreds of MB. A tree that was ever split (by an older build, or one restart that placed its sessions apart) stayed split on every restart, so the memory saving of tree sharing was lost for exactly the long-lived Ultra Mode trees that need it.
Not a goal
get_or_create,agent_scratch_trees). Unrelated trees reusing one recorded directory is Scratch isolation: unrelated session trees reuse one recorded scratch directory after a restart #37817.What changed (motivation -> approach -> change)
Symptom: resumed workers of one tree founded their own processes. Cause: a resumed chat binds the scratch directory it was recorded in, and
ChatRuntimeKeycarried that directory (shared_scratch). Sessions of one tree that ran on separate processes recorded different directories, so their keys never matched again. The earlier fixes (#37579, #37639) only matched a process that mounted the same directory.Change:
shared_scratchleavesChatRuntimeKey, so sessions of one tree share bytree_rootalone. A joiner runs in the directory of the process it joins, which is already what a fresh worker does and what the start path records for the next restart. The workarounds for the keyed directory are removed:_join_own_tree,_published_key_for,RuntimeOwnership.join_on_treeandacquire(published_key=...).runtime-ownership.mdsays the directory is not a sharing input.Trade-off, reversing the rule #37579 pinned (
test_a_restart_never_joins_a_process_that_does_not_expose_its_tree, deleted here): a resumed worker that joins its tree's process no longer mounts its own old recorded directory, so files it staged there before the restart are not reachable from that process. The maintainer chose this: the scratch directory is being retired as a sharing input, and sharing follows the session tree only. Keeping those files reachable (an extra mount, or refusing to join when the old directory holds content) is left out of this PR.Those files are not deleted. The old directory's owner is the process that exited with the gateway, so without more the hourly sweep would reclaim it an hour after the join.
ChatSharePlacement.placenow takes the resumed chat's recorded directory: before the acquisition it holds it for the sweep's grace window (agent_scratch.shared_scratch_window, the same hold a spawn takes on a tree it mounts), and right after a join, before any session setup, it adds the joined process to the directory's owner marker (agent_scratch.adopt_owner, the call companions and successors use) and logs a WARNING naming the session and the directory. The old directory therefore lives exactly as long as the tree's process; once that process exits it is swept by the ordinary rules (a directory holding a git repository is quarantined for 14 days first). If the owner update cannot keep it (stale: the marker still names only dead pids;refused: a planted link), the join is given up and the session founds its own process, which mounts its directory. The sweep itself is unchanged.Backwards compatibility
Compatible: the key only gets wider inside one tree. With the preview off no key is built, and
acquirewithoutpublished_keypublishes under the caller's key, as it did before.Removes nothing:
join_on_treeandpublished_keyhad one caller each, both inproviders/chat_share.py, both removed here;git grepfinds no other reader insrc/ortest/.Known limit: a resumed chat whose working directory sits inside its own old recorded scratch tree, and equals the working directory of the tree's live process, joins that process and no longer sees that directory, because the process does not mount the old tree; this PR adds no guard for it.
Tests
test_two_restarts_of_one_tree_with_different_recorded_trees_share: two resumed chats of one tree with different recorded directories get equal keys and the second joins. Red on main.test_chat_runtime_sharing_scratch_keep.py(new; split out because the cleanup test file hit the 2,000-line cap): a joiner's recorded directory gets the shared process as owner, a WARNING names it, the sweep keeps it while the process lives and reclaims it after; a sweep landing between the join and the owner update keeps it (red without the hold); astaleorrefusedowner update founds the session its own process and leaves the lead's process and lease alone (red without the fallback). The first is red with theadopt_ownercall removed.test_a_closed_worker_leaves_one_tenant_and_the_other_keeps_running: closing one of two chats on a process evicts it, drops the process to one lease, keeps the other chat and the process directory, and frees the seat for a new chat.test_preview_off_leaves_a_resumed_chats_recorded_tree_bound: with the preview off nothing is placed and the chat's recorded directory stays bound for its own spawn.test_a_restart_whose_tree_no_live_process_exposes_keys_that_treeandtest_a_restart_never_joins_a_process_that_does_not_expose_its_tree(they asserted the directory is keyed).test_a_founded_start_logs_which_key_fields_kept_it_offnow differs onwork_dir.shared_scratchmoved to the not-keyed list intest_chat_runtime_key_completeness.pywith its reason.Proof: test_two_restarts_of_one_tree_with_different_recorded_trees_share is red on main; each test in test_chat_runtime_sharing_scratch_keep.py is red with its part of the fix removed (head 6e8893e)
Manual verification
Pending: a gateway restart with a lead and resumed workers on the preview, checking the placement lines show
joinedon the lead's runtime.Related Issues
Closes #37816
Refs #37817
Sibling sweep
Swept: git grep -n "shared_scratch" -- src/kiro_crew/acp/chat_runtime_sharing.py src/kiro_crew/providers/chat_share.py src/kiro_crew/runtime_ownership.py
Siblings: none -- the sharing key is built in one place (ChatRuntimeKey.build) from one caller (ChatSharePlacement._build_key)
Pattern harvest
Not generalizable: a per-process input keyed for compatibility although the joining path never needed it to match; the key completeness test already makes each field carry a reason.
Checklist