Skip to content

fix(acp): end a quiet agent-started cycle on the shared runtime's stale gate - #37932

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/37904-shared-runtime-lost-turn
Nov 16, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/37904-shared-runtime-lost-turn

Conversation

@jeeshofone

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On a claude chat served by the shared runtime, a cycle Claude Code starts on its own and that then goes quiet ends on the stale-turn gate, instead of holding the chat until the prompt timeout.

A turn the agent starts on its own (for example the reply after a run_in_background command) ends only on the closing usage_update. claude-agent-acp sends that frame only when an assistant message set the cycle's usage. A cycle that sends a thought, a plan or an answered permission request and then nothing sends no closing frame. The stale-turn gate (_stale_eligible) was armed only after text or a settled tool call, so nothing ended that turn, and the chat stayed busy until the prompt timeout.

Why it matters

While that turn holds the chat, every message the user sends queues behind it. The turn is protected from cancellation by a send, so the chat looks stuck for up to the prompt timeout (2 hours by default). This affects every claude chat once chat_runtime_sharing is on.

Not a goal

  • The per-chat AcpClient path. Open PR fix(acp): keep an agent-started turn readable through a request wait #30797 fixes the same gap there.
  • The issue's first item, a request wait in the hand-off window. It did not reproduce in either of two test harnesses on main. At the session handle, _wait_for_response's finally puts the held frames back and calls _rearm_agent_turn, and the pre-turn drain clears _agent_turn_start before the empty agent turn ends, so the hand-off fires again once the wait returns. Through the dashboard's slot claim (chat_turn/agent_started._on_agent_turn over a real session handle), following the issue's steps, the turn opened during the wait reads nothing. The wait's answer then starts a second turn that reads the reply as its own message (test_a_reply_held_by_a_request_wait_reaches_the_dashboard_as_its_own_turn pins this). The issue stays open for a live reproduction.
  • Changing when a user-prompted turn's stale gate arms.

What changed (motivation → approach → change)

Symptom: a quiet cycle the agent started holds the chat until the prompt timeout. Cause: on the shared runtime's dispatch loop, nothing armed the stale-turn gate for an agent-started turn until text streamed. Change: in _dispatch_events, an agent-started turn now arms the gate on each of its own session's activity frames, if no tool call is in flight. This matches the per-chat client's rule. The gate is armed before the frame is handled, so a tool call that the frame opens disarms it again. Frames from a native child session are left out, because a child's tool calls are re-tagged as child activity and would never disarm the gate. A child's live tool keeps the tool watchdog's longer window. The gate stays liveness-oracle checked, so a working backend is not probed.

Backwards compatibility

Compatible: only an agent-started turn's stale gate arms earlier. A user turn and every other backend keep today's rule.

Removes nothing: the change only adds an arming condition. No path, key or record is removed.

Tests

  • test_an_agent_started_turn_silent_after_a_thought_is_probed_by_the_stale_gate: an agent-started claude turn that reads one thought and then goes silent is probed with session/cancel.
  • test_a_user_turn_silent_after_a_thought_is_not_probed_by_the_stale_gate: a prompted turn with the same frames is left alone.
  • test_a_childs_thought_does_not_arm_the_agent_started_turns_stale_gate: a native child's thought does not arm the parent's gate.
  • test_a_reply_held_by_a_request_wait_reaches_the_dashboard_as_its_own_turn: the issue's request-wait steps through the dashboard's slot claim. The reply lands as its own second turn. It passes on main too, and it pins today's recovery.

The stale-gate tests drive _dispatch_events directly, with fixed watchdog windows and no sleeps. The dashboard test waits on conditions through async_wait_until, not on time.

Proof: PROVEN test/test_acp_stale_recovery.py::test_an_agent_started_turn_silent_after_a_thought_is_probed_by_the_stale_gate (head b69f426)

Gate proof: tree 00fb9141eccb; ran 24; skipped none

Local runs: test_acp_stale_recovery.py, test_session_handle_bindings.py and test_claude_shared_agent_turns.py (625 passed). Earlier, test_claude_shared_runtime.py, test_acp_watchdog_windows.py, test_session_provider_agent_turns.py and test_dashboard_agent_started_turn.py also passed on this change.

Manual verification

N/A: unit coverage is sufficient. The shared runtime for claude chats sits behind chat_runtime_sharing, which is off by default, and the dispatch loop is tested at the frame level.

Related Issues

Part of #37904

Related: #30797 and #37922 (the per-chat AcpClient path; both leave the shared runtime out of scope).

Sibling sweep

Swept: git grep -n "_stale_eligible = " -- src/kiro_crew/acp/
Sibling: src/kiro_crew/acp/client_transport.py -- tracked in #30797
Sibling: src/kiro_crew/acp/session_handle_updates.py -- not affected -- arms on text or a settled tool for every turn, which stays correct

Pattern harvest

Not generalizable: the gap comes from one backend's habit of sending no closing frame for a cycle with no assistant message.

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 10:05
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@github-actions

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of b69f42640f999f73e6dfc4e2105fa9916ddf16c7 — 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

The fix sits at the mechanism, and its defect can be checked: #37904 is linked and a new test fails on base. The one gap is how the description frames its backend scope.

Notes

  • Item 1 — undeclared: the description says "every other backend keep today's rule", but the new branch checks only req_id == AGENT_STARTED_REQUEST_ID and the session id, not the backend. _note_queued_frame and watch_agent_turns open agent-started turns for any backend on the shared runtime when agent_started_turns is on.
    Subtraction: delete that sentence from ## Backwards compatibility, or limit the condition to the claude identity set (ACP_BACKENDS_*) so the claim is true.

What this change ships

Inventory (3 items) — 2 justified

Intent: stop a quiet cycle that Claude Code started on its own from holding a shared-runtime chat until the 2h prompt timeout — FIX.

  1. On the shared runtime, an agent-started cycle that goes quiet after a thought, plan or permission is now probed by the stale gate and ended — undeclared: it arms for every backend, not only claude
  2. A native child session's frames do not arm the parent turn's stale gate — justified
  3. New test pinning today's request-wait hand-off recovery through the dashboard slot claim — justified

[FIRST-PRINCIPLES-REVIEWED] b69f426

Description read

[DESCRIPTION-READ] df5e6bc1195767186b25dad3e2b4f2aa30fd0fd51e8739f727ecf98975441990

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the agent-started turn now arms the same liveness-checked stale gate the per-chat client already uses, and the change only adds an arming condition.

Notes

  • A permission request also counts as activity in _starts_agent_turn, so it now arms the gate while the request waits for an answer. Only _parked keeps the probe from firing then. If parked time doesn't cover an unanswered request, a slow human answer could be probed as a stale turn, so a test pinning that case would close the gap.

[DESIGN-REVIEWED] b69f426

Description read

[DESCRIPTION-READ] 459d643ee8d433eabbbd64721f4a3e934118ba4e49fd4f5a0d2cd2e80dc4793a

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] b69f426

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

@github-actions

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] b69f426

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

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

@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 16, 2026
@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.

In the shared runtime's dispatch loop, an agent-started turn now arms the stale-turn gate on each of its own session's activity frames when no tool call is in flight. It arms before the frame is handled, so a tool call the frame opens disarms it again. Agent-started turns exist only for claude on the shared runtime, because only claude builds an AgentTurnQueue. User turns and other backends are therefore unchanged, and the First Principles lane's backend-scope concern does not hold. Claude native children send frames under their own sessionId and are excluded. While a tool is in flight the gate was already off, so this cannot keep it on during a tool. Human permission waits are subtracted from the idle clock as parked time. When the probe fires, the turn ends through the same stale-recovery path an agent-started turn already takes after text goes quiet: the dashboard resets the session, shows a notice and re-queues nothing. The new test fails on base, and siblings cover the user-turn and child-frame negatives. CI and all review lanes are green.

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

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 16, 2026 11:48

@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.

