Skip to content

fix(mcp): answer every request with an id while a tool call runs - #18979

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/mcp-busy-loop-answers-unknown-methods
Oct 11, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/mcp-busy-loop-answers-unknown-methods

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A new chat's first turn is no longer about 30 s late when the shared kirocrew-core backend happens to be running another session's tool call.

The pooled kirocrew-core backend runs one tool call at a time. While a call runs, its stdio loop answers only cancel, ping, tools/list and tools/call; every other request with an id gets no answer, ever. An MCP client can open a connection with a version probe such as server/discover. A probe that lands while the backend is busy is dropped, so the client waits out its own timeout (about 30 s observed) before it falls back and reconnects. The same probe on an idle backend gets -32601 Unknown method in milliseconds.

Why it matters

Every dashboard session on a host with the MCP gateway's stub sharing on uses the same backend, so any session's in-flight call can push another session's first prompt back by 30 s. Measured on one host: first turns that hit this had a 38.9 s median before the prompt was sent, against 15.6 s without it.

Not a goal

What changed (motivation → approach → change)

Symptom: first turn ~30 s late. Cause: the busy branch drops unknown requests that the idle branch answers with -32601. Change: the busy branch now sends any other request with an id through the idle dispatcher, so it gets the answer it would get idle. Notifications without an id are still dropped.

Before After
server/discover (or any unknown method) while a call runs no answer -32601 at once
Same request while idle -32601 at once unchanged

Files: src/kiro_crew/mcp_shared.py (busy branch), test/test_mcp_shared.py.

Complementary to #18841: that PR parks wait, ask_question, spawn_run and spawn_sub_agents off the worker, which removes the most common busy window. Its busy branch keeps the same drop, so any other call on the worker (and the first step of a parked call) still swallows the probe. The two touch the same few lines; whichever lands second needs a small rebase.

Backwards compatibility

Compatible: requests that were answered before get the same answers; requests that got silence now get the idle path's answer.

Removes nothing: the change only adds answers to requests that were dropped.

Tests

  • test/test_mcp_shared.py::TestStdioLoopBusyQueue::test_unknown_method_gets_method_not_found_while_busy (server/discover, resources/list): a busy worker plus that request gets -32601 while the slow call is still running.
  • Local: pytest test/test_mcp_shared.py test/test_mcp_shared_cancelled_bound.py 214 passed. With the old busy branch restored, both new cases fail. black, flake8, isort clean on the two files.

Manual verification

N/A — unit coverage drives the real stdio loop with a blocked tool; no live gateway was restarted.

Related Issues

Closes #18978

Pattern harvest

Rule candidate: review-prompt
Pattern: a busy loop that serves a subset of methods drops the rest instead of answering them the way its idle path does.

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

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners October 11, 2026 00:12
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 11, 2026
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 57514d2abbd5e8d007ec3cfec3927c4e6b6b6f03 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 57514d2abbd5e8d007ec3cfec3927c4e6b6b6f03 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check _dispatch's docstring: it still says "while no tool is running", but the busy loop now calls it, so a new non-tools/call arm must not touch worker state.

[DESIGN-REVIEWED] 57514d2

Description read

[DESCRIPTION-READ] c6df574864730bcc830742e8f972a2f3e8ba6c808cd4189545825d4227880429

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 57514d2abbd5e8d007ec3cfec3927c4e6b6b6f03 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 57514d2

Verdict parsed from the review's SHA-scoped output markers for commit 57514d2abbd5e8d007ec3cfec3927c4e6b6b6f03.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 57514d2abbd5e8d007ec3cfec3927c4e6b6b6f03: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 57514d2abbd5e8d007ec3cfec3927c4e6b6b6f03 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (3 items) — 3 justified

Intent: stop a new chat's first turn from waiting about 30 s when the shared kirocrew-core backend is busy with another session's tool call. FIX (Closes #18978; the new test fails on base).

  1. A probe such as server/discover, or any other unknown method, sent while a tool call runs now gets -32601 straight away instead of no reply — justified
  2. An initialize sent while a tool call runs now gets its handshake reply instead of no reply — justified
  3. The busy loop no longer has its own copy of the tools/list handler and hands requests to the idle dispatcher _dispatch, so busy and idle answers can't drift apart — justified

[FIRST-PRINCIPLES-REVIEWED] 57514d2

Description read

[DESCRIPTION-READ] 35604c6f746691de8a093dd6e390990651dad1d4f79b7d70bfc62a4904f7a168

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 57514d2abbd5e8d007ec3cfec3927c4e6b6b6f03 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 57514d2

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 57514d2abbd5e8d007ec3cfec3927c4e6b6b6f03: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 11, 2026
@iamwhatever
iamwhatever force-pushed the fix/mcp-busy-loop-answers-unknown-methods branch from 311954d to 7b88ef1 Compare October 11, 2026 00:52
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 11, 2026
The busy stdio loop dropped any request other than ping, tools/list and tools/call. A client's version probe (server/discover) then went unanswered and the client waited out its own timeout before reconnecting. Route such requests through the idle dispatcher, which answers an unknown method with -32601 at once.
@iamwhatever
iamwhatever force-pushed the fix/mcp-busy-loop-answers-unknown-methods branch from 7b88ef1 to 57514d2 Compare October 11, 2026 05:35
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 11, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Self-review (crew-pr-reviewer, read-only): RECOMMEND APPROVE

The PR stops the pooled kirocrew-core backend from ignoring a client's version probe (for example server/discover) while another session's tool call is running. Ignored, that probe left a new chat's first turn waiting about 30 s for the client's timeout. The root cause is fixed: the busy branch in src/kiro_crew/mcp_shared.py now sends every other request with an id to the idle _dispatch. Unknown methods now get -32601, the same answer they get when the backend is idle. I checked _dispatch at 57514d2. The cancel, ping and tools/call arms still run before the new branch, so a busy request can never reach _dispatch's worker-starting tools/call arm. What can reach it is initialize (a capabilities reply), tools/list (the same handler as before) and the -32601 fallback, and none of them touches worker state. Notifications without an id are still dropped. The new parametrized test runs the real stdio loop with a blocked tool and asserts the -32601 arrives before the slow call finishes. It would fail on base, where the request gets no answer. All checks are green, and GPT, Opus, Design and First Principles all PASS; UX was skipped (no UI change). Reviewer note: the Design PASS punchline is unanswered. _dispatch's docstring still says "while no tool is running", but the busy loop now calls it. A one-line docstring fix, or a disposition, would stop a future arm from mutating worker state by mistake. — crew-pr-reviewer

@iamwhatever
iamwhatever enabled auto-merge (squash) October 11, 2026 07:52
@chenmingwei23
chenmingwei23 merged commit c06d2c8 into main Oct 11, 2026
101 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/mcp-busy-loop-answers-unknown-methods branch October 11, 2026 08:55
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pooled kirocrew-core drops server/discover while a tool call runs, delaying a new chat's first turn by 30 s

2 participants