Repository navigation
feat(acp): read turns claude starts on its own on the shared runtime - #37563
chenmingwei23 wants to merge 4 commits into
Conversation
UX Review (Opus 5.5) — ✅ PASS (a BLOCK with no Trigger and no Outcome does not block)UX-level review of UX-Verdict: PASS cannot evaluate: missing the new "Chats using Claude Code" switch in Settings. The only screenshot shows a chat transcript, not the settings row this diff adds. Evidence gaps
Notes
[UX-REVIEWED] a8500bd Description read[DESCRIPTION-READ] a2727c6a806c11695e9aec42a5f417675fda80e09bcb70dc444a533797e506c2 That sha256 names everything this verdict read: the PR description, plus the 4 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 |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns. The agent-started turn runs through the user turn's existing Notes
[DESIGN-REVIEWED] a8500bd Description read[DESCRIPTION-READ] 0b72bd2f62f00a78d694a580be87995b7a585c333916a6418241b2969266a60f 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Each item answers the dropped-turn harm the description names, and every new member has a counted consumer. The claude sharing switch stays off by default. Notes
What this change shipsInventory (8 items) — 7 justifiedIntent: a claude chat sharing one ACP process still shows the replies and permission asks Claude Code starts on its own between messages. ADDITION.
[FIRST-PRINCIPLES-REVIEWED] a8500bd Description read[DESCRIPTION-READ] ec8a10200617d72a2f9f95b65891e42498c0b888430a590ce1e34ee5af14f696 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — 🔴 changes requested (blocking)GPT 6.1 found at least one blocking issue that must be resolved before merging This comment is updated in place on each push. BLOCKING -- src/kiro_crew/acp/session_handle_dispatch.py:1071 -- Late prompt responses cannot close an agent-started turn
[BLOCK-MERGE] a8500bd Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 — UPHOLD. Harm rung: MEDIUM. The bug follows from the code as written:
The result: a turn that never ends and blocks the next prompt ( False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — 🔴 changes requested (blocking)Reviewed Blocks on one defect: on the shared runtime, a claude chat's session health counts every Agent-tool child the session has ever had as a resident native child, including finished ones. BLOCKING — src/kiro_crew/acp/session_handle_native_children.py:554 [BLOCK-MERGE] a8500bd Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
38a572e to
04dbee4
Compare
Code change approver recommendation: A person should decideWhy: the decider raised 1 possible problem and estimates a 72% chance that this change introduces a defect; a person should check it. Confirmed in code: on the shared runtime, late output from a cut prompt is handed off as an agent-started turn (_note_queued_frame ignores _abandoned_prompt_id). That turn can only end on an autonomous-origin usage_update, never on the prompt's response, so it hangs until the stale watchdog fires and blocks the next prompt. The per-chat client handles this case and has a test for it; the shared path does neither. Requesting changes: either skip the hand-off while a prompt is abandoned, or end an id -1 turn on an unclaimed response, and add a shared-runtime test. Things to check (possible problems the decider raised; at this confidence many turn out to be fine):
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 |
04dbee4 to
8cb317e
Compare
8cb317e to
5185fdd
Compare
5185fdd to
f5b590f
Compare
f5b590f to
7312a13
Compare
7312a13 to
3ecc8aa
Compare
3ecc8aa to
d1f2e40
Compare
d1f2e40 to
44ec20f
Compare
1cd0d2e to
9576ffc
Compare
claude-agent-acp sends Claude Code's background-task and API-retry messages as _claude/sdkMessage notifications. The per-chat AcpClient reads them in its transport reader; on the shared runtime they went to the session's queue, where the handle read them as nothing, so a shared claude chat lost the background-command end and API-retry notices and the Workflow agent cards. - A new harness seam, take_session_frame, lets the runtime's reader hand a session's notification to that session's harness state. ClaudeHarness reads a _claude/sdkMessage into the session's own ClaudeSharedSession._raw_sdk (raw_sdk_tasks.take), on no queue. - AcpSessionHandle reads that state as _raw_sdk; its dispatch takes the dashboard's mark (begin_draw) and draws what waits before each frame (pending_events), as the client's dispatch does. The handle lists its announced children ahead of a Workflow's agents (_native_child_roster), refuses a resume of a Workflow agent's card and counts the agents that still run. - AcpSessionProvider exposes the handle's state, so the dashboard's mark, its kept-open cards and its lost-cards callback reach it. - Ending the session forgets its tasks (ClaudeHarness.end_session), which closes the cards the dashboard kept open. Tests run two chats on one runtime through the real reader loop: chat A's messages, sent while chat B's turn reads, are drawn by A's next dashboard turn and never by B's.
9576ffc to
1c40e8c
Compare
… runtime claude-agent-acp announces an Agent-tool child on its parent's session (subagent_update, keyed on the update's sessionId) and sends the child's work under the child's own id. The shared runtime learned only codex-acp's subagent_spawned, so a shared claude chat's child frames had no route: its updates were dropped and its permission requests answered fail-closed, and the chat drew no card for it. - The runtime's reader learns a subagent_update's child as the announcing session's, so the child's frames reach that session. - AcpSessionHandle reads claude's child form with the client's own functions and row shape (session_handle_claude_children): the card roster, the delegated prompt, a background child listed again, a child's notice as card text, and a parent-session call stamped with a child's Agent call. The child's other frames keep the handle's child arm, and its text goes through its own redactor. - A child granted capabilities.cancel can be stopped alone: cancel_native_child sends session/cancel naming it on the shared connection, and the requests each child asks are kept for that Stop (native_child_requests), both reachable through the provider. Tests run two chats on one runtime through the real reader loop.
…ff by default A dashboard chat on the claude harness joins the shared ACP runtime when the ACP runtime sharing preview and its own "Chats on the Claude harness" switch are both on. Every other claude session (channels, members, background work, sage) keeps its own AcpClient process exactly as before. - claude joins ACP_BACKENDS_CHAT_RUNTIME_SHARING and the per-harness switch table (default off). ACP_BACKENDS_SHARED_RUNTIME_ONLY_FOR_CHATS marks it as served by the runtime only for a chat that got a shared placement. - The provider asks for the placement before choosing its arm, and the runtime start uses that placement; a refused placement keeps the per-chat client. - Each session's identity (session key, stub token) rides its own _meta.claudeCode.options.env instead of the founder's process env. - The chat's permission mode, side read-only and memory choices travel to ClaudeHarness.prepare_session with each session start. - The account era of a claude process is a digest of Claude Code's own credentials file, so a sign-in to another account founds a new process. - A resumed session sends its own envelope on session/load, as session/new does, and a resume cancelled after it registered closes its session. - An organization-policy model substitution on session/new is adopted and the start re-sent once, as the per-chat client does. - The spec's toolsSettings shell and write allowlists, which claude never reads, are read at session setup, carried by the envelope's ask rules and stamped on the shared session's permission requests, as the per-chat client does. - A substitution retry whose re-seed finds Crew's settings file replaced is refused instead of re-sending the array authorized under it, and a load abandoned mid-request is closed once the request settles. - A start cancelled or refused inside the starting-mode pin closes its session, and a refusal on the shared connection reads as a failed pin; the envelope's Connection asks read this session's own array.
A claude chat on the shared runtime now shows a reply Claude Code starts by itself between the chat's messages (a background command finishing, a background agent asking for a permission), as the per-chat client does, so claude chats share one process with the default settings. - The session queue of a host with per-session state (claude) is an AgentTurnQueue: each frame it takes is shown to the handle, and a frame that starts a turn while no turn or request reads calls the chat back. - stream_unsolicited reads that turn through the user turn's own loop (_run_turn with agent_started=True): nothing is sent, and the turn ends on the usage_update that closes Claude Code's own cycle. - A prompt that starts first keeps the pending turn's frames in its pre-turn drain and reads them as its own; a prompt waits while an agent-started turn is being read. - AcpSessionProvider and AcpProvider answer watch_agent_turns, agent_turn_pending and stream_unsolicited for a shared chat, and the watch follows a handle swap. - The agent_started_turns refusal in resolve_chat_share is removed.
1c40e8c to
a8500bd
Compare
Problem / Motivation
Goal: a claude chat that shares the ACP runtime still shows the replies Claude Code starts on its own, so claude chats can share with the default settings.
Claude Code can start a turn between a chat's messages: a
run_in_backgroundcommand finishes and it answers the task notification, or a background agent asks for a permission. The per-chat client sees that turn with its idle reader. A chat on the shared runtime has no such reader, so #37540 keeps a claude chat on its own process whileagent.agent_started_turnsis on, which is the default.Stack: this branch carries #37540 (and the PRs under it) below one commit of its own. Review only the top commit; it merges with #37540.
Why it matters
With the default settings, turning on "Chats on the Claude harness" shares nothing today. Without a reader on the shared session, a reply Claude Code starts by itself would be dropped unseen, and a permission it asks for would be rejected.
Not a goal
What changed (motivation -> approach -> change)
The shared runtime already routes every frame of a session into that session's queue -> the queue can tell its handle when a frame starts a turn nobody is reading -> the chat reads that turn through the user turn's own loop.
AgentTurnQueue(acp/session_handle_agent_turns.py): the session queuecreate_sessionandload_sessionbuild whenHarnessAdapter.per_session_stateis set. Each frame it takes is shown to the handle. A frame that starts a turn (client_transport._starts_agent_turn) while no turn or awaited request reads marks the turn pending and schedules the chat's callback.stream_unsolicitedruns_run_turn(..., agent_started=True): nothing is built or sent, and_dispatch_eventsends the turn on theusage_updatethat closes Claude Code's own cycle (_ends_agent_started_turn). Tool rows, permission cards and the terminal are the user turn's own._rearm_agent_turn), so a second cycle Claude Code began while a turn read is handed off as its own turn instead of waiting for the next prompt's drain.AcpSessionProvider(members inacp/session_provider_agent_turns.py) answerswatch_agent_turns,agent_turn_pendingandstream_unsolicited(under its shared-turn claim), and puts the watch on a handle that replaces its own.acp_turnsroutes the three calls to it for a shared claude chat.agent_started_turnsrefusal from feat(acp): let claude dashboard chats share one ACP process, switch off by default #37540 is removed, with its metric reason and the Claude row's condition text.Backwards compatibility
Compatible: only claude sessions on the shared runtime get the new queue, and those only exist with the off-by-default switch on.
Removes nothing: the refusal and its reason were added by #37540, which merges with this PR.
Tests
test/test_claude_shared_agent_turns.py(new): a turn the agent starts between prompts calls the chat back (scheduled, not from the reader) and is read whole with nothing written; a prompt that starts first reads the pending frames as its own; a second cycle queued behind the first is read as its own turn (fails with the re-arm disabled); a frame during a turn starts nothing; a host without per-session state keeps a plain queue. With_take_agent_turn_framesdisabled the first two fail.test/test_chat_runtime_sharing_cleanup.py: a claude chat shares whateveragent_started_turnssays.test/test_session_handle_bindings.py: the handle's inventory names the new members and owner.Proof: not provable -- other: new capability for shared claude chats, not a fix
Manual verification
Pod run with real claude-agent-acp and Claude Code, default settings (
agent.agent_started_turnson, preview and Claude switch on), two dashboard chats in one project:sleep 20 && echo <token>withrun_in_backgroundand answeredSTARTED; its turn ended at 12.9 s.meta.origin.kind == "agent": the reply Claude Code started on its own after the command finished, with no message sent.spawned, chat Bjoinedthe same runtime.That run predates #37466's session-tree key; on today's main two unrelated chats take a process each. Re-run inside one tree on #37615 (which carries this PR): a
kirocrew-conductorchat opened two worker sessions that joined its process, worker 1 ransleep 8 && echo <token>in the background, answeredSTARTED, and then posted the command's output in a turn it started itself (screenshot below).Screenshots / video
Pending: the pod recording is added here once uploaded.
Related Issues
Part of #5033
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...) -- not yet: the branch carries feat(acp): let claude dashboard chats share one ACP process, switch off by default #37540 and the PRs under it until they mergeContribution License Agreement
Contributed under the project's Apache-2.0 license.