Skip to content

fix(acp): apply a requested claude auto mode with session/set_mode - #30226

Open
shubhamkurkure wants to merge 1 commit into
kirodotdev:mainfrom
shubhamkurkure:fix/claude-apply-requested-auto
Open

shubhamkurkure wants to merge 1 commit into
kirodotdev:mainfrom
shubhamkurkure:fix/claude-apply-requested-auto

Conversation

@shubhamkurkure

@shubhamkurkure shubhamkurkure commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A Claude Code session that asks for auto mode (KIROCREW_CC_PERMISSION_MODE=auto) really runs in auto, or Kiro Crew logs that it could not.

With agent.acp_backend = claude and the auto opt-in, the session starts in default, so Claude asks before every tool call as if the setting were not there. Crew writes the request as {"permissions": {"defaultMode": "auto"}} into <work_dir>/.claude/settings.local.json, the local settings tier. The Claude Agent SDK removes an auto or bypassPermissions default mode that comes from the project or local tier (filterEscalatingDefaultMode, called by the adapter's SettingsManager) and does not fall back, so session/new reports default. Nothing warns, and the docs say every session is seeded with auto.

Why it matters

The opt-in is the only way an operator chooses Claude's own classifier for a Crew session, and today it silently does nothing on claude-agent-acp 0.97.0 and 0.100.0. An operator who turned it on still gets a permission prompt for every call and has no signal why. The SEL audit of unasked calls (_maybe_audit_unasked_tool_call) is built for auto sessions, and on main it credits Claude's classifier with calls that default allowed.

Not a goal

What changed (motivation → approach → change)

Symptom: the requested auto never applies. Root cause: Crew's only channel for it is a settings tier the SDK filters. session/set_mode works: on 0.100.0 set_mode auto answered {}, then a Bash call ran with no session/request_permission.

Change:

  • New _apply_claude_requested_mode on ClaudeAcpClient, in the new src/kiro_crew/acp/client_claude_mode.py. It sends session/set_mode auto only when the session requested auto, is not Side Chat, a zero-tool spec or one beside a foreign settings.local.json (below), is in default, and lists auto in availableModes. Any other mode is kept, with one warning; for acceptEdits or bypassPermissions it names KIROCREW_CC_PIN_INHERITED_MODE=1 and an SEL record has outcome kept_inherited_mode.
  • auto asks approval_mode_policy.session_mode_permitted("trust"); denial keeps default and audits. Side Chat and zero-tool sessions are unregistered. A POSIX stop checks the start id, then scans children and signals only the verified isolated group. An unknown or changed id skips the scan and root signal; recorded-child guards still apply. Windows without a start id kills the captured process only.
  • Foreign settings.local.json. A session that leaves it out (fix(acp): keep Crew's tools for a claude session that asks for auto beside a foreign settings file #33847, pinned to default with a chat notice) is skipped. So is one that could not leave it out: that file loads, so Crew does not govern it (_permission_surface_governed); one warning, the same notice, no record.
  • Order: the pin now returns default when it moved the session; _track_claude_starting_mode records that mode. The request follows the startup model. This holds on session/new, session/load and a fresh conversation (src/kiro_crew/acp/client_new_conversation.py). With KIROCREW_CC_PIN_INHERITED_MODE on (fix(acp): add an opt-in to move unrequested claude sessions out of auto #30308), a session the pin moves to default then gets auto if offered.
  • A JSON-RPC error answer, or auto not offered, logs one warning and keeps default; a dead child or broken pipe ends the start. No answer in time, or an answer reporting acceptEdits (a model without Auto mode support), is undone with session/set_mode default, as is an auto landing after that undo; a failed undo stops the session. A cancel before the drain reads the reports ends the process.
  • Live model switch. auto is applied at session start only: set_model first moves a requested-auto session in an approving mode to default (stopping it, unswitched, if that fails) and leaves it there.
  • Mode tracking. _read_message follows mode reports for requested-auto sessions. Adapter ids longer than MODE_ID_MAX are ignored at the start and in both report shapes. Startup reports are restored before the first prompt; after startup, a report of auto, acceptEdits, or bypassPermissions stops the captured process tree before an agent-started turn can dispatch a tool. A requested-auto start retains the drain idle window perf(acp): end the post-start drain at once on the claude harness #37154 removed, so it still reads late reports.
  • SEL attribution. Completed unasked calls name claude_classifier in auto, claude_permission_mode in bypassPermissions and for file edits in acceptEdits, otherwise claude_unattributed. Interrupted rows are always claude_unattributed because a following permission request may still be unread. Every row carries the scrubbed permission_mode.
  • Shape (harness-parity H13). client_start.py, client_transport.py and client_model_selection.py equal main: ClaudeAcpClient overrides existing seams (_initialize_params, _drain_notifications, _read_message, _push_model_config_option, ensure_ready) in src/kiro_crew/acp/client_claude_mode_seams.py. AcpClient gains only _unasked_call_attribution.
  • Docs: claude-code-provider.md, governance.md, sel.md, acp-client.md, agent-host-contract.md (under docs/system-specs/modules/), src/kiro_crew/docs/configuration.md.

Backwards compatibility

Compatible: a session that does not request auto sends nothing new; a session that requests it now runs in the mode the documented opt-in already promised. An excluded session behaves as on main. So does a session whose foreign settings.local.json could not be left out: it gets no set_mode auto, plus the same chat notice.

One new case to know about: claude-agent-acp resumes a session/load in the mode its transcript was left in. After this change, a session that ran in auto under the opt-in keeps that in its transcript. If the operator later removes the opt-in, that resumed session comes back in auto. That is the resumed-session half of #29909. Its fix, #30308, has merged and keeps today's behaviour by default at a maintainer's request: its pin moves an unrequested auto to default on session/load only when KIROCREW_CC_PIN_INHERITED_MODE is set. So by default such a resumed session stays in auto, as a session whose user ~/.claude names auto does today, and an operator who sets KIROCREW_CC_PIN_INHERITED_MODE=1 gets it moved to default before its first prompt.

A managed fleet whose approval_modes rule denies trust keeps default: with the opt-in set, Crew sends no set_mode auto, logs a warning and writes a mode_change:claude_auto SEL record with outcome approval_mode_denied_by_policy. If such a rule is installed while a requested-auto session is in auto, acceptEdits or bypassPermissions, Crew settles every observed unasked call before it stops the captured process, then writes one claude_unattributed interrupted_by_policy row per unsettled id. A callback queued for an older process does not touch its replacement. Side Chat and zero-tool sessions are not watched or registered, so a trust denial or approving report does not stop their text-only turns. A closed client loop or failed enqueue uses the same settle-stop-write order synchronously on the installing thread. On POSIX it rechecks the captured start id before and after child discovery and signals only the identity-checked isolated group; an unknown or changed id skips that scan and signal, while recorded escaped children keep their own guarded sweep. Windows keeps the pinned tree kill when a start id exists and otherwise kills only the captured process object. 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. A prompt whose pre-prompt restore is in flight fails once with the process-exit error. Its next attempt starts a fresh session, which reads the denying ceiling and keeps default. On main a requested-auto session that started in acceptEdits or bypassPermissions (a ~/.claude default, a resumed transcript) kept it under any policy. A requested-auto session whose start has settled and that then reports auto, acceptEdits or bypassPermissions Crew did not ask for (a model change Crew did not send, an auto landing after Crew withdrew it) is stopped the same way, from the reader that read the report, before an agent-started turn can dispatch a tool; the next prompt starts a fresh session. A start settles at its last step, the start drain or the end of a fresh conversation, so the report answering its own set_mode auto is the start's, and a fallback read during a start is still moved back before the first prompt. While a ceiling that narrows the scope is still being installed, the start or prompt waits for its final answer (up to approval_mode_policy's 30 s bound) instead of recording a denial.

Audit changes. On main a requested-auto session never leaves default, yet every call of it that asks nothing (one default itself allows, such as a read inside the project) gets an auto_approved / claude_classifier SEL row, which names the wrong decider. Every unasked call of a requested-auto session still gets its row, as on main, but the row now names what let it run: claude_classifier only in a confirmed auto; claude_permission_mode in bypassPermissions, and for file edits in acceptEdits; claude_unattributed for other calls in acceptEdits and for every call in default, plan, dontAsk or an unconfirmed mode, with permission_mode naming the mode. If an installed ceiling stops the process before a terminal update arrives, every unsettled observed call gets that same row shape with outcome and tool_status interrupted_by_policy, decided_by claude_unattributed, reason claude_unasked_call, and the confirmed permission_mode; the next session/request_permission may still be unread, so the row names no approver. Ids are settled and their rows built before the stop and written after it, so a racing terminal update does not duplicate one. 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. Requested-mode SEL 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 consumer that reads decided_by sees the new values. A requested-auto session that starts or resumes in another mode keeps it, as on main, but now logs one warning, and in acceptEdits or bypassPermissions writes a mode_change:claude_auto record with the new outcome kept_inherited_mode.

The change adds one session/set_mode call on the opt-in path, a second (default) only after an unanswered request or a report of acceptEdits or bypassPermissions. The installed-denial path sends none; it stops the process instead. On the claude harness #37154 ends the start drain at once; the start of a session that requested auto keeps the drain's 0.5 s idle window instead, so a mode report that follows an answer the start read is read before the first prompt. Every other claude start keeps #37154's speed-up. The requested auto is now applied after the startup model rather than before it, and a live model switch of a requested-auto session now moves it to default first and leaves it in Default mode for the rest of that session (one warning), where on main the session never left default.

Known limits, left for a follow-up: if the policy stop's kill fails and the captured process outlives its bounded wait, the deny mark is still cleared, so that session is not blocked afterwards; a ceiling install that races a session's pre-prompt check can write the approval_mode_denied_by_policy record twice; a denying ceiling that installs while a model switch is moving a requested-auto session back to default can still stop that session, because its stop reads the mode from before the switch; one that installs while set_mode auto is in flight sees default and leaves that session to the later restore check; on the installing thread the denial record is written before the stop is scheduled, so a slow first SEL write delays that stop; a session that resumes already in auto keeps it, as on main, even where Crew does not govern its permission surface; and a startup model switch that falls back to acceptEdits before it answers is recorded as kept_inherited_mode, although Crew then restores default.

Tests

  • Mid-session ceiling stop in test/test_claude_requested_mode_start.py: the registered hook stops idle requested-auto clients confirmed in auto, acceptEdits or bypassPermissions without sending set_mode, and the next start stays in default with the ceiling warning; a deny while a startup reader is active stops without starting a concurrent stdout read; a mid-turn deny settles every unsettled unasked call before the stop, writes its interrupted_by_policy row as claude_unattributed after it and does not duplicate an already-settled call (test_a_trust_deny_stops_then_records_each_unsettled_unasked_call); an SEL writer that blocks until released finds the process already stopped, and the rows keep the title and attribution the session had before the stop dropped them (test_a_trust_deny_stops_the_process_before_any_sel_write_is_awaited); a stop captured for an older process leaves its replacement alone, whether the old process has exited, is not yet reaped, or is replaced after the stop task is created (test_a_stop_scheduled_for_a_replaced_process_does_not_touch_the_replacement); a non-requesting client and a requested client confirmed in default are untouched; a synchronous fallback after a closed loop or failed enqueue settles one observed call before killing the captured tree, writes exactly one claude_unattributed interrupted_by_policy row, and ignores its later terminal update; and the weak registry does not retain clients. test_async_requested_mode_audit_runs_off_the_event_loop (the SEL write at a start runs off the loop thread); test_a_deny_that_lands_during_the_verdict_wait_owns_the_stop (a deny installed while the restore waits for the final verdict: one record, no set_mode, the process stopped); test_closed_loop_fallback_kills_the_captured_tree_and_escaped_children (the synchronous fallback kills the tree and sweeps stored and fresh children); test_idle_reader_stops_before_dispatching_a_turn_after_an_approving_report (a settled session's idle reader reads acceptEdits, then an agent-started turn frame: the process is stopped and no turn is dispatched); test_the_idle_reader_awaiting_its_stop_is_cancelled_and_the_stop_still_ends_the_process (the idle reader that awaits that stop is cancelled by the stop's own kill or by a prompt claiming stdout; neither waits on the other, and the stop finishes on the client's own kill, not the fallback); test_a_fresh_conversation_that_applies_auto_is_not_stopped_by_its_own_report (on the recorded 0.100.0 frame order, a fresh conversation reads its set_mode auto report before the {} answer and ends in auto, or in default after the acceptEdits fallback, and is not stopped).
  • test/test_claude_requested_mode_stop_safety.py: a matching POSIX start id scans children and signals only the identity-checked isolated group; a recycled or unknown id neither scans nor signals and sweeps only recorded children; Windows with no start id kills only the captured process object. Requested-auto zero-tool and Side Chat sessions stay out of the live registry and are not stopped by a trust denial or approving report. Both fix-specific revert mutations fail this file. test_a_failed_policy_stop_runs_its_tree_kill_fallback_off_the_event_loop: when the live-loop policy stop's client stop raises or is cancelled, the synchronous tree-kill fallback runs once, on a subprocess_executor thread rather than the loop thread, with the captured start id and child snapshot; a revert that runs it inline on the loop fails the matching case.
  • test/test_claude_requested_mode.py (new; the seam test file is over 1,500 lines, so it lives in its own module):
    • requested auto and reported default sends exactly one session/set_mode auto and logs at info;
    • a reported auto, plan, acceptEdits, dontAsk, bypassPermissions, no currentModeId, a malformed or missing modes block sends nothing;
    • no request, another request, a Side Chat session and a zero-tool spec send nothing;
    • auto missing from availableModes logs one warning and sends nothing;
    • a set_mode answered with a JSON-RPC error frame (an AcpError carrying a code) logs one warning, does not raise and does not stop the harness; test_a_dead_child_during_set_mode_auto_is_not_a_refusal: a process that exited, is not running, a shutdown or a broken pipe, raised on the send or on the wait, propagates as the same error with no such warning; an unanswered one is followed by set_mode default, and the harness is stopped and AcpError raised when that is refused or unanswered too;
    • the adapter's acceptEdits fallback is logged as a warning naming it, and the session is moved back to default;
    • a mode update buffered before the request, or one for another session, does not decide the outcome;
    • both establishment paths of _initialize_session pin through _pin_starting_mode, whose ClaudeAcpClient body records the pin's mode right after the pin, and the request is applied once, after the startup model;
    • a session the pin moved to default is moved on to auto whatever the response reported, a pinned session with no modes block warns and keeps default, and a pin return that is not a mode is ignored;
    • the whole handshake, with and without the opt-in, replaying a live 0.100.0 capture of session/new; the session/load case replays that same recorded answer under the loaded id, because no live session/load was captured;
    • the pin and the request together on both paths, with KIROCREW_CC_PIN_INHERITED_MODE unset and 1, with and without a request, starting in default, auto or bypassPermissions: a requested auto ends in auto, except a bypassPermissions start with the setting unset, which keeps it as on main; with no request the setting unset keeps the starting mode and 1 moves auto and bypassPermissions to default;
    • new for the cross-PR fix, test_an_excluded_requested_auto_session_keeps_the_pinned_mode, through _initialize_session on session/new and session/load, starting in default or auto: beside a foreign settings.local.json the session sends no session/set_mode auto, ends in default, keeps the fix(acp): keep Crew's tools for a claude session that asks for auto beside a foreign settings file #33847 notice, and a completed unasked call writes no auto_approved SEL row; with a Crew-owned file the same request ends in auto, has no notice and writes that row. With the early return removed, the 4 excluded cases fail ('auto' not in ['auto'] from a default start, 'auto' not in ['default', 'auto'] from an auto start) and the rest of the file passes;
    • for the SEL attribution, test_an_unasked_call_is_recorded_naming_the_mode_that_approved_it, 16 cases on session/new and session/load each, through _initialize_session and then a completed unasked call. claude_classifier / auto: an answered set_mode auto (with and without the recorded config_option_update auto), a start in auto, a bypassPermissions start the pin moves before auto is applied. claude_permission_mode naming the mode: a start in bypassPermissions with KIROCREW_CC_PIN_INHERITED_MODE unset, an edit in an acceptEdits start with it unset or 1. claude_unattributed naming acceptEdits: a read in such a start. claude_unattributed naming default: a refused or timed-out set_mode, auto not offered, the acceptEdits fallback reported as a current_mode_update or a config_option_update (moved back to default), and a pinned session whose set_mode auto is refused; naming plan: a plan start;
    • test_a_set_mode_auto_that_times_out_is_moved_back_to_default, on session/new and session/load, starting in default or pinned there from bypassPermissions: set_mode auto goes unanswered and default is sent; when default is answered the session continues, confirmed in default, and an unasked call gets a claude_unattributed row, and when it is refused or times out the process is killed and _initialize_session raises AcpError;
    • test_a_set_mode_auto_that_lands_elsewhere_is_moved_back_to_default, on session/new and session/load, with the fallback reported either way: session/set_mode auto and then default are sent; when default is answered the session continues and an unasked call gets a claude_unattributed row, and when it is refused or times out the process is killed and _initialize_session raises AcpError;
    • test_a_later_start_that_skips_the_mode_read_back_is_not_audited_as_auto: a second start on the same client whose restore fails after naming its session never reaches the read-back, and does not inherit the first session's confirmed auto: its unasked call gets a claude_unattributed row with no mode;
    • on a wire-level adapter (_WireAdapter: Crew's own _wait_for_response and _read_message read its frames off a fake stdout, and it keeps the session's mode as claude-agent-acp's SessionModeManager does), on session/new and session/load: test_the_requested_auto_goes_on_after_the_startup_model (the set_mode auto follows the model switch; a model with Auto mode support ends in auto, one without ends in default; the drain keeps its idle window); test_a_fallback_reported_after_the_set_mode_answer_is_undone_before_the_first_prompt (the acceptEdits report after the {} answer is read by the drain, which keeps its idle window, and undone, or the session is stopped when the undo is refused); test_the_real_start_drain_of_a_requested_auto_start_reads_a_late_report (Crew's real _drain_notifications on the same adapter: a fallback reported after the answer, or before it, is read and undone before the start returns). The adapter's drain stub, like the real drain, reads nothing off the wire when asked for no idle window; test_a_live_model_switch_into_accept_edits_stops_the_settled_session (a switch to a model without Auto mode support that Crew did not send, its report read during the switch or later inside a turn: the settled session's process is stopped, and no set_mode restore is sent);
    • a live switch through set_model on the same adapter, on session/new and session/load: test_a_live_model_switch_leaves_the_session_in_default (to a model with or without Auto mode support, its mode reports read before or after the answer: the switch reaches the adapter in default, no set_mode auto follows, and after the idle reader has read everything the session is in default, with a claude_unattributed row for an unasked edit and one warning over two switches); test_a_refused_move_to_default_before_a_live_switch_stops_the_session (killed, no switch sent); test_only_a_session_that_requested_auto_leaves_its_mode_before_a_live_switch (a session started in acceptEdits, bypassPermissions or auto that requested nothing switches with no set_mode and no warning; one that requested auto moves to default first); test_a_refused_model_leaves_the_session_in_default (AcpModelUnavailable raised, session in default, a claude_unattributed row); and only auto, acceptEdits and bypassPermissions are left before a switch;
    • the follower itself: a report of this session's own mode change updates the confirmed mode and marks only acceptEdits and bypassPermissions; a restated mode, another session's report or a frame with no mode changes nothing; a later report of an asking mode clears the mark; _read_message follows reports only for a session that requested auto; the move back is sent only when due; test_an_oversized_mode_report_is_ignored_without_scheduling_a_stop covers both report shapes, and test_an_oversized_starting_mode_is_not_retained covers the start response;
    • on the wire-level adapter, on session/new and session/load: test_a_child_that_dies_during_the_start_ends_it_in_either_step (the child exits or its pipe breaks during the startup model or during set_mode auto: _initialize_session raises the transport error alike in both steps); test_a_cancel_before_the_requested_auto_is_settled_ends_the_session (on a model with and without Auto mode support, a cancel right after set_mode auto is written, during its wait, or in the start drain before its late mode report is read: ensure_ready raises the cancel, the process is killed and the session dropped, and the next ensure_ready spawns a new child instead of the warm return); test_only_a_requested_auto_start_enters_the_cancel_guard (with client_claude_mode_seams._ended_on_requested_mode_cancel patched to record entries, a requested-auto start enters it once, around the request and the drain, and a claude start that asked for nothing never does).
  • test/fixtures/claude_mode_pin/requested-auto-applied.jsonl (new): the adapter's answers to initialize, session/new and session/set_mode auto, recorded by KIROCREW_ACP_RECORD_FRAMES while Crew's own AcpClient drove claude-agent-acp 0.100.0, pruned of host data (session id replaced, prompt turn dropped, config options cut to mode). It follows the claude_mode_pin/ convention; the acp_frames/ replay corpus and its host-data gate do not cover this directory.
  • test/test_acp_client_new_conversation.py: a fresh conversation, with KIROCREW_CC_PERMISSION_MODE=auto set and unset, whose new session answers with the recorded 0.100.0 modes (reporting default, or bypassPermissions with the pin returning default). With the opt-in, session/set_mode auto follows the startup model; without it none is sent. A fresh conversation after a session confirmed in auto writes the classifier row only when its own set_mode auto is answered; when it is refused, the row names no approver (claude_unattributed). A fresh session whose set_mode auto lands in acceptEdits, goes unanswered, or is reported in acceptEdits after its answer (read by the drain, which keeps its idle window for every requested-auto start), is moved back to default, and a refused move ends the process. A fresh session whose child exits or whose pipe breaks during set_mode auto raises that error, is not drained and ends the process, as a failure in its model step does. A cancel right after its set_mode auto is written, during its wait or in its drain ends the process too, on a model with and without Auto mode support.
  • test/test_claude_requested_mode_start.py (new; it reuses the _WireAdapter of test/test_claude_requested_mode.py, which is near the 1,600-line target): test_a_ceiling_that_denies_trust_keeps_the_session_in_default (on session/new, session/load and a respawn into a session the adapter resumes in auto: no set_mode auto, one policy warning, one approval_mode_denied_by_policy record, default confirmed and still watched, and an unasked call gets the claude_unattributed / default row); test_a_ceiling_that_permits_trust_applies_auto_and_records_it (one set_mode auto, one enabled record, no move before the next prompt); test_a_deny_installed_while_the_session_is_in_auto_moves_it_before_the_next_prompt (the next ensure_ready sends one set_mode default, the one after sends nothing, and a refused move stops the session); test_a_deny_moves_a_requested_auto_session_out_of_any_mode_that_approves (a resumed acceptEdits or bypassPermissions start is moved to default); test_a_start_in_auto_whose_model_switch_reports_late_is_undone_before_the_first_prompt and test_a_landing_reported_after_the_timeouts_move_back_is_undone_before_the_first_prompt (with the real drain: an acceptEdits report after the startup model's answer, or after the timeout's move back, is read and undone before the start returns); test_only_a_requested_auto_start_keeps_the_drain_idle_window (a claude start that asked for nothing still drains with idle_exit=0.0); test_a_mode_id_that_is_not_a_string_is_skipped (a list, object or number id in availableModes neither raises nor hides a string auto); test_a_requested_auto_session_refused_before_spawn_never_reaches_the_request and test_a_requested_auto_session_the_handshake_refuses_never_reaches_the_request (a requested-auto worker with narrowed built-ins on an adapter below the session-options floor, refused before its spawn or at its handshake, sends no set_mode, reads no ceiling and writes no record; the same worker at the floor gets auto). Also: test_a_session_crew_does_not_govern_is_not_switched_to_auto (a foreign settings.local.json beside a settings.json that sets hooks or sandbox, or that is a directory, on session/new, session/load and a fresh conversation: no set_mode auto, one warning per start, the exclusion path's notice, no record, default kept, and an unasked call gets the claude_unattributed / default row; with no foreign file Crew governs and applies auto); test_a_ceiling_install_in_progress_is_waited_out_before_the_request and test_a_session_in_auto_waits_out_a_ceiling_install_before_its_next_prompt (a real ceiling mid install: one that finishes during the wait gives auto or keeps it, one that outlasts it keeps or moves to default with no denial record); test_a_landing_reported_after_the_timeouts_move_back_is_undone_before_the_first_prompt now on a model with and without Auto mode support (a withdrawn auto landing late is moved back, no enabled record) and test_only_a_withdrawn_auto_is_due_when_it_is_reported; the deny-hook tests cover an idle approving session stopped with no set_mode and a fresh start kept in default; a startup reader stopped without a concurrent read; unsettled unasked calls recorded as interrupted_by_policy before the stop while an already-settled call gets no duplicate; a queued callback leaving a replacement process alone; non-requesting and confirmed-default sessions untouched; a closed-loop kill of the captured process; and weak registry ownership; test_a_marked_session_the_ceiling_denies_records_the_denial (a session marked by an acceptEdits report while the ceiling denies trust is moved once and the denial recorded). The unit-level _apply helper of test/test_claude_requested_mode.py and this PR's tests in test/test_acp_client_new_conversation.py mark the client as having written its own seed, since a session Crew does not govern now gets no auto. The _WireAdapter gained withhold_auto, which answers a set_mode auto only after the next set_mode. test_requested_mode_sequencing_stays_off_the_shared_client_paths (H13): the shared _initialize_session, ensure_ready, _read_message and set_model name none of the requested-mode steps, AcpClient carries none of them, and ClaudeAcpClient binds each seam override from client_claude_mode_seams. test_a_non_claude_unasked_call_keeps_mains_sel_row: a non-claude client's unasked-call row keeps main's metadata, with no permission_mode. test_a_requested_auto_session_already_in_auto_needs_no_write_or_warning, test_a_requested_auto_warns_for_every_inherited_mode_it_keeps (plan and dontAsk: one warning, no record; acceptEdits and bypassPermissions: one warning that Crew keeps the mode and names KIROCREW_CC_PIN_INHERITED_MODE=1, and one kept_inherited_mode record) and test_a_requested_auto_warns_when_the_current_mode_is_not_reported. test_a_mode_report_behind_raw_sdk_task_frames_is_followed: a current_mode_update or config_option_update read after two _claude/sdkMessage task frames in one _read_message is returned and followed (the move back is marked), the task frames reach the session's task state and no caller, and the turn's mode-change notice still reads the report.
  • test/test_acp_client_new_conversation.py also has test_a_fresh_session_asks_the_approval_modes_ceiling_before_auto (permitted: set_mode auto and auto confirmed; denied: none sent, default confirmed).
  • test/test_acp_client_tool_hooks.py also has test_the_reported_mode_is_scrubbed_before_it_reaches_the_row (a credential or an exfiltration URL reported as the mode reaches SEL scrubbed).
  • test/test_acp_client_tool_hooks.py: the unasked-call audit tests build a client confirmed in auto and check its row names claude_classifier and auto; a requested-auto client confirmed in bypassPermissions (any kind) or in acceptEdits (kinds edit, delete, move) writes a row naming claude_permission_mode and the mode; any other kind in acceptEdits, and any call of one confirmed in no mode, default, plan or dontAsk, writes a row naming claude_unattributed and that mode.
  • test/test_acp_claude_mode_pin_seam.py (from fix(acp): add an opt-in to move unrequested claude sessions out of auto #30308): the case of a requested auto that starts or resumes in bypassPermissions with the setting on now expects session/set_mode default and then auto. This existing assertion changes because the second call is the fix.
  • test/test_client_bindings.py: inventory rows for the members this PR adds (on ClaudeAcpClient the members bound from client_claude_mode, the seam overrides from client_claude_mode_seams and _follows_requested_mode; on AcpClient _unasked_call_attribution), and the pin's new signature digest (it now returns a mode). Main's test_only_the_facade_and_the_class_import_the_session_start becomes test_only_the_facade_class_and_late_claude_seam_import_session_start: the seam module, listed after client_start in _CLIENT_OWNERS, is a third importer of client_start.
  • On this head, this PR's test files, the files perf(acp): end the post-start drain at once on the claude harness #37154 and fix(acp): read a wrapped claude-agent-acp's version from its handshake #26459 changed or added (test/test_acp_post_session_new_drain.py, test/test_acp_session_mcp_client_seam.py, test/test_acp_refactor_facade.py, test/test_client_bindings.py, test/test_acp_client_model_substitution.py), the files fix(acp): keep Crew's tools for a claude session that asks for auto beside a foreign settings file #33847 added or changed (test/test_claude_member_auto_mode_mount.py, test/test_acp_client_tool_hooks.py, test/test_acp_session_mcp.py, test/test_acp_bindings.py, test/test_claude_member_tool_limits.py), test/test_cc_permission_mode_seed.py, test/test_acp_provider_new_conversation.py, the files feat: carry a claude crewmate worker's native-tool excludes #34475 and feat(chat): list a claude chat's own commands and skills in the / menu #34555 changed (test/test_claude_worker_tool_limits.py, test/test_crew_oauth_bridge_harnesses.py, test/test_crewmate_harness_inherit.py, test/test_mate_worker_harnesses.py, test/test_api_slash_commands.py), test/test_acp_client_session_setup.py, test/test_harness_parity.py, test/test_claude_requested_mode_start.py and the approval-mode tests (test/test_approval_modes_governance.py, test/test_approval_modes_trust_policy.py, test/test_members_roster_relay_teammate.py, test/test_remote_dispatch_work_item.py, test/integration/test_boot_smoke.py), and the files fix(acp): refuse an option-bound claude session before it spawns #37163 and perf: start kiro-cli's agent engine from a node compile cache #30671 added (test/test_claude_below_floor_before_spawn.py, test/test_acp_node_compile_cache.py, test/test_acp_node_compile_cache_engine.py), and the tests of the exclusion and declined paths (test/test_acp_client_settings_restore.py, test/test_acp_seed_provenance.py, test/test_acp_seed_provenance_sharer_teardown.py, test/test_acp_seed_provenance_sibling_sharing.py, test/test_member_dispatch_mount.py, test/test_member_panel_mount.py, test/test_seed_claim_released_on_teardown.py, test/test_settings_seed_declined_notice.py), and the other test files refactor(acp): move the claude-agent-acp session code off AcpClient into ClaudeAcpClient #37484 added or changed (test/test_claude_prepare_session.py, test/test_acp_seed_provenance_durable_grant.py, test/test_acp_client_agent_started_turns.py, test/test_acp_client_model_entitlement.py, test/test_acp_client_shutdown_eof_grace.py, test/test_acp_client_shutdown_reset.py, test/test_acp_goose_backend.py, test/test_acp_mcp_ref_guard.py, test/test_agent_sdk_backend_identity.py, test/test_backend_cards_advertised.py, test/test_core_path_redact_before_bound.py, test/test_deny_bounded_write.py, test/test_pi_saved_spec.py, test/test_post_compaction_continuation.py, test/test_provider_dispatch.py, test/test_security_posture.py), and the other test files feat: show the claude-agent-acp surfaces the dashboard drops #37512 and refactor(acp): move the goose session code off AcpClient into GooseAcpClient #37535 added or changed (test/test_acp_bindings.py, test/test_acp_mcp_startable.py, test/test_agent_sdk_capabilities.py, test/test_chat_handlers_composition_contract.py, test/test_chat_runner_composition_contract.py, test/test_chat_slot_reasoning_effort.py, test/test_claude_auto_memory_envelope.py, test/test_claude_compaction_summary.py, test/test_claude_fast_mode_toggle.py, test/test_claude_harness_notices.py, test/test_claude_native_child_stop.py, test/test_claude_native_subagent_cards.py, test/test_claude_plan_checklist.py, test/test_claude_raw_sdk_tasks.py, test/test_claude_raw_sdk_tasks_lifecycle.py, test/test_claude_read_image_rows.py, test/test_claude_subagent_card_tool_titles.py, test/test_claude_thinking_display.py, test/test_claude_zero_tools.py, test/test_codex_compaction.py, test/test_goose_tested_version_notice.py, test/test_json_object_body_guard.py, test/test_session_backend_model_list.py, test/test_side_readonly_goose.py, test/test_slot_running_readers.py, test/test_todo_pill_resync.py, test/test_transient_notice_parity.py, and test/test_acp_frame_replay.py, which replays the frames feat: show the claude-agent-acp surfaces the dashboard drops #37512 recorded), and the files feat(acp): ClaudeHarness, claude-agent-acp on the shared runtime with per-session setup (not routed) #37521, refactor(acp): move the opencode session code off AcpClient into OpencodeAcpClient #37602 and refactor(acp): move the deepseek session code off AcpClient into DeepseekAcpClient #37641 added or changed (test/test_claude_shared_runtime.py, test/test_acp_harness_contract.py, test/test_runtime_bindings.py, test/test_acp_opencode_backend.py, test/test_acp_deepseek_backend_enforcement.py, test/test_acp_mimocode_turn.py, test/test_member_mount_deepseek.py), and those feat(acp): GooseHarness, goose on the shared runtime with per-session checks (not routed) #37562 and feat(acp): route claude Agent-tool children per session on the shared runtime #37601 added or changed (test/test_goose_shared_runtime.py, test/test_claude_shared_children.py, test/test_session_handle_bindings.py), and the other approval-mode tests (test/test_approval_modes_enforcement.py, test/test_cron_approval_mode.py, test/test_dashboard_approval_modes.py, test/test_dashboard_chat_approval_mode.py, test/test_slack_code_channel_approval_mode.py), and fix(crew): keep a bot's deny rules when the upgrade moves it #35011's test/test_mate_held_rules.py, and the test files fix(acp): end a claude turn whose prompt was never sent #37922, feat: add Google Antigravity ACP harness #37974, fix(mimocode): refuse a chat that would answer from Xiaomi's hosted model unsigned #37629 and fix(metrics): split the sharing tenants bucket past 4 and count unshared turns' start #37980 added or changed (test/test_acp_antigravity_backend.py, test/test_acp_mimocode_hosted_fallback.py, test/metrics/test_chat_runtime_share.py, test/test_strands_model_switch.py and the 21 others they touched): 8,605 passed and 20 skipped with KIROCREW_CC_PIN_INHERITED_MODE unset, and the same with it set to 1. test/test_acp_*.py and test/test_claude_*.py: 10,893 passed, 17 skipped.
  • Determinism: all of test/test_claude_requested_mode_start.py and test/test_claude_requested_mode_stop_safety.py plus, in test/test_claude_requested_mode.py, test_a_requested_auto_session_reported_default_is_moved_to_auto, test_the_adapters_accept_edits_fallback_is_named_and_undone, test_both_session_establishment_paths_reach_the_claude_owned_drain_after_the_model, test_only_a_requested_auto_start_enters_the_cancel_guard and test_only_a_session_that_requested_auto_leaves_its_mode_before_a_live_switch, in test/test_acp_client_new_conversation.py, test_a_requested_auto_is_applied_to_the_fresh_session_after_its_model, test_a_fresh_session_asks_the_approval_modes_ceiling_before_auto and test_a_fresh_session_whose_fallback_is_reported_late_is_moved_back_or_ended (119 ids) passed 20 runs at -n0 and 10 runs at -n 4 --dist loadgroup --max-worker-restart=2 beside test/test_acp_post_session_new_drain.py and test/test_approval_modes_trust_policy.py (171 ids each), and one shuffled run of test/test_claude_requested_mode_start.py, test/test_claude_requested_mode.py, test/test_acp_client_new_conversation.py and test/test_acp_client_session_setup.py passed (361 ids, seed 74053). The deny-hook, settled-report and shield tests (30 ids) also passed 50 runs on their own at -n0. On the previous head (5379cd3874): test/test_claude_requested_mode.py, test/test_acp_client_tool_hooks.py::TestAcpClientUnaskedClaudeAutoAudit, test/test_acp_client_new_conversation.py and test/test_acp_client_session_setup.py passed 20 runs at -n0; those four files with test/test_acp_session_mcp_client_seam.py as a co-tenant passed 10 runs at -n 4 --dist loadgroup --max-worker-restart=2 (501 ids each); one shuffled run of the four files passed (381 ids, seed 30235). test/test_flake_pattern_ratchet.py passed.

Proof: PROVEN test/test_acp_claude_mode_pin_seam.py::TestUnrequestedModePin::test_an_opt_in_session_that_starts_or_resumes_in_bypass_is_pinned[new], test/test_acp_claude_mode_pin_seam.py::TestUnrequestedModePin::test_an_opt_in_session_that_starts_or_resumes_in_bypass_is_pinned[load], test/test_acp_client_new_conversation.py::test_a_requested_auto_is_applied_to_the_fresh_session_after_its_model[opt-in-reported-default], test/test_acp_client_new_conversation.py::test_a_requested_auto_is_applied_to_the_fresh_session_after_its_model[opt-in-pinned-to-default], test/test_acp_client_new_conversation.py::test_a_child_that_dies_during_the_fresh_sessions_set_mode_auto_ends_the_process[exited] (head ef16ab8)

Gate proof: tree d449b2817311; ran 24; skipped none

Manual verification

Kiro Crew's real AcpClient from this branch, driven by a script against live claude-agent-acp with Claude Code 2.1.318, a scratch CLAUDE_CONFIG_DIR holding only the model-access keys, scratch KIROCREW_HOME and KIRO_HOME, and one prompt that asks for a harmless echo ok > <scratch>/probe.txt through Bash:

  • 0.100.0 with KIROCREW_CC_PERMISSION_MODE=auto: session/new reported default; Crew sent session/set_mode auto (answered {}, preceded by a config_option_update with mode auto) and logged "claude session started in 'default'; applied the requested permission mode 'auto'"; the Bash call ran with no session/request_permission and the file was written.
  • 0.97.0 with the opt-in: the same result.
  • 0.100.0 without the opt-in: session/new reported default, no set_mode was sent, the Bash call sent a session/request_permission, and the script's ungated client refused it.
  • 0.100.0 with the opt-in on main (4a546774f): session/new reported default, no set_mode was sent, and the Bash call sent a session/request_permission. This is the bug.

These runs were made before this branch was rebased onto #30308, #31091 and #33847 and do not exercise KIROCREW_CC_PIN_INHERITED_MODE, a fresh conversation or the exclusion path; those cases are covered by the tests above.

Related Issues

Closes #30169

Related: #29909 (a session that asks for no mode starts in the user's own ~/.claude mode), fixed behind an opt-in by #30308, which has merged; this PR is rebased onto it. #31091 (a fresh claude conversation on the live adapter) has merged too, and this PR applies the request on its path as well. #33847 (Crew's tools for a requested-auto session beside a foreign settings file) has merged; this PR is rebased onto it and leaves its excluded sessions in the pinned mode, as its review asked.

This head is rebased onto #37154 (the claude start drain ends at once; see Backwards compatibility for the one start that keeps its idle window) and #26459 (a wrapped claude-agent-acp's version from its handshake; this PR reads no adapter version, and it skips an excluded session the same way whichever version source decided the exclusion), and #37484 (the claude session code moved from AcpClient to ClaudeAcpClient; this PR's fields and members are on that class, reached through its hooks). It is also rebased onto #37512 (claude-agent-acp surfaces: raw SDK task frames that _read_message keeps from every reader, and mode-change notice rows; mode reports still reach this PR's follower first) and #37535, #37602 and #37641 (GooseAcpClient, OpencodeAcpClient, DeepseekAcpClient, which keep every hook this PR adds as AcpClient has it), and #37521 (claude on the shared runtime, not routed yet: its per-session pin goes through the same _pin_starting_mode, but nothing there applies a requested auto, so such a session keeps default as on main). It is also rebased onto #37922 (a claude turn whose prompt was never sent is ended; the settled-mode stop runs inside the reader before the idle reader hands an agent-started turn off, and _release_unsent_turn is unchanged), #37974 (the Antigravity harness, whose class reaches none of this PR's Claude code), #37629 (MimocodeAcpClient's hosted-model refusal) and #37980 (unshared-turn metrics), whose behaviour this PR leaves as it is.

With this change the opt-in takes effect for every claude session the variable reaches, including cron and sub-agent sessions. A call the classifier approves skips Crew's gate before it runs and gets only the after-the-fact SEL row. A managed fleet refuses that through the approval_modes ceiling, the one precedence point governance names for an auto-approve mode: a policy that denies trust keeps a new session in default and stops an already-live approving process and then records its unsettled unasked calls.

Sibling sweep

Swept: git grep -n "defaultMode" -- src/kiro_crew/acp src/kiro_crew/agent_sdk
Sibling: src/kiro_crew/acp/client_claude_seed.py -- changed here

The claude seed writer is the only place Crew puts a requested permission mode into a settings tier the SDK filters; every other match is a docstring or another harness's own channel (goose's GOOSE_MODE, the deepseek gate module).

Swept: git grep -n -E "_apply_(claude_)?requested_mode\(|ACP_BACKENDS_NO_MCP_INIT_FRAMES" -- src/kiro_crew/acp
Sibling: src/kiro_crew/acp/client_start.py -- not affected -- equal to main; ClaudeAcpClient's _initialize_params, _drain_notifications and ensure_ready overrides (client_claude_mode_seams.py) carry the cold start's steps
Sibling: src/kiro_crew/acp/client_new_conversation.py -- changed here

The session/load and session/new calls and the fresh-conversation call reach the exclusion check and the mode record, which sit inside the function. They are also the two drains #37154 shortened; both keep the idle window for a session that requested auto (the _drain_notifications override on the cold start, _claude_mode_watched on the fresh conversation) and only for it.

Swept: git grep -n "_permission_surface_governed" -- src/kiro_crew
Sibling: src/kiro_crew/acp/client_seed_ownership.py -- not affected -- settings_withheld_cause already reads it for the chat's tools-off notice
Sibling: src/kiro_crew/acp/client_mcp_array.py -- not affected -- it already withholds the mcpServers array on it

The mirror, the member projection, the MCP array and settings_withheld_cause already withhold Crew's tools when this is false; _apply_claude_requested_mode now also withholds auto. Every other mode change this PR makes only moves a session to default, so it needs no such guard.

Swept: git grep -n -E "session_mode_permitted|register_deny_hook" -- src/kiro_crew
Sibling: src/kiro_crew/dashboard/server.py -- not affected -- its register_deny_hook callback drops slot Trust state on the installing thread; the claude callback (client_claude_mode._on_claude_trust_denied) registers beside it, captures each affected process, and schedules its audit-then-stop on that client's loop

Every site that sets or honours a session Trust asks session_mode_permitted. The requested claude auto now asks it where it is set (_apply_claude_requested_mode) and where it is honoured (_restore_claude_asking_mode_if_due, at the end of each start and in ensure_ready).

Swept: git grep -n -E "CC_PERMISSION_MODE_AUTO|claude_classifier|_permission_mode" -- src/kiro_crew
Sibling: src/kiro_crew/acp/client_tool_events.py -- changed here
Sibling: src/kiro_crew/acp/client_class.py -- changed here

The unasked-call audit (_maybe_audit_unasked_tool_call, which asks the _unasked_call_attribution hook what approved the call: main's classifier row in client_class.py, the confirmed mode in client_claude_mode.py) is the only reader that attributes a call to Claude's classifier; the seed, the pin and the exclusion read the requested mode only to ask for, keep or refuse a mode.

Swept: git grep -n -E "except \(?Acp(Error|TimeoutError)" -- src/kiro_crew/acp/client_claude_mode.py src/kiro_crew/acp/client_claude_session.py src/kiro_crew/acp/client_model_selection.py
Sibling: src/kiro_crew/acp/client_claude_mode.py -- changed here
Sibling: src/kiro_crew/acp/client_claude_session.py -- changed here
Sibling: src/kiro_crew/acp/client_model_selection.py -- not affected -- equal to main; ClaudeAcpClient._push_model_config_option makes the move before a strict (live) switch, only on a session that follows its requested mode, which raises before any switch is sent

_apply_claude_requested_mode now reads only an error frame as a refused auto. _set_claude_pinned_mode_or_stop stops the session (_claude_stop_session, which kills the process) and raises on any failure, so the move back before a prompt and the move before a model switch already stop the session on a dead child.

Pattern harvest

Not generalizable: the defect is one adapter's settings-tier filter silently dropping one value; the general lesson (read a harness's resolved mode back instead of trusting a written setting) is already how the pin and the VERIFIED_SEEDED_SETTINGS routing work.

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

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 5, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 5, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from 0537a74 to 52fe4e3 Compare November 5, 2026 11:56
@shubhamkurkure
shubhamkurkure marked this pull request as ready for review November 5, 2026 11:58
@shubhamkurkure

Copy link
Copy Markdown
Contributor Author

This should merge after #30308 (the fix for #29909), which is now open.

This PR lets a session that asked for auto actually reach auto. Without #30308, a later resume of that session would restore auto with no pin, because today the pin runs only on the exclusion path and Side Chat. With #30308 merged first, a resumed session that did not request auto is moved back to default, and one that did request it keeps it.

The two PRs touch the same docstring field list in client_claude_session.py, so whichever merges second needs a one-line rebase. I will do that as soon as #30308 lands.

@shubhamkurkure
shubhamkurkure requested a review from a team as a code owner November 5, 2026 11:58
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 5, 2026
@shubhamkurkure

Copy link
Copy Markdown
Contributor Author

#30308 now keeps today's behaviour by default, at a maintainer's request: its broader starting-mode pin runs only when KIROCREW_CC_PIN_INHERITED_MODE is set (off by default). So the merge order I asked for above no longer closes the resumed-session case by default, and either PR can merge first.

After this PR, a session that ran in auto under KIROCREW_CC_PERMISSION_MODE=auto and is resumed after the operator removes that opt-in comes back in auto, as a session whose user ~/.claude names auto does today. Setting KIROCREW_CC_PIN_INHERITED_MODE=1 moves it to default before its first prompt. I updated Backwards compatibility and Related to say this.

The two PRs still conflict as text in agent-host-contract.md, client_claude_seed.py, client_claude_session.py and configuration.md, so whichever lands second gets a rebase from me.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 5, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from 52fe4e3 to ffeb995 Compare November 5, 2026 18:34
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 5, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from ffeb995 to e0b74b9 Compare November 5, 2026 23:09
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 5, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from e0b74b9 to 708d8ef Compare November 6, 2026 06:50
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 6, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch 2 times, most recently from e4d7bf2 to a9bade0 Compare November 7, 2026 07:18
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

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

Revision a9bade0183a27d5b0d23eebdabc218d313adc61e 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 7, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of a9bade0183a27d5b0d23eebdabc218d313adc61e via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the change applies an operator opt-in that the docs already promised, through the one channel the SDK does not filter. If set_mode fails, the session keeps the narrower default mode.

Notes

  • The seed's permissions.defaultMode: auto write has no effect now and survives as a second, misleading writer of the same intent. Remove it in a follow-up once the other open seed PRs land.

[DESIGN-REVIEWED] a9bade0

Description read

[DESCRIPTION-READ] d2a37fbbac999cacbf1e821ca3400e6caee55b12de8e6d62fbc6cd5613dbe908

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

Copy link
Copy Markdown
Contributor

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

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

First-Principles-Verdict: PASS

Nothing blocks. This fix makes the existing opt-in auto actually take effect, which it did not do before. Every added item serves that Goal and none of them duplicates an existing mechanism.

What this change ships

Inventory (7 items) — 7 justified

Intent: an operator who sets KIROCREW_CC_PERMISSION_MODE=auto gets a Claude session that really runs in auto, or is told it could not. FIX.

  1. A cold-start session/new that reports default and offers auto is moved to auto before the first prompt — justified
  2. The same move on a successful session/load resume — justified
  3. The same move on a fresh conversation over the live adapter (new_conversation) — justified
  4. A session that requested auto and that the inherited-mode pin moved to default is then moved on to auto, because the pin now returns the mode it set — justified
  5. One warning, without stopping the session, when the adapter refuses, times out or does not offer auto — justified
  6. A warning when the adapter falls back to acceptEdits, read from the buffered current_mode_update — justified
  7. The docs and docstrings for the opt-in, the seed, the pin and the audit scope say that auto is now applied by session/set_mode — justified

[FIRST-PRINCIPLES-REVIEWED] a9bade0

Description read

[DESCRIPTION-READ] abb3f7b9c9ae567fab9e24af82566ad872d779bdcb3e18bdd1b9e04f8b3877c2

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] a9bade0

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] a9bade0

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Nov 7, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 8, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Heads-up from the review of #33847, which merged at 8cc73e9. That PR makes _claude_session_excludes_local() keep Crew's tools for a claude session that asks for auto next to a foreign settings file, and it pins that session's mode. This PR adds _apply_claude_requested_mode right after the pin with no _claude_session_excludes_local() check. After a rebase, an excluded requested-auto session would be set back to auto, the notice would be wrong, and its classifier approvals would get no SEL audit row.

Smallest fix: return early from _apply_claude_requested_mode when _claude_session_excludes_local() is true, and add one test at the _initialize_session level that asserts the excluded session keeps its pinned mode and writes no classifier-approval path.

@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from a9bade0 to db89f3f Compare November 10, 2026 00:33
@shubhamkurkure

Copy link
Copy Markdown
Contributor Author

Thanks for the heads-up. This is fixed in db89f3f, which is rebased onto main and so includes #33847.

_apply_claude_requested_mode now returns early when _claude_session_excludes_local() is true, so an excluded requested-auto session stays pinned to default and its chat notice stays true.

The new test test_an_excluded_requested_auto_session_keeps_the_pinned_mode in test/test_claude_requested_mode.py runs _initialize_session on both session/new and session/load. With a foreign settings.local.json it checks that no session/set_mode auto is sent, that the session ends in default, that the notice says Default mode, and that an unasked call writes no SEL row. With a Crew-owned file the same request still ends in auto and gets its auto_approved row.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 10, 2026
@shubhamkurkure

Copy link
Copy Markdown
Contributor Author

@bolichen97 @iamwhatever could you take a look at this PR when you have time?

It fixes #30169: with KIROCREW_CC_PERMISSION_MODE=auto, a claude session starts in default mode instead of auto. This PR applies the requested auto with session/set_mode when the session starts, moves the session back to default (or stops it) if Claude reports acceptEdits or never answers, and leaves a session in default after a live model switch. The note from the #33847 review is addressed in the comment above.

The branch merges cleanly with current main.

@KiroCrewCaptain

KiroCrewCaptain commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 20% chance that this change introduces a defect, above the 12% limit for approving on its own.

The PR makes the documented KIROCREW_CC_PERMISSION_MODE=auto opt-in take effect: after the pin and startup model, the session is moved to auto with session/set_mode. Each establishment path (session/new, session/load, fresh conversation) is covered. Excluded sessions, Side Chat, zero-tool specs and sessions with an ungoverned permission surface are skipped. The move is gated by the approval_modes ceiling (trust), which fails closed and waits out an install in progress; the ceiling is re-read at the end of each start and before every prompt. Failure handling: a JSON-RPC refusal keeps default; a dead child or broken pipe ends the start; a timeout or acceptEdits fallback is undone, and the session is stopped if the undo fails; a cancel while the mode is unsettled ends the process. Mode reports are followed through _read_message and are consistent with the _wait_for_response and idle-reader buffering. Every new step is gated by hooks that are inert on AcpClient, so other harnesses and non-requesting Claude sessions are unchanged. Tests cover the paths extensively, and files are under the line cap. Classifier-approved calls skipping Crew's gate is a pre-existing, documented trade-of

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

@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from db89f3f to fb9838d Compare November 11, 2026 13:10
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 11, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from fb9838d to 5379cd3 Compare November 13, 2026 02:31
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 13, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 15, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from 5379cd3 to d256382 Compare November 15, 2026 06:25
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 15, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from d256382 to 9116905 Compare November 15, 2026 09:25
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 15, 2026
@shubhamkurkure
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from 9116905 to 6178cb7 Compare November 17, 2026 10:01
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels 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
shubhamkurkure force-pushed the fix/claude-apply-requested-auto branch from 6178cb7 to ef16ab8 Compare November 18, 2026 00:44
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude backend: KIROCREW_CC_PERMISSION_MODE=auto starts the session in default mode, and turns off the user's own auto

2 participants