Repository navigation
fix(mcp): park waiting tools off the worker so a wait stalls nobody (0.9.0 backport of #18841) - #20631
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that the gateway still recycles a backend that is really stuck, given it now trusts the backend's own report of which calls are parked. [DESIGN-REVIEWED] b9c8a7c Description read[DESCRIPTION-READ] 17cc9198b264c78981e163bb9542652630b47c3a16b0eaf6f4fb0df3e5c1c01c 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 Before merge, confirm that every non-deferred Inventory (8 items) — 7 justifiedIntent: stop one session's
[FIRST-PRINCIPLES-REVIEWED] b9c8a7c Description read[DESCRIPTION-READ] 7cac2da6cc93b7de97c050f4a5d2b7bffb102413623d03f5e2fc951c7a9ce38a That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Review detailsOne advisory finding: the spec and a code comment describe an FINDING — docs/architecture/mcp.md:2906 — the spec says an ask step's slice is " [OPUS-REVIEWED] b9c8a7c 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: |
Problem / Motivation
Goal: On the 0.9.0 line, one session's
waitorspawn_sub_agentsno longer makes every other session'skirocrew-coretool calls queue behind it.This is a backport of #18841 (
d9990a26fe, merged tomain2026-10-12) torelease/0.9.0, cherry-picked with-x.On 0.9.0 the pooled
kirocrew-corebackend has one tool worker thread.wait(up to 1800s),spawn_sub_agents(up to 7200s) and thespawn_rungate wait sleep on that thread. While one session waits, every other session'smemory_recall,send_message,session_ledger_recordand so on sits in the queue behind it (#17031). The backend keeps answering pings, so the gateway never recycles it.Why it matters
Every session that shares the pooled
kirocrew-corebackend is hit. One babysit loop or one blocking subagent wave stalls the other chats' tools for minutes to hours, and new sessions can time out onsession/new. 0.9.0 insiders who turn on shared MCP backends get this today, and #18841 only reaches them through the release branch.Not a goal
session/newchanges, concurrent dispatch of calls that compute, the Windows synchronous path.ask_questionfrommain. 0.9.0 ships the non-blocking ask, which never held the worker.mainchanges to the same files that are not on 0.9.0 (per-taskbackendonspawn_run, themade_no_tool_callsnote).What changed (motivation → approach → change)
Symptom: one session's
waitstalls every co-tenant'skirocrew-corecall. Root cause: waiting handlers sleep on the backend's only worker thread. Change (from #18841, logic unchanged): those handlers return aDeferredTool. The stdio loop steps it on its own timer and an 8-thread step pool, and reports parked ids to the gateway (notifications/kirocrew/inflight) so its wedge detector neither recycles a healthy parked call nor ignores a stuck one.release/0.9.0is behindmainin the touched files. Conflicts were resolved as follows:ask_question: kept 0.9.0's non-blocking version. Dropped the blocking-ask half of fix(mcp): park waiting tools off the worker so a wait stalls nobody #18841:_AskStep, the/api/agent-ask/*client,ASK_WAIT_SLICE_SECS, their doc changes,test_ask_question_blocking.pyand the ask queue-budget test.mcp_tools/spawn.py: kept the_inline_resulthelper and the finished-with-errortextfield (fix(spawn_sub_agents): keep a failed child's transcript #18455), because the restructured collect step is written against them. Dropped the per-taskbackendfield (feat(subagents): let spawn_run pick the backend a sub-agent runs on #18150) and themade_no_tool_callsnote (fix(subagent): flag sub-agent runs with no tool calls in completions #18633), withtest_spawn_backend.pyandtest_subagent_no_tool_calls_note.py. Kept the_SA_ERROR_MAX_CHARSbound on retained gateway lines.mcp_shared.py: byte-identical tod9990a26fe. This also brings fix(mcp): answer every request with an id while a tool call runs #18979 (answer every request with an id while a tool runs), the only other difference betweenrelease/0.9.0and the parent ofd9990a26fein this file.test_mcp_core_more_coverage.py: dropped thekiro_crew.mcp_guidecase; that module does not exist on 0.9.0.Backwards compatibility
Compatible: tool names, schemas and results are unchanged for callers.
waitandspawn_sub_agentsreturn the same text, just without holding the worker. The newSPAWN_BATCH_MEMBERS_MAX(128) bound onspawn_run.tasks/agentsandspawn_sub_agents.agentsis twice the sub-agent ceiling of 64, the same as onmain.The diff removes the public
mcp_shared.is_tool_cancelled()(as #18841 does onmain). Its only readers onrelease/0.9.0(git grep is_tool_cancelled b4cf148542 -- src) are the two blocking loops this PR replaces:Reader: src/kiro_crew/mcp_tools/control.py:wait -- chat -- now returns _WaitStep (a DeferredTool); the dispatch loop drops a cancelled parked call; test_wait_tool_early_end.py
Reader: src/kiro_crew/mcp_tools/spawn.py:spawn_sub_agents -- subagent -- now returns _SubAgentsStep (a DeferredTool), cancelled the same way; test_mcp_core_spawn_sub_agents.py
Tests
From #18841, adapted to 0.9.0:
test_mcp_shared_deferred_tools.py(new): many parked calls hold no worker and all settle; per-call identity in each step; cancel before, during and after a step; parked overflow; pruned-install exit; the step pool's up-front threads and start failures.test_mcp_gateway_inflight_report.py(new): the inflight capability handshake both ways and the gateway's handling of the report.test_wait_tool_early_end.py,test_mcp_core_spawn_sub_agents.py,test_spawn_run_per_task_overrides.py,test_mcp_gateway_wedge_ping_gate.pyand the other touched files: updated for the deferred return.Results on this branch:
test_mcp*,test_spawn*,test_subagent*,test_wait*,test_gatewayd*,test_validation*file: 10664 passed, 42 skipped, 1 xfailed, 0 failed.ruff checkclean on every touched.pyfile.Manual verification
N/A -- this is a cherry-pick of a change already verified on
main; the tests above cover the parked and non-parked paths.Related Issues
Backport of #18841. Refs #17031.
Pattern harvest
Not generalizable: this PR carries an existing fix to a release branch; the pattern harvest for the defect is in #18841.
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.