Skip to content

fix(scratch): a resume never remounts a scratch directory another session tree recorded - #37836

Open
jeeshofone wants to merge 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/37817-recorded-tree-rescope
Open

jeeshofone wants to merge 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/37817-recorded-tree-rescope

Conversation

@jeeshofone

@jeeshofone jeeshofone commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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_SCRATCH directory, 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 the shared_scratch binding) hand back agent_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. A subagent: key is placed through the parent_session of 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 new src/kiro_crew/session_allocation_parts/scratch_ownership.py (owned by the src/kiro_crew/session_allocation.py facade), reading placements through share_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. Then abandon_tree_all retires 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 in src/kiro_crew/acp/launch.py never 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 its subagent: key on one directory still rebinds the chat.
  • test_a_co_owner_that_cannot_be_placed_quarantines_an_unmarked_directory and 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_directory and test_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.
  • The resume paragraph in docs/system-specs/modules/subagent.md and the scratch tree index section of docs/system-specs/modules/security.md describe the ownership check and the quarantine row.
  • Mark storage, bounds and clearing pins live in test/test_scratch_tree_quarantine.py; the resume pins stay in test/test_subagent_scratch_tree_index.py.
  • test_an_unusable_index_refuses_rather_than_reading_as_no_marks and test_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_cleared and test_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_owners and test_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.py share_tree_placement, read through src/kiro_crew/dashboard/state_parts/dashboard_state.py and src/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_readable and test_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_directories and test_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.
  • The testing-conventions example and src/kiro_crew/builtin_skills/kirocrew-dev/writing-tests/SKILL.md name the placement reader.
  • test_an_index_written_by_main_reads_as_before and test_a_mark_row_this_module_did_not_write_refuses: index compatibility.
  • test_a_settled_lineage_of_one_tree_clears_the_mark_and_rejoins and test_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

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@jeeshofone
jeeshofone requested review from a team and KiroCrewCaptain as code owners November 16, 2026 05:32
@jeeshofone
jeeshofone requested a review from buluoray November 16, 2026 05:32
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Nov 16, 2026
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from d79aabc to c8d0d30 Compare November 16, 2026 06:11
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 0ae2424

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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

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

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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

Premise-level review of 0ae242478ee40777a841f6f03a8f2c684a2eb06c 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

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

  • Item 6 — oversized: by the author's own account the in-memory mark "needs a double fault (the lineage is unavailable and the tree index itself refuses the write)". To cover it, _QUARANTINE_LIVE, _TOO_MANY_OWNERS/"overflow" and the "thinned" refusal were threaded through every index writer (_index_payload). Subtraction: delete _QUARANTINE_LIVE, _hold_unpersisted_mark and the held-mark merge/refusal branch in _index_payload. A mark write that fails then just refuses this resume, which return None already does, and logs at error.

What this change ships

Inventory (8 items) — 7 justified

Intent: after a restart, a resumed chat never mounts a scratch directory that another session tree's chat also recorded. FIX.

  1. A resume whose recorded directory has owners in two or more session trees starts in fresh scratch, and every binding is retired — justified
  2. Without a settled lineage, the directory is quarantined (a mark row in .trees.json) and refused across restarts until its owners resolve to one tree — justified
  3. A new subagent spawn on a parent's behalf (admit_shared_scratch) and an ACP respawn never mount a marked directory — justified
  4. The gateway records each dedicated subagent's spawn parent (\x00parents row), so it can still be placed after its run record is pruned — justified
  5. A tree placement now also reports whether it is verified, so an unchecked metadata-line creator cannot join another tree — justified
  6. A mark that fails to write is held in memory, gets an overflow value, and refuses index rewrites at the size cap — oversized
  7. set_share_tree_reader is renamed to set_share_tree_placement_reader and dropped from the ACP __all__ — justified
  8. An unusable tree index now refuses recorded directories when marks are read — justified

[FIRST-PRINCIPLES-REVIEWED] 0ae2424

Description read

[DESCRIPTION-READ] 1b2589d6ef092e87cc8a6ec5e7b24148e9e88a7de8df0d557b9fe4e548093a4c

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 Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 0ae242478ee40777a841f6f03a8f2c684a2eb06c 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 change targets a real cross-tree isolation leak at the resume seam, and the readers of the renamed setter and the .trees.json writers are all updated in the patch.

Notes

  • The quarantine is proportionate in purpose but not in mechanism. Held in-memory marks, overflow sentinels and size-cap refusals now ride on every binding writer (record_tree, abandon_tree, drop_other_row), so one directory's unwritable mark can refuse an unrelated binding removal. Once fix(acp): share a chat runtime by session tree, not by recorded scratch directory #37826 stops new cross-tree rows, consider a one-time sweep that retires existing multi-tree rows, so this state machine can shrink.
  • With the crew log off, any directory whose owners disagree across live slots falls back to fresh scratch on every resume, and nothing in the product tells the user. The description defers that notice; track it as an issue, not a one-line mention.
  • Skipped the release-path and app-bundle readers: no app or packaging code reads .trees.json or set_share_tree_reader in this tree.

[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 .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 Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] 0ae2424

@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from c8d0d30 to e817475 Compare November 16, 2026 07:21
@jeeshofone

Copy link
Copy Markdown
Contributor Author

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 (_known_tree_root in get_or_create.py). A subagent: key is placed through the parent_session of its run record, so it resolves to its chat's own root. A dashboard chat the slot reader cannot place counts as its own root, not unknown: startup restores only open tabs (closed sessions are skipped in slot_builders.py) and rebuilds other slots on demand, so a chat with no live slot at resume time may still be another tree, and treating it as unknown would let the first resume rebind a contaminated directory. A subagent with no run record, a cron key and a channel key resolve to "unknown" and never make a directory foreign. A directory is refused only when its keys resolve to two different known roots. Pinned with the gateway's real slot reader by test_a_chat_rejoins_the_directory_its_dedicated_subagent_also_recorded (fails on c8d0d30) and test_a_key_of_unknown_lineage_does_not_make_a_directory_foreign; test_two_chats_with_no_live_slot_on_one_directory_are_refused pins the fail-closed case. The opposite case is test_two_slot_chats_of_different_trees_on_one_directory_are_refused.

GPT 6.1 Review: retire contaminated directory bindings atomically. Fixed as suggested. abandon_tree_all(tree) in agent_scratch_trees.py retires every binding to the directory (live, fallback snapshot and disk) under the index lock, with one atomic write. keys_on_tree reads under the same lock, so a concurrent resume sees either every key bound (and refuses) or its own key gone (and starts fresh: the resume now checks its key is still on the directory). A failed write still retires the in-memory bindings. Pinned by test_a_refused_directory_is_retired_for_every_key_in_one_write, test_a_resume_racing_the_refusal_of_its_directory_does_not_mount_it and test_two_unrelated_resumes_at_once_neither_mounts_their_shared_directory.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 16, 2026
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from e817475 to cecf5dc Compare November 16, 2026 10:01
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Backend Tests shard 7 on e817475: both facade guards were ours and are fixed on cecf5dc, with no guard edits.

  • test_only_the_family_imports_an_owner: _known_tree_root in session_allocation_parts/get_or_create.py imported subagent_persistence_layout and subagent_persistence_state directly. It now imports the kiro_crew.subagent_persistence facade and reads read_state and subagent_id_from_conversation_key from it at call time. The facade re-exports the same functions, so behaviour is unchanged.
  • test_no_test_patches_a_shared_name_on_an_owner_directly: the subagent test in test/test_subagent_scratch_tree_index.py patched read_state on the owner module. It now patches it on the facade, which also writes through to the owner.

E2E (stub ACP backend, offline) on e817475 was the chat-form-switch-anchor.spec.ts retry flake; this PR changes no website file.

@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 Nov 16, 2026
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from cecf5dc to c761cc0 Compare November 16, 2026 11:02
@jeeshofone

Copy link
Copy Markdown
Contributor Author

GPT 6.1 Review on cecf5dc (unseeded lineage retires a lead's own directory): fixed on c761cc0.

  • Cause: a closed child chat has no live slot, so its root comes from the persisted lineage. Before the crew log's session-tree projection is seeded, that lineage is empty, the child reads as its own tree, and abandon_tree_all deleted both bindings.
  • Fix: session_allocation_parts/get_or_create.py:387 adds _seed_persisted_lineage. It runs the same fold a restore uses (projection().ensure_seeded(), blocking, called through asyncio.to_thread at line 426) and returns crew_mode.lineage_is_settled(). It returns False when the crew log is off or the fold fails.
  • Rule: _recorded_tree_of_own_session_tree (line 426) seeds before reading any root once a directory has more than one key. If the lineage is not settled, it retires nothing: it logs a warning, keeps every binding and hands the directory back. Retirement (line 441) happens only when a settled lineage gives two different roots. The refusal rule for a directory of two known trees is unchanged.
  • Tests: test_an_unseeded_lineage_retires_nothing_and_the_lead_keeps_its_directory records a closed child on the lead's directory with an unsettled lineage, then checks that the lead gets the directory back and both bindings survive. It fails on cecf5dc. test_a_settled_lineage_of_two_trees_still_retires_the_directory checks the retire still fires for two genuinely different trees.

Opus's non-blocking notes on the same head:

  1. A closed child bound while the crew log was off: once the log is on and the lineage settles without that child, the child has no recorded parent and reads as its own root, so the directory is retired and the lead starts in a fresh one. This is the isolation side of the rule: a key the settled lineage cannot place is treated as another tree, so files are never shared on a guess. The cost is the lead's staged files, which stay on disk for the sweep, and it needs a binding made while the crew log was off. It is not pinned by a test.
  2. No tree-root reader wired, so every chat is its own root: the unsettled-lineage guard does not cover this, because whether the lineage is settled does not depend on the reader. Only the gateway resumes dashboard chats, and it installs the reader at startup (dashboard_state.py, set_share_tree_reader). A process without the reader and with a settled lineage would retire a shared directory, which is the same fail-closed direction as note 1.
  3. The raising=False fixture: the refusal tests keep it from going stale. If _seed_persisted_lineage were renamed, the fixture would patch a name nothing reads, and the real function would return False because the crew log is off in tests. The retire tests (test_a_settled_lineage_of_two_trees_still_retires_the_directory, test_two_slot_chats_of_different_trees_on_one_directory_are_refused and the others that assert shared_scratch is None) would then fail.

@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from c761cc0 to 59f8b9c Compare November 16, 2026 12:06
@jeeshofone

Copy link
Copy Markdown
Contributor Author

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.

  • session_allocation_parts/get_or_create.py:387: _lineage_unavailable_reason loads the persisted lineage (projection().ensure_seeded(), called through asyncio.to_thread at line 427). It returns "" once the lineage is settled. Otherwise it returns the reason: the crew log is off, the lineage could not be loaded, or the lineage is not settled.
  • Lines 427-441: if a directory has more than one key and the lineage is unavailable, the resume does not get the directory back. It returns None, so this resume allocates fresh private scratch. Nothing is retired or deleted, and the warning names the reason and the directory. A directory with exactly one key is unaffected.
  • Why not the other two options: handing the directory back could mount another tree's files, and retiring it on an unknown lineage deletes bindings (the round-4 finding). The other keys' bindings and the directory stay on disk. The resuming chat records its new scratch, so its own row now names the new directory.
  • Tests:
    • test_an_unseeded_lineage_retires_nothing_and_does_not_hand_the_directory_back: the other binding survives, the directory still exists, and the resume gets fresh scratch.
    • test_with_the_crew_log_off_two_unrelated_chats_never_share_a_directory: neither chat is handed the shared directory.
    • test_a_settled_lineage_of_two_trees_still_retires_the_directory: unchanged.
  • The PR body declares the behaviour: with the crew log off, a multi-key directory is not shared until the lineage settles.

@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from 59f8b9c to 7bd838a Compare November 16, 2026 13:22
@jeeshofone

Copy link
Copy Markdown
Contributor Author

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.

  • Mark: when a resume is refused because the lineage is unavailable, agent_scratch_trees.quarantine_tree (agent_scratch_trees.py:443) records the directory and every key that owned it in .trees-quarantine.json (line 42). The file sits beside the index in the masked root and is refused to agents like the index (security/paths.py, PROTECTED_FILENAMES).
  • Honoured: every later resume of that directory reads the mark (get_or_create.py:430), across restarts and whatever the current member count. A marked directory runs the lineage check even with one binding left. Its owners are the keys bound now plus the marked keys, so a key that moved away still counts. If the lineage is unavailable, the resume gets fresh scratch and the mark grows (line 458). If the mark file cannot be read (missing is the only "no mark"; a non-file, oversized, unparseable or non-object file, or one with a row this module did not write, raises), the resume is refused too. If the mark cannot be written, it is held in memory for this process and logged at error level, so a later resume in the same process is still refused.
  • Cleared: only by a settled lineage over all of the owners. One tree clears the mark and rejoins (line 472). Two trees retire every binding and clear the mark (line 477).
  • Pins:
    • test_a_chat_left_alone_on_a_refused_directory_does_not_rejoin_it: your sequence. A is refused and moves, then B, the only binding, is refused. Fails on 59f8b9c.
    • test_a_quarantine_mark_survives_a_fresh_process: the restart case.
    • test_a_settled_lineage_of_one_tree_clears_the_mark_and_rejoins and test_a_settled_lineage_of_two_trees_retires_a_marked_directory: the clearing cases.
  • Known gap: a mark that could not be written does not survive a restart; after one, the chat left alone could rejoin. This needs the mark write and the index write in the same root to fail differently.
  • Also pinned: test_an_unreadable_mark_file_refuses_rather_than_reading_as_no_mark and test_a_mark_that_cannot_be_written_still_refuses_the_chat_left_alone.
  • Test fix: while writing these I found that the round-5 crew-log-off test had been running against the class fixture's stub instead of the real reason function. It now uses the real function.

@github-actions

Copy link
Copy Markdown
Contributor

Security Scope Review (fork) — 🔴 BLOCK (blocking)

Which legitimate operations does 7bd838a30c5614a98cc1810cf8f4ae2d6a4851fb newly refuse? Model proposes, scripts/deny_diff.py decides — updated in place on each push. A script-confirmed regression blocks PR readiness.

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 .trees-quarantine.json to the files refused inside an overridden scratch root. The resume-path change refuses to rejoin a scratch directory that two session trees share, which is a session-allocation guard and not a deny surface. No regression has been confirmed. Both guards are named under UNADJUDICATED because nothing could classify them.

TIGHTENING: the scratch-root protected-file check in _path_in_home_dirs (src/kiro_crew/security/paths.py) now matches a set of file names instead of one. It refuses an agent file tool that reads or writes the new quarantine mark, which would let the agent clear a mark and remount another tree's directory: - os.path.basename(cand_cf) == TREE_INDEX_FILENAME or cand_cf.endswith(".tmp") / + os.path.basename(cand_cf) in PROTECTED_FILENAMES or cand_cf.endswith(".tmp"), with PROTECTED_FILENAMES = (TREE_INDEX_FILENAME, QUARANTINE_FILENAME).

ADJUDICATED: 13 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: The diff compares a casefolded basename and os.path.dirname against the scratch root's resolved forms, so it depends on the separator and how the path is spelled.

  • posix: rows cover listing $KIROCREW_SCRATCH, reading back a JSON note in it, creating a .tmp file in $TMPDIR (the scratch tree), reading a repo fixture with the same .trees-quarantine.json name outside the scratch root, and this change's own test run.
  • windows: rows repeat these operations in PowerShell ($env:KIROCREW_SCRATCH, \ separators), in cmd.exe (%KIROCREW_SCRATCH%, type), and with the .venv\Scripts\python.exe interpreter.
  • any: rows cover a git diff scoped to the touched files and kirocrew logs.
  • Not probed: no candidate covers the macOS/APFS case-insensitive spelling (for example .Trees-Quarantine.json), and no shell row can set the scratch-root override the guard depends on.

UNADJUDICATED:

  • Guard 1: the scratch-root protected-file branch of _path_in_home_dirs, src/kiro_crew/security/paths.py:147-162.
    • Call path: an agent file tool (fs_read/fs_write) → is_sensitive_path / is_sensitive_write_path → _path_in_home_dirs. It only fires when scratch_root_override_path_hint() returns a path; the default home is already covered by the scratch/.trees.json leaf and the sandbox mask, and this change adds no leaf for the quarantine file under the default home.
    • Inputs I would have submitted: an fs_read of <override-scratch-root>/<tree>/notes.json, one directory below the root and so outside the guard; an fs_read of <override-scratch-root>/.trees-quarantine.json.bak, where the basename differs and should stay allowed; an fs_write of <project>/.trees-quarantine.json, whose parent is not the scratch root; and the Windows forms of these with a drive letter and \ separators.
    • Possible over-match, argued but not confirmed: none found. The new name is matched exactly on the basename and only when the parent is the scratch root.
  • Guard 2: the rejoin decision in _recorded_tree_of_own_session_tree, src/kiro_crew/session_allocation_parts/get_or_create.py.
    • Call path: _get_or_create_impl → the persistent-memory resume branch → _recorded_tree_of_own_session_tree, at both former recorded_tree call sites.
    • Inputs it newly refuses to hand back:
      • Any multi-owner directory, or any quarantined directory, while the crew log is off ("the crew log is off") or the lineage is not settled. A lead chat and its worker chat in one session tree therefore lose their shared scratch on resume whenever the crew log is disabled.
      • A quarantine file that cannot be read.
      • Two dashboard chats with no live slot on one directory. Each is treated as its own root, so a same-tree pair whose slots are not restored yet is split.
    • The legitimate flows I would have checked are a lead plus worker resuming with the crew log off, and a resume right after startup before the slots are restored. Neither can be written as a shell command line, so neither got a verdict.

[SCOPE-REVIEWED] 7bd838a

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 16, 2026
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from 7bd838a to 2b86ef4 Compare November 16, 2026 15:28
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 16, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Nov 17, 2026
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from 8287d86 to 609da92 Compare November 17, 2026 02:19
@jeeshofone

Copy link
Copy Markdown
Contributor Author

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 .trees.json (record_parent, called from subagent_manager/run_turn.py). At read time that recorded parent is only a claim. It counts when it resolves, verified, to the same root as another current owner that was placed without a claim. Otherwise the directory is quarantined.

  • Pins: test_a_chat_keeps_its_directory_after_its_own_subagents_record_is_pruned, test_a_recorded_parent_in_another_tree_quarantines, test_a_missing_or_unresolvable_recorded_parent_quarantines.

Round 14, Opus B2: a slack: or cron: parent that had spawned a subagent quarantined its directory on every resume. On main a plain channel chat rejoins its directory, so this regression came from this PR. A subagent now takes its parent's identity only when all of these hold:

  • it is a subagent: key;
  • the gateway recorded the parent for it;
  • the parent is a current owner that cannot be placed and is not a subagent;
  • the subagent has no live run record, or its live run record names the same parent.

The parent keeps exactly the verified flag it carries on its own.

  • Pins: TestChannelAndCronParents::test_its_own_subagent_keeps_the_directory (slack and cron, live and pruned) fails on 73b825b0cd; test_the_collapse_keeps_the_parents_own_flag (parity with the chat alone); test_a_recorded_parent_that_is_not_an_owner_quarantines.

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 {P, X} to {P} and grant the directory. Fixed with the four conditions above.

  • Pins: test_a_live_record_that_disagrees_with_the_row_quarantines (foreign parent, self-cycle, a cycle through another subagent) and test_a_parents_row_on_a_channel_key_never_hides_it. All four fail on 238106c6f0.

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 test_a_nested_subagent_of_a_channel_chat_still_quarantines, and the body names it as a follow-up.

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.

@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 Nov 17, 2026
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from 609da92 to 593f61c Compare November 17, 2026 03:28
@jeeshofone

Copy link
Copy Markdown
Contributor Author

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.

  • DashboardState installs only set_share_tree_placement_reader.
  • acp.chat_runtime_sharing.share_tree_root_of returns share_tree_placement_of(key)[0]. When the reader is unwired, raises, or answers an empty root, the result is still the session's own key.
  • _tree_root_reader, set_share_tree_reader and dashboard_state._share_tree_root are deleted.
  • Every test that patched the root reader now patches the placement reader: test_chat_runtime_tree_sharing.py, test_dashboard_state_process_hooks.py, test_host_isolation_floor_restores.py, test_subagent_scratch_tree_index.py, and the floor list in conftest_floor_restores.py. The testing-conventions example and the writing-tests skill name the placement reader.

Note 6: agent_sdk.chat_runtime_sharing.share_tree_root_of had no callers. It is deleted. providers/chat_share.py still imports the ACP function. The PR body now says the check reads placements through share_tree_placement_of, the only installed tree reader.

Note 3: replace the quarantine mark with abandon_tree_all. Declined. The mark is what lets a directory that was held because one co-owner was briefly unplaceable clear and rejoin once every marked owner resolves; one example is a pruned subagent that is later placed through its recorded parent. Abandoning the directory would turn every transient ambiguity into permanent fresh scratch and lose the rejoin cases that test_a_settled_lineage_of_one_tree_clears_the_mark_and_rejoins, test_a_chat_keeps_its_directory_after_its_own_subagents_record_is_pruned and TestChannelAndCronParents::test_its_own_subagent_keeps_the_directory pin. This PR's review convergence cap is also in force.

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.

  • _placement now returns the path it walked. A subagent takes the identity of a channel or cron owner when every hop on that path is a current owner of the directory and the walk ends at that unplaceable channel or cron owner.
  • The path follows the gateway-owned run record's parent_session at each hop. The parent row is used only where a run record is pruned, so a row is no longer required when a record exists.
  • These still quarantine: a hop that does not own the directory, a cycle, too many hops, a dead end, or a live record naming a foreign parent.
  • Pins: test_a_thread_from_before_parent_rows_keeps_its_directory (live record, no row) and test_a_nested_subagent_of_a_channel_chat (live and pruned; a middle hop that does not own the directory quarantines) fail on 4d87afb228d6. The round-14 and round-15 forged-parent, disagreeing-record and cron pins still pass.
  • The earlier "nested subagent still quarantines" follow-up is removed from the PR body, because it is fixed here.

@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from 593f61c to 115fcd0 Compare November 17, 2026 05:01
@jeeshofone

Copy link
Copy Markdown
Contributor Author

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 _index_payload in agent_scratch_trees.py. When the index has no room for a held mark, the fallback refuses any rewrite that takes an owner off the held directory while another owner stays bound to it: it raises OSError, and every writer already treats that as a failed write.

In your sequence, record_tree(A, fresh) now returns False. A starts in fresh scratch through the path that already handles a failed record. A's old row stays on disk, so after a restart A and B both still own the directory, and B's ownership check quarantines it again. The held mark is written by the next index write that fits (test_a_held_mark_goes_out_with_the_next_successful_index_write).

Two writes still land at the cap: removing a held directory's last binding (test_a_removal_too_large_with_held_marks_still_lands_and_stays_readable), and any rewrite when no mark is held. So the write-without-the-marks branch is still reachable, and I kept it.

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:

  • TestAHeldMarkAtTheSizeCap::test_a_resume_rebinding_off_a_held_directory_never_lets_the_other_owner_rejoin runs your exact trigger: an index at 1,048,512 bytes, the crew log off, a shared directory, A's resume, record_tree(A, fresh), a restart, then B's ownership check. B is refused, and both bindings stay.
  • test_a_rewrite_with_no_held_marks_still_writes_at_the_cap.
  • Mutation check: with the refusal replaced by pass, the trigger test fails.
  • The round-16 pins still pass.

First Principles: that lane ended "review incomplete" on 593f61c. Its job will be re-run on this head once its other checks finish.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 17, 2026
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from 115fcd0 to 118c0b4 Compare November 17, 2026 22:35
@jeeshofone

Copy link
Copy Markdown
Contributor Author

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:

  1. session_release separates chats A and B, which share directory D. A is evicted and resumes while B stays live. A's ownership check finds two trees on D. abandon_tree_all(tree, owners) now retires every binding and writes a quarantine mark naming A and B in the same index write. If that write would not fit the size cap, nothing is written to disk, the bindings are retired in memory only, and _retire_or_mark holds the mark. The bindings never go without the mark. The branch that retired without a mark is deleted, and so is the mark-clearing branch inside abandon_tree_all.
  2. B spawns a kept dedicated child. parent_work_scratch_dir in session_allocation_parts/companions.py now returns None for a directory that carries a mark, or whose mark cannot be read, so the child starts in its own directory and is never recorded on D.
  3. Suppose a child were bound to D anyway, and the gateway restarted. The mark is on disk, so its owners A and B join the child's ownership check. _recorded_tree_of_own_session_tree refuses D, and A's files are never mounted.

The mark stays through later registrations. It clears only when every marked owner resolves to one tree (clear_quarantine), or when the sweep reclaims D, because marks for directories that are gone are pruned on write. While A is still in the mark, A's files are still in D, so B's tree alone never clears it.

Pins (TestARetiredDirectoryStaysMarked in test/test_scratch_tree_quarantine.py):

  • test_a_live_co_owners_kept_child_never_remounts_it_after_a_restart runs the chain above. B's spawn is refused, the mark survives a restart, and the child's resume is refused. It fails on 115fcd0, and it fails again when the atomic mark is reverted.
  • test_the_mark_clears_once_its_owners_are_one_tree_or_the_directory_is_reclaimed also fails on 115fcd0.
  • test_a_single_keys_retirement_leaves_no_mark.
  • Three existing retirement tests now assert the mark that is kept and, at the size cap, the bindings that stay.

Local GPT lane B1 on the round-18 fix: a respawn remounted a marked directory. When B's process crashes or respawns, acp/launch.py reuses its previous directory as the shared one and checked it only through shared_scratch_window, which ignores the mark. Fixed: right after that check, _refused_across_trees reads the mark through the same agent_scratch_trees.quarantined_keys reader every other refusal site uses. If D carries a mark, or its marks can't be read, D is dropped and the process runs only in the fresh directory it was just allocated.

  • Pins: test_a_respawn_never_remounts_a_directory_refused_across_trees[retired] (A and B on D, A's retirement marks D, B's process respawns) and [unreadable]. Both fail on cef61748a01b, and both fail again with the check reverted. test_a_root_clients_respawn_joins_its_previous_directory (an unmarked respawn) still reuses its directory, unchanged.

@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 Nov 17, 2026
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from 118c0b4 to f6d1129 Compare November 18, 2026 00:22
@jeeshofone

Copy link
Copy Markdown
Contributor Author

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. parent_work_scratch_dir called quarantined_keys synchronously. That call takes _TREE_INDEX_LOCK and reads up to 1 MiB, and it was reached from _run_inner_impl and from companion runtime startup. Fixed:

  • parent_work_scratch_dir now only reads the parent's live provider, with no I/O.
  • The new companions.admit_shared_scratch runs the check through asyncio.to_thread. run_turn awaits it on the parent's directory, and get_subagent_runtime awaits it on the companion runtime's shared_scratch.
  • A marked directory, or one whose marks can't be read, is still refused on both spawn paths. The check was not dropped in favour of the launch-time refusal.
  • There is now one blocking predicate, agent_scratch_trees.refused_across_trees. The launch-time respawn check calls the same predicate through its own off-loop hop, and its private copy is deleted.

Pins:

  • TestTheSpawnPathChecksTheMarkOffTheLoop::test_both_spawn_paths_read_the_mark_off_the_loop records the thread of every quarantined_keys call. parent_work_scratch_dir makes none, and admit_shared_scratch makes them only off the loop. It fails on 118c0b4, and fails again with the to_thread removed.
  • The round-18 chain pin now passes B's spawn directory through admit_shared_scratch and is still refused.
  • The respawn pins are unchanged.

Not taken this round:

  • First Principles' note to delete the in-memory mark store and the overflow value is not taken: it would remove the double-fault handling that rounds 17 and 18 pinned.
  • Design's note to delete share_tree_root is not taken: it is a separate cleanup, outside this fix.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 18, 2026
…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
@jeeshofone
jeeshofone force-pushed the fix/37817-recorded-tree-rescope branch from f6d1129 to 0ae2424 Compare November 19, 2026 07:29
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Rebased onto current main. The head is now 0ae2424, with no change to what this PR does.

  • Conflicts: three files conflicted: session_allocation.py, session_allocation_parts/companions.py and session_allocation_parts/get_or_create.py. Each was resolved by keeping main's new eviction lines and placing this PR's lines next to them. In companions.py, main now builds the companion's settings earlier, so the quarantine check runs on those settings before the companion starts.
  • Content: every added and removed line in all 23 files is identical to f6d1129.
  • Checks on 0ae2424: the gate ran 24 checks with none skipped (exit 0). Prove reported PROVEN. The related suites gave 8557 passed and 3 skipped.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Nov 19, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: 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 0ae242478e · 2455 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

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 get_or_create.py now go through one ownership check, _recorded_tree_of_own_session_tree. Every spawn made on a parent's behalf goes through admit_shared_scratch. The mount-time recheck in acp/launch.py covers respawns on both launch arms. The reads fail closed: an unusable index or an unparseable mark refuses the directory. A failed mark write is held in memory and is not reported as a success. The new tests drive the defect through SessionManager.get_or_create with a simulated restart, and they pin both outcomes: unrelated trees are refused, and one tree still rejoins its directory.

Optional:

  • The body has no ## Real-machine verification section, which testing-conventions asks for on a PR that changes what runs. Please add a before run on the base and an after run on this head, for example with the two-chat restart repro from the issue, plus the machine and the cleanup.
  • test/test_subagent_scratch_tree_index.py grows from 1131 to 1984 lines. That passes the 1,600-line target and leaves 16 lines before the hard cap. Moving the new resume and quarantine pins into test/test_scratch_tree_quarantine.py or a sibling file would keep both files under 1,600 lines.
  • ## Backwards compatibility could name one upgrade effect. A chat whose own subagent was spawned before this change, and whose run record has since been pruned, starts in fresh scratch once on its first resume. The old directory stays on disk until the sweep removes it.

This branch has not been deployed

No deployments
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) readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scratch isolation: unrelated session trees reuse one recorded scratch directory after a restart

2 participants