Skip to content

perf(acp): end the post-start drain at once on the claude harness - #37154

Merged
bolichen97 merged 1 commit into
mainfrom
perf/claude-start-no-idle-drain
Nov 15, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
perf/claude-start-no-idle-drain

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A new chat on the Claude Code harness sends its first prompt as soon as the session is ready, without a fixed 0.5 s wait.

Every new chat on the Claude Code harness waited 0.5 s between the adapter's session/new answer and the first session/prompt. The drain after session/new ends only after _DRAIN_IDLE_EXIT (0.5 s) with no frame. claude-agent-acp sends no MCP init frame over ACP, so the drain always idled the whole window: 500, 501 and 501 ms in 3 of 3 timed starts, with nothing read.

Why it matters

The first prompt of every Claude Code chat, a fresh conversation on a live adapter included, paid that 0.5 s for nothing. Driving the same adapter directly, the prompt goes out the moment session/new answers.

Not a goal

  • Changing what a Claude Code chat sends: its first message, its tools, or Kiro Crew's own MCP servers.
  • Changing the drain on any other harness. kiro-cli, KAS and the rest keep the live drain their servers' reports need.
  • The unattended wait for declared servers (wait_for_declared_mcp).

What changed (motivation → approach → change)

The drain exists to fold MCP init frames (server initialized, init failure, sign-in requests) before the first prompt. claude-agent-acp sends none of them over ACP. Claude Code connects the servers in its own process and waits for them inside the first prompt. A server that needs sign-in arrives as a URL elicitation, a request the turn reader answers. So on that harness there is nothing for the drain to wait for.

Piece Change
agent_sdk/backends_mcp.py New set ACP_BACKENDS_NO_MCP_INIT_FRAMES = {claude}, with the reason above. Wired into agent_sdk/backends.py, acp_backends.py and agent_sdk/backend_cards.py, and classified Crew-side in scripts/check_harness_parity.py
acp/client_start.py, acp/client_new_conversation.py A member drains with idle_exit=0.0. Frames buffered while the start's own requests were answered are still folded. A frame that arrives later stays on the pipe for the idle reader and the first turn's reader. Every other harness takes the unchanged call
docs/system-specs/modules/acp-client.md Step 5 says when the drain does not wait

Linux, packaged builds, both on adapter 0.107.0 and the same Claude Code build. Medians of 6 new chats each, base and head interleaved in blocks:

base head
session/new answered to prompt sent 762 ms 215 ms
First token, no config 6.81 s 6.34 s
First token, 64 MCP servers 24.63 s 24.92 s

The rest of the saving moves into Claude Code's own wait. It holds a prompt until the session's MCP servers have connected, and Kiro Crew's own servers take about 1.4 s to connect. With no config, prompt to model call went from 644 to 1,483 ms. With 64 servers that wait is about 18.7 s on both builds, so the change is within noise there.

Backwards compatibility

Compatible: only the Claude Code harness changes, and only how long it idles after session/new. No frame is dropped: what was buffered is folded, and what arrives later is read by the next reader.

Removes nothing: the drain still runs and folds every buffered frame; only its idle window is zero on this one harness.

Tests

test/test_acp_post_session_new_drain.py:

  • A Claude cold start folds the frame it buffered and makes no live read.
  • A Claude fresh conversation does the same.
  • A kiro-cli cold start still reads the wire.
  • A frame that arrives after the drain is still returned by the next _read_message.
  • The set holds only claude.

test/test_acp_client_model_substitution.py: its stand-in for the drain accepts the keyword the Claude start now passes.

Proof: PROVEN test/test_acp_post_session_new_drain.py::test_a_claude_start_folds_what_it_buffered_and_reads_no_more, test/test_acp_post_session_new_drain.py::test_a_claude_fresh_conversation_reads_no_more_after_its_answers (head d7193343835b)

Related suites ran green: backend cards, harness parity, new conversation, session setup, agent-started turns and MCP ability (305 passed). The flake ratchet, the harness-parity gate, semgrep, mypy (Linux), black, isort, flake8, comment history, brand and docs lint all passed.

Manual verification

The before and after rows above come from real chats against a Claude Code build, with each line between Kiro Crew and the adapter timed by a stdio tee. A smoke run of MCP tool calls on Linux, macOS and Windows is still to come and will be posted as a comment.

Related Issues

Closes #37152

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 14, 2026 08:26
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 14, 2026
@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 2861bf3abcba02ee18eef414d460e04ef6c80349 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 14, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the change only shortens the idle window on one harness, and frames that arrive after the drain still reach the turn reader, which runs the drift tripwire on them.

Notes

  • Both call sites now repeat if backend in ACP_BACKENDS_NO_MCP_INIT_FRAMES: idle_exit=0.0. A single helper on the client that picks the idle window would stop a third drain site from forgetting the set.
  • _judge_activated_model in client_start.py expects "the drain usually reads step 4's agent/switched frame". If claude-agent-acp ever sends a frame like that late, nobody judges it before the first prompt. The spec should say this drain does not cover that frame on this harness.

[DESIGN-REVIEWED] 2861bf3

Description read

[DESCRIPTION-READ] bd55e3832a63c81ba369ad2a27bb7ef05ed112a5001246107e94eda09438f673

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 2861bf3abcba02ee18eef414d460e04ef6c80349 — 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 reuses the drain's existing idle_exit parameter, the new set has two real call sites, and the defect is measured and linked (#37152).

What this change ships

Inventory (4 items) — 4 justified

Intent: a new Claude Code chat sends its first prompt as soon as session/new answers, without idling 0.5 s first. This is a FIX (perf).

  1. On the Claude harness, the first prompt of a cold start goes out without the 0.5 s idle wait — justified
  2. On the Claude harness, a fresh conversation's first prompt skips the same wait — justified
  3. New named backend set ACP_BACKENDS_NO_MCP_INIT_FRAMES = {claude}, re-exported and classified for the harness-parity check, the backend cards and the backends doc table — justified
  4. Spec step 5 in acp-client.md now says when the drain does not wait — justified

[FIRST-PRINCIPLES-REVIEWED] 2861bf3

