Repository navigation
perf: relay own MCP servers' tool lists from the gateway - #35833
Conversation
Sensitive change review
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: every case where the gateway can't answer falls back to the server's own start, and the route answers exactly as before when Notes
[DESIGN-REVIEWED] add3644 Description read[DESCRIPTION-READ] e8aa22451629b402e94b5fa7f42c12e335a48fa4d3716c760918a9187783e760 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. The relay addresses a measured cost (913 ms → 187 ms spawn-to-listed). The only finding is a probe-diagnostics rider outside the Goal. Notes
What this change shipsInventory (8 items) — 7 justifiedIntent: an ADDITION (perf). New chats, sub-agents and cron runs reach their first prompt sooner because Kiro Crew's own four servers relay a tool list the gateway built.
[FIRST-PRINCIPLES-REVIEWED] add3644 Description read[DESCRIPTION-READ] 86d74aa55012d198141c200d29f131ac2f0ad06c7676d92e4cfa6afef197550d 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: |
4396d78 to
34c8686
Compare
Sensitive change review
|
Code change approver recommendation: A person should decideWhy: the decider raised 1 possible problem and estimates a 60% chance that this change introduces a defect; a person should check it. The relay is carefully built: any answer other than a list falls back to the old start, and the session-still-starting window is handled with care. But it now has the unsandboxed gateway import and run the listing builder modules on every session start, on every host. The repo's own code (mcp_discovery_probe.py:1021-1028, mcp_discovery_managed.py:71-79) says this import must not happen on hosts where the sandbox works, because editable installs leave the package agent-writable. The code stamp only checks .py metadata one import deep, so a swapped .pyc or a deeper edit passes. The PR moves this trust boundary without acknowledging it. The boot-path finding is covered by the rule's own exception. Things to check (possible problems the decider raised; at this confidence many turn out to be fine):
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 |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Thanks. One test can fail under load, and it needs a fix before this can merge.
test/test_mcp_listing_relay.py:1061(with the audit count at line 1069). The child in_SERVERruns the realrelay_before_boot, which callsfetch_listing(command)atsrc/kiro_crew/mcp_listing_relay.py:316with no timeout. So the call uses the productionRELAY_FETCH_TIMEOUT_SECS(1.0 s), and that default is bound when the function is defined. The rig gateway builds the whole body before it sends headers, and the firstmcp-corerequest also pays a cold import of the listing module. On a busy CI runner with-n auto, that can take more than 1.0 s. Thenfetch_listingreturns the timeout result, the child builds its own list,assert asked["listed"]fails, and for theunregisteredcase thetool_policy.unfiltered_listingcount is 2 instead of 1. The PR body's own load table already shows 2 of 120 requests hitting the 1.0 s bound. Smallest fix: in_SERVER, wrapmcp_listing_relay.fetch_listingso it passestimeout=FALLBACK_TIMEOUT_SECS. Patching the constant does not work, because the default is already bound. The timeout fallback keeps its own stubbed test, and the production bound stays as it is.
Optional:
- The probe fix for #35785 sits inside the
perf:commit. A separatefix:commit would follow one logical change per commit. Also, another contributor claimed #35785 shortly before this PR opened, so please settle that before it closes the issue. - No route test reaches the builder with a real member store, so a change to
private_member=bool(member_store)attool_policy.py:723would not turn any test red. Also,test_a_refused_root_run_falls_back_before_the_data_home_is_touchedcould assertstartup["relay"] == []. code_stampdoes not covermcp_instructions.pyor the cron constants module, so an edited dev checkout can relay stale description text until the gateway restarts. The body could say "a fixed set of listing sources" instead of "the same listing code".
34c8686 to
0ed974e
Compare
Runs on macOS and WindowsTwo other machines ran this PR against its base. Both ran head These runs were on source checkouts (edited after head Windows (Windows Server 2025, 8 vCPU, kiro-cli 3.2.0)
macOS (Apple silicon, macOS 26.2, kiro-cli 3.2.1)
What the macOS run found, fixed in head
Also seen, not a fault of this PR
Not run
|
|
Reply to the review of 15:17Z, on head
Also in this head: a failed probe shows the end of the server's stderr, redacted whole before it is cut. And, from the review lanes on |
Sensitive change review
|
0ed974e to
7fe1e04
Compare
|
Why the goal of this PR changed (this comment first asked not to merge head At the maintainer's request this PR now carries the relay only. The head is one commit, With that commit, two tests of In the results comment above, these macOS rows were measured with that commit and no longer apply to this PR:
The relay rows, the byte comparison, the smoke rows, the doctor rows and every Windows row stand. |
7fe1e04 to
cb336b0
Compare
|
Follow-up on the review of 15:17Z, checked on head cb336b0.
I found no code bug on this head. It cannot be approved yet, though, and two things need a person. For the security review: the security lane's blocking finding at The PR Readiness is red on this head because of these two lanes. The other reds look unrelated: Analyze failed on a rate-limit annotation, and a macOS CPU-timing test failed in a file this PR does not touch. Done well: any answer other than a verified list sends the server back to its own start. The two-process rig shows byte-identical lists for all four servers. Optional:
|
Withdrawn: every item in this review is fixed or answered on the current head (see the follow-up comment). Other holds on this PR are listed there.
An agent engine starts every MCP server of a session at session start and holds the first prompt until each has listed its tools. Kiro Crew's four own servers each loaded their configuration and the platform, and kirocrew-core its live descriptions, before they could list. A server now asks its gateway once, before it loads any of that, on the policy route it already reads, with the same credential, session key and session token. The gateway answers the server's initialize result and filtered tool list, built by the functions the server would have called, in a worker thread under that session, with nothing kept. Any other outcome leaves the server on the order it always started in. The gateway builds a list only on an install whose package tree the sandbox seals against a session's agent, by the sandbox's own classification: building one imports listing modules into the gateway, outside the sandbox, on a request a session can cause. A packaged install is answered a list; an editable or from-source checkout builds its own, as before. The gateway answers a list only where it is the server's own: same listing code on disk (the modules that build the lists and every module those import, read once by a startup hook in a worker thread and not at import), same data home and agents directory, standalone platform, no governance policy or bound profile, not a private member session. For a session whose start has not registered it yet, the allocation records the starting agent for that one request, and a list is answered only when the policy withholds none of the server's tools, which is the unfiltered list a server builds in that window. A plain policy read keeps its 404 there. The discovery probe no longer stops at the list for these servers: it asks for one more answer, so a server whose handlers cannot load probes as an error with its reason. That reason is the last thing a server writes, so a failed probe now shows the end of its stderr, not the start.
cb336b0 to
add3644
Compare
Problem / Motivation
Goal: A new chat or sub-agent gets to its first prompt sooner, because Kiro Crew's own four tool servers list their tools without waiting for their own start-up.
An agent engine starts every MCP server of a session when the session starts and holds the first prompt until each has listed its tools. Kiro Crew's own servers (
kirocrew-core,kirocrew-cron,kirocrew-guide,kirocrew-mate) each loaded their configuration and the platform before they could list, andkirocrew-corealso read the agents folder and the configuration for its descriptions. On Linux the four needed about 0.9 s from spawn to the last list.Why it matters
Every new chat, every sub-agent and every scheduled run pays this before its first prompt. It is a fixed wait the person sees as a slow start, and it grows when several sessions start at once.
Not a goal
tools/callstill reads the policy in the server and refuses there.pgrepand apsper process is a follow-up, not part of this change.What changed (motivation → approach → change)
Goal → approach. The gateway is one warm process that already has the configuration, the platform and the agent specs loaded, and every own server already asks it for its tool policy before it lists. So the server asks once, earlier, and the gateway answers with the two answers the server would have built.
One commit: own servers relay their first two answers from the gateway.
mcp_listing_relay(server side): after the root-run refusal and before the configuration loader, the platform or the audit log is imported, oneGET /api/session-tool-policywith alistingparameter, carrying the same internal credential, session key and session token as the policy read. On a list, the server answersinitializeandtools/listand goes on starting; the handlers load where they always did. On anything else (no session identity or port in the environment, a refusal, a timeout, the gateway's "build locally", a malformed answer) it starts in the order it always did and builds both answers itself.mcp_listing_gateway(gateway side): the server's declaredlist_toolsbehind the one filterwithin_policy, andinitialize_result, run in a worker thread under that session as the request-local caller, restored on failure, nothing kept between requests. A description that reads a value only the gateway process holds (the sub-agent cap in force) is built as a tool server builds it, so the sentence is unchanged.sandbox_tiers.install_root_targets_for, the one source; no second rule and no seal added): a packaged install, on every system. An editable or from-source checkout stays writable to the agent, so there the gateway answers "build locally" before any listing code runs and the server starts as on main. The classification is the install kind and does not read the sandbox setting: withagent.sandboxoff, a packaged install is still answered a list and a source checkout is not. An answer that cannot be had counts as not sealed.404 agent not resolvedand a server lists everything. The session allocation records the agent of a start in flight (starting_agents, written only by that start, removed at registration and at every exit). Only alistingrequest reads it, and the gateway answers a list only when that agent's policy withholds none of the server's tools, which is the same unfiltered list. A plain policy read keeps its404in that window.kirocrew doctor, the dashboard's server list) no longer stops attools/listfor these servers: it asks for one more answer, so a server whose handlers cannot load probes as an error with its reason. A failed probe of any stdio server now shows the END of its stderr (its last whole lines, at most 500 characters). It reads at most 32 KiB, from the first byte, and redacts all of it before it takes the end, because the redactors know a private key by its first line: a server prints its start-up warnings first and the reason it stopped last, and the first 500 characters could be all warnings.Measured on Linux, on packaged installs (aarch64, 32 cores; this branch and its base each installed non-editable into
site-packages, the kind of install that is answered a list; one isolated gateway at a time, default backend). Taken before the last two changes to the gateway side (the install check and the stamp read at startup), which add no work to a relayed request:kirocrew-core/ the other threeThe caveat. With five chats starting at once, 2 of 120 requests (both
kirocrew-core's) did not answer within the bound. Those two sessions took 3230 and 3484 ms, at the slow end of the base's range (2264 to 3535 ms): for them the relay cost time instead of saving it. The gateway's own answer times also have a longer tail while lists are built (max 61 ms against 30 ms).The bound is 1.0 s (
RELAY_FETCH_TIMEOUT_SECS), and these numbers are why: a request that answers inside it is sooner than building the list in the server (the list is out about 0.15 s after the answer, against about 0.9 s for the server's own start), and one that does not costs the bound on top of the old start. A shorter bound would turn the 0.4 to 0.9 s answers seen under load into fallbacks that are slower than waiting. Each timed-out request logs a warning; every other fallback logs one informational line with its reason.A governed install builds locally. With a governance policy installed, a profile bound to the session, or a platform that is not the standalone composition, the gateway answers "build locally" and the server starts as before. No test claims identical bytes there.
macOS and Windows. The relay ran on both, against its base, on an earlier head: all four servers relayed in every chat, and the relayed bytes are the server's own; the figures are in the results comment on this PR. Those runs were on source checkouts. From this head on a source checkout builds its own lists, so those figures show what the relay does where it engages, not what a source checkout gets; runs on packaged installs of this head are to follow in a comment. That earlier head also carried a second commit that read the macOS process tree in process. It is taken out of this PR: with it, two tests of
test/test_acp_client_shutdown_eof_grace.pyfailed on macOS, because a new child's name was recorded before the child had finished starting and the kill path, which needs the recorded name to read back, then left that child alive. The fix belongs in a change of its own. Nothing of that commit is in this head.Backwards compatibility
Compatible: a policy read without the new parameter is answered exactly as before, and a server that gets no list starts and answers exactly as before.
One thing is no longer written. For a list the gateway relays to a session that is still starting, the audit log no longer gets
tool_policy.agent_not_resolvedandtool_policy.unfiltered_listingfrom the server, nor the gateway'ssession_tool_policy"agent not resolved" row for that request: the gateway read the policy, and it answers a list only when the policy withholds nothing. A server that builds its own list writes all of them as before.Reader: src/kiro_crew/mcp_shared_policy.py:_resolve_tool_policy -- chat -- writer only; no code reads the row back (test_mcp_listing_relay.py::test_a_server_that_gets_no_list_has_loaded_nothing_and_answers_as_it_always_did)
Reader: src/kiro_crew/mcp_shared_listing.py:listable_tools -- chat -- writer only; no code reads the row back (test_mcp_listing_relay.py::test_a_client_reads_the_same_bytes_from_a_relayed_and_a_server_built_list)
Reader: docs/architecture/mcp.md -- release -- the description of both rows is updated in this PR
Tests
test/test_mcp_listing_relay.py: the bytes a client reads are the same from a relayed and a server-built list, for all four servers, with no policy, with excluded tools, with an include list and for a session that is not registered yet (two real processes); a server that gets no list has loaded no configuration loader, platform or audit module when the relay step returns, and answers what it always answered;kirocrew-core's gateway-built list equals its server-built list across backend, Tool Search, a pinned and an automatic sub-agent ceiling, and a parent with and withoutavailableAgents; the gateway builds off the event loop, under the asking session, restores the caller on failure and keeps nothing; another session's key gets the refusal and no list; a plain policy read of a starting session keeps its404; the route tells the builder a private member's session from that session's own execution record; the code stamp's set of imported modules equals the one read off the builders' import statements; the two-process rig waits the test's own bound, not the production one, for the gateway's answer and for each frame; a table over the install (packaged, source checkout, editable, the sandbox off, a classification that is unknown or raises) says which is answered a list and with which reason, and that no listing code runs for the others; the rig's gateway on the real source checkout answers "build locally"; no list is built before the stamp is read, loading the builder the route module imports reads no stamp, and the startup hook returns before the read is done.test/test_session_starting_agent.py: the starting agent is readable until the session is registered, and the row is gone after a failed and after a cancelled start.test/test_mcp_probe_past_listing.py: a server whose handler import fails turns the probe red, with the reason, also when it printed more start-up text than an error carries before it; a private key longer than the shown text is redacted whole; a stderr that never ends is read to a bound.test/test_mcp_slim_entry.py: the in-process entry tests no longer read the test process's own stdin or keep its stdout.Manual verification
kirocrew doctoron a scratch home shows a broken handler import as "the server listed its tools and then stopped before it could run one" with the import error.0ed974e6e504and shows the import error.Related Issues
Part of #35785
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license.