Skip to content

fix(kas): gate auto-approved calls and subagent tools on spec hooks - #14066

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/kas-spec-hooks-gaps-13926
Sep 28, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/kas-spec-hooks-gaps-13926

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: On KAS, an agent's PreToolUse hooks see and can block every tool call they cover, on chat, subagent and task-runner turns alike, and confirm: true hooks that cannot run say so.

Three gaps from #13926 (items 1, 2 and 5):

  • A KAS call that the projected permissions auto-approves never reaches Crew's permission path, so neither a spec hook nor a Hooks-page PreToolUse hook sees it.
  • A spec hook with confirm: true is skipped silently.
  • Subagent and task-runner turns on KAS never run the agent spec's own hooks, and did not gate on PreToolUse at the permission request.

Why it matters

A PreToolUse deny hook is a user-authored gate. On KAS it was silently bypassed for every auto-approved call and for every subagent or task-runner turn, so a user who wrote a hook to block a tool got no block and no warning.

Not a goal

What changed (motivation → approach → change)

Item 1: an auto-approved KAS call now meets a PreToolUse hook. A PreToolUse hook runs on Crew's permission path. A KAS call that the projected permissions auto-approves never takes that path, so neither a spec hook nor a Hooks-page hook saw it. The KAS projection now adds an unscoped ask rule for each auto-approvable capability that a PreToolUse hook's matcher covers (kas_permissions.withhold_hook_gated_auto_approval). KAS resolves the most restrictive matching rule (deny over ask over allow), so one ask outranks every allow on that capability: the ones derived from allowedTools and any the author's own permissions block relayed. The call comes back as a permission request, the hook runs, and Crew's own approval decides as for any other request. A deny still wins.

  • Same seam for both sources: kas_agents.pre_tool_hook_matchers lists the spec's own PreToolUse hooks and the Hooks-page store's, read when the session's agent batch is built.
  • A hook added while a session is live: KAS keeps the batch a session registered (set_mode activates, it re-sends nothing), so the runtime records what that batch auto-approves on the session handle (kas_auto_approved, from kas_agents.projected_auto_approved, on both session/new and session/load). Before a chat turn, a kept subagent claim or a task step claims the session, spec_hooks.invalidate_stale_kas_session compares it with what the PreToolUse hooks cover now; on an overlap it resets the session (skip_if_busy), and the claim registers a fresh batch. An unreadable spec also resets. That pre-claim reset is declined for a session another turn holds (it answers busy, not fresh), and the claim may have waited for exactly that turn, so spec_hooks.reproject_claimed_session decides again on the session the claim holds, under its lease and before any tool runs: a stale one is reset and re-claimed, and one still stale after two resets refuses the turn (StaleProjectionError, lease handed back). LLMProvider declares kas_auto_approved_capabilities with None meaning "no batch registered". The re-claim adopts its new permit (sessions.adopt_turn), so a task step's release after a reset unlocks the session it now holds.
  • A turn that names no agent (a subagent with no persona, a chat with none) runs the runtime's default, so the agent whose spec it meets is the one its session's batch was registered for: the runtime records it on the handle (kas_projected_agent, declared on LLMProvider as ""), and spec_hooks.session_agent reads it only when the turn names no agent (an agent the turn names, including one an in-turn switch moved to, always wins); a KAS mode switch (current_mode_update) moves the recorded agent too. With no agent known at all, a KAS turn fails closed (every permission request refused).
  • Coverage errs toward gating, read with the hook store's own _tool_matches: an empty matcher or * covers everything; a literal Crew tool name covers its capability (or nothing for execute_bash/fs_*, which are never auto-approved here); a literal MCP tool name (@server/tool, mcp__server__tool) covers MCP; any other literal covers everything, since it may be a harness's own name for a built-in; a glob covers the built-ins it matches plus MCP. If the hooks cannot be listed, every auto-approval is withheld.
  • "Which KAS tool does this matcher cover" reads fix(kas): match spec hook tool matchers against KAS's tool id #14065's KAS_TOOL_IDS_BY_KIRO_TOOL table; there is no second kiro-cli -> KAS table here.
  • Why this route and not (a) a notice or (c) the ACP hooks channel: a notice leaves the gap open, and the channel is not announced yet. Withholding from the derivation alone would miss an allow from the author's block; an ask covers both.
  • Cost: a call that was silently auto-approved now reaches Crew's approval. Unless Crew's own auto_approve_tools covers it, the user sees a prompt. Each withheld capability is written to the security event log through the projection's own permission audit (mcp_auto_approve_withheld). That is the price of the hook seeing the call, and the same trade the shell and filesystem families already make on KAS.