Description read

[DESCRIPTION-READ] ee845626ee610115bf0144658c1cf73b9b20e7b7bc255c9d56190c4344d5cc28

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 2861bf3

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

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

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2861bf3

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 14, 2026 08:50
@bolichen97
bolichen97 disabled auto-merge November 14, 2026 09:07
@bolichen97
bolichen97 force-pushed the perf/claude-start-no-idle-drain branch from 034723f to 10ba2cb Compare November 14, 2026 09:08
@bolichen97

Copy link
Copy Markdown
Contributor Author

Backend Tests: test/tracing/test_tracing_otlp.py fails on main since #37005 added the kirocrew.step span (tracked in #37169, fix in #37171). Not caused by this diff; this PR rebases onto main once that fix merges.

@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 14, 2026
Every new chat on the Claude Code harness waited a fixed 0.5 s before its
first prompt. The drain after session/new ends only after _DRAIN_IDLE_EXIT
of silence, and claude-agent-acp sends no MCP init frame over ACP: Claude
Code connects the servers in its own process and waits for them in the
first prompt, and a server that needs sign-in arrives as a URL
elicitation that the turn reader answers. So the drain always idled the
whole window on a quiet pipe.

ACP_BACKENDS_NO_MCP_INIT_FRAMES names that harness. Its cold start and
its fresh-conversation start drain with idle_exit=0.0: the frames
buffered while the start's own requests were answered are still folded,
and a frame that arrives later stays on the pipe for the idle reader and
the first turn's reader. Every other harness keeps the live drain.
@bolichen97
bolichen97 force-pushed the perf/claude-start-no-idle-drain branch from 10ba2cb to 2861bf3 Compare November 14, 2026 11:08
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Nov 14, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) November 14, 2026 13:21

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

Approved. On head 2861bf3 the review ran the new drain tests together with the new_conversation and model_substitution suites: 43 passed, and the new file stayed green across repeated and reversed runs. Mutation runs confirm the change is pinned. Reverting either claude branch in client_start.py or client_new_conversation.py fails its matching test. Putting idle_exit=0.0 on the kiro branch fails the kiro guard. Against the merge-base source, 3 of the 5 new tests fail. Harness parity also holds: kiro keeps the full drain behind the positive ACP_BACKENDS_NO_MCP_INIT_FRAMES set.
Done well: the fix reuses the existing idle_exit parameter at the two claude call sites and still folds every buffered frame. The body is honest that the 64-server case does not improve.
Optional:

  • Open PR #30226 expects this claude start drain to read a late set_mode report before the first prompt. Whichever of the two PRs lands second needs to reconcile them, so a merge-order note in the body would help.
  • The new text in acp-client.md (around line 2559) and the comment in backends_mcp.py say claude offers MCP sign-in as a URL elicitation. That contradicts acp-client.md:1838 and acp/types.py:393, which say claude-agent-acp never sends elicitation/create.
  • On a resumed claude chat the same drain also runs after session/load, which the body does not mention and no test covers. The Proof line also cites head d7193343835b instead of 2861bf3, and the promised cross-OS MCP smoke run has not been posted yet.

@bolichen97
bolichen97 disabled auto-merge November 14, 2026 13:21

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve on 2861bf3. This change lets a new Claude Code chat send its first prompt as soon as the session is ready, instead of waiting a fixed half second. Only the Claude harness changes, chosen by membership in a named set, so kiro-cli and KAS keep the same drain as before. The drain still folds every frame that was buffered during the start. A frame that arrives later is not dropped: it stays on the pipe, or the idle reader puts it back in the buffer, and the first turn's reader handles it with the same handlers the drain used. Both new branches have a test that fails when the branch is reverted, and a test also fails if another harness is added to the set. Non-blocking: the two call sites repeat the same check, and one new test pins the drain's existing behaviour rather than the new branch. Decisive lines: src/kiro_crew/acp/client_transport.py:1125-1157 (buffered frames are folded before the idle check), src/kiro_crew/acp/client_transport.py:1159-1176 (idle_exit=0.0 breaks before any live read), src/kiro_crew/acp/client_start.py:1271-1278, src/kiro_crew/acp/client_new_conversation.py:111-114, src/kiro_crew/agent_sdk/backends_mcp.py:539, src/kiro_crew/acp/client_transport.py:703-735 (idle reader puts every frame back in _buffer), src/kiro_crew/agent_sdk/backends_routing.py:691-695 (claude is not in ACP_BACKEND_FORBIDDEN_MODES), src/kiro_crew/acp/client_start.py:1202 (agent/switched activation is Kiro-only)

@bolichen97
bolichen97 merged commit 8b3a273 into main Nov 15, 2026
105 of 111 checks passed
@bolichen97
bolichen97 deleted the perf/claude-start-no-idle-drain branch November 15, 2026 01:09
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 15, 2026
shubhamkurkure added a commit to shubhamkurkure/KiroCrew that referenced this pull request Nov 15, 2026
A claude session that asks for auto (KIROCREW_CC_PERMISSION_MODE=auto)
started in default. Crew writes the request as permissions.defaultMode
in the session's settings.local.json, and the Claude Agent SDK drops an
auto default mode from that tier, so the opt-in did nothing.

After session/new and a successful session/load, once the mode pin and
the startup model selection have run, _apply_claude_requested_mode
sends session/set_mode auto when the session requested auto, is in
default and lists auto as available. It goes on after the model so
that auto is asked for on the model the session runs: a switch to a
model without Auto mode support moves an auto session to acceptEdits.
Side Chat and zero-tool sessions are never moved, and any other mode
is kept. A set_mode refused with an error answer, or an adapter that
does not offer auto, logs one warning and the session keeps default.
Only a JSON-RPC error frame (an AcpError carrying its code) is a
refusal: a child that exits, a broken pipe or a shutdown while
set_mode auto is sent or awaited propagates and ends the start, as it
does during the startup model, so the caller retries or restarts it.
A set_mode auto left unanswered is moved back to default with
session/set_mode, since the adapter may still apply it after the wait
gave up, and the session is stopped if that move fails; the request is
marked withdrawn, so an auto the adapter applies after the undo is
moved back before the first prompt as well. A cancel once
set_mode auto is on the wire and before the start drain has read its
mode reports is the same unknown answer, and it skips ensure_ready's
handler, so the start ends the process (_ended_on_cancel, as for a
cancelled member confirm) and the next prompt starts a new one. The
guard is entered only on a requested-auto claude start; every other
start keeps its direct awaits (harness-parity H13). A fresh
conversation on the live adapter (AcpClient.new_conversation) does the
same after its own pin, so a requested auto survives that reset too.

On a model without Auto mode support the adapter answers set_mode auto
with {} but reports acceptEdits, where an edit runs without asking
Crew's gate. Crew's own request put the session there, so it is moved
back to default with session/set_mode before the first prompt, and the
session is stopped if that move fails, through the pin's own move
(_set_claude_pinned_mode_or_stop, shared with the pin, and also used
for the unanswered set_mode above).

A session that left a foreign settings.local.json out (the exclusion
path, which since kirodotdev#33847 keeps Crew's tools for a requested auto and
pins it to default with a chat notice) is never moved either:
_apply_claude_requested_mode returns early when
_claude_session_excludes_local() is true, so that notice stays true
and the session has no classifier approvals that the SEL audit skips.
A session whose foreign file could not be left out (a project
settings.json that sets hooks or sandbox or cannot be examined, or an
adapter below the floor) loads that file, so Crew does not govern its
permissions (_permission_surface_governed is false) and withholds its
MCP tools. It is not moved to auto either: one warning, the same chat
notice, no record, and it keeps default.

A requested auto is applied at session start only. A live model switch
Crew sends (AcpClient.set_model: the picker, /model, a warm-pool claim)
is made while the session asks: a requested-auto session in auto,
acceptEdits or bypassPermissions is moved to default first, and stopped
with no switch sent if that move fails. It then stays in default for the
rest of that session, with one warning, so no mode report can follow the
switch and a turn the agent starts on its own, which does not pass
through ensure_ready, never runs in acceptEdits after it.

A requested-auto session's mode is followed for the whole session.
_track_claude_starting_mode records the mode the pin or the response
names, and from then on _read_message hands every frame off the wire to
_note_claude_mode_report, which keeps the confirmed mode current from
current_mode_update and mode config_option_update reports. A report
naming acceptEdits or bypassPermissions, which Crew never asks for (an
answer to set_mode auto reported after the answer, or a model change
Crew did not send), marks the session, which
is moved back to default at the end of its start and in ensure_ready
before its next prompt, and stopped if that move fails. The mark is
cleared only once that move is answered, so a prompt cancelled before
then leaves it for the next prompt. Each start clears the recorded
mode first.

