Skip to content

fix(kas): six KAS harness and mcp.json reach fixes - #33510

Merged
bolichen97 merged 1 commit into
mainfrom
fix/sweep-g1-kas-harness
Nov 10, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/sweep-g1-kas-harness

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An agent spec gets on Kiro Crew what its own settings say, on KAS and with the global mcp.json: a trusted sub-agent and a hook-covered MCP grant run without a prompt, a narrow tools list or useLegacyMcpJson: false keeps the other mcp.json servers out, a host below the KAS engine's glibc floor is told the real cause, and the agent-spec reference states kiro-cli v3's file:// prompt rule as it is.

This PR bundles six separate fixes, as the maintainer asked for larger grouped PRs. Each row is its own defect:

Fix What the user saw Issue
Trusted sub-agents on KAS an attended dashboard chat asked before it spawned a toolsSettings.subagent.trustedAgents sub-agent whenever any governance profile turned spawning off for another surface or app, and the chat said the setting had no effect #32973
Hook-covered MCP grants on KAS a PreToolUse hook that covered an allowedTools grant such as @docs/lookup made every chat call show an approval card, and a subagent or task-runner turn waited on its approver or was refused; kiro-cli runs the same spec unprompted #32923
tools and mcp.json an agent with a narrow tools list was still offered every stubbed ~/.kiro/settings/mcp.json server, and on KAS it got every MCP tool of them through includeMcpJson: true #32896
useLegacyMcpJson an agent that opted out with kiro-cli's deprecated useLegacyMcpJson: false still had the global servers injected and mounted #32973
glibc floor on Amazon Linux 2 (glibc 2.26, below the engine's 2.28) the chat and the dashboard said to connect and retry, an offline host saw only a fetch error, and kirocrew doctor said the engine downloads at the first chat #32973
file:// prompts (docs) the agent-spec reference called kiro-cli v3's refusal of an absolute or ~ prompt unverified, and claimed kiro-cli parity for .. and $VAR #32973

Why it matters

  • Trusted sub-agents: a host whose profiles turn spawning off for unattended surfaces, a common hardening, lost every trustedAgents grant in every chat, and the chat told the user the setting does nothing.
  • Hook-covered grants: every agent with an audit or guard PreToolUse hook prompted in the chat on each MCP tool its spec granted, and its subagent and task-runner turns waited on an approver or were refused.
  • tools and useLegacyMcpJson: an author who kept write-capable servers out of an agent still had them mounted. A call to one prompts rather than being refused, so with slot trust or yolo on, it runs.
  • glibc floor: operators of older Linux hosts chased a network problem they did not have, and every spawn, cron run and subagent paid a network round trip before the same refusal.
  • file:// prompts: a reader could not tell which agents fail on which route.

Not a goal

What changed (motivation → approach → change)

A trusted sub-agent and a hook-covered MCP grant run on KAS without a prompt, an agent's tools list and useLegacyMcpJson: false decide which mcp.json servers it gets, a host below the KAS engine's glibc floor gets a final error that names the cause, and the agent-spec reference states kiro-cli v3's file:// prompt rule. In each case Kiro Crew read a different condition from the engine or the gate that owns the setting. The six share one commit because they meet in the KAS projection and the MCP gateway rewriter.

Fix Root cause Change
Trusted sub-agents the translated allow asked may_skip_gate_now, which withholds when any configured profile governs use_subagent it asks may_skip_gate_for_session (platform/governance.py, governance_profiles.session_profiles_govern); the notice in agent_sdk/spec_hooks.py and dashboard/chat_turn/turn_spec_hooks.py asks the same
Hook-covered grants the projection turns a hooked capability to ask but recorded no MCP grant for the gate to answer kas_hook_coverage.hook_held_grants records them under _crewAnsweredHookHeld (acp/kas_permissions.py), stripped from the wire; the session handle stamps them as AcpEvent.spec_hook_held, and the batch-guard-grant row in hook_runtime/gate_tiers.py answers them only for a surface that tells the gate it fires the PreToolUse hooks (pre_tool_hooks_fire, a gate argument in hooks.py)
tools and mcp.json the rewriter stubbed every settings server into every agent that reads mcp.json, and KAS got includeMcpJson: true rewriter_spec._rewrite_single_spec injects only a server tools names, and gives a left-out server whose env holds a secret:// reference a refusing stub (_refusing_stub_entry); KAS gets the flag only as false, and the opt-in rides the settings stamp kas_settings_mcp.excluded_whole reads
useLegacyMcpJson the rewriter tested only includeMcpJson: false the rewriter reads the opt-in through include_mcp_json, the reader the KAS projection already used, so either spelling opts out and both sides read a non-bool flag the same way; the reader moved unchanged to mcp_cleanup.py, because mcp_gateway/ may not import kiro_crew.acp, and acp/kas_settings_mcp.py re-exports it
glibc floor install_pinned fetched the manifest before the glibc check, and the installer wrapped the refusal as an offline failure the host checks run first (acp/kas_bundle.py); kas_engine_install.py keeps KasHostUnsupported with the cause alone; the harness raises AcpKasHostUnsupported from acp/kas_host_unsupported.py; doctor (cli_doctor_parts/kas_relay.py) and kirocrew kas install run the same three checks through agent_sdk/kas_bundle.require_loadable_host
file:// prompts the reference predates a check of the v3 engine src/kiro_crew/docs/agent-spec-fields.md § Prompt and the acp/kas_prompt.py docstrings state each route's rule

For the trusted allow, the projection must know which session and app it serves. The provider hands its runtime its session key and owning_app (providers/acp_runtime_start.py, acp/runtime_class.py), and acp/runtime_session_setup.py and the acp/harness/ files pass them to the projection. Any other session on that process gets the app as not known, which counts every app profile. Three in-process app paths hand their gate their own app: the app agent-turn SDK (apps/agent_turn_sdk.py, which the meetings dispatch runs through), the auto-improvement member runner (apps/builtins/auto_improvement/spine/crew_runner.py) and the provider the auto-improvement runner builds itself (spine/agent_runner.py). Each names that app on its session's provider, so the projection judges the allow under the profile the gate applies. A reset successor and a compaction restart keep the app of the session they replace (allocation_identity in session_lifecycle_parts/parked_queue.py).

On the hook-covered grants, only the chat, subagent and task-runner turn loops tell the gate they fire the PreToolUse hooks on the request (dashboard/chat_turn/tool_approval.py, subagent_manager/run_turn.py, task_executor.py), so there a hook's exit 2 still blocks the call. Every other surface keeps asking, a channel bot's turn included: it runs the hooks too, but its gate is not told.

Both rewriter changes share one move of the rewrite fingerprint schema to 14 (mcp_gateway/rewriter.py), so a kept overlay holding stale stubs is rebuilt. acp/client_mcp_array.py states the opt-in rule in its docstring.

A routed mcp.json server whose env holds a secret:// reference cannot just be left out: the host's own merge would start it with the literal reference (rewriter_env._must_stay_wrapped). An agent whose tools leaves one out gets a refusing stub under its name, sent at session/new so it outranks that merge. It runs stub --refuse, which starts nothing, never reaches the gateway and answers as a server with no tools (stub_link._serve_refusal). It names no target, so no launch is approved for it. KAS gets it only for an agent opted in to mcp.json, and an opted-out agent gets none.

On a host below the glibc floor, transient = False on the refusal tells the retry layer not to retry. The chat, the dashboard and doctor show the engine's own glibc message, which suggests a newer base image.

The specs (governance.md, security.md, acp-client.md, agent-host-contract.md, app-kit-platform.md, docs/architecture/mcp.md and the stub decoupling note) state each rule.

These changes would take acp/kas_agents.py past the 2,000-line cap, so its registered-entry readers (projected_*, switched_*, active_registered_entry) move unchanged to acp/kas_agents_registered.py. kas_agents imports each name back, so callers and tests keep that path.

Backwards compatibility

Compatible: no spec is refused and no key changes meaning. A trusted sub-agent or a hook-covered MCP grant runs where it used to prompt; a narrowed or opted-out agent stops being offered mcp.json servers it never named; a host the engine cannot run on gets a final error in place of a retry.

Three behaviour changes to name:

  • A session an app's agent-turn SDK or the auto-improvement runner allocates or builds, and a reset or compaction successor of an app's session, carries that app as owning_app, so its session setup and readmission judge it under that app's profile as well. This only narrows, and it matches what the gate already applied.
  • kirocrew doctor on a host the engine publishes no build for (an architecture such as riscv64) names that cause on a failing row, where it said the first chat downloads the engine; every install refuses that host the same way.
  • A narrow agent's session lists a routed mcp.json server that carries a secret:// reference and that its tools leaves out as a server with no tools. Before, it got that server's tools through the gateway.

Reader: src/kiro_crew/mcp_gateway/session_servers.py:pooled_session_servers -- chat -- reads the overlay, so it sends exactly the stubs the rewriter wrapped: test_only_the_named_settings_server_is_injected
Reader: src/kiro_crew/mcp_gateway/launch_resolve.py:resolve_launches -- crew page -- runs the same rewrite pass, so a stub toggle resolves a launch for a settings server some agent's tools names; the launch-approval tests name their server in tools
Reader: src/kiro_crew/acp/kas_settings_mcp.py:excluded_whole -- chat -- reads the opt-in from the settings stamp, not the sent flag, so an opted-in agent keeps its file servers: test_an_opted_in_spec_keeps_the_server_its_tools_names
Reader: src/kiro_crew/acp/runtime_session_create.py:without_excluded_stubs -- chat -- uses excluded_whole, so an opted-in agent keeps its pooled stubs: test_an_opted_in_agent_keeps_its_pooled_stubs
Reader: src/kiro_crew/acp/runtime_session_load.py:without_excluded_stubs -- chat -- a resumed session's session/load calls the same helper on the same stamp, so an opted-in agent keeps its pooled stubs there too: test_an_opted_in_agent_keeps_its_pooled_stubs
Reader: src/kiro_crew/acp/harness/kas.py:excluded_whole -- chat -- stamps the spec's own opt-in, which the wire entry never carries, before it asks excluded_whole which servers start: test_kas_stamps_the_specs_own_mcp_json_opt_in
Reader: src/kiro_crew/llm_helpers_parts/backend_errors.py:acp_error_is_transient -- chat -- reads transient = False off the refusal, so a host below the floor is not retried: test_a_host_that_cannot_run_the_engine_is_not_told_to_retry
Reader: src/kiro_crew/dashboard/handlers/kas_bundle.py:_install_task -- app -- catches KasBundleError, which KasHostUnsupported subclasses, and shows its text, which names the cause alone

Tests

Fix Tests that lock it in
Trusted sub-agents test_kas_trusted_agents_session_profile.py (new): the allow travels where no profile of the session governs and is withheld where one does, the notice agrees, the runtime, harness, provider and both app runners hand down the session and app, and a rebuilt session keeps its app (TestPlumbing::test_a_rebuilt_session_keeps_the_app_its_gate_judges); test_auto_improvement_members.py::test_member_session_runs_under_the_app_its_gate_judges and ::test_a_runner_built_session_runs_under_the_app_its_gate_judges; test_app_agent_turn_sdk.py expects owning_app on a turn's allocation
Hook-covered grants test_kas_hook_reach.py: a hook-held grant is recorded apart from the other answered grants and stamped on the session's own request, the gate answers it without a prompt only for a surface that fires the hooks (test_a_surface_that_fires_no_hook_keeps_asking), only the chat, subagent and task-runner turn loops say they do, the task runner's ladder answers it, an authored ask or an ungranted tool still prompts, and a real dashboard _run_chat turn runs the hook (exit 0 approves, exit 2 rejects); test_hooks.py pins the new event field and gate argument
tools and mcp.json test_mcp_gateway_settings_inject_tools.py (new); test_kas_agents.py::TestInclusionFlagProjection; test_kas_settings_mcp.py; test_acp_harness_contract.py::test_kas_stamps_the_specs_own_mcp_json_opt_in; in test_secret_uri_launch_paths.py, the refusing stub: test_a_settings_server_with_a_reference_gets_a_refusing_stub_when_tools_omits_it (tools absent, [] or ["@other"], the command resolvable or not), none for either opt-out spelling, the stub in the session array, KAS excluding or outranking the file's server, and the stub run through its own entry point answering as a server with no tools
useLegacyMcpJson test_mcp_gateway_rewriter.py: both spellings, true and false, and TestSettingsInjection::test_injection_reads_the_opt_in_the_kas_projection_reads, which checks the rewriter against include_mcp_json on six spellings (a junk or null includeMcpJson beside the alias's false or true, both flags stated either way, junk alone)
glibc floor test_kas_bundle.py::test_install_pinned_refuses_an_old_glibc_host_before_the_manifest; test_kas_route.py (no retry advice, type kept); test_cli_doctor_agent_auth.py::test_a_host_below_the_glibc_floor_is_told_so_not_to_install and ::test_a_host_with_no_engine_build_is_told_so_not_to_install
file:// prompts test_agent_spec_fields_doc.py::test_prompt_section_states_the_v3_absolute_rule_crew_keeps_looser

Injection fixtures whose specs carried no tools grant ["*"] or name their server, the brace-glob cases in test_kas_settings_mcp.py state their opt-in through the stamp, and test_runtime_bindings.py pins the new runtime field.

Rebased onto main after review; patch unchanged. This head is 029d9da on main 51242a5. git range-diff shows the same patch as 24e1b1e739 on main 11684ff, where the rest of this section ran, and main's 5 commits between the two touch no file this PR edits. At this head, the two backend test files main changed (test_acp_strands_backend.py, test_build_desktop_job_timeouts.py), test_acp_harness_contract.py, test_rewriter_facade.py, test_mcp_gateway_rewriter.py and test_kas_settings_mcp.py ran 426 passed, 2 skipped, 0 failed. Everything ran on a Linux DevSpace host (Amazon Linux 2023), except the glibc repro, which ran on an Amazon Linux 2 DevSpace host (glibc 2.26).

Rebasing 08c3064 met one conflict, in the hooks row of agent-spec-fields.md, and kept both sides: this PR's hook-held grant sentences stay, and main's (#34020) sentence that a channel-agent turn runs only the spec's PreToolUse hooks, on each permission request before any approval, replaces this PR's older one that said it runs none. channel.py passes the gate no pre_tool_hooks_fire, so that turn keeps its own approval for a hook-held grant. Main's later commits touch no file this PR edits.

The patch also answers the First Principles review of 08c3064: the rewriter reads the opt-in through include_mcp_json, the KAS projection's reader, moved unchanged to mcp_cleanup.py, and _excludes_global_mcp_json is gone; the rewriter facade's TYPE_CHECKING block names the new import (test_rewriter_facade.py). test_injection_reads_the_opt_in_the_kas_projection_reads passes its 6 cases; with only the rewriter's call site put back to the old reader, junk-then-false and null-then-false fail on the assertion and the other 4 pass. The test passed 20 runs of 20 at -n0, and 10 of 10 at -n 4 --dist loadgroup --max-worker-restart=2 beside test_kas_settings_mcp.py, and the 109 tests of test_mcp_gateway_rewriter.py passed in a shuffled order (seed 4127: 107 passed, 2 skipped).

The refusing stub, this PR's answer to the Opus review at 35ad16a, has 16 new and changed cases. At 08c3064, with its four production files reverted (rewriter_spec.py, stub.py, stub_link.py, rewriter.py), 11 of them failed by name and the 5 controls passed. At 0e5ad530f0, an earlier head with the same refusing stub, those cases ran 20 times at -n0 and 10 times at -n 4 --dist loadgroup --max-worker-restart=2 beside test_mcp_gateway_rewriter.py and test_kas_settings_mcp.py, all green, and the 94 tests of the two changed files passed in a shuffled order (seed 9234).

At 24e1b1e739, pytest -n 6 --dist loadgroup --max-worker-restart=2: 184 test files ran 10368 passed, 21 skipped, 0 failed. They are the 23 changed and added test files, every test file that imports mcp_cleanup, kas_settings_mcp or the rewriter's modules, test files that import another module or read a doc this PR changes (kas_agents, hooks.py, the KAS harness and permission modules, agent-spec-fields.md), the channel-turn, cron and messaging spec-hook tests beside the merged hooks row, and the ratchet, budget, contract and facade-mirror guards.

Every profile gate exited 0 at 24e1b1e739: black, subprocess encoding, isort, flake8, mypy --platform linux (4,421 files), comment history, brand name, the file line cap, harness parity (HARNESS_BASE_REF main), the agent-SDK boundary, docs lint, the flake-pattern ratchet (68 passed) and semgrep scan --config semgrep/ against main (0 findings). The scoped backend and frontend suites and the Electron tests are not run locally: GitHub CI runs the full suites.

Proof: PROVEN src/kiro_crew/apps/builtins/auto_improvement/tests/test_auto_improvement_members.py::test_member_session_runs_under_the_app_its_gate_judges, src/kiro_crew/apps/builtins/auto_improvement/tests/test_auto_improvement_members.py::test_a_runner_built_session_runs_under_the_app_its_gate_judges, test/test_agent_admission_paths_ratchet.py::test_every_agent_argv_site_is_classified, test/test_agent_spec_fields_doc.py::test_prompt_section_states_the_v3_absolute_rule_crew_keeps_looser, test/test_app_agent_turn_sdk.py::test_a_turn_carries_the_contexts_identity_and_the_hook_gate (head 24e1b1e739b8)

prove.py --base 11684ff344 exited 0 at 24e1b1e739: with the production hunks reverted, tests of the changed test files fail on an assertion (the line names the first five). Each fix has at least one: the app-runner allocations, the runner-built provider, the SDK pins and the rebuilt session's app, the gate's new event field and the three turn loops that say they fire the hooks, the tools and useLegacyMcpJson injection cases and the refusing stub's, the KAS flag and stamp, the glibc order, the harness and doctor wording (the architecture row included), and the prompt section's doc test. The projection cases in TestProjection and TestNotice, and the hook-held record and gate cases, raise without the new code rather than assert, so the proof does not count them; they are the behaviour pins.

Live repros, one per fix, fix side only, ran at 24e1b1e739; each exited 0 as in the table. Each starts a real python -m kiro_crew gateway or the real CLI from a fresh worktree, on its own KIROCREW_HOME, HOME and loopback port. Five ran on a Linux DevSpace host (Amazon Linux 2023), where the KAS engine and kiro-cli are Kiro Crew's packaged fake ACP backend wrapped to log frames, because the host has no model sign-in. The glibc repro ran on an Amazon Linux 2 DevSpace host (glibc 2.26). Server names are generalized.

Fix Result
Trusted sub-agents exit 0: with spawn-off profiles bound to other surfaces and apps, the dashboard chat's KAS session/new carries {capability: subagent, match: [helper], effect: allow} and no trustedAgents notice
Hook-covered grants exit 0: no approval card for @docs/lookup; Kiro Crew answered the engine's request in 0.77 s after the hook ran once, the tool ran once, and no Kiro Crew-only key reached the wire
tools and mcp.json exit 0: on kiro-cli and on the KAS relay (acp --agent-engine v3) the narrow agent got only the server its tools names, KAS saw no includeMcpJson, and the tools: ["*"] control still got all three. This host's kiro-cli is 2.37.1, so the launcher replayed the --version and acp --help answers of kiro-cli 3.1.0 from another DevSpace host; with the 2.37.1 answers Crew keeps the v2 launch for the KAS phase and the script exits 2 (inconclusive)
useLegacyMcpJson exit 0: the useLegacyMcpJson: false agent got no settings stubs and kept its own server; the no-flag control still got both, and the includeMcpJson: false control got none
glibc floor exit 0 on Amazon Linux 2: the chat error, the offline chat error, the dashboard's GET /api/kas-bundle error and doctor's bundle: row each name the glibc cause with no retry advice, and two offline chats made 0 connections to the manifest host
file:// prompts exit 0: the v3 engine refuses an absolute and a ~ prompt, expands no $VAR and keeps the home-directory boundary, as the reference says; on KAS the session/new for abs-prompt carries the file text inlined and the engine takes that mode; the Kiro CLI launch pins --agent-engine v2. Each turn then ends with the not-signed-in error, which the check does not judge

Manual verification

The live repros under Tests drive a real gateway, its HTTP API, the gate, spec hooks and stdio MCP servers. Still to do by hand: one run against a signed-in KAS engine, and a hook-held grant on a channel bot's turn in interactive mode, which should still show its approval buttons.

Screenshots / video

N/A: the diff touches no frontend file. The user-visible effects are a prompt or a notice that no longer appears and an error text; the repro results under Tests show them.

Related Issues

Fixes #32973
Fixes #32923
Fixes #32896

Related: #30625, #30712, #30822, #31906, #32912, #32980

Sibling sweep

Swept: git grep -nE "ceiling_permits=|may_skip_gate_now(entry)" -- src/kiro_crew/acp/kas_agents.py (every KAS projection step that judges a spec's allow against the profiles; _ceiling_permitted at :581 and the authored permissions merge at :1144 are the two left)
Sibling: src/kiro_crew/acp/kas_agents.py:581 -- tracked in #32980
Swept: git grep -nE "get_or_create(" -- src/kiro_crew/apps/ (in-process app runners that hand their gate an app)
Sibling: src/kiro_crew/apps/agent_turn_sdk.py -- changed here
Sibling: src/kiro_crew/apps/builtins/auto_improvement/spine/crew_runner.py -- changed here
Sibling: src/kiro_crew/apps/builtins/issue_radar/backend/http_routes/ai.py:235 -- not affected -- a kirocrew-lite helper turn under ToolApprovalPolicy.REJECT_ALL, so no gate judges a spec allow there
Swept: git grep -nE 'owning_app ?=|"owning_app"] =' -- src/kiro_crew/apps src/kiro_crew/subagent_manager (every provider an app path names its gate's app on, including one built outside allocation; subagent_manager/run_turn.py:311 already hands the child its spawn's app as owning_app)
Sibling: src/kiro_crew/apps/builtins/auto_improvement/spine/agent_runner.py -- changed here
Swept: git grep -nE 'allocation_identity(|get_or_create(key)' -- src/kiro_crew/session_lifecycle_parts src/kiro_crew/session_compaction.py (every allocation that replaces a session under its key; hand_queue_to_successor in the same file serves a messaging channel's forced stop, whose gates judge with no app)
Sibling: src/kiro_crew/session_lifecycle_parts/parked_queue.py:204 -- changed here
Sibling: src/kiro_crew/session_lifecycle_parts/turn_stop.py:588 -- not affected -- the hard stop's eager respawn rebuilds no identity at all (default agent, no cwd, model or app), a loss older than this change and wider than the app
Swept: git grep -nE 'spec_granted_builtins' -- src/kiro_crew/hook_runtime/gate_tiers.py (every gate row that answers a request the projection kept at ask; spec-builtin-grant at :1571 answers the shell, filesystem and read-path built-ins KAS keeps at ask with or without a hook)
Sibling: src/kiro_crew/hook_runtime/gate_tiers.py:1638 -- changed here
Swept: git grep -nE "pre_tool_hooks_fire=True|permission_pre_tool_block(|.pre_tool_refusal(" -- src/kiro_crew (every turn loop that runs the PreToolUse hooks on a KAS permission request, and whether it tells the gate)
Sibling: src/kiro_crew/dashboard/chat_turn/tool_approval.py:769 -- changed here
Sibling: src/kiro_crew/subagent_manager/run_turn.py:596 -- changed here
Sibling: src/kiro_crew/task_executor.py:673 -- changed here
Sibling: src/kiro_crew/channel_spec_hooks.py:54 -- not affected -- a channel-agent turn (channel.py) runs the spec's PreToolUse hooks before any approval but does not tell the gate, so a hook-held grant keeps that channel's own approval
Sibling: src/kiro_crew/cron_service/turn_hooks.py:109 -- not affected -- a cron turn runs the spec's PreToolUse hooks on the request but does not tell the gate, so a hook-held grant still asks there, as before
Sibling: src/kiro_crew/messaging/driver.py:1184 -- not affected -- a channel bot's turn runs the hooks after its tool gate answers and does not tell the gate, so a hook-held grant keeps that channel's own approval, as before (named under Not a goal)
Swept: git grep -nE "def withhold_[a-z_]*|CREW_ANSWERED_[A-Z_]+_KEY = " -- src/kiro_crew/ (every projection step that turns a granted allow into ask, and every record the gate answers from)
Sibling: src/kiro_crew/acp/kas_hook_coverage.py -- changed here
Sibling: src/kiro_crew/acp/batch_guard.py -- not affected -- withhold_write_auto_approval records every MCP write it holds at ask under CREW_ANSWERED_WRITES_KEY, which the same gate row answers
Sibling: src/kiro_crew/acp/kas_spec_grants.py:34 -- not affected -- the read allowedPaths record, which the spec-builtin-grant row answers whether or not a hook covers the read
Sibling: src/kiro_crew/acp/kas_env_launch.py -- not affected -- a deliberate per-call hold: the gateway proxy forwards a tools/call only against an approval Kiro Crew's gate granted for those exact arguments
Swept: git grep -nE "inject_servers|pooled_session_servers(|includeMcpJson|useLegacyMcpJson|includePowers" -- src/kiro_crew/mcp_gateway/ src/kiro_crew/acp/ (includePowers, forwarded at kas_agents.py:1343, has no kiro-cli reading to diverge from)
Sibling: src/kiro_crew/mcp_gateway/rewriter_spec.py:588 -- tracked in #32912
Sibling: src/kiro_crew/acp/client_mcp_array.py:133 -- not affected -- spec_is_toolless fails closed: it needs includeMcpJson to be exactly false, so a spec that opts out only through the alias is read as not toolless and keeps its gate
Sibling: src/kiro_crew/acp/kas_mcp_json_legacy.py:57 -- not affected -- the one-time legacy list asks whether either key is stated at all, not what the opt-in says
Sibling: src/kiro_crew/acp/session_mcp.py:440 -- not affected -- the mirrors already drop a stub their ToolsAllowlist does not grant
Swept: git grep -nE '_must_stay_wrapped(' -- src/kiro_crew/mcp_gateway/ (every place that decides whether a routed server carrying a secret:// reference keeps an overlay entry, all in rewriter_spec.py: :577 is changed here; :701 and :877 keep a declared or a named server wrapped whether or not its launch is approved, and :1043 keeps it in the injection set when its command does not resolve)
Swept: git grep -nE "offline_install_message(|except .*KasBundleError" -- src/kiro_crew/
Sibling: src/kiro_crew/acp/harness/kas.py:789 -- changed here
Sibling: src/kiro_crew/cli_kas.py:385 -- not affected -- kirocrew kas install already catches KasHostUnsupported first and exits with its own code
Sibling: src/kiro_crew/dashboard/handlers/kas_bundle.py:147 -- not affected -- it catches the subclass and shows the text install_pinned_engine words without retry advice
Swept: git grep -nE 'require_loadable_host()|_require_loadable_glibc(None, None)' -- src/kiro_crew (every local host check that runs before an install)
Sibling: src/kiro_crew/agent_sdk/kas_bundle.py:173 -- changed here
Sibling: src/kiro_crew/agent_sdk/backend_install.py:240 -- not affected -- _engine_installable_here already runs the glibc, platform and node checks

Pattern harvest

Rule candidate: review-prompt
Pattern: a Kiro Crew projection of an agent spec that judges a setting by a different condition than the engine or gate that owns it: one spelling of a kiro-cli alias, every profile instead of the session's, or a flag forwarded to a backend that reads it differently

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

Contributed under the project's Apache-2.0 license, per the Licensing section of CONTRIBUTING.md.

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 9, 2026 00:11
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 029d9da

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

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 9, 2026 00:14
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

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

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

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

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The shell deny composite is not tightened. The sensitive-bash, exfil and deny-rules tiers are unchanged, and the hooks.py/gate_tiers.py hunks only pass through a flag for a grant row. So the 17 shell candidates probe nearby tiers, and the harness gives a verdict only on those rows. The real tightening is in the MCP gateway overlay rewriter (which settings servers an agent gets, and the new refusing stub). No classifier can judge that, so it is named under UNADJUDICATED as an argued gap, not a confirmed one.

TIGHTENING: settings-server injection in the gateway overlay rewriter (rewriter_spec._rewrite_single_spec) -- refuses one threat: a global ~/.kiro/settings/mcp.json server the agent's tools leaves out being mounted and callable anyway, or being started by the host's own merge with a literal secret:// reference in its env. The hunk: named = _named_in_tools(inject, spec.get("tools")) / refused = {... if name not in named and isinstance(entry, dict) and _must_stay_wrapped(_normalized_env(entry))} / inject = named, plus new_servers[alias] = _refusing_stub_entry(...) served by stub --refuse (stub_link._serve_refusal).

ADJUDICATED: 17 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix, windows and any.

  • posix: rows cover reading the settings file (cat, grep), an agent spec query with jq, the stub fallback log under $KIROCREW_HOME, python -m kiro_crew.mcp_gateway.stub --help through .venv/bin/python, this PR's own targeted pytest run, and kiro-cli mcp list.
  • windows: rows probe the same operations with %USERPROFILE% (cmd) and $env:USERPROFILE / $env:KIROCREW_HOME (PowerShell), \ separators, .venv\Scripts\python.exe and kiro-cli.exe. These cover the diff's one platform assumption: the refusing stub is built through platform_compat.isolated_python_argv / _cmd_safe_command, the cmd-safe path on Windows.
  • any: the kirocrew doctor, doctor --bundle and gateway -vv rows have no path or separator in them.
  • Not coverable: whether the refusing-stub overlay entry actually launches under Windows cmd quoting with an empty --target-command "" argument. That is an overlay launch, not a shell command line a row can carry.

UNADJUDICATED:

  • Guard: rewriter_spec._named_in_tools plus the refused split in _rewrite_single_spec, served at runtime by stub_link._serve_refusal.
  • Call path: _injectable_settings_servers → _rewrite_single_spec(spec, inject_servers=...) → include_mcp_json(spec) (now also honours useLegacyMcpJson: false) → _named_in_tools(inject, spec["tools"]) → a server that isn't named is dropped. If its env holds a secret:// reference, it is instead replaced by _refusing_stub_entry, which offers no tools and answers -32601 to tools/call.
  • Inputs I would have submitted (no verdict was possible):
    1. An agent with no tools key at all. _named_in_tools treats a missing or malformed tools as naming nothing. Such an agent used to get a pooled stub for every settings server; now it gets none. Any secret-bearing server is replaced by a refusing stub, which also takes it away from the host merge. Losing it matters only if kiro-cli would otherwise have exposed that server's tools to an agent with no tools list.
    2. A tools entry that names a server in a form parse_tools_refs may not read as that server: @server/*, @server/tool_*, a server whose raw key differs from its mcp_server_alias, or a case/spelling mismatch between tools and the mcp.json key. If it is missed, the server is no longer pooled. If it is secret-bearing it now gets a refusing stub, which removes a server the author did grant.
    3. An agent that reaches a secret-bearing settings server through allowedTools or toolsSettings but not through tools.
    4. A mode switch onto an agent whose tools differs from the original one, where the overlay was rewritten for the first agent.
  • Hook-held grant row: gate_tiers._tier_batch_guard_grant's new held branch is a loosening, gated on pre_tool_hooks_fire. Surfaces that don't pass the flag (a channel bot's turn) keep asking as before, so nothing is newly refused there.
  • Governance: governance.may_skip_gate_for_session / governance_profiles.session_profiles_govern narrows which profiles withhold a grant, which is also a loosening. Its fallback (an unkeyed session, an unresolved store, or an error) answers like any_configured_profile_governs or withholds, the same as base. Those are admission-policy paths that no shell row can reach.

[SCOPE-REVIEWED] 029d9da

@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 labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/hook_runtime/gate_tiers.py

  • src/kiro_crew/hook_runtime/tool_identity.py

  • src/kiro_crew/hooks.py

  • @bolichen97 posted a complete reasoning template for 029d9da.

@bolichen97
bolichen97 force-pushed the fix/sweep-g1-kas-harness branch from a65fb65 to 309ea27 Compare November 9, 2026 06:36
@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 9, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 309ea27
  • What rule changed: The tool gate's batch-guard-grant row (hook_runtime/gate_tiers.py) can also answer a KAS permission request for an @server/tool grant that the agent spec's own allowedTools grants and that a PreToolUse hook kept at ask (ToolCall.spec_hook_held), but only when the surface says it runs the PreToolUse hooks on that request (pre_tool_hooks_fire, set by the chat, subagent and task-runner turn loops). hooks.py and hook_runtime/tool_identity.py only carry the new field and argument through to that row.
  • Before -> after (what was allowed/blocked, now): Before, such a hook-held grant always showed an approval card, and an unattended turn waited on it, though kiro-cli runs the same spec unprompted. Now, on a turn loop that fires the hooks, the gate answers it with no card after every deny tier and governance, and the hook still runs on the call and can still reject it. On any other surface, such as a channel bot's turn, it keeps asking. Nothing denied before is allowed now: the row runs after every deny tier, and an ungranted tool or an authored ask still prompts.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): A tool the spec already granted runs without a person's click on a surface that does not really run the hook, so the hook's own check is skipped for that call. It cannot reach a tool the spec did not grant, and it cannot pass a deny rule, a governance profile or the sandbox.
  • Evidence checked (which sandbox result proves it): No sandbox rule changed: no sandbox.py file or owner is in the diff. The live repro on a Linux DevSpace host at edb182f1a8, the same patch as this head, ran a real gateway in the default interactive approval mode: no approval card for @docs/lookup, the PreToolUse hook ran once, the tool ran once, and no Kiro Crew-only key reached the wire. test_kas_hook_reach.py::test_a_surface_that_fires_no_hook_keeps_asking pins the channel case, and test_a_dashboard_turn_runs_the_hook_on_the_answered_grant pins that the hook's exit code still decides.
  • No regression:
    • Tools still work (which tools/commands were run, result): In that repro the stdio MCP server answered lookup once. The five other live repros of this PR (trusted sub-agents, tools and mcp.json, useLegacyMcpJson, file:// prompts, glibc floor) each exited 0 on this patch.
    • Backward compatible (old config / old data / old callers still work, how checked): Both new inputs default to off (pre_tool_hooks_fire=False, an empty spec_hook_held), so a caller that passes neither is judged exactly as before, and no harness but KAS fills the field. test_hooks.py pins the new event field and gate argument.
    • Existing tests (which suites passed on this head): At this head, 824 passed and 0 failed over main's 8 newest test files, the facade and rewriter tests and three of this PR's test files. At edb182f1a8 (same patch), 68 test files ran 3973 passed and 0 failed, among them test_hooks.py, test_kas_hook_reach.py and the denied-command and sandbox test files that read security.md. GitHub CI runs the full suites.
  • How to undo: Revert this PR's commit. Narrower: drop the held clause in _tier_batch_guard_grant, so spec_hook_held grants nothing and every hook-held grant asks again.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: each of the six fixes changes the condition that owns its setting, and none of them widens a grant without a hook or a person still deciding.

Notes

  • _named_in_tools treats a missing tools as naming no server. An authored agent with no tools key that used to get every injected mcp.json stub now gets none. The ## Backwards compatibility section is cut off by the truncation notice, so check that it lists that reader.
  • Bundling six defects into one commit means reverting one fix reverts all six. The hook-held grant answer (spec_hook_held plus pre_tool_hooks_fire) is the riskiest of them and would be cheapest to roll back if it were split into its own commit.

[DESIGN-REVIEWED] 029d9da

Description read

[DESCRIPTION-READ] 04438f539523355de7bd47c71bf9d8db7d2b4c91e73a6b0e06438fc744ebc0bd

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

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

Each of the six fixes links an issue (#32973, #32923, #32896) and has counted consumers. Nothing blocks; one in-PR second spelling is noted.

Notes

  • Item 6 — duplicate of src/kiro_crew/agent_sdk/kas_bundle.py:require_loadable_host: install_pinned now writes out the same three host checks inline (_require_loadable_glibc(None, None), host_platform_key(), host_node_key()), and this PR adds that same sequence to require_loadable_host too. That is 2 copies, grepped in the patch, and they will drift apart. Subtraction: keep the three calls in one function in acp/kas_bundle.py and have both install_pinned and require_loadable_host call it.

What this change ships

Inventory (9 items) — 8 justified

Intent: an agent spec gets on KAS and with the global mcp.json what its own settings say. This is a FIX, six bundled fixes.

  1. Trusted trustedAgents sub-agents spawn without a prompt in chat when only other-surface or other-app profiles turn spawning off — justified
  2. MCP grants covered by a PreToolUse hook run without an approval card on chat, subagent and task-runner turns — justified
  3. An agent with a narrow tools list no longer gets stubs for mcp.json servers it does not name, and KAS no longer gets includeMcpJson: true — justified
  4. A left-out server whose env holds a secret:// reference gets a refusing stub (--refuse) that starts nothing — justified
  5. useLegacyMcpJson: false now keeps the global servers out on the rewriter side — justified
  6. A host below the glibc floor, or with no build for its OS or architecture, is refused before the manifest fetch, with a final error that does not suggest a retry — duplicate of agent_sdk/kas_bundle.require_loadable_host, which has the same three checks
  7. doctor and kirocrew kas install name the unsupported-host cause — justified
  8. The agent-spec reference states kiro-cli v3's file:// prompt rule — justified
  9. Sessions, including the auto-improvement runners, pass their session key and owning app to the KAS projection — justified

[FIRST-PRINCIPLES-REVIEWED] 029d9da

Description read

[DESCRIPTION-READ] 698dada67e86465c4310e1f9bc81e1a8e9e0c016db1f8a10fde5a886ef3a1cf4

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 029d9da

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

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

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 9, 2026
buluoray
buluoray previously approved these changes Nov 9, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving. Six KAS fixes: trustedAgents is judged per session; hook-held MCP grants are answered only where PreToolUse hooks still fire; mcp.json stubs follow tools and useLegacyMcpJson; the glibc floor is a final error; and a file:// doc. Each new grant is still bounded by the spec's own allow list, the deny tiers, governance and the hook (hook_runtime/gate_tiers.py:1632, platform/governance_profiles.py:1067-1103, platform/governance.py:843-870, mcp_gateway/rewriter_spec.py:436-459, 530-533, dashboard/chat_turn/tool_approval.py:739-741, 912-962). Tests are green and mutations turn them red.

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 9, 2026
@bolichen97
bolichen97 force-pushed the fix/sweep-g1-kas-harness branch from 309ea27 to 35ad16a Compare November 9, 2026 14:43
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 35ad16a
  • What rule changed: The tool gate's batch-guard-grant row (hook_runtime/gate_tiers.py) can also answer a KAS permission request for an @server/tool grant that the agent spec's own allowedTools grants and that a PreToolUse hook kept at ask (ToolCall.spec_hook_held), but only when the surface says it runs the PreToolUse hooks on that request (pre_tool_hooks_fire, set by the chat, subagent and task-runner turn loops). hooks.py and hook_runtime/tool_identity.py only carry the new field and argument through to that row.
  • Before -> after (what was allowed/blocked, now): Before, such a hook-held grant always showed an approval card, and an unattended turn waited on it, though kiro-cli runs the same spec unprompted. Now, on a turn loop that fires the hooks, the gate answers it with no card after every deny tier and governance, and the hook still runs on the call and can still reject it. On any other surface, such as a channel bot's turn, it keeps asking. Nothing denied before is allowed now: the row runs after every deny tier, and an ungranted tool or an authored ask still prompts.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): A tool the spec already granted runs without a person's click on a surface that does not really run the hook, so the hook's own check is skipped for that call. It cannot reach a tool the spec did not grant, and it cannot pass a deny rule, a governance profile or the sandbox.
  • Evidence checked (which sandbox result proves it): No sandbox rule changed: no sandbox.py file or owner is in the diff. The live repro on a Linux DevSpace host at 6f588dbbb3 (this patch on main 3987f3a) ran a real gateway in the default interactive approval mode: no approval card for @docs/lookup, Kiro Crew answered the engine's request in 0.77 s after the PreToolUse hook ran once, the tool ran once, and no Kiro Crew-only key reached the wire. This head is a rebase of 309ea27 onto main 445dd36 with the same patch for gate_tiers.py, tool_identity.py and hooks.py (same patch-id). test_kas_hook_reach.py::test_a_surface_that_fires_no_hook_keeps_asking pins the channel case, and test_a_dashboard_turn_runs_the_hook_on_the_answered_grant pins that the hook's exit code still decides.
  • No regression:
    • Tools still work (which tools/commands were run, result): In that repro the stdio MCP server answered lookup once. The five other live repros of this PR (trusted sub-agents, tools and mcp.json, useLegacyMcpJson, file:// prompts, glibc floor on Amazon Linux 2) each exited 0 at 6f588dbbb3.
    • Backward compatible (old config / old data / old callers still work, how checked): Both new inputs default to off (pre_tool_hooks_fire=False, an empty spec_hook_held), so a caller that passes neither is judged exactly as before, and no harness but KAS fills the field. test_hooks.py pins the new event field and gate argument.
    • Existing tests (which suites passed on this head): At 6f588dbbb3, 158 test files ran 8517 passed, 19 skipped and 0 failed, among them test_hooks.py, test_kas_hook_reach.py, the 23 changed and added test files and every test file main changed since 6cff114. At edb182f1a8 (same patch), 68 test files ran 3973 passed and 0 failed, among them the denied-command and sandbox test files that read security.md. GitHub CI runs the full suites.
  • How to undo: Revert this PR's commit. Narrower: drop the held clause in _tier_batch_guard_grant, so spec_hook_held grants nothing and every hook-held grant asks again.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 9, 2026

@buluoray buluoray left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes at 35ad16a (security). We missed this when we approved 309ea27; the code is unchanged since then, and main has no _named_in_tools, so this PR introduces it.

The new _named_in_tools filter (src/kiro_crew/mcp_gateway/rewriter_spec.py:536) drops every settings server that tools does not name, including servers whose env carries a secret:// value. Those servers must stay wrapped by a refusing stub (_must_stay_wrapped, same file :658 and :834), so they never launch with a literal secret:// value. Once the stub is gone, kiro-cli merges mcp.json itself and launches the server as is.

Suggested fix: when an entry has _must_stay_wrapped true and tools does not name it, still emit the refusing stub instead of leaving it to the kiro-cli merge. Opus 5.5 flagged this at 14:55Z on this head, and we confirmed it in source.

@bolichen97
bolichen97 force-pushed the fix/sweep-g1-kas-harness branch from 35ad16a to 08c3064 Compare November 10, 2026 01:53
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: the _named_in_tools filter this PR added to rewriter_spec._rewrite_single_spec

  • BLOCKING src/kiro_crew/mcp_gateway/rewriter_spec.py: the tools filter dropped the stub of a secret:// settings server span=2fa39bbbe174

fixed in 08c3064: an agent whose tools leaves out a routed mcp.json server whose env holds a secret:// reference now gets a refusing stub under that name (rewriter_spec._refusing_stub_entry). It is sent at session/new, so it outranks kiro-cli's own merge of the file. It runs stub --refuse, which starts nothing, never reaches the gateway and answers as a server with no tools (stub_link._serve_refusal), and it names no target, so no launch approval of that server can serve this agent. An agent with includeMcpJson: false or useLegacyMcpJson: false still gets none, since nothing is merged into it.
Evidence: test_secret_uri_launch_paths.py::test_a_settings_server_with_a_reference_gets_a_refusing_stub_when_tools_omits_it covers tools absent, [] and ["@other"] with a resolvable and an unresolvable command. All six cases fail with the fix's production files reverted and pass at this head, and the stub run through its own entry point answers initialize, tools/list, ping and a refused tools/call and exits 0 when stdin closes.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 08c3064
  • What rule changed: The tool gate's batch-guard-grant row (hook_runtime/gate_tiers.py) can also answer a KAS permission request for an @server/tool grant that the agent spec's own allowedTools grants and that a PreToolUse hook kept at ask (ToolCall.spec_hook_held), but only when the surface says it runs the PreToolUse hooks on that request (pre_tool_hooks_fire, set by the chat, subagent and task-runner turn loops). hooks.py and hook_runtime/tool_identity.py only carry the new field and argument through to that row.
  • Before -> after (what was allowed/blocked, now): Before, such a hook-held grant always showed an approval card, and an unattended turn waited on it, though kiro-cli runs the same spec unprompted. Now, on a turn loop that fires the hooks, the gate answers it with no card after every deny tier and governance, and the hook still runs on the call and can still reject it. On any other surface, such as a channel bot's turn, it keeps asking. Nothing denied before is allowed now: the row runs after every deny tier, and an ungranted tool or an authored ask still prompts.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): A tool the spec already granted runs without a person's click on a surface that does not really run the hook, so the hook's own check is skipped for that call. It cannot reach a tool the spec did not grant, and it cannot pass a deny rule, a governance profile or the sandbox.
  • Evidence checked (which sandbox result proves it): No sandbox rule changed: no sandbox.py file or owner is in the diff. The live repro on a Linux DevSpace host at this head ran a real gateway in the default interactive approval mode: no approval card for @docs/lookup, Kiro Crew answered the engine's request in 0.16 s after the PreToolUse hook ran once, the tool ran once, and no Kiro Crew-only key reached the wire. This head rebases the reviewed patch onto main 73e3275 and adds a refusing gateway stub in mcp_gateway/ for a review finding; gate_tiers.py, tool_identity.py and hooks.py carry the same patch as at 35ad16a (same patch-id for each). test_kas_hook_reach.py::test_a_surface_that_fires_no_hook_keeps_asking pins the channel case, and test_a_dashboard_turn_runs_the_hook_on_the_answered_grant pins that the hook's exit code still decides.
  • No regression:
    • Tools still work (which tools/commands were run, result): In that repro the stdio MCP server answered lookup once. The five other live repros of this PR (trusted sub-agents, tools and mcp.json, useLegacyMcpJson, file:// prompts, and the glibc floor on Amazon Linux 2) each exited 0 at this head.
    • Backward compatible (old config / old data / old callers still work, how checked): Both new inputs default to off (pre_tool_hooks_fire=False, an empty spec_hook_held), so a caller that passes neither is judged exactly as before, and no harness but KAS fills the field. test_hooks.py pins the new event field and gate argument.
    • Existing tests (which suites passed on this head): At this head, 429 test files ran 18789 passed, 957 skipped and 1 failed, among them test_hooks.py, test_kas_hook_reach.py, every changed and added test file, every test file main changed since 01fcf6d and every ratchet, guard and contract file. The one failure is a 30 s subprocess timeout under load in test_push_guard_diagnostics.py, which this PR does not touch; alone it passed 3 runs of 3. GitHub CI runs the full suites.
  • How to undo: Revert this PR's commit. Narrower: drop the held clause in _tier_batch_guard_grant, so spec_hook_held grants nothing and every hook-held grant asks again.

@bolichen97

Copy link
Copy Markdown
Contributor Author

On the change request at 35ad16a (review 5827828909, the secret:// settings server dropped by the _named_in_tools filter): fixed in 08c3064 as suggested. When an entry has _must_stay_wrapped true and tools does not name it, _rewrite_single_spec now emits a refusing stub for it (rewriter_spec._refusing_stub_entry, run as stub --refuse), so kiro-cli's own merge of mcp.json is outranked and never launches it with the literal value. The stub starts nothing, never reaches the gateway, offers no tools and names no target. includeMcpJson: false and useLegacyMcpJson: false agents still get no entry. The six cases of test_a_settings_server_with_a_reference_gets_a_refusing_stub_when_tools_omits_it (tools absent, [] or ["@other"]; command resolvable or not) fail with the fix reverted and pass at this head. The review stays open for its author to re-check.

@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 10, 2026
- trustedAgents on KAS: a trusted sub-agent allow is judged by the
  profiles that govern this session, so it is no longer dropped.
- Hook-covered grants on KAS: Kiro Crew answers an allowedTools MCP grant
  a preToolUse hook holds at ask on the chat, subagent and task-runner
  turn loops, which tell the gate the hook runs on the request, so the
  chat stops waiting on a person. Any other surface keeps asking.
- tools allowlist: mcp.json stubs and KAS includeMcpJson follow the
  agent's tools, so a narrow agent no longer gets every mcp.json tool.
  A routed mcp.json server whose env holds a secret:// reference that
  tools leaves out gets a refusing stub instead, which starts nothing
  and offers no tools, so the host's own mcp.json merge cannot start
  it with the literal reference.
- useLegacyMcpJson: the rewriter reads kiro-cli's alias through the
  reader the KAS projection uses (mcp_cleanup.include_mcp_json), so an
  agent with useLegacyMcpJson: false gets no injected mcp.json stubs.
- glibc floor: below the engine's glibc 2.28 (Amazon Linux 2) chat,
  dashboard and doctor name the cause and a newer image, not a retry.
- file:// prompts: the spec reference states kiro-cli v3 refuses an
  absolute or ~ file:// prompt and why Kiro Crew keeps accepting it.

Both rewriter changes share one move of the rewrite fingerprint schema
to 14, so a kept overlay holding stale injected stubs is rebuilt. The
app agent-turn SDK, which the meetings dispatch runs through, names its
app at session allocation, and a reset or compaction successor keeps
the app of the session it replaces, so those sessions judge the allow
under that app.

Fixes #32973
Fixes #32923
Fixes #32896
@bolichen97
bolichen97 force-pushed the fix/sweep-g1-kas-harness branch from 08c3064 to 029d9da Compare November 10, 2026 09:36
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: rewriter_spec._excludes_global_mcp_json, the second reader of the mcp.json opt-in that this PR added for useLegacyMcpJson
resolution: removed

  • Second opt-in reader for useLegacyMcpJson, duplicate span=ddc045f456ba

fixed in 029d9da: _excludes_global_mcp_json is deleted, and rewriter_spec._rewrite_single_spec tests include_mcp_json(spec) is False. include_mcp_json moved unchanged to kiro_crew.mcp_cleanup, which both sides already import, because scripts/check_agent_sdk_boundary.py forbids mcp_gateway/ importing kiro_crew.acp; kas_settings_mcp re-exports it, so the rewriter and the KAS projection call one function and no reader of the rewriter's own is left. test_mcp_gateway_rewriter.py::TestSettingsInjection::test_injection_reads_the_opt_in_the_kas_projection_reads checks the rewriter against kas_settings_mcp.include_mcp_json on six spellings, {"includeMcpJson": "x", "useLegacyMcpJson": false} among them; with the old reader put back at the call site, junk-then-false and null-then-false fail on the assertion.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 10, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Automated, not a person, and not a review: a maintainer still decides.

decider-v3c@217fe607 · p_defect 0.2 · router R0 (approves only when p_defect <= 0.12, on changes of at most 400 changed lines) · head 029d9dabe3 · 2619 changed lines

Why: the decider approves but is not confident enough to auto-approve (p_defect 0.2 > 0.12).

Six bundled KAS/mcp.json fixes; I checked each against the code. (1) Hook-held MCP grants: the gate answers one only when pre_tool_hooks_fire is set, and only chat, subagent and task-runner set it. Chat fires PreToolUse hooks after an auto-approve and the subagent/task ladders run the SpecHooks floor before the gate, so a hook's exit 2 still blocks. Deny rows and governance still run first; child calls never carry the held set; the record key is in CREW_ONLY_ENTRY_KEYS so it is stripped from the wire. (2) The rewriter now pools only servers named in tools, matching ToolsAllowlist's reading of a missing tools, and shares one include_mcp_json reader with KAS. The refusing stub names no target and only narrows access; fingerprint schema moved to 14. (3) The trusted-agents allow now asks only the session's resolvable profiles: active scope including the unattended deny-all, every task bind, and the session's app bind or all app binds when the app is unknown. Errors withhold. owning_app falls back to app_name, the app runners set it, and successors keep it. (4) Host checks run before the manifest fetch, raise KasHostUnsupported, and that type is kept through to a non-retryable error

If this recommendation is wrong, reply here; the replies are how the approver is evaluated.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 029d9da
  • What rule changed: The tool gate's batch-guard-grant row (hook_runtime/gate_tiers.py) can also answer a KAS permission request for an @server/tool grant that the agent spec's own allowedTools grants and that a PreToolUse hook kept at ask (ToolCall.spec_hook_held), but only when the surface says it runs the PreToolUse hooks on that request (pre_tool_hooks_fire, set by the chat, subagent and task-runner turn loops). hooks.py and hook_runtime/tool_identity.py only carry the new field and argument through to that row.
  • Before -> after (what was allowed/blocked, now): Before, such a hook-held grant always showed an approval card, and an unattended turn waited on it, though kiro-cli runs the same spec unprompted. Now, on a turn loop that fires the hooks, the gate answers it with no card after every deny tier and governance, and the hook still runs on the call and can still reject it. On any other surface, such as a channel bot's turn, it keeps asking. Nothing denied before is allowed now: the row runs after every deny tier, and an ungranted tool or an authored ask still prompts.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): A tool the spec already granted runs without a person's click on a surface that does not really run the hook, so the hook's own check is skipped for that call. It cannot reach a tool the spec did not grant, and it cannot pass a deny rule, a governance profile or the sandbox.
  • Evidence checked (which sandbox result proves it): No sandbox rule changed: no sandbox.py file or owner is in the diff. The live repro on a Linux DevSpace host at 24e1b1e739, the same patch one main rebase earlier, ran a real gateway in the default interactive approval mode: no approval card for @docs/lookup, Kiro Crew answered the engine's request in 0.16 s after the PreToolUse hook ran once, the tool ran once, and no Kiro Crew-only key reached the wire. This head rebases the patch onto main 51242a5 and moves the gateway rewriter's mcp.json opt-in reader onto the KAS projection's (mcp_cleanup.include_mcp_json) for a review finding; gate_tiers.py, tool_identity.py and hooks.py carry the same patch as at 08c3064 and 35ad16a (same patch-id for each). test_kas_hook_reach.py::test_a_surface_that_fires_no_hook_keeps_asking pins the channel case, and test_a_dashboard_turn_runs_the_hook_on_the_answered_grant pins that the hook's exit code still decides.
  • No regression:
    • Tools still work (which tools/commands were run, result): In that repro the stdio MCP server answered lookup once. The five other live repros of this PR (trusted sub-agents, tools and mcp.json, useLegacyMcpJson, file:// prompts, and the glibc floor on Amazon Linux 2) each exited 0 at 24e1b1e739.
    • Backward compatible (old config / old data / old callers still work, how checked): Both new inputs default to off (pre_tool_hooks_fire=False, an empty spec_hook_held), so a caller that passes neither is judged exactly as before, and no harness but KAS fills the field. test_hooks.py pins the new event field and gate argument.
    • Existing tests (which suites passed on this head): At 24e1b1e739, 184 test files ran 10368 passed, 21 skipped, 0 failed, among them test_hooks.py, test_kas_hook_reach.py, the channel, cron and messaging spec-hook tests, every changed and added test file, and the ratchet, guard and contract files. At this head, the two backend test files main changed since, the harness contract and the rewriter tests ran 426 passed, 2 skipped, 0 failed. GitHub CI runs the full suites.
  • How to undo: Revert this PR's commit. Narrower: drop the held clause in _tier_batch_guard_grant, so spec_hook_held grants nothing and every hook-held grant asks again.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 10, 2026
@bolichen97
bolichen97 merged commit d4f82fb into main Nov 10, 2026
117 of 119 checks passed
@bolichen97
bolichen97 deleted the fix/sweep-g1-kas-harness branch November 10, 2026 11:49
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 10, 2026
@LuisBrel LuisBrel mentioned this pull request Nov 10, 2026
5 tasks done
bolichen97 added a commit that referenced this pull request Nov 10, 2026
…fixes (#33510)

Backport of the parts of #33510 that release/0.12.0 can carry:

- tools allowlist: mcp.json stubs and KAS includeMcpJson follow the
  agent's tools, so a narrow agent no longer gets every mcp.json tool.
  A routed mcp.json server whose env holds a secret:// reference that
  tools leaves out gets a refusing stub instead, which starts nothing
  and offers no tools, so the host's own mcp.json merge cannot start
  it with the literal reference.
- useLegacyMcpJson: the rewriter reads kiro-cli's alias through the
  reader the KAS projection uses (mcp_cleanup.include_mcp_json), so an
  agent with useLegacyMcpJson: false gets no injected mcp.json stubs.
- glibc floor: below the engine's glibc 2.28 (Amazon Linux 2) chat,
  dashboard and doctor name the cause and a newer image, not a retry.
- file:// prompts: the spec reference states kiro-cli v3 refuses an
  absolute or ~ file:// prompt and why Kiro Crew keeps accepting it.

Both rewriter changes share one move of the rewrite fingerprint schema
to 14, so a kept overlay holding stale injected stubs is rebuilt.

Fixes #32973
Fixes #32923
Fixes #32896

(cherry picked from commit d4f82fb)

Backport note: left out the trustedAgents on KAS fix. Release has no
canonical_tools_settings, trusted_agents_withheld or per-session
governance (may_skip_gate_for_session, session_profiles_govern), so the
governance_app and governance_scope plumbing and its test and
governance.md hunks are not carried.
Backport note: left out the hook-covered grants fix. Its only answerer
is the batch-guard-grant gate row and batch_guard._auto_approved, which
are not on release, so CREW_ANSWERED_HOOK_HELD_KEY, hook_held_grants,
spec_hook_held, pre_tool_hooks_fire and their tests and docs are not
carried.
Backport note: dropped the app files (apps/agent_turn_sdk.py,
parked_queue owning_app, auto_improvement runners and its test) as out
of scope; src/kiro_crew/acp/harness/kas_cloud.py,
test_kas_tools_settings_aliases.py and test_app_agent_turn_sdk.py stay
deleted as on release.
Backport note: kas_agents_registered.py (a pure move of the projected_*
and switched_* readers) is not carried; they stay in kas_agents.py.
Backport note: kas_agents.py keeps release's imports and
to_client_custom_agent body, with only the includeMcpJson-true-stays-off
-the-wire change and the resolve_prompt docstring applied.
Backport note: agent-spec-fields.md and security.md take release's text
plus the includeMcpJson, prompt and secret:// refusing stub hunks; the
hooks row and the hook-held security paragraph are not carried.
KiroCrewCaptain added a commit to KiroCrewCaptain/kirocrew-app-auto-improvement that referenced this pull request Nov 13, 2026
Ports, with their tests, the fixes the Kiro Crew wheel copy took after
the GitLab change:

- kirodotdev/KiroCrew#33556: on Windows the dependency check resolves
  git, gh and glab from PATH's absolute entries only.
- kirodotdev/KiroCrew#33565: pinning git attributes refuses a Windows
  directory junction as it refuses a symlink.
- kirodotdev/KiroCrew#34238: a session key ending in a newline is
  refused.
- kirodotdev/KiroCrew#33510: member and runner-built sessions name this
  app as their owning_app, so their governance reads are judged under
  the same app as their tool calls.
- kirodotdev/KiroCrew#35779: the suite's git reads no host global
  config, so a host core.hooksPath cannot refuse a fixture commit.

The runner coverage docstring drops its stale location claim
(kirodotdev/KiroCrew#35994).

Co-authored-by: KiroCrewCaptain <312312717+KiroCrewCaptain@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants