Repository navigation
perf(mcp-gateway): spell out managed server names in the stub to drop agent_sdk - #20753
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS The PR title still describes the abandoned approach ("spell out managed server names in the stub"); retitle it to match the lazy import before merge. [DESIGN-REVIEWED] 4ec3b7e Description read[DESCRIPTION-READ] b419d55605d641a37899de57bd2a711ce31d26118d51eb5da971ac46b6d5fbd8 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 The PR title still says "spell out managed server names in the stub". The diff instead defers What this change shipsInventory (2 items) — 2 justifiedIntent: make each per-session MCP stub process start lighter by not loading the unused
[FIRST-PRINCIPLES-REVIEWED] 4ec3b7e Description read[DESCRIPTION-READ] 5d97d1b5637cdac17497b377cc98709671cb34e76533bd013a0139fd4bb3e26a That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
c7684d7 to
18c0430
Compare
|
Thanks — fixed in 18c0430. The comment at On the leaf-module suggestion: a shared names-only module would remove the hand-kept copy, but it also edits |
|
On the First Principles CONCERNS (advisory) at head 18c0430 — answering the subtraction point by point: 1. "Make the 2. "A third hand-typed copy of the 10 names." 3. "This is an addition / perf change, no defect fixed." Net: the subtraction is viable but out of this PR's goal and footprint. I've left the stub-local copy + drift test as the minimal change for #20642 and noted the deferred-import refactor as a reasonable follow-up. CONCERNS is advisory and does not block readiness; holding this as the shipped shape unless a maintainer directs the |
18c0430 to
7725619
Compare
|
Adopted the subtraction in 7725619. The eager import at A fresh stub import now loads 214 modules (down from 228) with no |
|
Update for 7725619: the hand-kept copy you flagged (and its drift test) is gone. The root cause is now fixed instead — |
…rops it The per-session MCP stub imports the 10 managed server NAMES from mcp_cleanup. mcp_cleanup imported agent_sdk.mcp_refs at module scope for a single constant (RESERVED_TOOL_NAMESPACES), so that NAME import pulled kiro_crew.agent_sdk and its 14 submodules into every stub. Move the agent_sdk.mcp_refs import into its one reader (prune_dangling_tool_refs). A lazy import is behaviour-preserving. A fresh stub import drops from 228 to 214 modules and no longer loads agent_sdk, and the saving also reaches mcp_cleanup's other importers. The module-set regression test forbids kiro_crew.agent_sdk in a bridging stub so the footprint cannot silently return.
7725619 to
4ec3b7e
Compare
|
Follow-up for 4ec3b7e: the description now matches the diff. It describes the lazy-import approach in |
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed head 4ec3b7e. The change itself looks good to ship.
What I checked:
- Moving the
agent_sdk.mcp_refsimport intoprune_dangling_tool_refsis behaviour preserving.RESERVED_TOOL_NAMESPACEShas no other reader inmcp_cleanup, nothing re-imports it frommcp_cleanup, and no test patches it there. - Red first holds: with main's
mcp_cleanup.pythe updated import budget test fails 3 cases; at this head it andtest_mcp_dangling_tool_refs.pypass (36 passed). A fresh stub import at this head does not loadkiro_crew.agent_sdk. - All five AI lanes name this head with no blocking findings, and readiness is passed.
One should fix, non blocking:
🟡 The PR title still describes the earlier revision. It says "spell out managed server names in the stub", but this head no longer touches stub.py; it defers an import in mcp_cleanup. The squash commit takes the PR title, so the history on main would describe a change that did not land. Suggested title: perf(mcp-gateway): defer mcp_cleanup's agent_sdk import so the stub drops it, which matches the commit headline.
Not approving yet: the CodeQL Analyze (python) run on this head is still in progress. Once the title matches the diff and that check is green, this is ready.
|
Hold at 4ec3b7e. The code is ready. One requested change is still open. The Design and First Principles lanes, and bolichen97's review, all ask for a new title before merge, and there has been no reply. The title still says "spell out managed server names in the stub", but this head no longer touches The change itself is sound. The deferred import has no other reader in — crew-pr-reviewer (r119) |
Problem / Motivation
Goal: make each MCP stub process start lighter by not loading a 14-module
subtree it never uses.
The Python MCP stub (
kiro_crew.mcp_gateway.stub) runs once per session per MCPserver, so whatever it imports is multiplied by every stub on a host (on one
measured host, 965 stubs). A fresh stub import on current
mainloads 228modules, including
kiro_crew.agent_sdkand its 14 submodules — which the stubnever uses. It pulls them only because it imports the 10 managed server names
from
mcp_cleanup, andmcp_cleanupeagerly importsagent_sdk.mcp_refsfor anunrelated constant. The stub needs only the names.
Why it matters
Every byte and module the stub imports is paid again by each of the many stub
processes a host runs. Dropping the
agent_sdksubtree from the stub's importpath cuts per-stub resident memory and start cost at the only point the stub
actually touches those names, with no behaviour change.
Not a goal
PoolKey, hashing, or any security code — not touched.concurrent.futures,urllib,ctypes, orexecutors/subprocess_pool: these are not stub-local (stdlib/shared-leaf,pulled on paths used across the codebase), so they are deliberately left alone.
What changed (motivation → approach → change)
agent_sdk(14 submodules)resident though unused.
mcp_cleanupimportedagent_sdk.mcp_refsat module scope(
mcp_cleanup.py:24) for a single constant,RESERVED_TOOL_NAMESPACES. Thestub's
from kiro_crew.mcp_cleanup import KIROCREW_BIN_MCP_SERVERSthereforedragged the whole
agent_sdkpackage into every stub.prune_dangling_tool_refs, so itis paid only when that function runs. A lazy import is behaviour-preserving.
An earlier revision of this PR copied the names into
stub.pyinstead; theFirst Principles review asked for the cause to be fixed rather than the symptom
worked around, and this revision adopts that — fixing the eager import removes
agent_sdkfrom the stub and frommcp_cleanup's other importers, with noduplicated list and no drift test to maintain. (See the First Principles
thread on this PR.)
Before / after a fresh stub import, measured on current
main:kiro_crew.agent_sdk14 fewer modules per stub (the whole
agent_sdksubtree); the stub still importsmcp_cleanup, which no longer pullsagent_sdk.Backwards compatibility
Removes nothing: the only change is when
agent_sdk.mcp_refsis importedinside
mcp_cleanup— moved from module scope into the one function(
prune_dangling_tool_refs) that readsRESERVED_TOOL_NAMESPACES. Every publicname
mcp_cleanupexports is unchanged,KIROCREW_BIN_MCP_SERVERSis still thesame object every importer reads, and the function's behaviour is identical (the
import resolves on first call instead of at module load). No default, UI, or
user-facing output changes.
Tests
test_mcp_gateway_stub_import_budget.pygainskiro_crew.agent_sdkto itsforbidden-when-bridging set, so a fresh/bridging stub import may never load
agent_sdkagain. It fails onmain(wheremcp_cleanup's eager import pullsagent_sdkinto the stub) and passes here (red-first).prune_dangling_tool_refs/RESERVED_TOOL_NAMESPACEScoverage(
test_mcp_dangling_tool_refs.py,test_agent.py) continues to pass with theimport deferred into the function, confirming the lazy import is
behaviour-preserving.
Manual verification
N/A — unit coverage is sufficient; the change moves one import inside a function
and the module-set bound locks the stub footprint in.
Related Issues
Closes #20642
Part of #20640
Checklist
perf: ...)CI note
Dependency License Gatefails on every PR in this repository (a repositorysetting, not something this diff affects) and is left as-is.
Note on
test/test_app_mcp_tool_policy_scope.py(serves_managed_tools): aWindows shard flagged two of its cases once on an earlier run, but they are
outside this diff — this PR touches only
mcp_cleanup.pyand one stub importtest, not
mcp_shared.pywhereserves_managed_toolslives — and they passhere. The behaviour is a known Windows code-location fragility that #20711
addresses on
main.