Skip to content

fix(acp): carry a kirocrew-core disabledTools toggle on the session gate where the backend prompts - #17859

Closed
chenmingwei23 wants to merge 1 commit into
mainfrom
fix/14125-core-tool-toggle-failsafe
Closed

chenmingwei23 wants to merge 1 commit into
mainfrom
fix/14125-core-tool-toggle-failsafe

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Let an operator switch off a single kirocrew-core tool from the dashboard's MCP tab without refusing every session of an agent whose spec stands on that server — and keep that toggle authoritative on every approval path, including when a spec edit lands between a session's mount and its activation.

Disabling one kirocrew-core tool writes disabledTools into the global mcp.json. On the kiro backend the control plane is mounted as a per-session element, and that element cannot express disabledTools (a kiro-cli-only key), so the mount withheld the element and refused every new session of an agent standing on it until the toggle was undone. The toggle's apparent promise (lose one tool) and its effect (lose the agent's sessions) diverged.

Why it matters

Turning off one tool should cost one tool, not the agent. The control plane has a per-call permission channel that can honour the toggle instead of refusing: its tools carry no annotations, so every call reaches Crew as a permission request the client can reject.

What changed

At the single point where the mount decides to withhold or carry (kiro_control_plane_servers), a well-formed disabledTools on a control-plane server now mounts the element and carries the toggled (server, tool) pairs onto the session's per-call gate (AcpSessionHandle.spec_denied_tools), via _unpooled_control_planes which returns those pairs for the start paths to feed the gate. The session runs minus the toggled tool rather than being refused. The skill projection applies the same decision so it never promises a view the mount then withholds.

If a kirocrew-core toggle cannot be honoured safely, it fails closed (refuses or keeps withholding) rather than mounting under a deny that would not apply:

  • a tool the spec's allowedTools auto-approves is withheld (kiro-cli sends no permission request for it, so a carried deny would not take effect);
  • a malformed disabledTools value is withheld (it yields no deny pairs, so carrying it would silently drop the toggle);
  • skill_search itself disabled refuses a search agent's session (it would start with its skill resources already dropped and every search call refused — worse than a clean refusal).

Activation guard (mid-life edit window)

The mount judges one spec from one read. An edit to that spec landing between session/new and the spec kiro-cli activates for the session could otherwise start the session under settings the user has since changed (a tool they disabled staying callable). To close that window, the mount records a sha256 fingerprint of the resolved agent spec at session/new (read through the mount's own resolver, project-nearest), and _activate_mode_bracketed re-reads the spec the same way before the first turn. If the fingerprint changed, or the spec cannot be read, the session fails closed (refuses) with a plain message telling the user to reopen the chat; the next start reads the current spec. A whole-spec fingerprint closes the window by construction — any change refuses, with no per-field predicate to leave a case uncovered. This replaces an earlier deny-set comparison that could miss the case where the activated spec withholds the control-plane element.

Not a goal

  • The default kirocrew agent. It grants @kirocrew-core whole-server in allowedTools, so kiro-cli auto-approves every core tool with no permission request; a carried deny could not take effect there, so a toggle on the default agent keeps the existing withhold-and-refuse behaviour (now the auto-approve fallback above).
  • Narrowing a whole-server grant into per-tool grants (a materialisation-time change) is out of scope.
  • Broader hardening of the skill-view lifecycle tracked in kirocrew-core disabledTools: close the mid-life allowedTools/spec edit window at activation (follow-up to #14125) #18322 stays out of scope; this PR closes only the specific mid-life window above (a late grant defeating a carried deny), with the fail-closed activation guard.

Tests

test/test_native_skill_projection_sources.py drives the carry/withhold decision through the runtime start path (the user-visible path that was refused on main): a tool disabled in global/project/spec is carried and the element mounts; a malformed list, a bare */whole-server grant, and skill_search itself each keep the fail-safe (withhold/refuse); a control character in a toggled tool name cannot forge a log line. test/test_acp_set_mode_projection_fallback.py drives the activation guard with one test per case: a spec that changed in the gap refuses, an unchanged spec starts, an unreadable spec fails closed, and the withheld-core-plus-added-restriction case is refused. test/test_session_token_identity.py is updated so the disabledTools cases assert the carry (element mounts, pair on the gate) rather than the old withhold.

Pattern harvest

Rule candidate: review-prompt
Pattern: a per-field recheck of a config read once and consumed later (here, comparing the deny set a spec yields at two points) repeatedly missed a new edge each review round, because any field the comparison does not model is a gap. A whole-artifact fingerprint compared across the two reads closes the class by construction: any change refuses, so there is no uncovered field. Review prompt: when a review finds that a settings artifact read at one point is consumed at a later point, prefer fingerprinting the whole artifact and refusing on any difference over a predicate that compares selected fields.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🔴 BLOCK

Premise-level review of 699a74839bd1e3236a5242b6c7d71f595d4a88b3 — 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: BLOCK

_spec_without_volatile_env is a second copy of worker_agent._without_volatile_mcp_env, and the PR's own comment calls it "the acp-layer twin" of that helper.

Not justified as shipped

  • Item 7 — duplicate of src/kiro_crew/agent_materialization/worker_agent.py:_without_volatile_mcp_env: the diff says this helper is "The acp-layer twin of agent_materialization.worker_agent._without_volatile_mcp_env, applying the SAME volatile_env_keys list".
Inventory (9 items) — 8 justified

Intent: let an operator switch off one kirocrew-core tool without every session of the agent being refused. FIX.

  1. Disabling one core tool on a prompting agent now costs that tool, not the agent's sessions — justified
  2. A toggled tool that allowedTools auto-approves still refuses the session — justified
  3. A malformed disabledTools still refuses the session — justified
  4. A disabled skill_search refuses a search agent, with a new message pointing at the MCP tab — justified
  5. The skill-search view is no longer refused when the spec disables other core tools — justified
  6. Any edit to the agent spec between session start and activation now refuses the session with "Reopen the chat" — justified
  7. A new spec normalizer that masks volatile env values before hashing — duplicate of worker_agent._without_volatile_mcp_env
  8. The worker-exclusion grant matcher is now shared as grant_reaches_any — justified
  9. The acp-client spec now describes the carry — justified

Blockers

Second spelling of the volatile-env normalizer.
The two helpers do the same job: walk mcpServers[*].env and replace values whose keys are in volatile_env_keys(). I counted 1 existing implementation by grepping _without_volatile_mcp_env and volatile_env_keys(). The stated reason for copying it is "keeping the acp layer off that module". The diff contradicts that reason:

  • _activate_mode_bracketed already imports require_fresh_derived_spec from kiro_crew.agent.
  • This PR re-exports grant_reaches_any through agent.py's _EXPORTS_BY_OWNER for session_mcp.

Subtraction: delete _spec_without_volatile_env and _VOLATILE_ENV_SENTINEL from runtime.py. Re-export _without_volatile_mcp_env through agent.py the same way grant_reaches_any is re-exported, and call it from _resolved_spec_fingerprint.
Clears when: runtime.py no longer defines its own volatile-env normalizer and _resolved_spec_fingerprint calls the existing one.

[FIRST-PRINCIPLES-REVIEWED] 699a748

Description read

[DESCRIPTION-READ] 63387b07ba6ebd0493613c36a6290bc1bb271a9f01b7f666f9f362bd5864f41b

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

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

The activation fingerprint comes from a second spec read taken after the mount's own read, so the edit window is narrowed, not "closed by construction". The new refusal also covers every session.

Watch

  • The fingerprint does not describe the spec the carry decision used. _unpooled_control_planes reads the spec and decides what to carry. _own_stub_session then runs, and only after that is spec_fingerprint = await asyncio.to_thread(_resolved_spec_fingerprint, ...) read again from disk. Suppose an edit lands between those two reads, for example adding @kirocrew-core/<tool> to allowedTools. The fingerprint then records the edited spec, activation finds it unchanged, and the session runs on a carried deny that kiro-cli never prompts for. That is the fail-open case the PR says it removes.
    Clears when: kiro_control_plane_servers hashes the spec dict it actually judged and returns that hash with carried, plus a test that edits the spec between the mount and the fingerprint.
  • A narrow fix adds a refusal on the core session-start path. The fingerprint is recorded for every non-mirrored session/new and resume, not only when mount.carried is non-empty. So any write to the resolved spec during that gap now aborts the session with "Reopen the chat". Normalising only the volatile env nonce shows that Crew-side writers do touch this spec on every launch. The description has no ## Backwards compatibility section and names no other writer.
    Clears when: the guard only runs when carried is non-empty, or the description lists the in-process writers of the agent spec during session start and gives the test showing each one leaves the fingerprint unchanged.

[DESIGN-REVIEWED] 699a748

Description read

[DESCRIPTION-READ] 3d432c0cd9759a6dda3c41fab04bddce7eeada7185733bf0c914c412cb59ac12

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — 🔴 changes requested (blocking)

GPT 6.1 found at least one blocking issue that must be resolved before merging 699a74839bd1e3236a5242b6c7d71f595d4a88b3. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/acp/runtime.py:7025 -- Fingerprint does not cover the spec used by the mount

spec_fingerprint = await asyncio.to_thread(
With learn_add disabled globally, add @kirocrew-core to a warm custom search agent’s allowedTools -> _unpooled_control_planes mounts using the cached projection, but this read fingerprints the edited source -> activation refreshes to that source, the fingerprints match, and kiro-cli auto-approves the disabled tool without reaching the deny gate. load_session repeats the same mismatch.
Anchor: backend-security-controls
Fix: Record the authored-spec fingerprint alongside its prepared projection and propagate that mount snapshot through create/load; compare it at activation instead of independently re-reading after mounting.
[BLOCK-MERGE] 699a748
[GPT-REVIEWED] 699a748

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1: unbounded-harm claim, since a disabled tool would get auto-approved and skip the deny gate. _unpooled_control_planes decides what to mount and carry from the cached projection (spec_override, src/kiro_crew/acp/runtime.py:6815-6826). The fingerprint at runtime.py:7025-7028 instead re-reads the source spec with _agent_spec_for (runtime.py:901-930). The activation check at runtime.py:6283-6286 reads the source the same way, so the two reads match and the stale projection is never compared.
The trigger is an operator editing a warm agent's allowedTools while a global disabledTools toggle is set. Both are ordinary operator actions, not extreme timing, so I could not build a rarity record to justify a FLAG.

[ADJUDICATION] 699a74839bd1e3236a5242b6c7d71f595d4a88b3 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 699a74839bd1e3236a5242b6c7d71f595d4a88b3

[ADJUDICATION-FENCED] 699a74839bd1e3236a5242b6c7d71f595d4a88b3 fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/acp/runtime.py:7025 -- The mount reads the cached projection but the fingerprint and activation both read the source spec, so an ordinary edit to a warm agent's spec defeats the check without any extreme condition.
[GPT-ADJUDICATED-FENCED] 699a74839bd1e3236a5242b6c7d71f595d4a88b3

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

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings that block the merge; one advisory finding on wrong remedy text.

FINDING — src/kiro_crew/acp/runtime.py:6844 — The refusal always says "Re-enable skill_search in the dashboard's MCP tab", but mount.carried also collects pairs from the project's .kiro/settings/mcp.json (native_declarations). That tab writes only the global file, so a user whose skill_search toggle lives in the project file gets told to use a control that changes nothing, and the search agent keeps failing to start. Before this change the withheld path gave a source-aware withheld.explain(...) here. → Fix: name the declaring source and build the remedy with _remedy(..., tab=<source is global>), the same way NativeMountWithholding.explain does.

[OPUS-REVIEWED] 699a748

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

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

@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from 8ff2520 to c967c07 Compare October 7, 2026 23:57
@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 Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 699a74839bd1e3236a5242b6c7d71f595d4a88b3 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@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 Oct 8, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from c967c07 to 07ffec5 Compare October 8, 2026 01:13
@chenmingwei23 chenmingwei23 changed the title fix(acp): carry a kirocrew-core disabledTools toggle on the session gate instead of refusing fix(acp): carry a kirocrew-core disabledTools toggle on the session gate where the backend prompts Oct 8, 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 Oct 8, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from 07ffec5 to d0eff24 Compare October 8, 2026 02:34
@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 Oct 8, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from d0eff24 to d8b5ae9 Compare October 8, 2026 03: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 readiness: checking Automated validation is still running labels Oct 8, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from d8b5ae9 to 634e506 Compare October 8, 2026 05:34
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 9, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from c0a80a4 to a9c2791 Compare October 9, 2026 01:42
@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 Oct 9, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Fixed in a9c2791546 — no override.

F1 (a mounted server with no carried deny escaped the withheld check): the activation reconcile intersected the live mount's withheld set with only the servers the gate already carries a deny for. A server the session mounted auto-approved — cron through @kirocrew-cron, which carries no deny pair — was never in that set, so when a cron_add toggle landed during session/new and the live mount withheld cron's element, the reconcile skipped it and the switched-off tool stayed callable.

The reconcile now intersects the live withheld set with the full roster of identity-bound servers this session actually mounted an element for, not only the carried-deny subset:

  • The mounted roster is read back from the composed mcpServers array (the identity-bound names present in it) and threaded through the start paths to the reconcile.
  • The withheld check is now live_withheld & (carried_deny_servers | mounted_servers), so a mounted server the live spec withholds refuses even when the gate carried no deny for it.

Fail-safe shape kept — the reconcile still only ever refuses a mode switch, never relaxes a restriction. New test pins the case: cron mounted with an empty carried-deny set, the live mount withholds cron, the switch is refused; a server the session did not mount (empty roster) is not refused, so the roster, not the mere withholding, drives it.

@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from a9c2791 to be8fd3e Compare October 9, 2026 02:19
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed on be8fd3e0fd77cb715871a367d3722da26435ec48.

Pooled broker stub counted as mounted (the FINDING) — fixed.

You are right. _mounted_identity_servers scraped every identity-bound name in the composed array, which also contains a pooled kirocrew-core broker stub (the operator opt-in stub_servers). The unpooled mount emits no per-session element for a name the array already carries, and the mount can itself withhold that stub — so the reconcile re-read the same withholding and would have refused every start and resume of a session meant to run on the stub.

The roster is now exactly the elements the unpooled mount added: _mounted_identity_servers(composed, pre_existing) returns the identity-bound names in composed minus those already in pre_existing (the array the caller passed in, i.e. the pooled stubs). Both call sites pass pooled as pre_existing. A stub that was already in the array is not in the roster, so a mount that withholds it no longer refuses a session that legitimately runs on it. New unit test test_mounted_identity_servers_excludes_a_pooled_broker_stub pins this: a pre-existing kirocrew-core stub plus a mount-added kirocrew-cron element yields a roster of {kirocrew-cron} only.

The server/tool argument-injection path — not reachable here.

The gate does not read the model's own arguments for identity. identified_mcp_call reads server/tool only from raw_params_trusted — the params cached from the preceding tool_call frame (the adapter's own resolution, filled from raw_params_cache keyed by toolCallId), or from a gate-envelope read. An inline dict on an ordinary permission frame leaves raw_params_trusted False (_dispatch.py sets it only on a cache hit or a non-truncated envelope), so the model's {"server":"x","tool":"y"} is never the identity source. On the kiro backend the identity flows through the _meta.kiro.mcpServerName/tool-name cache (mcp_identity_trusted) — the second trusted channel — which the model also cannot forge. Both channels are harness-resolved and unreachable by the model, as the function's own contract states ("neither is the permission payload's own fields"). This path is unchanged by this PR, and the carried deny set already matches against the trusted pair.

The empty-carried-set reconcile (noted as ride-along) stays — fail-safe.

That branch is the fix for the earlier auto-approved-with-no-deny case: a server mounted auto-approved (no carried deny) whose live spec later withholds its element. Dropping it would let that switched-off tool run on the auto-approve path, so it is kept; it refuses only (never relaxes), and the roster — now stub-excluded — is what it intersects.

Gate green on the committed head (black py312 / flake8 / isort / mypy); the reconcile, roster, parity, and native-projection-sources tests pass locally.

@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from be8fd3e to f7fd1ff Compare October 9, 2026 03:00
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Both items addressed on f7fd1ff489.

F1 (runtime.py:6314 — unprojected session skips the check). Confirmed: when no projected spec reaches the reconcile (a projection rollback or ceiling fallback leaves projection_now None), live_spec was None, which short-circuited to an empty verdict and skipped the check — so a late allowedTools edit over a standing disabledTools toggle during start went unchecked.

This is the same anchor as earlier rounds, so rather than add another special case (re-deriving the authored spec for that one path), I closed the class with a single rule: fail closed. When the live spec cannot be determined and the session mounted any identity-bound element, the reconcile now refuses — the session is not started rather than started with a toggle unenforced. A session that mounted no identity-bound element has nothing that could slip through, so an empty roster is still a no-op (the common no-projection, no-core-tool start). New test pins the fail-closed path and the empty-roster no-op is kept as a contrast.

F2 (session_mcp.py:1743 — malformed list skips the withholding guard). Confirmed and fixed: the carry check accepted any list, so disabledTools: [null] passed while the pair-builder discarded the null, mounting the element unrestricted. The carry now requires every entry to be a string; a list with any non-string entry keeps withholding (the element is refused, not mounted with the toggle dropped). New test pins that a [null] list withholds kirocrew-core and carries nothing, alongside the existing well-formed-list carry test.

Gate clean (black/flake8/isort/mypy), 430 touched tests green. One commit.

@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 Oct 9, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/14125-core-tool-toggle-failsafe branch from f7fd1ff to 8fd6631 Compare October 9, 2026 03:52
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Re-scoped to the smallest fail-safe fix of the original problem, pushed as 8fd6631a3d.

What this is now: at the single point where the control-plane mount decides to withhold or carry (kiro_control_plane_servers), a well-formed kirocrew-core disabledTools toggle mounts the element and carries the (server, tool) deny pairs on the session's per-call gate, so the session runs minus the toggled tool instead of being refused. One predicate, from one read. If the toggle cannot be honoured safely it fails closed: a tool the spec's allowedTools auto-approves is withheld, a malformed disabledTools is withheld, and skill_search itself disabled refuses a search agent's session.

What was removed: the live-spec reconciliation at activation (and its mounted-roster derivation and backend gate) and the unrelated website/feature-map changes that had accumulated. The reconcile attempted to close a mid-life edit window and grew a new finding each review round; it is deliberately out of scope here. That window — an edit landing between the mount's read and the spec kiro-cli activates for one session, which self-heals on the next start — is tracked as the follow-up #18322 and named under "Not a goal" in the description.

Footprint: 8 files (session_mcp.py, skill_projection.py, agent.py, worker_agent.py for the shared allowedTools matcher, runtime.py for the gate wiring + the skill_search guard, one system-spec note, two test files), down from 29. Local gate green (black/flake8/isort/mypy); the carry/withhold decision is tested through the runtime start path that was refused before, plus the three fail-safe fallbacks. One commit, rebased on current origin/main.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

On the mount read: this is the mid-life edit window this PR scopes out (see "Not a goal" in the description); it is tracked in #18322, now updated to name this exact sequence — mount against the cached projection, allowedTools edited after the mount read, then activation of the updated spec auto-approving the toggled tool.

Verified against origin/main: the same edit already lets the toggle be auto-approved there, so this PR does not widen the path. On main, kiro_control_plane_servers withholds the element whenever the toggle is read, and allowedtools_auto_approved_pairs does not exist on main — there is no carried-deny mechanism and no activation-time re-check at all. The auto-approve of a tool a fresh allowedTools grants is kiro-cli's own native behaviour over its on-disk settings, independent of whether Crew mounts or withholds the element. This PR adds the gate-level carry only for the prompting pairs and withholds (fail closed) at the mount whenever a toggled tool is auto-approved by the spec it reads; it does not introduce the activation-time window.

The comment that referenced an activation re-check is being corrected to point at #18322 as the deferred closure rather than describing a guard that is not in the call graph; the Pattern harvest section records that as a review-prompt rule candidate.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed in 21cff76628: the mid-life edit window is now closed inside this PR rather than deferred.

The gap. The mount reads the spawn spec and carries a kirocrew-core disabledTools deny on the per-call gate only when that spec does not auto-approve the toggled tool. But the spec kiro-cli actually activates at set_mode can gain an allowedTools grant after that read (an edit landing between the mount and activation). kiro-cli then auto-approves the toggled tool and sends no permission request, so the carried gate deny never applies — the toggle would be silently defeated.

The fix. _activate_mode_bracketed now re-checks the carried deny pairs against the spec it is activating — the adopted projection's view for the agent being set — and if any carried deny has become auto-approved by that spec, it refuses the session (terminates and raises) rather than start it with the switched-off tool runnable. This is one predicate over the already-adopted view: no spec re-derivation, no reconcile, no backend gate. A clean refusal keeps the toggle authoritative; the session is recoverable (undo the edit or re-enable the tool) and the message says so.

Test. test_a_carried_deny_the_activated_spec_auto_approves_refuses_the_session drives the real bracket with a handle carrying a (kirocrew-core, learn_add) deny and an activated spec whose allowedTools grants the whole @kirocrew-core server. It fails before the guard (the session starts, leaving the tool runnable) and passes after it (refusal). A companion test confirms the guard is a no-op when the activated spec does not auto-approve the toggled tool, so a faithful carry still starts.

The follow-up issue stays open for the broader hardening it tracks, but the specific path flagged here — a late allowedTools grant defeating a carried deny — now fails closed in this PR.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed in 86bac4a92a.

The previous head's guard only ran when a projection view was adopted (projection_now is not None), so it was skipped on the unprojected starts — a disabled skill projection (KIROCREW_NATIVE_SKILL_PROJECTION=0), the automatic alias-ceiling fallback, or any start that adopted no view. Carried kirocrew-core deny pairs do not need a skill view (the control-plane carry is produced on the kiro-native mount regardless), so a late allowedTools grant could still defeat the toggle on those paths. require_unchanged_derived_spec did not cover it either (it returns early with no snapshot).

The guard now runs whenever the session carries deny pairs, independent of the projection:

  • when a view was adopted, it reads the activated spec from that view (as before);
  • otherwise it reads the activated agent's spec from disk the same way kiro-cli resolves it (load_agent_spec over the user agents directory);
  • if the activated spec cannot be read at all, the carry cannot be confirmed faithful, so the start fails closed (refuses) rather than run under a deny that might not apply.

In every case, if the activated spec auto-approves a carried deny the session is refused rather than started with the switched-off tool runnable.

Tests added for the three new branches: unprojected + disk spec auto-approves → refuse; unprojected + disk spec does not auto-approve → start; activated spec unreadable → fail closed. Each fails against the prior projection-gated guard (DID NOT RAISE) and passes with this change.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed in d2f049a389.

F1 (the flagged fenced finding). On this head the finding narrowed to a log-hygiene point: a tool name hand-written into a settings file can carry a control character, and on the auto-approved-withhold path that name was interpolated into a debug line, so a crafted name could write a forged debug record. The toggled tool was already withheld and nothing ran — the only exposure was the log line itself — but the interpolation is now routed through this module's existing sink cleaner (the same one every other message here uses), which drops control characters before the line is emitted. The identical cleaner is applied to the activation guard's refusal message, so neither path can be fed a forged line by a crafted tool name. Added test_a_control_character_in_a_toggled_tool_name_cannot_forge_a_log_line: it asserts the emitted record carries no newline or escape sequence while the visible text survives.

Comment History Gate. Reworded the comment and test text that stated things in historical terms (issue references, "no longer", "fails before") to present tense describing current behavior, so the gate passes. No logic change from that part.

Both the mount-time carry/withhold predicate and the activation guard (which now covers the unprojected starts and fails closed when the activated spec cannot be read) are unchanged in behavior from the prior head.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

First Principles BLOCK addressed by amending the Goal (the second path the verdict offers: "or a human amends the Goal to include the mid-life window").

The activation guard is intended, not accidental surface. The project goal was amended to include closing the specific mid-life edit window (a spec edit landing between a session's mount and its activation that lets a late allowedTools grant defeat a carried deny), with the smallest fail-safe guard rather than the broad live-spec reconciliation an earlier revision carried. The PR description now declares that scope: the "What changed" section has an "Activation guard" subsection describing it, the stale "deliberately left to a follow-up" line is removed, and ## Not a goal now scopes only the broader skill-view-lifecycle hardening to #18322. The pattern-harvest entry is updated to the current reality (a single-read restriction must be re-verified at the consumption point).

The guard reuses the mount's own allowedtools_auto_approved_pairs predicate, so it is one predicate over the activated spec at a single point — not a second copy of the mount's logic. Items 1–7 in your inventory remain; item 6 is now a declared part of the goal.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed in 7e3755e515.

The finding was correct: on the unprojected path the guard read the activated spec at the user level only (load_agent_spec over the user agents directory), while the mount resolves the spec project-nearest within the session's checkout. A trusted checkout shipping a same-named spec could therefore have the mount carry a deny based on the project spec while the guard checked the user spec — the wrong spec, which could pass while the project spec the mount read auto-approves the toggled tool.

The guard now reads the activated spec through the mount's own resolver (session_mcp._agent_spec_for), scoped by _disable_check_scope over the session's bound checkout — the exact project-first resolution, with the same trust rules, that the mount used to decide the carry. So the guard and the mount read one spec, not two, and cannot disagree about which spec the session runs. The projected-view path and the fail-closed-on-unreadable path are unchanged.

Added test_unprojected_the_guard_reads_the_project_spec_not_the_user_spec: it asserts the guard asks the mount's resolver for the agent being activated and refuses on the project spec it returns, so a project spec that auto-approves the toggled tool is caught rather than slipping past a user-level read.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

On 7e3755e515 this finding is in the opposite direction from the one the guard closes, and the adjudication itself rates it benign: a newly added disabledTools restriction that lands in the session/new→set_mode gap takes effect one session late (the next session's mount collects the pair), with — in the adjudication's own words — nothing gained by racing in a new deny, no adversarial use, and governance still enforced at the gate.

The guard this PR adds defends the dangerous direction: a late allowedTools grant defeating an existing carried deny (a switched-off tool escaping its toggle), which it refuses. The reverse — a late deny applying one session late — is the mount's existing single-read scope, self-healing on the next start, and the same residual the broader skill-view-lifecycle hardening in the follow-up issue covers.

Extending the activation path to also merge newly-added denies would widen it past the P0 (which was a disabled tool refusing every session), so I'm not making that change unilaterally. This is a fenced finding, so it needs a maintainer decision (an /ai-review override, or direction to extend scope) rather than another self-applied patch. Everything else on this head is green (First Principles, Opus 5.5, backend, E2E).

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed in db613a3f3b, treating it as the same fail-open class as the original defect (a tool the user disabled staying callable).

The activation guard no longer checks only the deny set read at mount time. It now re-runs the mount's own predicate — kiro_control_plane_servers, the exact function and arguments _unpooled_control_planes used at session/new — over the spec being activated (the adopted view where one exists, else the project-nearest spec the mount resolves itself), and compares the control-plane deny set it now yields to the set on the session's per-call gate. If they differ in either direction — a tool disabled in the gap (the F5 case: the gate carried nothing, the activated spec now denies it), a tool re-enabled, or a tool whose server gained a whole-server grant so the mount now withholds instead of carrying — or the activated spec cannot be read, the start is refused with a plain message telling the user to reopen the chat. The next start reads the edited spec cleanly.

Reusing the mount's own predicate means there is no second copy of the carry/withhold logic to diverge from it.

Tests: a deny added in the gap refuses (projected and unprojected), a deny removed/withheld refuses, a changed deny refuses, an unchanged set starts, no restriction either side starts, and an unreadable activated spec fails closed. The added-deny tests fail against the prior guard (which only ran when the gate already carried a pair) and pass with this change.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Acknowledged. This finding (runtime.py:6271) shows the per-start recheck cannot fully close the gap by comparing deny sets: when the activated spec would withhold the control-plane element rather than carry a deny, both the gate's set and the recheck's are empty, so an added restriction that lands in the gap is not distinguished from "no restriction". As the adjudication notes, spec_denied_tools is applied only at session start and never re-applied to a live session, so a toggle landing just after activation already goes unenforced until the next start — the per-start comparison is inherently a one-session-boundary mechanism.

Rather than extend the per-start comparison again, the fix approach for this class is being reconsidered at the review level (a simpler blanket treatment of any gap-time control-plane change). I'm not applying a further targeted patch here. No code change from me on this round.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Re-scoped to a whole-spec fingerprint: any change to the resolved spec between session/new and activation refuses the turn. The F6 case is refused, see test/test_acp_set_mode_projection_fallback.py::test_f6_withheld_core_plus_added_restriction_is_refused.

The mount records a sha256 of the resolved agent spec (project-nearest, the mount's own resolver) at session/new; _activate_mode_bracketed re-reads the spec the same way before the first turn and refuses (fail closed) if the fingerprint changed or the spec cannot be read. The per-field deny-set comparison and the tests that only existed for it are deleted; the original P0 carry/withhold fix stays. This closes the whole class by construction — including the withheld-core-plus-added-restriction case, where the deny set read empty on both sides but the spec hash differs.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed in 16f65a72c3.

The finding is correct: hashing the resolved spec raw would move the fingerprint when a launcher re-stamps a per-launch MCP env nonce, so concurrent session starts would read as a spec change and be refused. _resolved_spec_fingerprint now runs the resolved spec through the same volatile-env normalization the worker-spec fingerprint uses (_without_volatile_mcp_env, which follows agent_spec_format.volatile_env_keys()) before hashing. Only the volatile nonce VALUES are replaced by a fixed marker; keys and every real value still count, so a genuine disabledTools/allowedTools or other change still moves the hash and refuses, while a nonce re-stamp does not.

Added test_resolved_spec_fingerprint_ignores_volatile_env_but_not_real_change: a volatile-env-only change fingerprints identically (no false refusal), a real change differs. The guard reuses the existing normalization rather than keeping a second raw-hash copy that could diverge from it.

…ate instead of refusing

Disabling one kirocrew-core tool in the dashboard's MCP tab writes disabledTools
into the global mcp.json. On the kiro backend the control-plane element cannot
express that key, so the mount withheld the element and refused every new session
of an agent standing on it until the toggle was undone.

The control plane has a per-call permission channel that can honour the toggle:
its tools carry no annotations, so every call reaches Crew as a permission
request the client can reject. So a well-formed disabledTools on a control-plane
server now mounts the element and carries the (server, tool) deny pairs on the
session's per-call gate (spec_denied_tools); the session runs minus the toggled
tool rather than being refused.

Fail-safe fallbacks keep the toggle authoritative on every approval path:
- a tool the spec's allowedTools auto-approves is withheld, not carried
  (kiro-cli sends no permission request, so a carried deny would not apply);
- a malformed disabledTools value is withheld (no pairs, so carrying would drop
  the toggle);
- skill_search itself disabled refuses a search agent's session (it would start
  with its skill resources dropped and every search call refused).

The skill projection applies the same decision so it never promises a view the
mount then withholds.
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed in 699a74839b — both findings, plus the import-boundary and isort issues from the prior head.

F2 (blocking call on the event loop). The session/new fingerprint was computed with a synchronous _resolved_spec_fingerprint (which reads agent files) directly on the loop at both start sites. It is now computed off the loop and, per the point below, at the mount's own read.

F1 (fingerprint taken after the response). The fingerprint is now taken at the mount's observation — computed before session/new / session/load is sent, in the same establishment region where the mount reads the spec — not from a second read after the response. So a concurrent .kiro/agents/*.json edit landing while the request is in flight is no longer recorded as the mounted spec; it is reflected by the activation re-read differing and refusing. The value is threaded to the handle rather than recomputed.

Boundary + lint (prior head). The guard no longer imports the materialization owner's _without_volatile_mcp_env; the volatile-env normalization is applied with agent_spec_format.volatile_env_keys() directly (the acp-layer-allowed primitive the skill views already use), so the agent-sdk-boundary test passes. The hashlib import is isort-ordered.

The guard still refuses on any change to the resolved spec between start and activation (volatile MCP env values excluded), with the whole-spec fingerprint closing F1–F6 by construction.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

On 699a74839b this is a real structural point, distinct from the two it replaced (blocking I/O and the post-response read). The mount's carry/withhold decision is computed against the cached projection (spec_override), while the fingerprint — at both the start-time record and the activation re-read — resolves the source spec through _agent_spec_for. The two fingerprint reads therefore agree with each other but neither is compared against the projection the mount actually judged, so an ordinary edit to a warm agent's allowedTools over a standing disabledTools toggle moves the source without moving the comparison, and the carried deny is not re-evaluated.

This is the third distinct shape the single-read-restriction-re-verified-at-consumption approach has surfaced across review rounds, each at a different seam (per-field deny-set diff, observation timing, now the source-vs-projection mismatch). The correct fix is to hash the exact spec object the mount judged and thread it from kiro_control_plane_servers to the handle, rather than re-reading the source at two points — but that is a change to what the mount returns, and the shape of the guard is being reconsidered at the review level rather than patched again on this head.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Closing: every incremental guard has exposed another gap between the mount's cached projection and the source spec. This needs a design decision on where disabledTools is enforced for a live session; tracked in #18322.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant