Repository navigation
perf(mcp-gateway): let a Bot's worker sessions share Crew's own MCP servers - #37695
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns: the change reuses the conductor's overlay path, still applies the worker's own merged limits ( Notes
[DESIGN-REVIEWED] 35f741b Description read[DESCRIPTION-READ] 39d76dd93df7a648f6928dc5d4e419b2e99472d2971fa2e49eb60e973fc34563 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Each item has a measured or named cause: per-worker server cost, and the Notes
What this change shipsInventory (6 items) — 4 justifiedIntent: let a Bot's worker sessions on KAS share Kiro Crew's five MCP servers through the gateway instead of each spawning its own. ADDITION (perf).
[FIRST-PRINCIPLES-REVIEWED] 35f741b Description read[DESCRIPTION-READ] 11944991e4e5fca009dbbc4854f101b5cd601fcc6f32b4768bca417139ca15f5 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
…ervers A worker session started its own kirocrew-core/cron/guide/mate/work, because the overlay pass never rewrote the stock worker spec and worker_overlay_spec skipped every base server. The pass now rewrites kirocrew-mate-worker.json next to the conductor's, and worker_overlay_spec returns its base-server stubs (shaped by the governed merged spec: muted, dropped and registry servers left out, disabledTools from the merged spec, autoApprove dropped) plus the stubs the Bot's own file adds. The worker overlay is never served by agent name: without the KAS session key the lookup answers nothing, so a host that cannot apply a worker's merged limits keeps declaring the servers itself.
1fdf0fd to
35f741b
Compare
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 14% chance that this change introduces a defect, above the 12% limit for approving on its own. Worker sessions on KAS now get the shared stubs for Crew's own MCP servers. The stock worker spec is rewritten through An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
|
The review found no code defect on this head, but one design point needs a maintainer before merge. The new guard in What the review checked on this head:
Done well: the ABBA measurements with an A/A spread, and the real-gatewayd test that proves two Bots' workers and a conductor share one backend while each call keeps its own caller key. Optional:
|
|
Review of Design conflict (needs a maintainer call). The new guard in My read, for whoever decides: the guard is the safer default. A by-name lookup hands the stock worker overlay's stubs to any session running that spec, without that session's merged limits (the Bot's mutes, drops and Isolation checks (all hold on this head):
Tests. 61 test files that import the touched modules: 3312 passed, 15 skipped, 5 xfailed. I also wrote five throwaway checks (not pushed), all passing: a user Optional (non-blocking): the stale docstrings and the missing worker twin of AI-assisted, sent by Bolin Review bot |
|
Maintainer call on the conflict with #37352 / #36370: keep this PR's guard at With that settled, nothing else blocks here from my side; I'll approve once #37352 is updated to match or the two are confirmed not to collide on the same hunk. AI-assisted, sent by Bolin Review bot |
Problem / Motivation
Goal: A Bot's worker sessions use the shared copies of Kiro Crew's own MCP servers instead of each starting five of their own.
Every worker session starts its own
kirocrew mcp-core,mcp-cron,mcp-guide,mcp-mateandmcp-work, even with the MCP gateway on. The overlay pass never rewrote the stock worker spec (kirocrew-mate-worker.json), andworker_overlay_specskipped every server the base spec declares, so only servers a Bot's own file adds could be stubbed. A Bot's conductor chat already shares these servers.Why it matters
A conductor hands work to several worker sessions at once, and each one pays for five Python servers: about 309 MB PSS per worker session and about 0.96 s before the five servers answer
tools/list(measured below). Sharing cuts both for every worker after the first.Not a goal
excludedToolson KAS).What changed (motivation → approach → change)
Cause: the worker's base servers never got stubs. Change, reusing the conductor's path rather than a new one:
mate_overlays.with_conductor_sourcenow adds the stock worker spec next to the conductor spec, so the agents half writes<overlay_dir>/kirocrew-mate-worker.jsonwith stubs under--agent kirocrew-mate-worker. Their launch argv equals the conductor stubs' apart from--agent, which is not a pool dimension, so a worker joins the conductor's backends (checked on a pod's real overlays).worker_overlay_specreturns those base-server stubs, shaped by the governed merged worker spec the same way it already shaped a Bot's added stubs: a server the merged spec drops, mutes or markstype: registryis left out,disabledToolscomes from the merged spec,autoApproveis dropped. A worker whose Bot owns no file gets them too. A Bot file's added stubs are unchanged.session_servers._load_overlay_for_agentnever answerskirocrew-mate-workerby name. Before, nothing was written under that name, so the by-name path was empty by accident. Now a file is there, and a host that passes no KAS session key would otherwise get the base stubs with the file'sautoApproveand none of the session's limits.docs/architecture/mcp.md("Bot overlays") and the module docstring describe the new behaviour.Session isolation
The pool already keys on launch inputs, not agent, and each forwarded call carries its own caller block. The new integration test runs two workers and a conductor on one real gatewayd and one shared backend, interleaves their calls in reverse order, and checks that the backend saw each caller's own session key. A run of the real
kirocrew-workserver under sharing was not done; that test uses the repo's fake backend.Measurements
Rig: a pod (
pod_up, its own home, port and gatewayd; the live gateway was not touched) running this branch withmcp_gateway.enabledand the five Crew servers stubbed. Each "session" starts the five servers at once exactly as the worker's spec (arm D, main today) or this branch's worker overlay (arm S) declares them, sendsinitializeandtools/list, and is ready when all five answered. kiro-cli/KAS was not in the loop: its own time before it starts the servers is the same in both arms and is not in these numbers. Both arms returned the same tool counts (81/9/12/13/7). 6 rounds per arm in ABBA order, 4 sessions per round, host load 7.5-10.4.The ready-time gap (about 500 ms) is about 20 times the A/A spread (25 ms). Each extra worker session saves about 176 MB. The 5 shared backends are the same processes a running conductor already uses, so a worker adds no backends when a conductor is up.
Cold start, the first session after the gatewayd restarted (no backend running): S 1445, 1494 and 1678 ms against D 936, 977 and 1003 ms (3 samples each). So a worker that starts when no shared backend is warm is about 0.5-0.7 s slower than today. How often a worker meets a cold backend on a real host was not measured; a conductor keeps them warm while it runs, and the gatewayd evicts an idle backend after
idle_timeout_secs.Backwards compatibility
Compatible: workers on KAS get stubs where they had none, and every stub falls back to starting its server directly when the gatewayd refuses it, as stubs already do.
Reader: src/kiro_crew/mcp_gateway/session_servers.py:_load_overlay_for_agent -- chat|subagent -- non-KAS hosts read
kirocrew-mate-workerby name; it now answers nothing, which is what they got before because no such overlay existed (test_without_a_kas_session_key_no_worker_stub_is_injected_by_name)Reader: src/kiro_crew/acp/harness/kas.py:injection_server_names -- chat -- the KAS projection's fallback when it has no worker stub names; it now gets an empty set and projects every declared server, as before
Tests
test_the_worker_gets_the_base_servers_stubs_from_the_worker_overlay: the real rewrite writes a wrapped base stub under--agent kirocrew-mate-worker; the worker gets it with the mergeddisabledToolsand noautoApprove, also without a Bot file; a muted or dropped base server is not injected.test_a_worker_overlay_with_another_identity_gives_no_base_stub.test_without_a_kas_session_key_no_worker_stub_is_injected_by_name: with the worker overlay on disk, a by-name lookup injects nothing.test_worker_and_conductor_stubs_on_one_backend_keep_their_own_identity(integration, real gatewayd and stubs).None, since a refused Bot file no longer stops the base stubs.Proof: not provable -- other: prove.py reverting every production hunk makes these tests error at collection. Reverted by hand instead: without the source changes the three overlay tests fail (no worker overlay is written); with only the by-name guard reverted, the by-name test fails because the lookup injects the base stub carrying
autoApprove: ["*"].Ran locally: 128 test files that import the touched modules: 5329 passed. 7 failures in
test_doctor_authored_agent_mcp_refs.pyfail the same way on the unchanged tree.Manual verification
On the pod, the rewriter wrote
kirocrew-mate-worker.jsonwith wrapped stubs for all five servers, and their argv matched the conductor overlay's apart from--agent. A real KAS worker session receiving the stubs end to end was not run.Checklist
Contribution License Agreement
Contributed under the project's Apache-2.0 license.