Item 2: confirm: true spec hooks get a notice. They are still skipped, since Crew cannot ask for the confirmation. A new KAS session now gets one notice row through the same channel as the toolsSettings/slashCommand notice: "Agent X has 2 hooks ask to be confirmed before running. This backend cannot ask, so they do not run in this session." The count comes from the cached conversion, so it costs no extra read and no extra audit.

Item 5: subagent and task-runner turns gate on their PreToolUse hooks. spec_hooks.turn_spec_hooks(provider, agent) answers for a turn outside the chat loop, keyed on that turn's OWN agent and provider. On KAS, each permission request runs hooks.permission_pre_tool_block: the Hooks page's PreToolUse hooks and the agent spec's together, as the chat loop runs them, matched on every name the call is known by: its title (what the chat loop matches), its canonical tool_name, and for an MCP call the @server/tool and mcp__server__tool forms built from the trusted mcp_server_name (ScriptHookStore.fire(tool_match_names=...)). Exit 2 or no verdict refuses the call, and an unreadable spec refuses every call. Such a turn skips the informational tool-call fire: KAS sends a call's tool-call frame before its permission request (seen in the live probe), and item 1 sends every call a PreToolUse hook covers to the gate, so firing on both would run each hook twice. A Hooks-page hook added mid-session reaches these turns through the re-projection above. Item 1 makes every call such a hook covers arrive as a permission request, so the gate sees it. A subagent also passes the spec hooks to PostToolUse. A process that registers no hook store (the standalone kirocrew run task runner) reads the saved Hooks-page hooks from disk (hooks.persisted_hook_store), for the projection and for the gate, so a saved deny hook still gates a standalone KAS task. That read is strict, runs in a worker thread when the gate calls it, and reads the file once under the writers' hooks.json.lock, validating and loading that one snapshot: a hooks.json that cannot be read or parsed, or holds an entry the store could not load, raises, and both consumers fail closed (the gate refuses the call, the projection withholds every auto-approval). An agent switch is a projection change too: KAS's set_mode activates an entry of the batch the session already registered, so the handle re-reads what the switched-to agent auto-approves (kas_agents.switched_auto_approved; a mode the batch does not carry counts as approving everything), and if that agent's hooks cover any of it the turn is cancelled and refused (spec_hooks.refuse_stale_switch), since those calls would never reach the permission request; the next claim finds the session stale and re-projects it for the new agent. A switch to a KAS built-in mode with no spec on disk (vibe) carries no spec hooks (kas_agents.agent_spec_absent), so only the Hooks page's hooks decide; a spec that exists but cannot be read still fails closed. On chat the refusal runs before the switch is recorded, so a refused switch never leaves the slot on the switched-to agent. A subagent's session on its parent's shared runtime is created per run, so spec_hooks.replace_stale_shared_session checks it right after creation and replaces a stale one (refusing the run if it stays stale); the dedicated-process fallback goes through the same claim-time re-check as the dedicated arm. A kiro-cli subagent under a KAS parent is not gated here and its spec is not read.