Approving. On this head the review checked four things. The new positive test fails on merge-base source and passes at the head. Each of the req_id and sessionId clauses reds exactly its own negative test when removed. The probe goes out only for an agent-started turn, and the watch for those turns is registered only for backends in the positive ACP_BACKENDS_AGENT_STARTED_TURNS set. A tool call that the frame opens still disarms the gate. The touched stale-recovery and shared-runtime test files also passed on eight back-to-back runs.

Done well: the gate is armed before the frame is handled. So the existing tool_call disarm stays in charge, and the opener and the new reader share one predicate.

Optional:

  • In the positive test, set a short cancel grace and assert that the turn ends in EVENT_COMPLETE with STOP_REASON_STALE_RECOVER, not only that the probe was sent.
  • In the body, say what the user sees when a cycle ends this way: a stalled notice and a session reset.
  • Change "matches the per-chat client's rule" to "matches the rule #30797 adds to the per-chat client", since that rule is not on main yet.

@KiroCrewCaptain
KiroCrewCaptain merged commit 675a53a into main Nov 16, 2026
98 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/37904-shared-runtime-lost-turn branch November 16, 2026 11:49
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 16, 2026
buluoray pushed a commit that referenced this pull request Nov 19, 2026
buluoray pushed a commit that referenced this pull request Nov 19, 2026
buluoray pushed a commit that referenced this pull request Nov 19, 2026
buluoray pushed a commit that referenced this pull request Nov 19, 2026
bolichen97 added a commit that referenced this pull request Nov 19, 2026
… main (#39387)

Backports to release/0.13.0 the fixes from #39342, squashed into one
commit and brought up to date with release/0.13.0 after the Kiro Memory
preview backport (#39360). Picks, in order; each [pick sha] is the
commit on the #39342 branch, whose body has main's cherry-picked-from line:

- fix(monitor): wake the session once when its watched PR merges or closes (#37776) [pick 84da419]
- fix(security): match deny rules against Windows program suffixes and cmd/PowerShell in-word escapes (#33569) [pick e4941b7]
- fix(mimocode): refuse a chat that would answer from Xiaomi's hosted model unsigned (#37629) [pick 1bfdce3]
- fix(acp): end a quiet agent-started cycle on the shared runtime's stale gate (#37932) [pick fa870a2]
- fix(conductor): re-read goal-conductor after a compaction (#37917) [pick ccdd67c]
- fix(security): refuse a command nested past 32 substitutions before the floors walk it (#37875) [pick 2f9bd67]
- fix(mates): carry a moved Bot's shell toolsSettings entry as execute_bash instead of holding it (#37973) [pick 16022f4]
- fix: hold an app to its own sessions, jobs and runs (#37804) [pick 3dff0c0]
- fix(acp): keep a KAS chat's stored record when its resume fails after the load (#37955) [pick 6ceb7b5]
- fix(gateway): ignore a repeat SIGTERM during graceful shutdown (#38031) [pick b48287d]
- fix(security): keep a quote in a $( ) from hiding a later ssh (#37558) [pick b9fed61]
- fix(agent): rebuild takes a server's disabledTools from the kiro global (#38147) [pick c50bbcc]
- fix(mcp_gateway): keep the backend when a stub leaves an open listen (#38121) [pick 3e9c7f9]
- fix: refresh plan and model list after a kiro-cli sign-in to another account (#38053) [pick 5ad3d36]
- fix(slack): keep a picture sent in a linked thread for the dashboard turn (#38076) [pick 7f8903e]
- fix: keep a resolved tool policy when the gateway is too slow to answer (#36669) [pick 9be5691]
- fix: open owner-only files and prune overlay folders without following links (#36994) [pick 6a1acc9]
- fix: refuse the local token mint to app backends (#38113) [pick d166dab]
- fix(subagent): hold a spawn's first prompt for its MCP servers (#38127) [pick e3e0298]
- fix(security): refuse a headless git --output write with no approver (#36326) [pick 1abee40]
- fix(restore): require an explicit mode, never default to replace (#38094) [pick ca86c06]
- fix: make the deny gate's shell walk linear in command length (#36437) [pick 22c100b]
- fix(chat): let a cancelled background start finish its session teardown (#36664) [pick b1dd34f]
- fix(acp): refuse a start when two differing specs declare the agent's name (#38411) [pick 80ccfff]
- fix: probe a silent turn while its co-tenant keeps the process busy (#38662) [pick 6354490]
- fix(kas): let a reopened chat switch to models its load select omits (#38376) [pick 1640822]
- fix(cloud): install a patched node 22 on run on aws instances (#38732) [pick 059cb90]
- fix: write member record files without following links (#37303) [pick aac9642]
- fix: fail a kas start fast once the host has turned its mcp off (#38677) [pick e147238]
- fix(decisions): fall back to HTTP/1.1 when h2 is missing (#38759) [pick fc16482]
- fix(mcp_gateway): free a spawn permit when its backend exits before initialize (#38793) [pick a084ba2]
- fix(kas): start an app chat whose tool policy hides every kirocrew-cron tool (#38761) [pick ccea5a9]
- fix(acp): give the tool-stall watchdog a margin over native waits (#34117) [pick b5d9e89]
- fix(mcp): bind the working-folder answer to its launch; observe launch changes behind name grants (#38983) [pick a1069be]
- fix(mcp): hide the gateway secret files from the npm install and third-party probe spawns (#39000) [pick 14d8571]
- fix(sandbox): fold env name case on Windows in the agent env scrub (#33997) [pick 9bdce76]
- fix(apps): let app turns follow the Auto approval mode (#38830) [pick e8336df]
- fix: end a dashboard turn stopped while it is still being prepared (#36478) [pick 37fff93]
- fix(acp): cleanup_session deletes the record on the session's own host (#39046) [pick 31b5ec4]
- fix(acp): scan only the new part of a streamed tool result (#38852) [pick e2870db]
- fix(sandbox): make an unscoped session host the OOM victim, not the gateway (#39189) [pick 2be6dde]
- fix(security): read aws s3 downloads piped into tail, with 2>&1, or with an AWS_PROFILE prefix (#38271) [pick bf65d97]
- fix: redact four display and log paths and use a fixed 502 message for session switch refusals (#38982) [pick 55d9ec7]
- fix(sandbox): pin a credential-masking app's folder after the masks on the namespace backend (#34339) [pick afd2b14]
- fix(acp): wait for systemd scope admission as its own startup stage (#37008) [pick 3e29c86]
- fix(acp): wait for systemd scope admission on the AcpClient spawn path (#38303) [pick 85f0a25]
- fix(acp): stamp the spawn instance on the AcpClient child (#38810) [pick f36eb5a]
- fix: end the turn when the agent never confirms a stop (#38512) [pick 2665c9d]
- fix(kas): renew a refused crew sign-in instead of failing every start (#38978) [pick 2f48cac]
- fix(security): keep self-host detection when the ssh verb is a glob (#34056) [pick ab53f10]
- fix(security): judge each substitution body for ssh-to-self (#37616) [pick d5b7ac3]
- test: check the ssh floor's nesting bound below the gate's depth cap (#37964) [pick 6c9ae1d]
- fix(mate): apply held Bot limits on shared claude sessions and refuse unnarrowed KAS children (#39212) [pick 721bbbe]
- test(integration): wait out and reset the hidden-chat refresh between boots (#37933) [pick e77586d]
- fix(browser): fall back to Kiro's Chromium under Automatic when Chrome's remote debugging is off (#39265) [pick 31912eb]

Left out of #39342's set (not needed for 0.13.0): the provider_labels
refactor, #34045, #36668, #39120 and #37627.

Merge with release/0.13.0: kept both imports in runtime_session_load,
runtime_spawn_launch and session_provider; session_allocation lists the
memory_policy owner; the keep-record resume path passes kas_memory_mode
as main does; dropped the ACP_BACKENDS_SESSION_EVICTION import that
moved to session_provider_new_conversation.
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