Skip to content

fix(acp): rejoin the shared chat process a restarted chat's tree lives on - #37579

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/chat-share-restart-scratch-key
Nov 15, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/chat-share-restart-scratch-key

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: a dashboard chat that restarts with ACP runtime sharing on goes back to the shared process its work already lives on, instead of starting a second one.

With the preview on, a chat that restarts keys its placement on the tree its session was recorded in (recorded_tree on the resume path in session_allocation_parts/get_or_create.py, or the process it last ran on in providers/acp_runtime_start.py). The process that founded the shared group allocated that same tree for itself and keyed no tree (shared_scratch=""). The two keys differ only in that field, so the restarted chat founds a second process mounting the same tree.

The common way to hit it: a chat's first message arrives while its pre-warm (eager spawn) is still in its handshake. The message takes the start over, the pre-warm is dropped, and the chat restarts with a resume id and the recorded tree. A pod run with three chats on one project showed two processes where one was expected; the placement log reads spawned for the restarted chat right after left to first turn (refused) for its pre-warm.

KAS is hit on main. KAS is the only member of ACP_BACKENDS_CHAT_RUNTIME_SHARING on main, and the restart path is backend-agnostic, so KAS dashboard chats with the preview on lose sharing this way today. The codex and claude chat routes in review (#37472, #37540) and the goose one (#37567) reuse the same placement and would inherit it. #37466 (per-tree KAS sharing) keeps shared_scratch in the key, so the same rule should carry over when it rebases; not checked further here.

Why it matters

Each extra process is the memory and start-up cost the preview exists to remove. A user who opens a chat and types at once gets no sharing for that chat, and the operator sees spawned with no refusal line to explain it.

Not a goal

  • No change when the preview is off: no chat is placed through ChatSharePlacement.
  • A restart whose tree no live process exposes still keys that tree and founds a process that mounts it, as before, so the session's staged work survives the restart.
  • No change to the eager-spawn race itself: the pre-warm is still dropped when a message overtakes it.

What changed (motivation -> approach -> change)

A restarted chat keyed a path its group's founder never keyed -> let the restart join only the live process that exposes its tree and matches every other field of its key -> one registry join that never spawns, tried before the normal acquisition.

  • RuntimeOwnership.join_on_tree(key, tree, session_key, cap) (runtime_ownership.py): a lease on a live runtime whose key equals key AND whose work_scratch_dir is tree, with the same room and same-session rule as acquire. It never spawns; on no match it returns None.
  • ChatSharePlacement._join_own_tree and place (providers/chat_share.py): a chat carrying a tree first tries join_on_tree with its key read as the founder's (shared_scratch=""). Every other field is still compared, so a chat on another model, effort, agent, account or folder does not join. When no process on its tree can take it (none alive, or full), the normal acquisition runs on the key that still names the tree, so the restart founds a process that mounts it and never lands on a same-key process on another tree. The confirm-and-retry loop is unchanged.

Backwards compatibility

Compatible: only placements with the preview on change, and only a restart whose tree a live shared process with an otherwise equal key exposes and has room for; such a chat now joins that process instead of founding a second one on the same tree.

Tests

  • test/test_chat_runtime_sharing_cleanup.py::TestChatSharePlacement::test_a_chat_restarted_onto_its_shared_tree_rejoins_that_process: chat A founds a process; chat B's pre-warm joins it and is held mid-handshake on an asyncio.Event gate (waited on with kiro_crew.testing.wait bounds, so a pre-warm that fails early reports instead of hanging); the first message drops it (the task is cancelled); B restarts carrying A's process's tree and must join that process. No sleeps.
  • test/test_chat_runtime_sharing_cleanup.py::TestChatSharePlacement::test_a_restart_whose_tree_no_live_process_exposes_keys_that_tree: with no live process on the tree, the restart founds its own process and a fresh chat does not land on it.
  • test/test_chat_runtime_sharing_cleanup.py::TestChatSharePlacement::test_a_restart_never_joins_a_process_that_does_not_expose_its_tree: cap 2, the process on the chat's tree is full and a same-key process on another tree has room; the restart founds its own process instead of joining the other tree.
  • Run locally: test/test_chat_runtime_sharing.py, test/test_chat_runtime_sharing_cleanup.py and test/test_runtime_ownership.py pass; flake8, black and isort are clean on the changed files.

Proof: PROVEN test/test_chat_runtime_sharing_cleanup.py::TestChatSharePlacement::test_a_chat_restarted_onto_its_shared_tree_rejoins_that_process (head f4aedcd)

Manual verification

Pod run with three goose dashboard chats on one project and the preview on (the #37567 stack, where this was found): without this change, the chat whose first message overtook its pre-warm founded a second process (two chat processes for three chats). The rerun with this change follows on #37567.

Screenshots / video

None: no user-visible surface changes.

Pattern harvest

Not generalizable: one key field that two start paths filled differently (a founder allocates its own tree and keys none; a restart keys the recorded tree). The restart now joins by tree identity (the process that exposes the tree) rather than by an equal spelling of the path.

Related Issues

Part of #5033

Based on main. Found while measuring #37567.

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

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@chenmingwei23
chenmingwei23 marked this pull request as ready for review November 15, 2026 10:02
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 15, 2026
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of f4aedcde73eba3aecb2116948efda6260b40b5e1 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the restart joins only a live process that exposes its tree and matches every other key field, and otherwise falls back to the unchanged acquire path.

Notes

[DESIGN-REVIEWED] f4aedcd

Description read

[DESCRIPTION-READ] c5005fd3997c8f1f2861ea4a78fccd60a7f7791b7d50252a6a5c33a14be30bae

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 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of f4aedcde73eba3aecb2116948efda6260b40b5e1 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks: the fix acts on the actual cause — the founder's key leaves the tree empty while a restart's key names it — and is gated on tree identity, so it reaches only a process already mounting that tree.

What this change ships

Inventory (3 items) — 3 justified

Intent: when a dashboard chat restarts with ACP runtime sharing on, it should go back to the shared process its work already lives on, not start a second one. This is a FIX.

  1. With the preview on, a restarted chat joins the live shared process that exposes its recorded tree and matches every other key field. — justified
  2. New registry entry point RuntimeOwnership.join_on_tree: it gives a lease by key plus tree and never spawns. — justified
  3. When no live process on its tree has room, a restart still founds its own process on that tree and never lands on a same-key process on another tree. — justified

[FIRST-PRINCIPLES-REVIEWED] f4aedcd

Description read

[DESCRIPTION-READ] 39e908abdcfe03e0bf27ebd65140d66dc12695e02f68a79821c2a5a3859f4b51

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 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed f4aedcde73eba3aecb2116948efda6260b40b5e1 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] f4aedcd

Verdict parsed from the review's SHA-scoped output markers for commit f4aedcde73eba3aecb2116948efda6260b40b5e1.

False positive or not applicable? A repository writer can comment:
/ai-review override fable f4aedcde73eba3aecb2116948efda6260b40b5e1 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of f4aedcde73eba3aecb2116948efda6260b40b5e1 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f4aedcd

False positive or not applicable? A repository writer can comment:
/ai-review override gpt f4aedcde73eba3aecb2116948efda6260b40b5e1 false-positive: <reason, 20 to 500 characters>

@chenmingwei23
chenmingwei23 force-pushed the fix/chat-share-restart-scratch-key branch from a897fea to 57b24a1 Compare November 15, 2026 10:09
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Disposition for a897fea (First Principles BLOCK, Opus BLOCK, PR Hygiene): all three were real. The edit had dropped the def spawn_agent_env line, so a founding shared spawn would raise AttributeError. Head 57b24a1 puts it back; _build_key ends at return key. test_chat_runtime_sharing.py and test_chat_runtime_sharing_cleanup.py pass (170), including the existing spawn_agent_env test. The body now carries a Pattern harvest section and the prove.py Proof line.

@chenmingwei23
chenmingwei23 force-pushed the fix/chat-share-restart-scratch-key branch from 57b24a1 to bc8afca Compare November 15, 2026 10:25
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Disposition for 57b24a1 (GPT BLOCK and Opus BLOCK, same finding): real. Swapping the founder's empty shared_scratch into the key let acquire() pick any same-key process with room, including one on another tree (founder full) or one whose key matched only after the swap. Head bc8afca drops the key swap. A restart now first tries RuntimeOwnership.join_on_tree, which takes only a live runtime that exposes the chat's tree AND equals its key read with shared_scratch="" (so effort, model, agent, account and folder are all still compared), and never spawns. Otherwise the normal acquire runs on the key that still names the tree, so the restart founds a process that mounts it. New test: test_a_restart_never_joins_a_process_that_does_not_expose_its_tree (cap 2, full founder plus a same-key process on another tree).

@chenmingwei23
chenmingwei23 force-pushed the fix/chat-share-restart-scratch-key branch from bc8afca to f4aedcd Compare November 15, 2026 10:37
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Disposition for GPT on bc8afca (unbounded test waits): real. Head f4aedcd waits for the pre-warm's gate with async_wait_until on (gate set or task done) and surfaces a pre-warm that failed early via task.result(); the cancelled task is awaited with await_until. Both are bounded by kiro_crew.testing.wait; test_wait_discipline_ratchet.py passes.

@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: Approve

Why: the decider estimates a 12% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes.

The fix targets the real asymmetry: a founder keys shared_scratch="" (provider has no tree when the placement is built) while a restart keys its recorded tree. join_on_tree takes a lease only on a live, open runtime whose key equals the restart's key with shared_scratch blanked and whose work_scratch_dir is the restart's tree. It applies the same admits rule (room, closed, one lease per session key) and never spawns. Any miss falls back to the unchanged acquire on the tree-bearing key, so the restart still starts a process that mounts its tree. The give-up path (unique key) skips the new step, and dead runtimes are dropped first. Only dashboard chats with the preview on are placed this way, and every session on a shared process already shares its tree, so a restart rejoining the process that mounts its own tree crosses no new trust boundary. Three tests cover the race (it would start a second process without the fix), the no-live-tree case and the full-process case. No regression found on main paths or the preview-off path.

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

@chenmingwei23
chenmingwei23 enabled auto-merge (squash) November 15, 2026 11:21
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 15, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked head f4aedcd. join_on_tree uses the same room check, liveness check and lease mint as acquire, plus one test: the runtime's work_scratch_dir must equal the chat's tree. It never spawns. When nothing matches, placement falls back to the unchanged acquire, using the key that still names the tree. Only dashboard chats that are persistent and not members can reach this path, and it sits behind the chat_runtime_sharing preview. Reverting the place hunk fails test_a_chat_restarted_onto_its_shared_tree_rejoins_that_process. Removing the room check or the tree comparison fails the cap 2 negative test. The new tests wait on an Event with bounded timeouts and never sleep.

Done well: the fix stays narrow and fails safe, so a restarted chat can never land on a process that runs on another tree.

Optional:

  • Add a short paragraph on the join_on_tree pre-step to the Leases section of docs/system-specs/modules/runtime-ownership.md. Today that section describes placement as key only.
  • Removing entry.key == key from join_on_tree leaves every test green. One test with a live process on the same tree under a different configured_model or era would pin the claim that a chat on another model or account does not join.
  • A founder keyed on a tree it later dropped is still missed by a restart that carries the founder's live tree. This already happens on main, so it can go to #37466 or a follow-up.

@chenmingwei23
chenmingwei23 merged commit 6a3deeb into main Nov 15, 2026
101 of 106 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/chat-share-restart-scratch-key branch November 15, 2026 12:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants