Repository navigation
fix: arm the mcp drain once declared servers report in kas status - #39196
Open
lucasmokwa wants to merge 1 commit into
Open
lucasmokwa wants to merge 1 commit into
lucasmokwa wants to merge 1 commit into
Conversation
lucasmokwa
force-pushed
the
fix/kas-drain-init-mcp-status
branch
from
November 18, 2026 19:31
486cbaa to
b632dc5
Compare
lucasmokwa
marked this pull request as ready for review
November 18, 2026 19:53
1 task done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Motivation
Goal: A KAS session whose agent declares only external MCP servers sends its first prompt as soon as those servers have reported, instead of always waiting the full 6 s no-report ceiling.
On the KAS engine, every such session waits 6.0 s between
set_modeand its first prompt, even when its servers connected in well under a second.kirocrew-litewith one external server is such an agent, so every Optimize prompt call pays it: in a DEBUG gateway log, 6.0 s of a 13 s call sat betweenset_modeanddrain_initreturning.Why it matters
Every KAS session start for an agent with only external MCP servers is 6 s slower than it needs to be. The Optimize prompt button is the most visible case: about half of each call is this wait. It is part of the session-start time #36680 measured.
Not a goal
AcpClientpath's own drain, which KAS sessions do not use.What changed (motivation → approach → change)
drain_initends its wait early only when it sees a classic_kiro.dev/mcp/*frame. KAS reports MCP readiness in_kiro/mcp/statussnapshots instead, which no drain action names, so nothing ends the wait and every such session runs to the ceiling.The session's MCP report (
McpSessionReport) already reads both spellings, and the reader loop folds each frame into it before queueing it. Sodrain_initnow also arms its idle shortcut once no server the session declares is still starting, using the report's ownstill_startingtest (the one the first-turn hold reads). A server that is still connecting cannot end the wait early, and a declared list cut at its cap skips the check. A mode-switched session gets the same check: the switch has already dropped the pre-switch agent's reports. The drain section ofdocs/system-specs/modules/acp-client.mddescribes the new rule.Backwards compatibility
Compatible: the drain still ends on every signal it ended on before; it gains one more way to end early, only once every declared server has reported.
Removes nothing: the change adds an exit condition to a wait and takes no path, record or key away.
Tests
Three tests in
test/test_acp_runtime_drain_init.py:test_drain_init_exits_once_every_declared_server_reported_in_kas_status: a declared server'sconnectedstatus ends the drain long before its ceiling.test_drain_init_pending_kas_status_does_not_arm_the_shortcut: aconnectingstatus keeps the drain waiting until the final status arrives.test_drain_init_mode_switched_session_arms_on_the_switched_agents_report: after a mode switch drops the earlier report, a staleconnecteddoes not end the drain and the switched-to agent's own status does.Each test gives the drain a ceiling far past its own wait bound, so all three fail by name with the fix reverted.
Determinism: each new test passed 20/20 at
-n0; the whole file passed 10/10 at-n 4 --dist loadgroupand in a shuffled order. The test files that reference the drain, this module orstill_startingpass (2,249 tests).Proof: PROVEN test/test_acp_runtime_drain_init.py::test_drain_init_exits_once_every_declared_server_reported_in_kas_status, test/test_acp_runtime_drain_init.py::test_drain_init_pending_kas_status_does_not_arm_the_shortcut, test/test_acp_runtime_drain_init.py::test_drain_init_mode_switched_session_arms_on_the_switched_agents_report (head b632dc5)
Manual verification
One headless chat session on a test agent whose only MCP server is an external stdio server (Kiro Crew's own servers excluded through
managedToolPolicy.excludeServers), run through a throwaway gateway on the KAS backend. Main reproduces the 6 s wait; this head removes it (below).Real-machine verification
Machine: author's Linux cloud desktop, Amazon Linux 2023 (kernel 6.12, x86_64), 16 vCPU / 30 GiB. Gateway run from this checkout with
HOMEand the data home pointed at a throwaway folder, loopback port 6777,KIROCREW_PROFILE=standalone, KAS backend, kiro-cli 3.5.0, DEBUG log.Command:
kirocrew chat --headless --agent rmv-ext --message-file msg.txt, withsession_handle_mcp.pytaken from each side.Before (main be0b414):
set_mode outcome=ready19:45:53 ->drain_init: drained 15 init frame(s)andCreated session19:45:59 (6 s).After (head b632dc5):
set_mode outcome=ready19:46:19 ->drain_init: drained 15 init frame(s)andCreated session19:46:20 (about 1 s).Cleanup: own computer; both gateways stopped, the throwaway home signed out of kiro-cli and deleted, the checkout back on the head with a clean tree.
Related Issues
Closes #39175
Sibling sweep
Swept: git grep -nE "_MCP_DRAIN_REPORT_ACTIONS|no_report_ceiling" -- src/
Sibling: src/kiro_crew/acp/session_handle_mcp.py -- changed here
Sibling: src/kiro_crew/acp/client_transport.py -- not affected -- the AcpClient drain has no no-report ceiling and exits on idle
Pattern harvest
Not generalizable: the drain predates KAS and keyed readiness on one wire spelling; the report tracker that reads every spelling already existed.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)