From 2bd77f369e91283ee6a3b68ac9ff8187e0920440 Mon Sep 17 00:00:00 2001 From: kirocrew-agent Date: Tue, 6 Oct 2026 21:55:52 +0000 Subject: [PATCH] fix(acp): carry a kirocrew-core disabledTools toggle on the session gate instead of refusing --- src/kiro_crew/acp/runtime.py | 31 ++- src/kiro_crew/acp/session_mcp.py | 117 ++++++++- src/kiro_crew/acp/skill_projection.py | 12 +- test/test_native_skill_projection_sources.py | 243 ++++++++++++------- 4 files changed, 309 insertions(+), 94 deletions(-) diff --git a/src/kiro_crew/acp/runtime.py b/src/kiro_crew/acp/runtime.py index df7277ca8116..f8dd4b8a1616 100644 --- a/src/kiro_crew/acp/runtime.py +++ b/src/kiro_crew/acp/runtime.py @@ -6835,7 +6835,7 @@ async def _own_stub_session( async def _unpooled_control_planes( self, entries: list[dict[str, Any]], agent: str | None, work_dir: str | Path - ) -> list[dict[str, Any]]: + ) -> tuple[list[dict[str, Any]], frozenset[tuple[str, str]]]: # A shared Kiro process has no session-valued environment. Its native # managed servers need per-element identity even with the broker off. if self.acp_backend == ACP_BACKEND_KIRO: @@ -6878,6 +6878,14 @@ async def _unpooled_control_planes( # this agent's skill resources on the element's promise, and # without the element kirocrew-core mounts natively, carries no # identity and answers identity_unattested to every skill_search. + # + # A ``disabledTools`` toggle on kirocrew-core no longer reaches + # here as a withheld element: the mount carries it on the gate + # and emits the element, so the element IS in ``mount.elements`` + # and this branch is not taken for it. What is still kept native + # -- a mute, a non-stdio transport, a key the element cannot + # express -- has no per-call form, so refusing stays the only + # honest answer for those (#14125). withheld = mount.withheld.get("kirocrew-core") if withheld is not None: raise AcpRuntimeError(f"Agent {name!r}: {withheld.explain('skill search')}") @@ -6886,8 +6894,8 @@ async def _unpooled_control_planes( "Cannot bind skill_search to this session without losing native MCP " "restrictions. Check the agent's kirocrew-core server configuration." ) - return [*entries, *mount.elements] - return entries + return [*entries, *mount.elements], mount.carried + return entries, frozenset() @staticmethod async def _source_agent(agent: str | None) -> str | None: @@ -7021,9 +7029,18 @@ async def create_session( self.acp_backend, session_work_dir, ) - mcp_servers = await self._unpooled_control_planes( + mcp_servers, carried_denied = await self._unpooled_control_planes( pooled, agent or self._agent, session_work_dir ) + # On the kiro backend a ``disabledTools`` toggle on the control + # plane is carried on the per-call gate rather than withholding + # the element and refusing the session (#14125). The pairs land + # on this session's ``spec_denied_tools`` the same way a mirrored + # host's do -- the handle refuses a switched-off tool at the + # permission request -- so the session runs minus the toggled + # tool and keeps skill_search. Empty on every other backend and + # whenever nothing is toggled. + denied_tools = carried_denied mcp_servers, stub_token = await self._own_stub_session(mcp_servers, session_key) else: # An explicit array is the caller's own composition (a mirror's @@ -7906,9 +7923,13 @@ async def load_session( self.acp_backend, session_work_dir, ) - mcp_servers = await self._unpooled_control_planes( + mcp_servers, carried_denied = await self._unpooled_control_planes( pooled, active_agent, session_work_dir ) + # Carry a control-plane ``disabledTools`` toggle on the gate here too, + # so a RESUMED session keeps the same deny set a fresh one gets and + # the toggled tool stays refused across session/load (#14125). + denied_tools = carried_denied mcp_servers, stub_token = await self._own_stub_session(mcp_servers, session_key) member_withheld = False # False for every non-member session, set without an awaited call so the diff --git a/src/kiro_crew/acp/session_mcp.py b/src/kiro_crew/acp/session_mcp.py index ef4dc0f2f0c2..7106fe6850a5 100644 --- a/src/kiro_crew/acp/session_mcp.py +++ b/src/kiro_crew/acp/session_mcp.py @@ -795,6 +795,36 @@ def session_mcp_disabled_tools( return frozenset(pairs) +def native_carried_disabled_tools( + name: str, spec_entry: Any, settings: Collection[NativeSettingsSource] +) -> frozenset[tuple[str, str]]: + """The ``(name, tool)`` pairs *name*'s declarations switch off, for the gate. + + The companion of :func:`native_mount_withholding` for the one restriction it + now carries rather than withholds (#14125): when a control-plane server's + per-session element mounts with a ``disabledTools`` toggle standing, the + restriction has nowhere native to live, so :func:`kiro_control_plane_servers` + feeds these pairs to the session's per-call gate instead. Read from the SAME + declarations the withholding predicate reads -- the spec entry and each + settings file, through :func:`native_declarations` -- so the mount's two + decisions (mount the element, deny these calls) come from one source set and + cannot disagree. This is the ONE place the mount's reader spells the + ``disabledTools`` key; the mount itself keeps no copy of it. Free of I/O: the + sources are already read. + """ + pairs: set[tuple[str, str]] = set() + for _source, declared in native_declarations(name, spec_entry, settings): + if not isinstance(declared, dict): + continue + disabled = declared.get("disabledTools") + if not isinstance(disabled, list): + continue + for tool in disabled: + if isinstance(tool, str) and tool: + pairs.add((name, tool)) + return frozenset(pairs) + + def session_mcp_disabled_servers(spec: Any, settings: Any) -> frozenset[str]: """Every server switched off WHOLE by ``disabled: true``, from both sources. @@ -1511,10 +1541,22 @@ class NativeControlPlaneMount(NamedTuple): files the mount performs, so a caller that refuses a session on ``withheld`` refuses it for the reason the array was built on, never for what the files say a moment later. + + ``carried`` names the ``(server, tool)`` pairs the mount DID produce an + element for while a ``disabledTools`` restriction stood on that server, so + the restriction rides the session's per-call permission gate instead of + withholding the element (#14125). Only a control-plane server appears here: + its tools carry no annotations, so every call reaches Crew as a permission + request the client can reject (see :func:`session_mcp_restricted_servers`). + The caller MUST feed these to ``AcpSessionHandle.spec_denied_tools`` -- the + element carries only command/args/env and expresses no restriction on its + own, so without the gate the toggled tool would run. From the same one read + as ``elements`` and ``withheld``. """ elements: list[dict[str, Any]] withheld: dict[str, NativeMountWithholding | NativeSettingsUnreadable] + carried: frozenset[tuple[str, str]] = frozenset() def _named(value: Any) -> str: @@ -1552,13 +1594,17 @@ def _named_tools(value: Any) -> str: def _native_restriction( - declared: Any, *, dashboard_writes: bool = False, crews_registry_marker: bool = False + declared: Any, + *, + dashboard_writes: bool = False, + crews_registry_marker: bool = False, + carry_disabled_tools: bool = False, ) -> tuple[str, str] | None: """``(restriction, remedy)`` when one declaration keeps its server native. The order is the order the questions are cheapest to answer and matters only - for which reason a declaration with several is named for. The two flags say - which declaration this is, because two answers depend on it. ``dashboard_writes``: + for which reason a declaration with several is named for. The three flags say + which declaration this is, because three answers depend on it. ``dashboard_writes``: the declaration lives in the file the dashboard's MCP tab writes -- the global settings -- so a mute or a ``disabledTools`` there is offered the tab as the way back; a spec or project entry is not, since following that remedy would @@ -1568,6 +1614,20 @@ def _native_restriction( registry mode is on, the one state in which the spec rebuild stamps it there -- so it restricts nothing. In every other state the same value is one kiro-cli drops, and the caller says so by leaving the flag off. + ``carry_disabled_tools``: the server this declaration is for has a per-CALL + channel that CAN carry a ``disabledTools`` restriction (a control-plane + server, whose tools carry no annotations, so every call reaches Crew as a + ``session/request_permission`` the client answers with the reject option -- + see :func:`session_mcp_restricted_servers`). For such a server the + ``disabledTools`` arm is NOT a reason to withhold the element: the element + mounts and the restriction rides the per-call gate instead, so the session + runs minus the toggled tool rather than being refused outright (#14125). + This narrows ONLY the ``disabledTools`` arm; a mute, a non-stdio transport + and a key the element cannot express still keep the declaration native -- + none of those has a per-call form a gate could carry. The flag is off by + default, so a server without that channel (an opt-in server whose + read-only-annotated tools codex auto-approves without asking) keeps the old + withholding behaviour. """ if not isinstance(declared, dict): return ("its entry is not a server object", "declare it as an object there") @@ -1606,7 +1666,7 @@ def _native_restriction( _remedy("re-enable the server", "set disabled to false there", tab=dashboard_writes), ) disabled_tools = declared.get("disabledTools", []) - if disabled_tools != []: + if disabled_tools != [] and not carry_disabled_tools: return ( f"its disabledTools {_named_tools(disabled_tools)}", _remedy( @@ -1632,7 +1692,11 @@ def _remedy(action: str, edit: str, *, tab: bool) -> str: def native_mount_withholding( - name: str, spec_entry: Any, settings: Collection[NativeSettingsSource] + name: str, + spec_entry: Any, + settings: Collection[NativeSettingsSource], + *, + carry_disabled_tools: bool = False, ) -> NativeMountWithholding | None: """Whether *name*'s per-session element must be withheld, and why. @@ -1666,6 +1730,18 @@ def native_mount_withholding( ``session/new`` would fail with an error pointing at the wrong file; so both call this one function, and neither keeps a copy of the merge or of the predicate. + + ``carry_disabled_tools`` says the caller has a per-CALL channel that can + honour a ``disabledTools`` restriction on *name* (a control-plane server: + its tools carry no annotations, so every call reaches Crew as a permission + request the client answers with the reject option). For such a server a + ``disabledTools`` declaration no longer withholds the element; the element + mounts and the restriction is carried on the gate instead, so the session + runs minus the toggled tool rather than being refused (#14125). Only the + ``disabledTools`` arm is narrowed -- a mute, a non-stdio transport and an + uncarriable key still withhold, because none has a per-call form -- and the + caller must then actually feed those ``(server, tool)`` pairs to the gate, + which :func:`kiro_control_plane_servers` does. """ dashboard_writes = {s.named for s in settings if s.label == NATIVE_SOURCE_GLOBAL} registry_mode = _registry_mode() @@ -1674,6 +1750,7 @@ def native_mount_withholding( declared, dashboard_writes=source in dashboard_writes, crews_registry_marker=source == NATIVE_SOURCE_SPEC and registry_mode, + carry_disabled_tools=carry_disabled_tools, ) if verdict is not None: restriction, remedy = verdict @@ -1740,6 +1817,7 @@ def kiro_control_plane_servers( return NativeControlPlaneMount([], {name: exc for name in IDENTITY_BOUND_SERVERS}) out: list[dict[str, Any]] = [] withheld_by_name: dict[str, NativeMountWithholding | NativeSettingsUnreadable] = {} + carried: set[tuple[str, str]] = set() for name in IDENTITY_BOUND_SERVERS: if not allow.grants(name): continue @@ -1747,11 +1825,36 @@ def kiro_control_plane_servers( managed = managed_mcp_spec_entry(name, include_opt_in=True) if not isinstance(entry, dict) or not isinstance(managed, dict): continue - withheld = native_mount_withholding(name, entry, settings) + # The control plane has a per-call channel that CAN carry a + # ``disabledTools`` restriction: its tools carry no annotations, so every + # call reaches Crew as a ``session/request_permission`` the client + # answers with the reject option. So for it a ``disabledTools`` toggle no + # longer withholds the element and refuses the session -- the element + # mounts and the pairs ride the gate instead (#14125, carried below). An + # opt-in server has no such channel (a ``readOnlyHint`` tool is + # auto-approved inside codex without asking), so it keeps the old + # withholding behaviour and the flag stays off for it -- the same split + # :func:`session_mcp_restricted_servers` draws, for the same reason. + can_carry = name in CONTROL_PLANE_SERVERS + withheld = native_mount_withholding( + name, entry, settings, carry_disabled_tools=can_carry + ) if withheld is not None: logger.debug("session MCP: %s", withheld.explain("its per-session element")) withheld_by_name[name] = withheld continue + # The element (or a pre-existing broker stub for the same name) will be + # on the session, and neither can express ``disabledTools`` -- so a + # restriction we chose to carry rather than withhold has to reach the + # gate. Collect its pairs from the SAME source set the withholding + # predicate read, before the ``existing_names`` continue: a stub carries + # the restriction no better than the element does, so the pairs are owed + # on that path too. The reader lives in + # :func:`native_carried_disabled_tools`, so this keeps no copy of the key + # -- only the control plane reaches it with a non-empty set, the opt-in + # servers withheld above. + if can_carry: + carried |= native_carried_disabled_tools(name, entry, settings) if name in existing_names: continue # The launch is the managed source's, never the spec's. A hand-authored @@ -1793,4 +1896,4 @@ def kiro_control_plane_servers( element = acp_server_element(name, owned) if element is not None: out.append(element) - return NativeControlPlaneMount(out, withheld_by_name) + return NativeControlPlaneMount(out, withheld_by_name, frozenset(carried)) diff --git a/src/kiro_crew/acp/skill_projection.py b/src/kiro_crew/acp/skill_projection.py index e34891f536e8..6c57b1a35460 100644 --- a/src/kiro_crew/acp/skill_projection.py +++ b/src/kiro_crew/acp/skill_projection.py @@ -2956,7 +2956,17 @@ def prepare_native_skill_projection( # withholding the view for it would refuse a supported customization # and abort the spawn over a restriction that reaches the session. if per_session_element: - withheld = session_mcp.native_mount_withholding("kirocrew-core", original_core, []) + # kirocrew-core is a control-plane server: its ``disabledTools`` + # ride the per-call gate the mount feeds, so they no longer + # withhold the element and must not refuse the view either -- + # ``carry_disabled_tools`` makes this reader agree with the mount + # (#14125). ``skill_search`` itself being disabled was already + # refused above; what remains for carry are the OTHER tools the + # toggle named, which leave skill search standing. A mute, a + # non-stdio transport and an uncarriable key still withhold. + withheld = session_mcp.native_mount_withholding( + "kirocrew-core", original_core, [], carry_disabled_tools=True + ) if withheld is not None: errors[agent.name] = withheld.explain("skill search") continue diff --git a/test/test_native_skill_projection_sources.py b/test/test_native_skill_projection_sources.py index c68cad61fc4b..03db43b4f992 100644 --- a/test/test_native_skill_projection_sources.py +++ b/test/test_native_skill_projection_sources.py @@ -100,6 +100,16 @@ async def _session_refusal(prepared, tree, entries=()) -> str: return str(refused.value) +async def _session_carries(prepared, tree, entries=()): + """The entries and carried deny pairs a ``kirocrew`` session gets on a warm + runtime, for a restriction the mount carries rather than refusing.""" + from test_acp_runtime import _make_runtime + + runtime, _, _ = _make_runtime() + runtime._native_skill_projection = prepared + return await runtime._unpooled_control_planes(list(entries), "kirocrew", tree.project) + + def _mount(prepared, tree, entries=()) -> session_mcp.NativeControlPlaneMount: """What the mount yields for a ``kirocrew`` session over the view, as the runtime asks it.""" return session_mcp.kiro_control_plane_servers( @@ -117,39 +127,49 @@ def _withheld(prepared, tree) -> str | None: @pytest.mark.asyncio -async def test_a_tool_disabled_in_the_global_settings_refuses_the_search_agents_sessions_by_name( +async def test_a_tool_disabled_in_the_global_settings_carries_on_the_gate_not_refusing( tree, ): - """The toggle is written into a file every agent of the process shares, so it - refuses the search agent's SESSIONS, naming the file -- never the spawn, which - every other agent's sessions ride on, and never the other agents.""" + """A control-plane tool toggled off in the file every agent of the process + shares no longer refuses the search agent's SESSIONS (#14125): the element + mounts and the ``(server, tool)`` pair rides this session's per-call gate, so + the session runs minus the toggled tool and keeps skill_search. kirocrew-core + carries no annotations, so every call reaches Crew as a permission request the + client can reject -- the one channel that honours the restriction without a + file the element cannot write.""" _write(tree.settings, TOGGLED) prepared = projection.prepare_native_skill_projection(tree.project) assert prepared is not None # The view stands: the spec is clean, so the spawn goes ahead under the alias. assert prepared.search_agents == {"kirocrew"} and prepared.errors == {} assert (tree.agents / f"{prepared.agent('kirocrew')}.json").exists() - reason = _withheld(prepared, tree) - assert reason is not None - assert reason.startswith("kirocrew-core is withheld by the global MCP settings") - assert str(tree.settings) in reason - assert "disabledTools lists learn_add" in reason - assert "dashboard's MCP tab" in reason and reason.endswith("to restore skill search") - assert await _session_refusal(prepared, tree) == f"Agent 'kirocrew': {reason}" + # The element is NOT withheld -- the mount carries the restriction instead. + assert _withheld(prepared, tree) is None + mount = _mount(prepared, tree) + assert "kirocrew-core" not in mount.withheld + assert any(e["name"] == "kirocrew-core" for e in mount.elements) + assert mount.carried == frozenset({("kirocrew-core", "learn_add")}) + # The runtime does not refuse the session; the pairs flow back for the gate. + entries, carried = await _session_carries(prepared, tree) + assert carried == frozenset({("kirocrew-core", "learn_add")}) + assert any(e["name"] == "kirocrew-core" for e in entries) # The agent that never asked for the element is untouched by the restriction. assert (tree.agents / f"{prepared.agent('plain')}.json").exists() assert "plain" not in prepared.search_agents @pytest.mark.asyncio -async def test_a_tool_disabled_in_the_project_settings_refuses_the_search_agents_sessions(tree): +async def test_a_tool_disabled_in_the_project_settings_carries_on_the_gate_not_refusing(tree): _write(_project_settings(tree), TOGGLED) prepared = projection.prepare_native_skill_projection(tree.project) assert prepared.search_agents == {"kirocrew"} - reason = _withheld(prepared, tree) - assert reason.startswith("kirocrew-core is withheld by the project's MCP settings") - assert str(_project_settings(tree)) in reason and "learn_add" in reason - assert await _session_refusal(prepared, tree) == f"Agent 'kirocrew': {reason}" + assert _withheld(prepared, tree) is None + mount = _mount(prepared, tree) + assert any(e["name"] == "kirocrew-core" for e in mount.elements) + assert mount.carried == frozenset({("kirocrew-core", "learn_add")}) + entries, carried = await _session_carries(prepared, tree) + assert carried == frozenset({("kirocrew-core", "learn_add")}) + assert any(e["name"] == "kirocrew-core" for e in entries) @pytest.mark.parametrize( @@ -209,10 +229,6 @@ def test_every_restriction_the_mount_knows_refuses_the_session_with_its_name(tre @pytest.mark.parametrize( "core, reason", [ - ( - {**MANAGED, "disabledTools": ["learn_add"]}, - "kirocrew-core is withheld by the agent spec", - ), # A mute is caught by the spec-shape check ahead of the predicate. ({**MANAGED, "disabled": True}, "skill_search is disabled"), ({**MANAGED, "type": "http"}, "kirocrew-core is withheld by the agent spec"), @@ -222,7 +238,9 @@ def test_a_restriction_authored_in_the_spec_entry_refuses_the_view_at_preparatio tree, core, reason ): """The spec is this preparation's input and a restriction there is static for - the view's life, so the view is refused now, naming the spec.""" + the view's life, so the view is refused now, naming the spec. A + ``disabledTools`` toggle is NOT among these -- it is carried on the gate and + covered by its own test below (#14125).""" spec = {**tree.specs["kirocrew"], "mcpServers": {"kirocrew-core": core}} (tree.agents / "kirocrew.json").write_text(json.dumps(spec), encoding="utf-8") prepared = projection.prepare_native_skill_projection(tree.project) @@ -232,6 +250,36 @@ def test_a_restriction_authored_in_the_spec_entry_refuses_the_view_at_preparatio prepared.agent("kirocrew") +def test_disabled_tools_authored_in_the_spec_entry_carries_the_view_not_refusing(tree): + """A ``disabledTools`` on kirocrew-core authored in the spec (naming a tool + other than skill_search) leaves the view standing: it is a restriction a + control-plane server's per-call gate carries, so the mount emits the element + and reports the pair rather than withholding it (#14125). skill_search itself + being disabled is still refused, by the explicit check ahead of the + predicate.""" + core = {**MANAGED, "disabledTools": ["learn_add"]} + spec = {**tree.specs["kirocrew"], "mcpServers": {"kirocrew-core": core}} + (tree.agents / "kirocrew.json").write_text(json.dumps(spec), encoding="utf-8") + tree.specs["kirocrew"] = spec + prepared = projection.prepare_native_skill_projection(tree.project) + assert prepared.search_agents == {"kirocrew"} and prepared.errors == {} + assert prepared.agent("kirocrew") # the spawn has an alias to run + mount = session_mcp.kiro_control_plane_servers( + "kirocrew", work_dir=tree.project, spec_override=prepared.specs.get("kirocrew") + ) + assert "kirocrew-core" not in mount.withheld + assert any(e["name"] == "kirocrew-core" for e in mount.elements) + assert mount.carried == frozenset({("kirocrew-core", "learn_add")}) + + # skill_search itself disabled still refuses, by the pre-predicate check. + core_search = {**MANAGED, "disabledTools": ["skill_search"]} + spec_search = {**tree.specs["kirocrew"], "mcpServers": {"kirocrew-core": core_search}} + (tree.agents / "kirocrew.json").write_text(json.dumps(spec_search), encoding="utf-8") + prepared = projection.prepare_native_skill_projection(tree.project) + assert "kirocrew" not in prepared.search_agents + assert prepared.errors["kirocrew"].startswith("skill_search is disabled") + + @pytest.mark.parametrize("where", ["spec", "global", "project"]) def test_a_timeout_on_the_entry_keeps_the_declaration_native_and_names_the_key(tree, where): """The element replaces the declaration it is named after and carries no @@ -425,18 +473,22 @@ async def test_an_empty_settings_file_starts_the_search_agents_sessions(tree, sc assert _withheld(prepared, tree) is None runtime, _, _ = _make_runtime() runtime._native_skill_projection = prepared - servers = await runtime._unpooled_control_planes([], "kirocrew", tree.project) + servers, _carried = await runtime._unpooled_control_planes([], "kirocrew", tree.project) assert [server["name"] for server in servers] == ["kirocrew-core"] @pytest.mark.asyncio async def test_a_session_of_an_agent_the_spec_refused_reaches_no_guard(tree): - """The ``session/new`` guard is unreachable once the projection has refused.""" + """The ``session/new`` guard is unreachable once the projection has refused. + + Uses a non-stdio transport in the spec -- a restriction with no per-call form, + so it still refuses the view (a ``disabledTools`` toggle would now be carried, + #14125). The session reaches no guard and no element is mounted.""" from test_acp_runtime import _make_runtime spec = { **tree.specs["kirocrew"], - "mcpServers": {"kirocrew-core": {**MANAGED, "disabledTools": ["learn_add"]}}, + "mcpServers": {"kirocrew-core": {**MANAGED, "type": "http"}}, } (tree.agents / "kirocrew.json").write_text(json.dumps(spec), encoding="utf-8") tree.specs["kirocrew"] = spec @@ -445,7 +497,7 @@ async def test_a_session_of_an_agent_the_spec_refused_reaches_no_guard(tree): runtime, _, _ = _make_runtime() runtime._native_skill_projection = prepared try: - servers = await runtime._unpooled_control_planes([], "kirocrew", tree.project) + servers, _carried = await runtime._unpooled_control_planes([], "kirocrew", tree.project) except AcpRuntimeError as exc: # pragma: no cover - the defect this module pins pytest.fail(f"session start raised for a restriction the projection can read: {exc}") assert servers == [] @@ -455,40 +507,39 @@ async def test_a_session_of_an_agent_the_spec_refused_reaches_no_guard(tree): @pytest.mark.asyncio -@pytest.mark.parametrize( - "restriction, named", - [ - pytest.param( - lambda tree: _write(tree.settings, TOGGLED), - "the global MCP settings", - id="global-toggle", - ), - pytest.param( - lambda tree: _write(_project_settings(tree), {**MANAGED, "disabled": True}), - "the project's MCP settings", - id="project-mute", - ), - ], -) -async def test_a_broker_stub_in_the_array_does_not_carry_a_restricted_agents_session( - tree, restriction, named -): +async def test_a_broker_stub_does_not_carry_an_uncarriable_restriction(tree): """The sources decide; a stub ``session/new`` would mount is not one of them. A stub element can carry a kiro-cli-only restriction no better than the native element can, and the overlay it comes from is written once, from the spec and the global file as they were then, so a stub's presence in the array is no - evidence that the restriction reaches the session. The runtime asks the files - before it accepts the stub, and refuses the session with the file's name. + evidence that an uncarriable restriction (a mute) reaches the session. The + runtime asks the files before it accepts the stub, and refuses the session + with the file's name. """ - restriction(tree) + _write(_project_settings(tree), {**MANAGED, "disabled": True}) prepared = projection.prepare_native_skill_projection(tree.project) assert prepared.search_agents == {"kirocrew"} message = await _session_refusal(prepared, tree, entries=[dict(STUB)]) - assert message.startswith(f"Agent 'kirocrew': kirocrew-core is withheld by {named}") + assert message.startswith("Agent 'kirocrew': kirocrew-core is withheld by the project's") assert "Cannot bind skill_search" not in message +@pytest.mark.asyncio +async def test_a_disabled_tool_behind_a_broker_stub_is_carried_on_the_gate(tree): + """A ``disabledTools`` toggle in the global file is CARRIED, not withholding -- + and a stub carries the restriction no better than the element does, so the + pairs are owed on the stub path too (#14125). The session is not refused; the + stub stays in the array and the deny pair comes back for the gate.""" + _write(tree.settings, TOGGLED) + prepared = projection.prepare_native_skill_projection(tree.project) + assert prepared.search_agents == {"kirocrew"} + entries, carried = await _session_carries(prepared, tree, entries=[dict(STUB)]) + assert carried == frozenset({("kirocrew-core", "learn_add")}) + # The stub pre-empts the element, so the array still carries exactly it. + assert [e["name"] for e in entries] == ["kirocrew-core"] + + @pytest.mark.asyncio async def test_a_broker_stub_carries_the_session_while_the_files_allow_the_element(tree): from test_acp_runtime import _make_runtime @@ -496,7 +547,9 @@ async def test_a_broker_stub_carries_the_session_while_the_files_allow_the_eleme prepared = projection.prepare_native_skill_projection(tree.project) runtime, _, _ = _make_runtime() runtime._native_skill_projection = prepared - servers = await runtime._unpooled_control_planes([dict(STUB)], "kirocrew", tree.project) + servers, _carried = await runtime._unpooled_control_planes( + [dict(STUB)], "kirocrew", tree.project + ) assert servers == [STUB] @@ -509,11 +562,6 @@ def _corrupt(path: Path) -> None: @pytest.mark.parametrize( "edit, named", [ - pytest.param( - lambda tree: _write(tree.settings, TOGGLED), - ("the global MCP settings", "disabledTools lists learn_add", "dashboard's MCP tab"), - id="global-toggle", - ), pytest.param( lambda tree: _write(_project_settings(tree), {**MANAGED, "disabled": True}), ("the project's MCP settings", "it is disabled"), @@ -545,7 +593,7 @@ async def test_a_restriction_written_after_the_spawn_refuses_the_next_session_by assert _withheld(prepared, tree) is None runtime, _, _ = _make_runtime() runtime._native_skill_projection = prepared - first = await runtime._unpooled_control_planes([], "kirocrew", tree.project) + first, _carried = await runtime._unpooled_control_planes([], "kirocrew", tree.project) assert [entry["name"] for entry in first] == ["kirocrew-core"] edit(tree) with pytest.raises(AcpRuntimeError) as refused: @@ -565,29 +613,54 @@ async def test_a_restriction_written_after_the_spawn_refuses_the_next_session_by assert message == f"Agent 'kirocrew': {_withheld(fresh, tree)}" +@pytest.mark.asyncio +async def test_a_disabled_tool_written_after_the_spawn_carries_the_next_session_on_the_gate(tree): + """A ``disabledTools`` toggle written while the runtime is warm is CARRIED at + the next session start, not refusing it (#14125): the element stays mounted + and the pair comes back for the gate. Undoing the toggle drops the pair with + no respawn, the symmetry the carried path keeps with the withholding one.""" + from test_acp_runtime import _make_runtime + + prepared = projection.prepare_native_skill_projection(tree.project) + assert prepared.search_agents == {"kirocrew"} + runtime, _, _ = _make_runtime() + runtime._native_skill_projection = prepared + first, carried = await runtime._unpooled_control_planes([], "kirocrew", tree.project) + assert [e["name"] for e in first] == ["kirocrew-core"] and carried == frozenset() + _write(tree.settings, TOGGLED) + entries, carried = await runtime._unpooled_control_planes([], "kirocrew", tree.project) + assert [e["name"] for e in entries] == ["kirocrew-core"] + assert carried == frozenset({("kirocrew-core", "learn_add")}) + _write(tree.settings, MANAGED) + _entries, carried = await runtime._unpooled_control_planes([], "kirocrew", tree.project) + assert carried == frozenset() + + @pytest.mark.asyncio async def test_a_stub_ahead_of_the_element_does_not_carry_a_session_started_after_the_edit(tree): """The stub array comes from an overlay written before the edit, so the stub is exactly what a restriction written since cannot have reached; the files are - asked before it is accepted, and the session is refused with the file's name.""" + asked before it is accepted, and the session is refused with the file's name. + Uses a mute -- an uncarriable restriction -- since a ``disabledTools`` toggle + is now carried on the gate rather than refusing (#14125).""" from test_acp_runtime import _make_runtime prepared = projection.prepare_native_skill_projection(tree.project) runtime, _, _ = _make_runtime() runtime._native_skill_projection = prepared - first = await runtime._unpooled_control_planes([dict(STUB)], "kirocrew", tree.project) + first, _carried = await runtime._unpooled_control_planes([dict(STUB)], "kirocrew", tree.project) assert first == [STUB] - _write(tree.settings, TOGGLED) + _write(tree.settings, {**MANAGED, "disabled": True}) with pytest.raises(AcpRuntimeError) as refused: await runtime._unpooled_control_planes([dict(STUB)], "kirocrew", tree.project) message = str(refused.value) assert message.startswith( "Agent 'kirocrew': kirocrew-core is withheld by the global MCP settings" ) - assert "disabledTools lists learn_add" in message - # Undoing the toggle restores the next session without a respawn. + assert "it is disabled" in message + # Undoing the restriction restores the next session without a respawn. _write(tree.settings, MANAGED) - again = await runtime._unpooled_control_planes([dict(STUB)], "kirocrew", tree.project) + again, _carried = await runtime._unpooled_control_planes([dict(STUB)], "kirocrew", tree.project) assert again == [STUB] @@ -615,7 +688,7 @@ def test_the_mount_and_the_projection_ask_one_predicate_with_one_source_set(tree that one verdict on.""" seen: list[tuple[str, object, list[str]]] = [] - def recorder(name, spec_entry, settings): + def recorder(name, spec_entry, settings, *, carry_disabled_tools=False): labels = [source.label for source in settings] seen.append((name, spec_entry, labels)) if not labels: @@ -957,8 +1030,8 @@ def test_a_settings_path_in_a_retained_message_is_cut_from_the_front_keeping_the @pytest.mark.asyncio @pytest.mark.parametrize( "core", - [{**MANAGED, "disabledTools": ["learn_add"]}, {**MANAGED, "type": "http"}], - ids=["disabledTools", "type"], + [{**MANAGED, "timeout": 60000}, {**MANAGED, "type": "http"}], + ids=["timeout", "type"], ) async def test_a_view_the_spec_refused_fails_the_spawn_as_the_error_the_startup_paths_translate( tree, monkeypatch, core @@ -1062,10 +1135,16 @@ async def admit(factory): # The restriction reaches the session as written, on the managed launch. assert core["disabledTools"] == ["learn_add"] and core["command"] == MANAGED["command"] assert projection._SEARCH_TOOL in view["tools"] and "skill_search" not in core["disabledTools"] - # The same spec on the shared runtime still refuses the view: there the element - # would replace the declaration and cannot carry the list. + # The same spec on the shared runtime now ALSO lets the view stand: the + # element mounts and the control-plane gate carries the restriction, so a + # ``disabledTools`` toggle no longer refuses the view there either (#14125). shared = projection.prepare_native_skill_projection(tree.project) - assert shared.errors["kirocrew"].startswith("kirocrew-core is withheld by the agent spec") + assert shared.errors == {} and "kirocrew" in shared.search_agents + mount = session_mcp.kiro_control_plane_servers( + "kirocrew", work_dir=tree.project, spec_override=shared.specs.get("kirocrew") + ) + assert any(e["name"] == "kirocrew-core" for e in mount.elements) + assert mount.carried == frozenset({("kirocrew-core", "learn_add")}) @pytest.mark.parametrize("where", ["spec-disabledTools", "spec-timeout", "spec-skill_search"]) @@ -1107,7 +1186,7 @@ def test_the_mount_hands_on_the_verdict_it_withheld_on_from_its_one_read(tree, s stub carries a kiro-cli-only restriction no better than the element does, and the guard that refuses the session has to learn it from this read.""" if shape == "withheld": - _write(tree.settings, TOGGLED) + _write(tree.settings, {**MANAGED, "disabled": True}) elif shape == "unreadable": _corrupt(tree.settings) prepared = projection.prepare_native_skill_projection(tree.project) @@ -1122,7 +1201,7 @@ def test_the_mount_hands_on_the_verdict_it_withheld_on_from_its_one_read(tree, s if shape == "withheld": assert isinstance(verdict, session_mcp.NativeMountWithholding) assert verdict.source.startswith(session_mcp.NATIVE_SOURCE_GLOBAL) - assert "learn_add" in verdict.restriction + assert "it is disabled" in verdict.restriction else: assert isinstance(verdict, session_mcp.NativeSettingsUnreadable) # Nothing can be read, so nothing identity-bound is mounted: every name says so. @@ -1135,8 +1214,8 @@ def test_the_mount_hands_on_the_verdict_it_withheld_on_from_its_one_read(tree, s "restriction, entries", [ pytest.param(None, [], id="allowed"), - pytest.param(TOGGLED, [], id="withheld"), - pytest.param(TOGGLED, [dict(STUB)], id="withheld-behind-a-stub"), + pytest.param({**MANAGED, "disabled": True}, [], id="withheld"), + pytest.param({**MANAGED, "disabled": True}, [dict(STUB)], id="withheld-behind-a-stub"), pytest.param(None, [dict(STUB)], id="allowed-behind-a-stub"), ], ) @@ -1171,26 +1250,28 @@ def counted(work_dir): @pytest.mark.asyncio @pytest.mark.parametrize("entries", [[], [dict(STUB)]], ids=["no-stub", "stub"]) -async def test_a_toggle_undone_between_two_reads_cannot_send_the_session_to_the_wrong_guard( +async def test_a_restriction_undone_between_two_reads_cannot_send_the_session_to_the_wrong_guard( tree, monkeypatch, entries ): - """The window a second read opened: the mount read the toggle and withheld the - element; the user undid the toggle; a re-read for the guard answered "allowed", - and the session fell to the generic guard naming the agent's configuration - (or, behind a stub, was carried while its array was built under the - restriction). With one read there is no second answer: the session is - refused for the verdict the array was built on, naming the file.""" + """The window a second read opened: the mount read the restriction and withheld + the element; the user undid it; a re-read for the guard answered "allowed", and + the session fell to the generic guard naming the agent's configuration (or, + behind a stub, was carried while its array was built under the restriction). + With one read there is no second answer: the session is refused for the verdict + the array was built on, naming the file. Uses a mute -- an uncarriable + restriction that still withholds -- since a ``disabledTools`` toggle is now + carried on the gate rather than refusing (#14125).""" from test_acp_runtime import _make_runtime read = session_mcp.native_settings_sources answers: list[list[session_mcp.NativeSettingsSource]] = [] - def toggled_then_undone(work_dir): - _write(tree.settings, TOGGLED if not answers else MANAGED) + def restricted_then_undone(work_dir): + _write(tree.settings, {**MANAGED, "disabled": True} if not answers else MANAGED) answers.append(read(work_dir)) return answers[-1] - monkeypatch.setattr(session_mcp, "native_settings_sources", toggled_then_undone) + monkeypatch.setattr(session_mcp, "native_settings_sources", restricted_then_undone) prepared = projection.prepare_native_skill_projection(tree.project) runtime, _, _ = _make_runtime() runtime._native_skill_projection = prepared @@ -1200,6 +1281,6 @@ def toggled_then_undone(work_dir): assert message.startswith( "Agent 'kirocrew': kirocrew-core is withheld by the global MCP settings" ) - assert "disabledTools lists learn_add" in message + assert "it is disabled" in message assert "Cannot bind skill_search" not in message and "server configuration" not in message assert len(answers) == 1