KAS writes its own tool id only in the permission request's _meta.kiro.toolId (title Fetch URL, id web_fetch, empty canonical tool_name). Rebased on #14065, the subagent and task gate reads it (harness_tool_id through spec_hook_tool_names, one table): a spec hook matches that id's names and the trusted identity, never the title, and a Hooks-page hook matches the title and those names both. The chat turn loop builds the same names through the one helper (hooks.pre_tool_match_names), so an @server/tool or mcp__server__tool hook meets a KAS MCP call there too, and on a backend where Crew fires the spec's hooks the chat's informational tool-call fire is skipped, as on the subagent loop: the permission request is where the hooks run, so each runs once. hook_gated_capabilities reads the same KAS_TOOL_IDS_BY_KIRO_TOOL / KIRO_TOOL_ALIASES, so remote_web_search covers web_search and run_command covers nothing auto-approved.

Docs: agent-spec-fields.md (hooks row) and agent-host-contract.md state the new behaviour.

Backwards compatibility

Compatible: nothing main accepts is rejected, renamed or removed. On KAS, a call a PreToolUse hook covers now reaches Crew's approval instead of being silently auto-approved; kiro-cli sessions are untouched (the projection bookkeeping is recorded by the KAS harness's record_session_projection seam; the base harness's default records nothing, so the shared runtime has no KAS branch).

Tests

  • New test/test_kas_spec_hook_gaps.py (124 tests): matcher coverage cases, including a glob that matches no name the table spells (Fetch*) covering everything; ask added and input untouched; no hook or no policy changes nothing; the projection and the built batch withhold what a spec hook covers; Hooks-page listing skips disabled, command-less and PostToolUse hooks; listing failure withholds everything; confirm notice once per new KAS session, singular copy, none on kiro-cli or without confirm hooks; turn_spec_hooks on kiro-cli returns nothing and reads no spec; on KAS returns the agent's own hooks and cwd, or flags an unreadable spec; the gate runs stored and spec hooks, blocks on exit 2, 1 and -1, matches the canonical tool name over the title, a KAS web_fetch request titled "Fetch URL" with _meta.kiro.toolId=web_fetch meets a web_fetch deny hook (spec and Hooks page) and is rejected, and blocks with no store only when spec hooks were loaded; a KAS subagent denies on its permission request (reject, no approve) with no second PreToolUse fire, and passes the spec hooks to PostToolUse; a Hooks-page deny alone also denies; an unreadable spec denies; a kiro-cli subagent is not gated and gets no spec hooks; the same for a KAS and a kiro-cli task step; with no hook store registered (standalone kirocrew run) the saved Hooks-page hooks are read from disk and still withhold auto-approval and deny at the gate, and a corrupt hooks.json (unparseable, wrong root, non-list hooks, unloadable entry) makes the gate refuse and the projection withhold everything; a KAS subagent or task step switched to another agent mid-run is gated by that agent's hooks, and so is a task step retried on a session an earlier attempt switched (the loop carries the switched-to agent across attempts and spec_hooks.running_agent prefers what the session records; a step that switches A to B, fails, and retries meets B's deny hook); a switch re-reads what the session auto-approves (the switched-to agent's registered entry, or everything for a mode the batch does not carry), and a switch to an agent whose deny hook covers an auto-approved capability stops the turn (chat, subagent, task) so the next claim resets the session and the rebuilt batch asks for the call, which the hook then denies. Re-projection: what a projected policy auto-approves (allow, unscoped/scoped ask, meta, deny), the active agent's entry, the provider read-through, stale on a new Hooks-page or spec hook only for an auto-approved capability, not stale off KAS or without a batch, stale on an unreadable spec, a hook added mid-session resets the session and the rebuilt batch asks for it, a chat turn checks before it claims and again under the lease before its tools run, a turn refused as stale hands its lease back, busy is told apart from fresh, a turn that waited behind a busy stale session re-projects before running, and one that stays stale is refused. Mutation sweeps (fire again on the tool call in either loop, match on the title, pass with no store, drop the audit, drop the chat check, never stale, ignore an ask, no read-through, drop the claim-time re-check in chat or in the helper, drop the final refusal, answer fresh for busy, drop the lease hand-back, drop the base declaration, drop the unknown-glob widening, drop harness_tool_id at the subagent gate, drop the id's names for a Hooks-page hook or a spec hook, drop the table lookup in coverage, fire the chat's informational hook on KAS, drop the chat's MCP identity, keep the old projection on a switch, treat an unknown mode as approving nothing, skip the stale-switch check in chat, subagent or task loop, drop the saved-hooks fallback in the gate or the projection, make the saved-hooks read fail-soft again, drop the KAS harness's projection record on create or load, record a projection in the base harness, gate a retried task step with its original agent, read the saved hooks without the lock or twice, read them on the event loop) are caught each time.
  • test_acp_runtime.py fails 53 tests on unmodified origin/main on this host (reader loop "attached to a different loop"), and 52 on this branch; it is not a signal here.
  • Existing: test_crew_fired_spec_hooks.py, test_acp_session_provider.py, test_kas_session_teardown.py, test_kas_permissions.py, test_kas_agents.py, test_fire_tool_hooks.py, test_acp_harness_contract.py, test_harness_parity.py, test_subagent.py, test_subagent_component_globals.py, test_script_hooks.py, the taskrunner suites, and the doc suites that read both docs. All pass.
  • black, isort, flake8, mypy on touched files; brand and comment-history gates pass.
  • Two reds are main-side and fail the same way on origin/main be067a3503 locally: test_spawn_approval_channel_delivery_2381.py::...test_it_registers_no_wait_so_the_window_is_never_spent and test_sandbox_protected_name_holds.py::...test_leaf_only_count_has_not_grown.

Manual verification

Live KAS probes on this host, below.

Live KAS probe

kiro-cli 2.24.1, acp --agent-engine v3, Crew's own projection (build_kas_custom_agents on this branch), prompt "fetch https://example.com with your web fetch tool". Both agents set allowedTools: ["web_fetch"].

Agent Projected permissions Permission requests Spec hook runs Fetch completed
no hook web_fetch: allow 0 0 yes
preToolUse hook, matcher web_fetch web_fetch: allow, web_fetch: ask 1 (toolId=web_fetch, title Fetch URL) 1 yes, after approval

So ask outranks allow on the live engine, and the session starts with both rules.

Hook added mid-session (same host, live_probe_reproject.py): one KAS process, agent with allowedTools: ["web_fetch"] and no hook.

Step Result
Turn 1 0 permission requests (auto-approved)
Hooks-page PreToolUse hook on web_fetch added hook_projection_stale = True
Reset as on KAS (_kiro/session/delete), claim re-projects batch now web_fetch: allow + web_fetch: ask; stale = False
Turn 2 1 permission request (toolId=web_fetch), hook ran once

Busy-session race (live_probe_busy_race.py, real reproject_claimed_session over one KAS process):

Step Result
Turn A runs, no hook 0 permission requests
Hook added; turn B's pre-claim check while A holds the session busy (reset declined)
A done; B's claim the SAME stale session
Claim-time re-check reset, new session registered
Turn B 1 permission request, hook ran once

A second probe (probe_variants.py) shows which KAS operations take a new batch: a NEW session on the same process does (1 request), and session/load on a NEW process does (1 request); session/load of a session the same process still holds does not, which is why the fix ends the session instead of re-loading it in place. The probe fired Crew's spec-hook path matching on _meta.kiro.toolId, the input #14065 matches on; the title (Fetch URL) alone does not match web_fetch, which is the item-3 gap #14065 closes.

Related Issues

Refs #13926 (items 1, 2 and 5). Builds on #14065.

Pattern harvest

Rule candidate: review-prompt
Pattern: a hook or gate that runs on a permission request is blind to whatever the backend auto-approves; when adding a gate there, also take away the auto-approval for what it covers, and wire every fire site (chat, subagent, task runner) at the permission request, not only at the informational tool-call event.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested a review from a team September 26, 2026 01:04
@iamwhatever iamwhatever added the no-screenshots PR has no visual delta; screenshot gate exempt label Sep 26, 2026
@iamwhatever
iamwhatever requested a review from Zedmor September 26, 2026 01:04
@iamwhatever iamwhatever added the no-screenshots PR has no visual delta; screenshot gate exempt label Sep 26, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 26, 2026
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

Design-level review of 06f70bda09a0168ad8c92567e26ed663cf07e994 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Hook gating rests on KAS resolving ask over allow — probed on one kiro-cli version — while the informational fire that would reveal a silent regression is removed.

Watch

The whole item-1 guarantee is a behavioral property of an external engine. The projection adds an unscoped ask and relies on "KAS resolves the most restrictive matching rule" (description), evidenced only by a live probe on kiro-cli 2.24.1; CI cannot exercise it. Simultaneously the gated turn "skips the informational tool-call fire" (chat, subagent, task). If a future engine version resolves first-match or allow-over-ask, covered calls are auto-approved again with no permission request — and now no hook fires at all, so the regression this PR fixes returns strictly worse (before, the hook at least ran informationally) and invisibly: no fire, no block, no notice, no audit row.
Clears when: a runtime tripwire exists (a completed tool call for a withheld capability that raised no permission request on a gated turn logs loudly or refuses the turn), or the withhold stops depending on resolution order (see below).

Suggestions

  • A resolution-order-independent withhold: omit/strip the allow rules (derived and relayed) for hook-covered capabilities instead of out-ranking them with ask — no bet on the engine's rule resolution, same user-visible outcome.
  • Cheap sentinel for the Watch above: on a gated turn, treat an EVENT_TOOL_RESULT for a withheld capability with no preceding permission request as a projection failure and end the turn, mirroring refuse_stale_switch.

[DESIGN-REVIEWED] 06f70bd

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 06f70bda09a0168ad8c92567e26ed663cf07e994 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 06f70bd

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 06f70bda09a0168ad8c92567e26ed663cf07e994: <one-sentence reason>

@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 06f70bda09a0168ad8c92567e26ed663cf07e994 — 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/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

invalidate_stale_kas_session's fresh/reset/busy vocabulary has zero production consumers — every caller discards it; only tests read the three constants.

Not justified as shipped

  • Item 10 — zero consumers: PROJECTION_FRESH/PROJECTION_RESET/PROJECTION_BUSY are returned by invalidate_stale_kas_session and read nowhere in src/ — grepped PROJECTION_FRESH|PROJECTION_RESET|PROJECTION_BUSY, 0 non-test readers; all 3 call sites (chat_runner.py:11593, subagent_manager/run.py:1458, task_executor.py:494) ignore the value, because reproject_claimed_session re-decides regardless.
    Subtraction: delete the three PROJECTION_* constants in spec_hooks.py and make the function return None; the busy-vs-reset distinction lives in reproject_claimed_session already.
    Clears when: the constants are deleted, or a production caller that branches on the answer is added and counted.

What this change ships

Inventory (10 items) — 9 justified

Intent: a user-authored PreToolUse hook on KAS actually sees and can block every call it covers — chat, subagent, and task-runner alike — and unrunnable confirm: true hooks are announced. This is a FIX (three gaps from issue #13926). The change has more than 10 quiet items (harness seam, provider properties, handle fields); these are the 10 a person would notice.

  1. A KAS call a PreToolUse hook covers now arrives as a permission prompt instead of being silently auto-approved — justified
  2. Adding a PreToolUse hook mid-session resets the live KAS session before its next turn, so the hook applies — justified
  3. A mid-turn agent switch that would put calls beyond the hooks' reach stops the turn; the next one re-projects — justified
  4. A new KAS session shows one notice counting confirm: true hooks that cannot run — justified
  5. Subagent and task-runner turns on KAS now refuse a call their PreToolUse hooks deny, failing closed on an unreadable spec — justified
  6. Standalone kirocrew run tasks now enforce the saved Hooks-page hooks, blocking when hooks.json is corrupt — justified
  7. A hook matcher now meets a call by every name it is known by (title, canonical name, MCP forms) — justified
  8. On gated KAS turns hooks no longer fire twice; the tool-call frame audits as "invoked", not "auto_approved" — justified
  9. A KAS turn with no nameable agent refuses every permission request — justified
  10. invalidate_stale_kas_session answers a fresh/reset/busy tri-state — zero consumers: no production caller reads it

[FIRST-PRINCIPLES-REVIEWED] 06f70bd

@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 Sep 26, 2026
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🟡 CONCERNS

Which legitimate operations does 06f70bda09a0168ad8c92567e26ed663cf07e994 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: the reviewer's own judgement; no confirmed regression.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • ubuntu-latest (platform posix): 9 classified, 0 newly refused, 9 still allowed.
  • windows-latest (platform windows): 8 classified, 0 newly refused, 8 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: CONCERNS

TIGHTENING: The KAS agent projection now withholds auto-approval for every capability a PreToolUse hook's matcher covers -- "the KAS projection adds an ask rule for every auto-approvable capability a PreToolUse hook's matcher covers (spec or Hooks page), and ask outranks allow there" (kas_permissions.withhold_hook_gated_auto_approval, plus the fail-closed companions: pre_tool_hook_matchers answering ("*",) when hooks cannot be listed, permission_pre_tool_block blocking on any nonzero hook exit, the strict persisted_hook_store, and the StaleProjectionError turn refusals). The ONE threat it refuses: a tool call a deny-authoring PreToolUse hook covers running auto-approved on KAS, where it never reaches Crew's permission path and the hook never sees it.

ADJUDICATED: 12 candidates, 0 confirmed newly-refused

No confirmed rows were handed back at review time. The candidates probe the touched area's daily operations (the standalone kirocrew run invocations this diff wires the persisted hook store into, kirocrew doctor / setup --agent-only --clean, the saved-hooks and agent-spec reads the new fail-closed paths make diagnostic necessities, and this PR's own test invocation in both spellings). The diff leaves hooks.on_tool_call and every module under src/kiro_crew/security/ untouched, so no candidate is expected to flip -- but that expectation is the script's to confirm, not mine to assert.

PLATFORM COVERAGE: Candidates were written in all three spellings: any for the bare kirocrew CLI operations and the path-scoped git read; posix and windows as separate rows for every operation carrying a path or interpreter (the ~/.kiro/crew/hooks.json read, the ~/.kiro/agents listing and spec read, and the pytest invocation, each with its %USERPROFILE%/$env:USERPROFILE, backslash, and .exe counterpart). The diff itself makes no shell-visible platform assumption -- its file reads go through pathlib and the hook matchers are tool names, not paths -- so the paired rows cover the only platform surface the change grazes (the config and agents directories it now fails closed on). No assumed platform was left without a candidate. The per-leg verdicts are the deterministic fold's to report, per leg, after this review is captured.

UNADJUDICATED: The entire tightening lives outside the tool-call deny composite the classifier adjudicates. The guard is the KAS permission projection plus the script-hook permission gate; the call path an input takes: agent spec hooks field and Hooks-page store → kas_agents.pre_tool_hook_matchers → kas_permissions.hook_gated_capabilities → withhold_hook_gated_auto_approval appends unscoped ask rules to the wire batch → the covered call comes back as a permission request → hooks.permission_pre_tool_block (subagent/task-runner) or the chat loop's hook fire decides; in parallel, spec_hooks.hook_projection_stale drives invalidate_stale_kas_session / reproject_claimed_session / refuse_stale_switch / replace_stale_shared_session, each of which can end a turn with StaleProjectionError. No shell command line reaches any of this, so no verdict is available for it. The candidate legitimate inputs I would have submitted:

  • A KAS agent with allowedTools: ["web_search"] plus one Hooks-page PreToolUse hook whose matcher is a literal the table does not spell (the tests show ("WebFetch",) and ("Fetch*",) cover EVERYTHING): every auto-approvable capability becomes ask. On an interactive chat that is a prompt; on a headless kirocrew run task -- deny-by-default per docs/task-runner.md, a request off hooks.auto_approve_tools is rejected as headless_no_authorization -- a call that auto-approved yesterday is now rejected outright, and the hook whose matcher caused it never even matches the call. This is the sharpest over-refusal shape: the cover-everything fallback in hook_gated_capabilities gates operations the hook's author never named.
  • A hooks.json with ONE malformed entry in a store-less kirocrew run process: the old load was fail-soft (skip the entry); persisted_hook_store now raises whole, which both withholds every auto-approval (("*",)) and blocks every gated permission request ("saved PreToolUse hooks could not be read").
  • A PreToolUse hook that exits nonzero for an environmental reason (missing interpreter, timeout): permission_pre_tool_block blocks on ANY nonzero exit, so an observability-only hook that flakes refuses every covered subagent and task-runner tool call.
  • A mid-turn /agent switch on KAS to an agent whose hooks cover an auto-approved capability: refuse_stale_switch cancels the whole in-flight turn rather than the single covered call; a session still stale after two resets refuses the turn (reproject_claimed_session, replace_stale_shared_session).
  • An existing Hooks-page deny hook whose matcher equals a canonical tool name (web_fetch): the broadened tool_match_names matching now fires it on KAS calls titled "Fetch URL" that it never matched before -- calls that ran yesterday are denied today, with no per-hook opt-in recording that the author chose the wider reach.