On the claude harness the start drain reads nothing off the wire
(kirodotdev#37154), except on the start of a session that requested auto
(session/new, session/load or a fresh conversation): its drain keeps
the idle window, so a mode report that follows an answer the start
read (to set_mode auto, to its move back after a timeout, or to the
startup model) is still read and undone before the first prompt.

The enterprise approval_modes ceiling gates the request. In auto
Claude's classifier approves a call without asking anyone, which is
what a session Trust grants, so Crew asks
approval_mode_policy.session_mode_permitted("trust") before sending
set_mode auto. While a ceiling that narrows the scope is being
installed it answers deny as a placeholder, which Crew does not commit:
it waits for the final answer off the loop (ensure_resolved, bounded),
at the start and before a prompt, and an install that outlasts the
wait keeps or moves the session to default with a warning and no
record. Denied, no set_mode auto is sent: one warning, an
SEL mode_change:claude_auto record with outcome
approval_mode_denied_by_policy, and the session keeps default. An
applied auto writes the same record with outcome enabled. The ceiling
is read again at the end of every start and in ensure_ready before
every prompt, so a requested-auto session in auto, acceptEdits or
bypassPermissions when the ceiling denies trust (one installed later,
or a resumed transcript) is moved to default first, and stopped if
that move fails; the denial is recorded even when a mode report had
marked the session for that move.
A session that needs the session options and is refused below the
settingSources floor, before its spawn or at its handshake, never
reaches the request: no set_mode, no ceiling read and no record.

The SEL row for an unasked call of a requested-auto session now names
what approved it. In a confirmed auto the row keeps decided_by
claude_classifier. In bypassPermissions, and for a file edit (ACP kind
edit, delete or move) in acceptEdits, decided_by is
claude_permission_mode; any other call in acceptEdits, which that mode
does not approve, gets claude_unattributed. So does every unasked call
of a session confirmed in an asking mode (default, plan, dontAsk, or
none): it keeps its row, as on main, but names no approver. Every row
carries permission_mode.

With KIROCREW_CC_PIN_INHERITED_MODE on, the pin moves a requested-auto
session that starts in bypassPermissions, or reports no mode, to
default. The response still names the starting mode, so
_pin_claude_starting_mode now returns the mode it set, which
_track_claude_starting_mode records, and _apply_claude_requested_mode
moves the session on to auto when availableModes offers it. Off the
exclusion path the pin keeps an auto the session requested, so neither
step undoes the other. A session
that requested nothing is unchanged: with the setting off it keeps the
mode it started in, and with it on the pin moves an approving mode to
default.
shubhamkurkure added a commit to shubhamkurkure/KiroCrew that referenced this pull request Nov 15, 2026
A claude session that asks for auto (KIROCREW_CC_PERMISSION_MODE=auto)
started in default. Crew writes the request as permissions.defaultMode
in the session's settings.local.json, and the Claude Agent SDK drops an
auto default mode from that tier, so the opt-in did nothing.

After session/new and a successful session/load, once the mode pin and
the startup model selection have run, _apply_claude_requested_mode
sends session/set_mode auto when the session requested auto, is in
default and lists auto as available. It goes on after the model so
that auto is asked for on the model the session runs: a switch to a
model without Auto mode support moves an auto session to acceptEdits.
Side Chat and zero-tool sessions are never moved, and any other mode
is kept. A set_mode refused with an error answer, or an adapter that
does not offer auto, logs one warning and the session keeps default.
Only a JSON-RPC error frame (an AcpError carrying its code) is a
refusal: a child that exits, a broken pipe or a shutdown while
set_mode auto is sent or awaited propagates and ends the start, as it
does during the startup model, so the caller retries or restarts it.
A set_mode auto left unanswered is moved back to default with
session/set_mode, since the adapter may still apply it after the wait
gave up, and the session is stopped if that move fails; the request is
marked withdrawn, so an auto the adapter applies after the undo is
moved back before the first prompt as well. A cancel once
set_mode auto is on the wire and before the start drain has read its
mode reports is the same unknown answer, and it skips ensure_ready's
handler, so the start ends the process (_ended_on_cancel, as for a
cancelled member confirm) and the next prompt starts a new one. The
guard is entered only on a requested-auto claude start; every other
start keeps its direct awaits (harness-parity H13). A fresh
conversation on the live adapter (ClaudeAcpClient.new_conversation) does the
same after its own pin, so a requested auto survives that reset too.

On a model without Auto mode support the adapter answers set_mode auto
with {} but reports acceptEdits, where an edit runs without asking
Crew's gate. Crew's own request put the session there, so it is moved
back to default with session/set_mode before the first prompt, and the
session is stopped if that move fails, through the pin's own move
(_set_claude_pinned_mode_or_stop, shared with the pin, and also used
for the unanswered set_mode above).

A session that left a foreign settings.local.json out (the exclusion
path, which since kirodotdev#33847 keeps Crew's tools for a requested auto and
pins it to default with a chat notice) is never moved either:
_apply_claude_requested_mode returns early when
_claude_session_excludes_local() is true, so that notice stays true
and the session has no classifier approvals that the SEL audit skips.
A session whose foreign file could not be left out (a project
settings.json that sets hooks or sandbox or cannot be examined, or an
adapter below the floor) loads that file, so Crew does not govern its
permissions (_permission_surface_governed is false) and withholds its
MCP tools. It is not moved to auto either: one warning, the same chat
notice, no record, and it keeps default.

A requested auto is applied at session start only. A live model switch
Crew sends (AcpClient.set_model: the picker, /model, a warm-pool claim)
is made while the session asks: a requested-auto session in auto,
acceptEdits or bypassPermissions is moved to default first, and stopped
with no switch sent if that move fails. It then stays in default for the
rest of that session, with one warning, so no mode report can follow the
switch and a turn the agent starts on its own, which does not pass
through ensure_ready, never runs in acceptEdits after it.

A requested-auto session's mode is followed for the whole session.
_track_claude_starting_mode records the mode the pin or the response
names, and from then on _read_message hands every frame off the wire to
_note_claude_mode_report, which keeps the confirmed mode current from
current_mode_update and mode config_option_update reports. A report
naming acceptEdits or bypassPermissions, which Crew never asks for (an
answer to set_mode auto reported after the answer, or a model change
Crew did not send), marks the session, which
is moved back to default at the end of its start and in ensure_ready
before its next prompt, and stopped if that move fails. The mark is
cleared only once that move is answered, so a prompt cancelled before
then leaves it for the next prompt. Each start clears the recorded
mode first.

On the claude harness the start drain reads nothing off the wire
(kirodotdev#37154), except on the start of a session that requested auto
(session/new, session/load or a fresh conversation): its drain keeps
the idle window, so a mode report that follows an answer the start
read (to set_mode auto, to its move back after a timeout, or to the
startup model) is still read and undone before the first prompt.

The enterprise approval_modes ceiling gates the request. In auto
Claude's classifier approves a call without asking anyone, which is
what a session Trust grants, so Crew asks
approval_mode_policy.session_mode_permitted("trust") before sending
set_mode auto. While a ceiling that narrows the scope is being
installed it answers deny as a placeholder, which Crew does not commit:
it waits for the final answer off the loop (ensure_resolved, bounded),
at the start and before a prompt, and an install that outlasts the
wait keeps or moves the session to default with a warning and no
record. Denied, no set_mode auto is sent: one warning, an
SEL mode_change:claude_auto record with outcome
approval_mode_denied_by_policy, and the session keeps default. An
applied auto writes the same record with outcome enabled. The ceiling
is read again at the end of every start and in ensure_ready before
every prompt, so a requested-auto session in auto, acceptEdits or
bypassPermissions when the ceiling denies trust (one installed later,
or a resumed transcript) is moved to default first, and stopped if
that move fails; the denial is recorded even when a mode report had
marked the session for that move.
A session that needs the session options and is refused below the
settingSources floor, before its spawn or at its handshake, never
reaches the request: no set_mode, no ceiling read and no record.

The SEL row for an unasked call of a requested-auto session now names
what approved it. In a confirmed auto the row keeps decided_by
claude_classifier. In bypassPermissions, and for a file edit (ACP kind
edit, delete or move) in acceptEdits, decided_by is
claude_permission_mode; any other call in acceptEdits, which that mode
does not approve, gets claude_unattributed. So does every unasked call
of a session confirmed in an asking mode (default, plan, dontAsk, or
none): it keeps its row, as on main, but names no approver. Every row
carries permission_mode.

The code is ClaudeAcpClient's: its four fields are set in
ClaudeAcpClient.__init__, its members live in a new claude owner,
acp/client_claude_mode.py (listed in _CLIENT_OWNERS after
client_claude_turn), and the pin's return value and
_set_claude_pinned_mode_or_stop, which moves through _claude_set_mode
and stops through _claude_stop_session, stay in client_claude_session.
The shared code reaches it through AcpClient hooks in the style of
_pin_starting_mode, each of which does nothing on AcpClient:
_forget_confirmed_mode, _apply_requested_mode and
_restore_asking_mode_if_due in the start, behind _pins_starting_mode;
_note_mode_report in _read_message, _leave_approving_mode_for_model_switch
in set_model and the warm ensure_ready restore, behind
_follows_requested_mode, a property that is False on AcpClient; and
_unasked_call_attribution in the unasked-call audit, whose AcpClient
body keeps the row an auto session wrote before this change. Each flag
is read before the call it gates, so a kiro or other non-claude session
makes none of these calls.

With KIROCREW_CC_PIN_INHERITED_MODE on, the pin moves a requested-auto
session that starts in bypassPermissions, or reports no mode, to
default. The response still names the starting mode, so
_pin_claude_starting_mode now returns the mode it set, which
_track_claude_starting_mode records, and _apply_claude_requested_mode
moves the session on to auto when availableModes offers it. Off the
exclusion path the pin keeps an auto the session requested, so neither
step undoes the other. A session
that requested nothing is unchanged: with the setting off it keeps the
mode it started in, and with it on the pin moves an approving mode to
default.
shubhamkurkure added a commit to shubhamkurkure/KiroCrew that referenced this pull request Nov 17, 2026
A claude session that asks for auto (KIROCREW_CC_PERMISSION_MODE=auto)
started in default. Crew writes the request as permissions.defaultMode
in the session's settings.local.json, and the Claude Agent SDK drops an
auto default mode from that tier, so the opt-in did nothing.

After session/new and a successful session/load, once the mode pin and
the startup model selection have run, _apply_claude_requested_mode
sends session/set_mode auto when the session requested auto, is in
default and lists auto as available. It goes on after the model so
that auto is asked for on the model the session runs: a switch to a
model without Auto mode support moves an auto session to acceptEdits.
Side Chat and zero-tool sessions are never moved. Any other mode is
kept with one warning; for acceptEdits or bypassPermissions, which
approve on their own, the warning says so and names
KIROCREW_CC_PIN_INHERITED_MODE=1 (which moves a session carrying Crew's
tools out of bypassPermissions first), and a mode_change:claude_auto
SEL record has outcome kept_inherited_mode. A set_mode refused with an error answer, or an adapter that
does not offer auto, logs one warning and the session keeps default.
Only a JSON-RPC error frame (an AcpError carrying its code) is a
refusal: a child that exits, a broken pipe or a shutdown while
set_mode auto is sent or awaited propagates and ends the start, as it
does during the startup model, so the caller retries or restarts it.
A set_mode auto left unanswered is moved back to default with
session/set_mode, since the adapter may still apply it after the wait
gave up, and the session is stopped if that move fails; the request is
marked withdrawn, so an auto the adapter applies after the undo is
moved back before the first prompt as well. A cancel once
set_mode auto is on the wire and before the start drain has read its
mode reports is the same unknown answer, and it skips ensure_ready's
handler, so the start ends the process (as for a cancelled member
confirm) and the next prompt starts a new one. The guard is entered
only on a requested-auto claude start. A fresh
conversation on the live adapter (ClaudeAcpClient.new_conversation) does the
same after its own pin, so a requested auto survives that reset too.

On a model without Auto mode support the adapter answers set_mode auto
with {} but reports acceptEdits, where an edit runs without asking
Crew's gate. Crew's own request put the session there, so it is moved
back to default with session/set_mode before the first prompt, and the
session is stopped if that move fails, through the pin's own move
(_set_claude_pinned_mode_or_stop, shared with the pin, and also used
for the unanswered set_mode above).

A session that left a foreign settings.local.json out (the exclusion
path, which since kirodotdev#33847 keeps Crew's tools for a requested auto and
pins it to default with a chat notice) is never moved either:
_apply_claude_requested_mode returns early when
_claude_session_excludes_local() is true, so that notice stays true
and the session has no classifier approvals that the SEL audit skips.
A session whose foreign file could not be left out (a project
settings.json that sets hooks or sandbox or cannot be examined, or an
adapter below the floor) loads that file, so Crew does not govern its
permissions (_permission_surface_governed is false) and withholds its
MCP tools. It is not moved to auto either: one warning, the same chat
notice, no record, and it keeps default.

A requested auto is applied at session start only. A live model switch
Crew sends (set_model: the picker, /model, a warm-pool claim)
is made while the session asks: a requested-auto session in auto,
acceptEdits or bypassPermissions is moved to default first, and stopped
with no switch sent if that move fails. It then stays in default for the
rest of that session, with one warning, so no mode report can follow the
switch and a turn the agent starts on its own, which does not pass
through ensure_ready, never runs in acceptEdits after it.

A requested-auto session's mode is followed for the whole session.
_track_claude_starting_mode records the mode the pin or the response
names, and from then on _read_message hands every frame off the wire to
_note_claude_mode_report, which keeps the confirmed mode current from
current_mode_update and mode config_option_update reports. Adapter-sourced
mode ids longer than harness_notices.MODE_ID_MAX are ignored in both report
shapes and in the start response, so none is retained or copied into SEL.
Reports read during startup are restored before the first prompt: one naming
acceptEdits or bypassPermissions, which Crew never asks for (an answer
to set_mode auto reported after the answer, or the startup model's
fallback), marks the session, which is moved back to default at the
end of its start, and stopped if that move fails. A start settles at
its last step (the Claude-owned start drain, or the end of a fresh
conversation; _claude_mode_settling), so the report that answers the
start's own set_mode auto is the start's. Once startup has settled, a
report of auto, acceptEdits or bypassPermissions stops the captured
process tree from the existing reader before an agent-started turn can
dispatch a tool. The reader awaits that stop through asyncio.shield:
the stop's own kill cancels the idle reader that awaits it, and the
stop goes on; no second stdout reader starts. Each start clears the
recorded mode first.

On the claude harness the start drain reads nothing off the wire
(kirodotdev#37154), except on the start of a session that requested auto
(session/new, session/load or a fresh conversation): its drain keeps
the idle window, so a mode report that follows an answer the start
read (to set_mode auto, to its move back after a timeout, or to the
startup model) is still read and undone before the first prompt.

The enterprise approval_modes ceiling gates the request. In auto
Claude's classifier approves a call without asking anyone, which is
what a session Trust grants, so Crew asks
approval_mode_policy.session_mode_permitted("trust") before sending
set_mode auto. While a ceiling that narrows the scope is being
installed it answers deny as a placeholder, which Crew does not commit:
it waits for the final answer off the loop (ensure_resolved, bounded),
at the start and before a prompt, and an install that outlasts the
wait keeps or moves the session to default with a warning and no
record. Denied, no set_mode auto is sent: one warning, an
SEL mode_change:claude_auto record with outcome
approval_mode_denied_by_policy, and the session keeps default. An
applied auto writes the same record with outcome enabled. Records
written from the client's event loop go through asyncio.to_thread, so
a first SEL use does no file I/O on that loop; the deny hook writes its
record on the thread that installs the ceiling. A ceiling
that denies trust while a requested-auto session is in auto,
acceptEdits or bypassPermissions stops that process: one Claude-owned
approval_mode_policy deny hook, over a weak registry of requested-auto
clients and their event loops, records approval_mode_denied_by_policy
on the installing thread and captures the current process. On the
client's loop it settles every unsettled observed call and builds its
interrupted_by_policy SEL row without awaiting, stops that exact
process, and only then writes the rows. Every interrupted row is
claude_unattributed with reason claude_unasked_call, while
permission_mode keeps the confirmed mode, because the following
session/request_permission may still be unread. Nothing awaits between the
capture check and the stop, so a delayed callback leaves a replacement
alone. A closed loop or an enqueue RuntimeError uses the same
settle-stop-write order synchronously on the installing thread and kills
the captured process tree, sweeping children that left its process group.
A stop that is cancelled or fails uses the tree fallback too. The hook sends no set_mode and reads no stdout. A deny
that lands while a start or prompt waits for the ceiling's final
answer is left to that stop: the restore re-reads the mark after each
wait and sends no set_mode and no second record. If the hook lands while a
prompt's ensure_ready restore is waiting for a mode answer, that prompt
fails once with the process-exit error. The next prompt starts a fresh
session, whose start reads the denying ceiling and keeps default. The
ceiling is also read again at the end of every start and in ensure_ready
before every prompt, so a resumed transcript in such a mode is moved to
default first, and stopped if that move fails; the denial is recorded
even when a mode report had marked the session for that move.
A session that needs the session options and is refused below the
settingSources floor, before its spawn or at its handshake, never
reaches the request: no set_mode, no ceiling read and no record.

The SEL row for a completed unasked call of a requested-auto session now
names what approved it. In a confirmed auto the row keeps decided_by
claude_classifier. In bypassPermissions, and for a file edit (ACP kind
edit, delete or move) in acceptEdits, decided_by is
claude_permission_mode; any other call in acceptEdits, which that mode
does not approve, gets claude_unattributed. So does every unasked call
of a session confirmed in an asking mode (default, plan, dontAsk, or
none): it keeps its row, as on main, but names no approver. Every row
carries permission_mode. If the ceiling stop lands before a terminal
update, every unsettled observed call gets outcome and tool_status
interrupted_by_policy, decided_by claude_unattributed and reason
claude_unasked_call while retaining permission_mode. Ids are settled
before the stop, so a racing terminal update cannot write a duplicate.
Ending the process cannot classify a frame still unread in the pipe: an already observed call may be
recorded as interrupted_by_policy, while a call not yet observed gets
no row.

The code is ClaudeAcpClient's: its requested-mode fields are set in
ClaudeAcpClient.__init__, its members live in a new claude owner,
acp/client_claude_mode.py (listed in _CLIENT_OWNERS after
client_claude_turn), and the pin's return value and
_set_claude_pinned_mode_or_stop, which moves through _claude_set_mode
and stops through _claude_stop_session, stay in client_claude_session.
The shared Kiro path is unchanged (harness-parity H13):
client_start.py, client_transport.py and client_model_selection.py
equal main. ClaudeAcpClient overrides seams AcpClient already has, in
acp/client_claude_mode_seams.py: _initialize_params forgets the last
session's mode before session/load or session/new; main's
_pin_starting_mode hook records the mode and keeps the response;
_drain_notifications, which the start reaches after the startup model,
applies the request, keeps the idle window, undoes a late report and
ends the session on a cancel; _read_message follows mode reports;
_push_model_config_option leaves an approving mode before a live
switch, only on a session that follows its requested mode (any other
claude session switches in the mode it is in, as on main); and
ensure_ready restores the asking mode before a prompt. Those restores
never run at the same time on one client: the cold-start drain runs
inside ensure_ready, a fresh-conversation reset runs only on an idle
pooled client, and warm ensure_ready owns stdout through the idle-reader
wrapper.
AcpClient gains only _unasked_call_attribution, whose body keeps the row
an auto session wrote before this change.

With KIROCREW_CC_PIN_INHERITED_MODE on, the pin moves a requested-auto
session that starts in bypassPermissions, or reports no mode, to
default. The response still names the starting mode, so
_pin_claude_starting_mode now returns the mode it set, which
_track_claude_starting_mode records, and _apply_claude_requested_mode
moves the session on to auto when availableModes offers it. Off the
exclusion path the pin keeps an auto the session requested, so neither
step undoes the other. A session
that requested nothing is unchanged: with the setting off it keeps the
mode it started in, and with it on the pin moves an approving mode to
default.

Fix 5 bounds adapter mode ids at MODE_ID_MAX, attributes every interrupted
row to claude_unattributed, and gives both synchronous policy-stop fallbacks
the live-loop settle-stop-write order. Focused regressions cover both report
shapes, the start response, interrupted attribution, closed loops, enqueue
failure and a terminal update after settlement.
Fix 6 identity-checks the closed-loop POSIX stop before and after child
discovery, then signals only the isolated group returned by
process_identity.isolated_group_of. If the captured start id is unknown
or no longer matches, it does not scan or signal the root and sweeps
only previously recorded children through their own guards. The Windows
path keeps its pinned tree kill when a start id exists; without one it
kills only the captured process object.

It also shares the requested-auto callable-surface predicate between
mode tracking and mode application. Side Chat and zero-tool sessions
are not watched or put in the live requested-auto registry, so a trust
deny or approving mode report cannot stop a text-only turn.

Fix 7 moves the live-loop policy stop's synchronous tree-kill fallback
off the event loop: when _claude_stop_session raises or is cancelled,
both arms await it on subprocess_executor() under asyncio.shield, as
_kill_process does, so a Windows tree drain or a macOS ps/pgrep spawn
cannot stall the gateway loop. The closed-loop path on the installing
thread still calls it inline. The synchronous trust-deny fallback test
now pins IS_WINDOWS, so its POSIX group-kill assertion holds on Windows
shards.
shubhamkurkure added a commit to shubhamkurkure/KiroCrew that referenced this pull request Nov 18, 2026
A claude session that asks for auto (KIROCREW_CC_PERMISSION_MODE=auto)
started in default. Crew writes the request as permissions.defaultMode
in the session's settings.local.json, and the Claude Agent SDK drops an
auto default mode from that tier, so the opt-in did nothing.

After session/new and a successful session/load, once the mode pin and
the startup model selection have run, _apply_claude_requested_mode
sends session/set_mode auto when the session requested auto, is in
default and lists auto as available. It goes on after the model so
that auto is asked for on the model the session runs: a switch to a
model without Auto mode support moves an auto session to acceptEdits.
Side Chat and zero-tool sessions are never moved. Any other mode is
kept with one warning; for acceptEdits or bypassPermissions, which
approve on their own, the warning says so and names
KIROCREW_CC_PIN_INHERITED_MODE=1 (which moves a session carrying Crew's
tools out of bypassPermissions first), and a mode_change:claude_auto
SEL record has outcome kept_inherited_mode. A set_mode refused with an error answer, or an adapter that
does not offer auto, logs one warning and the session keeps default.
Only a JSON-RPC error frame (an AcpError carrying its code) is a
refusal: a child that exits, a broken pipe or a shutdown while
set_mode auto is sent or awaited propagates and ends the start, as it
does during the startup model, so the caller retries or restarts it.
A set_mode auto left unanswered is moved back to default with
session/set_mode, since the adapter may still apply it after the wait
gave up, and the session is stopped if that move fails; the request is
marked withdrawn, so an auto the adapter applies after the undo is
moved back before the first prompt as well. A cancel once
set_mode auto is on the wire and before the start drain has read its
mode reports is the same unknown answer, and it skips ensure_ready's
handler, so the start ends the process (as for a cancelled member
confirm) and the next prompt starts a new one. The guard is entered
only on a requested-auto claude start. A fresh
conversation on the live adapter (ClaudeAcpClient.new_conversation) does the
same after its own pin, so a requested auto survives that reset too.

On a model without Auto mode support the adapter answers set_mode auto
with {} but reports acceptEdits, where an edit runs without asking
Crew's gate. Crew's own request put the session there, so it is moved
back to default with session/set_mode before the first prompt, and the
session is stopped if that move fails, through the pin's own move
(_set_claude_pinned_mode_or_stop, shared with the pin, and also used
for the unanswered set_mode above).

A session that left a foreign settings.local.json out (the exclusion
path, which since kirodotdev#33847 keeps Crew's tools for a requested auto and
pins it to default with a chat notice) is never moved either:
_apply_claude_requested_mode returns early when
_claude_session_excludes_local() is true, so that notice stays true
and the session has no classifier approvals that the SEL audit skips.
A session whose foreign file could not be left out (a project
settings.json that sets hooks or sandbox or cannot be examined, or an
adapter below the floor) loads that file, so Crew does not govern its
permissions (_permission_surface_governed is false) and withholds its
MCP tools. It is not moved to auto either: one warning, the same chat
notice, no record, and it keeps default.

A requested auto is applied at session start only. A live model switch
Crew sends (set_model: the picker, /model, a warm-pool claim)
is made while the session asks: a requested-auto session in auto,
acceptEdits or bypassPermissions is moved to default first, and stopped
with no switch sent if that move fails. It then stays in default for the
rest of that session, with one warning, so no mode report can follow the
switch and a turn the agent starts on its own, which does not pass
through ensure_ready, never runs in acceptEdits after it.

A requested-auto session's mode is followed for the whole session.
_track_claude_starting_mode records the mode the pin or the response
names, and from then on _read_message hands every frame off the wire to
_note_claude_mode_report, which keeps the confirmed mode current from
current_mode_update and mode config_option_update reports. Adapter-sourced
mode ids longer than harness_notices.MODE_ID_MAX are ignored in both report
shapes and in the start response, so none is retained or copied into SEL.
Reports read during startup are restored before the first prompt: one naming
acceptEdits or bypassPermissions, which Crew never asks for (an answer
to set_mode auto reported after the answer, or the startup model's
fallback), marks the session, which is moved back to default at the
end of its start, and stopped if that move fails. A start settles at
its last step (the Claude-owned start drain, or the end of a fresh
conversation; _claude_mode_settling), so the report that answers the
start's own set_mode auto is the start's. Once startup has settled, a
report of auto, acceptEdits or bypassPermissions stops the captured
process tree from the existing reader before an agent-started turn can
dispatch a tool. The reader awaits that stop through asyncio.shield:
the stop's own kill cancels the idle reader that awaits it, and the
stop goes on; no second stdout reader starts. Each start clears the
recorded mode first.

On the claude harness the start drain reads nothing off the wire
(kirodotdev#37154), except on the start of a session that requested auto
(session/new, session/load or a fresh conversation): its drain keeps
the idle window, so a mode report that follows an answer the start
read (to set_mode auto, to its move back after a timeout, or to the
startup model) is still read and undone before the first prompt.

The enterprise approval_modes ceiling gates the request. In auto
Claude's classifier approves a call without asking anyone, which is
what a session Trust grants, so Crew asks
approval_mode_policy.session_mode_permitted("trust") before sending
set_mode auto. While a ceiling that narrows the scope is being
installed it answers deny as a placeholder, which Crew does not commit:
it waits for the final answer off the loop (ensure_resolved, bounded),
at the start and before a prompt, and an install that outlasts the
wait keeps or moves the session to default with a warning and no
record. Denied, no set_mode auto is sent: one warning, an
SEL mode_change:claude_auto record with outcome
approval_mode_denied_by_policy, and the session keeps default. An
applied auto writes the same record with outcome enabled. Records
written from the client's event loop go through asyncio.to_thread, so
a first SEL use does no file I/O on that loop; the deny hook writes its
record on the thread that installs the ceiling. A ceiling
that denies trust while a requested-auto session is in auto,
acceptEdits or bypassPermissions stops that process: one Claude-owned
approval_mode_policy deny hook, over a weak registry of requested-auto
clients and their event loops, records approval_mode_denied_by_policy
on the installing thread and captures the current process. On the
client's loop it settles every unsettled observed call and builds its
interrupted_by_policy SEL row without awaiting, stops that exact
process, and only then writes the rows. Every interrupted row is
claude_unattributed with reason claude_unasked_call, while
permission_mode keeps the confirmed mode, because the following
session/request_permission may still be unread. Nothing awaits between the
capture check and the stop, so a delayed callback leaves a replacement
alone. A closed loop or an enqueue RuntimeError uses the same
settle-stop-write order synchronously on the installing thread and kills
the captured process tree, sweeping children that left its process group.
A stop that is cancelled or fails uses the tree fallback too. The hook sends no set_mode and reads no stdout. A deny
that lands while a start or prompt waits for the ceiling's final
answer is left to that stop: the restore re-reads the mark after each
wait and sends no set_mode and no second record. If the hook lands while a
prompt's ensure_ready restore is waiting for a mode answer, that prompt
fails once with the process-exit error. The next prompt starts a fresh
session, whose start reads the denying ceiling and keeps default. The
ceiling is also read again at the end of every start and in ensure_ready
before every prompt, so a resumed transcript in such a mode is moved to
default first, and stopped if that move fails; the denial is recorded
even when a mode report had marked the session for that move.
A session that needs the session options and is refused below the
settingSources floor, before its spawn or at its handshake, never
reaches the request: no set_mode, no ceiling read and no record.

The SEL row for a completed unasked call of a requested-auto session now
names what approved it. In a confirmed auto the row keeps decided_by
claude_classifier. In bypassPermissions, and for a file edit (ACP kind
edit, delete or move) in acceptEdits, decided_by is
claude_permission_mode; any other call in acceptEdits, which that mode
does not approve, gets claude_unattributed. So does every unasked call
of a session confirmed in an asking mode (default, plan, dontAsk, or
none): it keeps its row, as on main, but names no approver. Every row
carries permission_mode. If the ceiling stop lands before a terminal
update, every unsettled observed call gets outcome and tool_status
interrupted_by_policy, decided_by claude_unattributed and reason
claude_unasked_call while retaining permission_mode. Ids are settled
before the stop, so a racing terminal update cannot write a duplicate.
Ending the process cannot classify a frame still unread in the pipe: an already observed call may be
recorded as interrupted_by_policy, while a call not yet observed gets
no row.

The code is ClaudeAcpClient's: its requested-mode fields are set in
ClaudeAcpClient.__init__, its members live in a new claude owner,
acp/client_claude_mode.py (listed in _CLIENT_OWNERS after
client_claude_turn), and the pin's return value and
_set_claude_pinned_mode_or_stop, which moves through _claude_set_mode
and stops through _claude_stop_session, stay in client_claude_session.
The shared Kiro path is unchanged (harness-parity H13):
client_start.py, client_transport.py and client_model_selection.py
equal main. ClaudeAcpClient overrides seams AcpClient already has, in
acp/client_claude_mode_seams.py: _initialize_params forgets the last
session's mode before session/load or session/new; main's
_pin_starting_mode hook records the mode and keeps the response;
_drain_notifications, which the start reaches after the startup model,
applies the request, keeps the idle window, undoes a late report and
ends the session on a cancel; _read_message follows mode reports;
_push_model_config_option leaves an approving mode before a live
switch, only on a session that follows its requested mode (any other
claude session switches in the mode it is in, as on main); and
ensure_ready restores the asking mode before a prompt. Those restores
never run at the same time on one client: the cold-start drain runs
inside ensure_ready, a fresh-conversation reset runs only on an idle
pooled client, and warm ensure_ready owns stdout through the idle-reader
wrapper.
AcpClient gains only _unasked_call_attribution, whose body keeps the row
an auto session wrote before this change.

With KIROCREW_CC_PIN_INHERITED_MODE on, the pin moves a requested-auto
session that starts in bypassPermissions, or reports no mode, to
default. The response still names the starting mode, so
_pin_claude_starting_mode now returns the mode it set, which
_track_claude_starting_mode records, and _apply_claude_requested_mode
moves the session on to auto when availableModes offers it. Off the
exclusion path the pin keeps an auto the session requested, so neither
step undoes the other. A session
that requested nothing is unchanged: with the setting off it keeps the
mode it started in, and with it on the pin moves an approving mode to
default.

Fix 5 bounds adapter mode ids at MODE_ID_MAX, attributes every interrupted
row to claude_unattributed, and gives both synchronous policy-stop fallbacks
the live-loop settle-stop-write order. Focused regressions cover both report
shapes, the start response, interrupted attribution, closed loops, enqueue
failure and a terminal update after settlement.
Fix 6 identity-checks the closed-loop POSIX stop before and after child
discovery, then signals only the isolated group returned by
process_identity.isolated_group_of. If the captured start id is unknown
or no longer matches, it does not scan or signal the root and sweeps
only previously recorded children through their own guards. The Windows
path keeps its pinned tree kill when a start id exists; without one it
kills only the captured process object.

It also shares the requested-auto callable-surface predicate between
mode tracking and mode application. Side Chat and zero-tool sessions
are not watched or put in the live requested-auto registry, so a trust
deny or approving mode report cannot stop a text-only turn.

Fix 7 moves the live-loop policy stop's synchronous tree-kill fallback
off the event loop: when _claude_stop_session raises or is cancelled,
both arms await it on subprocess_executor() under asyncio.shield, as
_kill_process does, so a Windows tree drain or a macOS ps/pgrep spawn
cannot stall the gateway loop. The closed-loop path on the installing
thread still calls it inline. The synchronous trust-deny fallback test
now pins IS_WINDOWS, so its POSIX group-kill assertion holds on Windows
shards.
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.

Claude backend: every new chat waits a fixed 0.5 s after session/new

3 participants