Repository navigation
fix(cron): keep a script cron's MCP server after a tool error - #16905
iamwhatever merged 1 commit into
Conversation
A call the server answers with a tool error (a JSON-RPC error reply or an isError result) now keeps its server for the run's next call, so a rate-limited call no longer makes the next call start a new server and sign in again. McpToolClient raises the new McpToolError for those answers; a call that fails any other way still stops its server. The cron spec also says what happens to kept servers when a run is killed at its timeout.
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check one case before merge: a server whose startup sign-in failed and that reports it as an [DESIGN-REVIEWED] a50334e Description read[DESCRIPTION-READ] 95ff96fb6d81312738eaaecef0bbc954e598ecc15070d3b635d484681716d824 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, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Before merging, check that the Slack MCP server answers a rate-limited call with an What this change shipsInventory (3 items) — 3 justifiedIntent: let a script cron's Slack calls keep going after a rate-limited answer without signing in to Slack again and drawing another HTTP 429. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] a50334e Description read[DESCRIPTION-READ] 6717a2b8a865d7b854405612a1b0646b123dd7d441cbbb3c90cc51a03d33ccc8 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
iamwhatever
left a comment
There was a problem hiding this comment.
The error split is correct. Only a reply whose id matched becomes McpToolError, so a reused server cannot be out of sync with the client. Disconnects, the 1000-line cap and malformed replies still stop the server. The tests pin both branches, and every check is green. Please answer the Design note: a server whose startup sign-in failed and that reports it through isError now fails for the rest of the run instead of restarting. That only lasts one run, but say in the spec whether you accept it. Approving.
|
@iamwhatever Accepted. A server that reports a failed sign-in as a tool error is still answering, so it is kept, and its own retry rules decide when it signs in again. For the Slack server behind this change that beats a restart: after a failed sign-in it fails calls fast until Slack's Retry-After has passed, then signs in again on the next call. A restarted process would sign in again at once, and sign-ins close together are what drew the 429s in #16659. A server that never retries a failed startup sign-in stays failed until the run ends, and the next run starts it fresh. The spec does not say this yet. |
…accepted A server whose start-up sign-in failed and that reports it as a tool error is kept for the rest of the run since kirodotdev#16905. The spec now says that this is accepted and why: the server's own retry rules decide when it signs in again, the next run starts fresh servers, and restarting it after each error would sign in again at once. Refs kirodotdev#16659
…accepted A server whose start-up sign-in failed and that reports it as a tool error is kept for the rest of the run since kirodotdev#16905. The spec now says that this is accepted and why: the server's own retry rules decide when it signs in again, the next run starts fresh servers, and restarting it after each error would sign in again at once. Refs kirodotdev#16659
…accepted A server whose start-up sign-in failed and that reports it as a tool error is kept for the rest of the run since kirodotdev#16905. The spec now says that this is accepted and why: the server's own retry rules decide when it signs in again, the next run starts fresh servers, and restarting it after each error would sign in again at once. Refs kirodotdev#16659
…accepted (#17121) A server whose start-up sign-in failed and that reports it as a tool error is kept for the rest of the run since #16905. The spec now says that this is accepted and why: the server's own retry rules decide when it signs in again, the next run starts fresh servers, and restarting it after each error would sign in again at once. Refs #16659
Problem / Motivation
Goal: A script cron's call that the MCP server answers with a tool error keeps the run's server, so a rate-limited call no longer makes the run's next call start a new server that signs in again.
Since #16661, a script cron run keeps one MCP server per name for its later calls. A call the server answered with a tool error still stopped that server, the same as a call that got no answer. A Slack server answers a rate-limited call with a tool error, so the run's next Slack call started a new server, and that server signed in to Slack again. Sign-ins that come close together are what Slack refuses with HTTP 429 (#16659).
The approval on #16661 also asked for one sentence in the cron spec on what happens to kept servers when a run is killed at its timeout.
Why it matters
Every tool error from a server that signs in when it starts costs the run another server start, handshake and sign-in. For Slack, that extra sign-in comes seconds after the last one, and sign-ins close together are what Slack refuses. Without the spec sentence, a reader cannot tell whether a timeout leaves kept servers running.
Not a goal
What changed (motivation → approach → change)
A call the server answers with a tool error now keeps the run's server, the same as a call it answers with a result. The script still gets the error. Only a call that gets no answer stops its server.
errorreply or anisErrorresult)McpToolClient.call_toolinsrc/kiro_crew/cron_script.pyraised a plainRuntimeErrorfor both kinds of failure, soKeptMcpServerscould not tell a server that answered from one that did not. It now raisesMcpToolError, a newRuntimeErrorsubclass with the same message, for the two error answers.KeptMcpServers.call_toolkeeps the client when it catchesMcpToolError, then re-raises it. Both cron contexts, the run's andkirocrew cron preview's, go throughKeptMcpServers, so both behave this way.The server-lifetime bullet in
docs/system-specs/modules/learn-cron-dashboard.mdsays this. It also says what a timeout does: the kill skips the launcher'sfinally, but kept servers still stop, because each runs inside the script child's process group (SIGKILLon POSIX) or process tree (taskkill /Ton Windows). Only a server that starts a session of its own outlives the kill, until it reads end-of-file on its stdin.Backwards compatibility
Compatible: a script gets the same results and the same error messages from the same calls.
McpToolErrorsubclassesRuntimeError, so code that catchesRuntimeErrorstill catches it. Only how long a server stays up after a tool error changes.Removes nothing: no key, function or record is removed or renamed.
cron_script.pygainsMcpToolError.Tests
test_a_tool_error_keeps_its_server_for_the_next_callintest/test_cron_script.py: a call that raisesMcpToolErrorleaves its server running, the next call uses the same server, andclose()stops it once.test_a_call_without_an_answer_stops_its_server_and_the_next_call_starts_another(renamed fromtest_a_failed_call_stops_its_server_and_the_next_call_starts_another): a disconnect still stops the server, and the next call starts another.TestMcpToolClientProtocol: an error reply and anisErrorresult raiseMcpToolError; a disconnect raises aRuntimeErrorthat is not one.Each part reverted on its own turns a named test red: stopping the server after a tool error, keeping it after a call without an answer, and either error answer raising a plain
RuntimeError.Manual verification
On Linux, two script crons ran through
run_script_sandboxedwith a 10-second timeout. Each made onectx.call_tooland then slept. Both servers ignore end-of-file on stdin, so only a signal could stop them.os.setsid()first was still running 5 seconds after the kill. The check then stopped it.This host has no systemd user session, so
systemd-run --scopewas not in the spawn path.cgroup_scope_argvdocuments that--scopeexecs into the target, so it leaves the process group as it is. The Windows path (taskkill /T) was traced in code, not run.Related Issues
Refs #16659
Follow-up to #16661: its Design review's tool-error point and the timeout note in its approval.
Pattern harvest
Not generalizable:
KeptMcpServers.call_toolis the one place that builds anMcpToolClient, so it is the one place that decides whether a server outlives a failed call, and both cron contexts go through it.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)