The honest verdict over a guard nothing could classify is CONCERNS, not PASS.

[SCOPE-REVIEWED] 06f70bd

@iamwhatever
iamwhatever force-pushed the fix/kas-spec-hooks-gaps-13926 branch from 9cce2df to 29ac79f Compare September 26, 2026 01:29
@iamwhatever iamwhatever changed the title fix(kas): gate auto-approved calls and fire spec hooks in subagents fix(kas): gate auto-approved calls and subagent tools on spec hooks Sep 26, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 26, 2026
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

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

Review details

Advisory only — nothing blocks: with a wildcard PreToolUse hook, every mid-turn KAS agent switch now aborts the turn and the switch is silently discarded.

FINDING — src/kiro_crew/dashboard/chat_runner.py:16217 — one enabled PreToolUse hook with an empty or * matcher (documented as "empty means every call") makes hook_gated_capabilities return all of AUTO_APPROVABLE_CAPABILITIES, and because the projected batch is single-entry the switch target is never in it, so session_handle sets kas_auto_approved = switched_auto_approved(self.kas_registered_agents, mode_id) to that same full set — await refuse_stale_switch(client, new_agent) therefore always raises, and it sits before _require_current_binding(), record_provider_agent_switch and slot.agent = new_agent, so the turn dies, the switch is never recorded, the needs_session_reset teardown re-projects the OLD agent, and the next attempt reproduces it identically → Fix: persist the switch (slot + record_provider_agent_switch) before refusing so the reset re-projects for the switched-to agent, or narrow switched_auto_approved's absent-entry answer instead of assuming every auto-approvable capability.

[OPUS-REVIEWED] 06f70bd

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 06f70bda09a0168ad8c92567e26ed663cf07e994: <one-sentence reason>

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 26, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-spec-hooks-gaps-13926 branch from 29ac79f to ade06a4 Compare September 26, 2026 07:07
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 26, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-spec-hooks-gaps-13926 branch 2 times, most recently from eb502df to beeb6e8 Compare September 26, 2026 08:11
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 26, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-spec-hooks-gaps-13926 branch from ae93af1 to a842f6a Compare September 26, 2026 15:16
@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 Sep 26, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-spec-hooks-gaps-13926 branch from a842f6a to e8ffafe Compare September 26, 2026 15:39
@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 Sep 26, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-spec-hooks-gaps-13926 branch from e8ffafe to 2ef1acc Compare September 26, 2026 16:39
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 26, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-spec-hooks-gaps-13926 branch from 2ef1acc to 68e9db8 Compare September 26, 2026 17:39
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 26, 2026
@iamwhatever
iamwhatever force-pushed the fix/kas-spec-hooks-gaps-13926 branch from 68e9db8 to fe42ba8 Compare September 26, 2026 17:51
@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 Sep 26, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

