Skip to content

fix: arm the mcp drain once declared servers report in kas status - #39196

Open
lucasmokwa wants to merge 1 commit into
kirodotdev:mainfrom
lucasmokwa:fix/kas-drain-init-mcp-status
Open

lucasmokwa wants to merge 1 commit into
kirodotdev:mainfrom
lucasmokwa:fix/kas-drain-init-mcp-status

Conversation

@lucasmokwa

@lucasmokwa lucasmokwa commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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_mode and its first prompt, even when its servers connected in well under a second. kirocrew-lite with 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 between set_mode and drain_init returning.

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

What changed (motivation → approach → change)

drain_init ends its wait early only when it sees a classic _kiro.dev/mcp/* frame. KAS reports MCP readiness in _kiro/mcp/status snapshots 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. So drain_init now also arms its idle shortcut once no server the session declares is still starting, using the report's own still_starting test (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 of docs/system-specs/modules/acp-client.md describes 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's connected status ends the drain long before its ceiling.
  • test_drain_init_pending_kas_status_does_not_arm_the_shortcut: a connecting status 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 stale connected does 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 loadgroup and in a shuffled order. The test files that reference the drain, this module or still_starting pass (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 HOME and 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, with session_handle_mcp.py taken from each side.
Before (main be0b414): set_mode outcome=ready 19:45:53 -> drain_init: drained 15 init frame(s) and Created session 19:45:59 (6 s).
After (head b632dc5): set_mode outcome=ready 19:46:19 -> drain_init: drained 15 init frame(s) and Created session 19: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

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KAS: first prompt waits the full 6 s MCP no-report ceiling for agents with only external servers, because drain_init ignores _kiro/mcp/status

1 participant