/ai-review override scope 0835d26: prior attempt's CONCERNS verdict (0 newly refused, no confirmed regression; run 36305445798 attempt 1) failed only to publish on the App rate limit; the rerun classified clean

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@iamwhatever marked the scope AI finding as false positive, not applicable, or explicitly accepted for 0835d26a93366ba2b5cf776818f2c728af9c5ac9.

prior attempt's CONCERNS verdict (0 newly refused, no confirmed regression; run 36305445798 attempt 1) failed only to publish on the App rate limit; the rerun classified clean

This decision applies only to this commit. A new push requires a new judgment.

@bolichen97

Copy link
Copy Markdown
Contributor

Maintainer sweep (2026-09-27, on behalf of @bolichen97): not merging yet, although every gate is green on 0835d26. The intent -- make a user's own PreToolUse hooks actually run for auto-approved and subagent calls -- is right, and the extra prompts for hook authors are the point, not a regression. What holds it is the GPT finding on this head: standalone kirocrew run reaches "hook store not initialized" (src/kiro_crew/hooks.py:5674), so for a CLI user whose spec declares hooks, valid hooks never execute and every covered tool is rejected. That turns a working CLI path into a hard refusal on upgrade, which is the one shape we do not ship. Please either create the local ScriptHookStore off-loop when spec hooks exist (as the finding suggests) or make kirocrew run fall back to today's behaviour when no store is available, then re-push; I will approve on the new head.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

/ai-review override scope 9090055: Fable produced zero candidate rows on three consecutive runs (two heads + a full rerun); the validator fails closed on an empty corpus by design, and this diff changes spec-hook gating on KAS sessions, not the shell denylist, so there is no newly refused operation to measure.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@iamwhatever marked the scope AI finding as false positive, not applicable, or explicitly accepted for 90900550197407a133294107d6b9789147ab3404.

Fable produced zero candidate rows on three consecutive runs (two heads + a full rerun); the validator fails closed on an empty corpus by design, and this diff changes spec-hook gating on KAS sessions, not the shell denylist, so there is no newly refused operation to measure.

This decision applies only to this commit. A new push requires a new judgment.

Three gaps left after agent spec hooks started running from Crew on KAS
(refs #13926, items 1, 2 and 5):

- A PreToolUse hook runs on Crew's permission path, which an auto-approved
  KAS call never takes. The KAS projection now adds an `ask` rule for each
  auto-approvable capability a PreToolUse hook's matcher covers (the spec's
  own hooks and Hooks-page hooks), and records each one in the security
  event log. KAS resolves the most restrictive match, so `ask` outranks
  every `allow` on that capability and the call comes back as a permission
  request (confirmed in a live KAS session). A live session keeps the batch
  it registered, so the runtime records what that batch auto-approves on the
  session handle. Before a turn claims the session it is reset when a
  PreToolUse hook now covers one of those capabilities, and because that
  reset is declined for a session another turn holds, the decision is made
  again on the claimed session under its lease: a stale one is reset and
  re-claimed, and one still stale after two resets refuses the turn (both
  confirmed live). `LLMProvider` declares `kas_auto_approved_capabilities`.
- A `confirm: true` spec hook is skipped because Crew cannot ask for the
  confirmation. A new KAS session now gets one notice naming how many were
  skipped.
- On KAS, subagent and task-runner turns gate each permission request on
  their PreToolUse hooks (`hooks.permission_pre_tool_block`: the Hooks
  page's and their own agent's spec hooks together, matched on the event's
  canonical tool name before its title; exit 2 or no verdict refuses the
  call; an unreadable spec refuses every call), and skip the informational
  tool-call fire, which KAS sends before the permission request. Keyed on
  the turn's own provider's `crew_fires_spec_hooks`, so a kiro-cli subagent
  under a KAS parent is not gated and gets no spec hooks, and nothing fires
  twice. A subagent also passes the spec hooks to PostToolUse.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-screenshots PR has no visual delta; screenshot gate exempt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Agent spec hooks: remaining gaps after KAS delivery (#11116)

3 participants