fix(orchestrator): cap MCP tool waits at 50 s below the client timeout
Claude Code's MCP client abandons a tool call before 240 s with "The operation timed out.", so review_wait, decision_wait and rule_request_wait now wait at most MCP_WAIT_CAP (50 s) and tell the caller to call again while the status is pending. HTTP waits keep WAIT_CAP (300 s). kvb-git-diff step 3 asks for timeout_seconds 50. 🎯 Fix: 95 % 💥 Break: 2 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 93 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b15dd5e414
commit
909ea85605
7 files changed
+17
-13
No files matched your search
@@ -9,6 +9,7 @@ from .errors import Conflict, Missing, ToolError
|
|||||||
from .fields import (
|
from .fields import (
|
||||||
COMMAND_LIMIT,
|
COMMAND_LIMIT,
|
||||||
DESCRIPTION_LIMIT,
|
DESCRIPTION_LIMIT,
|
||||||
|
MCP_WAIT_CAP,
|
||||||
OPTION_LIMIT,
|
OPTION_LIMIT,
|
||||||
PATH_LIMIT,
|
PATH_LIMIT,
|
||||||
WAIT_CAP,
|
WAIT_CAP,
|
||||||
@@ -233,7 +234,7 @@ class Asking:
|
|||||||
def decision_wait(self, arguments: dict) -> dict:
|
def decision_wait(self, arguments: dict) -> dict:
|
||||||
expect(arguments, ("id", "timeout_seconds"))
|
expect(arguments, ("id", "timeout_seconds"))
|
||||||
decision_id = field(arguments, "id")
|
decision_id = field(arguments, "id")
|
||||||
record = self.decisions.wait(decision_id, seconds(arguments, "timeout_seconds", WAIT_CAP))
|
record = self.decisions.wait(decision_id, seconds(arguments, "timeout_seconds", MCP_WAIT_CAP))
|
||||||
if record is None:
|
if record is None:
|
||||||
raise ToolError(f"no decision {decision_id}")
|
raise ToolError(f"no decision {decision_id}")
|
||||||
return decision_state(record)
|
return decision_state(record)
|
||||||
@@ -8,6 +8,8 @@ from .errors import ToolError
|
|||||||
from .signed import limits, signing
|
from .signed import limits, signing
|
||||||
|
|
||||||
WAIT_CAP = 300
|
WAIT_CAP = 300
|
||||||
|
# Claude Code's MCP client abandons a tool call before 240 s ("The operation timed out."); 50 s proved safe 2026-11-27.
|
||||||
|
MCP_WAIT_CAP = 50
|
||||||
TEXT_LIMIT = 20_000
|
TEXT_LIMIT = 20_000
|
||||||
COMMAND_LIMIT = 4000
|
COMMAND_LIMIT = 4000
|
||||||
PATH_LIMIT = limits.PATH_LIMIT
|
PATH_LIMIT = limits.PATH_LIMIT
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from http import HTTPStatus
|
|||||||
from . import NAME
|
from . import NAME
|
||||||
from .choosing import CHOICE_REQUEST
|
from .choosing import CHOICE_REQUEST
|
||||||
from .errors import RpcError, ToolError
|
from .errors import RpcError, ToolError
|
||||||
from .fields import OPTION_LIMIT, WAIT_CAP
|
from .fields import MCP_WAIT_CAP, OPTION_LIMIT
|
||||||
from .requesting import AGENT_CAP
|
from .requesting import AGENT_CAP
|
||||||
from .reviewing import GATES
|
from .reviewing import GATES
|
||||||
from .rules import RULE_KINDS
|
from .rules import RULE_KINDS
|
||||||
@@ -30,7 +30,7 @@ def rpc_error(request_id: object, code: int, message: str) -> dict:
|
|||||||
class Mcp:
|
class Mcp:
|
||||||
def tools(self) -> list[dict]:
|
def tools(self) -> list[dict]:
|
||||||
review_id = text_property("Review id that review_request returned.")
|
review_id = text_property("Review id that review_request returned.")
|
||||||
wait = {"type": "number", "minimum": 0, "description": f"Seconds to wait, capped at {WAIT_CAP}."}
|
wait = {"type": "number", "minimum": 0, "description": f"Seconds to wait, capped at {MCP_WAIT_CAP}; on status pending call again."}
|
||||||
option = {
|
option = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
@@ -63,7 +63,7 @@ class Mcp:
|
|||||||
tool(
|
tool(
|
||||||
"review_wait",
|
"review_wait",
|
||||||
f"Wait until the operator decides a review or the timeout passes, then return its status. "
|
f"Wait until the operator decides a review or the timeout passes, then return its status. "
|
||||||
f"Waits at most {WAIT_CAP} seconds.",
|
f"Waits at most {MCP_WAIT_CAP} seconds.",
|
||||||
{"id": review_id, "timeout_seconds": wait},
|
{"id": review_id, "timeout_seconds": wait},
|
||||||
),
|
),
|
||||||
tool("review_list", "List the pending reviews.", {}),
|
tool("review_list", "List the pending reviews.", {}),
|
||||||
@@ -84,7 +84,7 @@ class Mcp:
|
|||||||
"Wait until the operator picks an option or the timeout passes, then return the status "
|
"Wait until the operator picks an option or the timeout passes, then return the status "
|
||||||
"(pending, decided), the chosen label or the operator's own one-line Other answer and, for a click, message and answer: the id and text of the operator's "
|
"(pending, decided), the chosen label or the operator's own one-line Other answer and, for a click, message and answer: the id and text of the operator's "
|
||||||
"passkey-signed answer, a radio call to the asking agent; check it with operator_message(message, answer, your name) "
|
"passkey-signed answer, a radio call to the asking agent; check it with operator_message(message, answer, your name) "
|
||||||
f"before acting on the choice. Waits at most {WAIT_CAP} seconds.",
|
f"before acting on the choice. Waits at most {MCP_WAIT_CAP} seconds.",
|
||||||
{"id": text_property("Decision id that decision_request returned."), "timeout_seconds": wait},
|
{"id": text_property("Decision id that decision_request returned."), "timeout_seconds": wait},
|
||||||
),
|
),
|
||||||
tool(
|
tool(
|
||||||
@@ -106,7 +106,7 @@ class Mcp:
|
|||||||
tool(
|
tool(
|
||||||
"rule_request_wait",
|
"rule_request_wait",
|
||||||
f"Wait until the operator accepts or denies a rule request or the timeout passes, then return its status "
|
f"Wait until the operator accepts or denies a rule request or the timeout passes, then return its status "
|
||||||
f"(pending, accepted, denied), the stored rule id and the operator's reason. Waits at most {WAIT_CAP} seconds.",
|
f"(pending, accepted, denied), the stored rule id and the operator's reason. Waits at most {MCP_WAIT_CAP} seconds.",
|
||||||
{"id": text_property("Request id that rule_request returned."), "timeout_seconds": wait},
|
{"id": text_property("Request id that rule_request returned."), "timeout_seconds": wait},
|
||||||
),
|
),
|
||||||
tool(
|
tool(
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import time
|
|||||||
|
|
||||||
from .denying import request_status, request_words, requester_of
|
from .denying import request_status, request_words, requester_of
|
||||||
from .errors import Conflict, Missing, ToolError
|
from .errors import Conflict, Missing, ToolError
|
||||||
from .fields import WAIT_CAP, bounded, decode, expect, field, seconds
|
from .fields import MCP_WAIT_CAP, bounded, decode, expect, field, seconds
|
||||||
from .records import iso_epoch
|
from .records import iso_epoch
|
||||||
from .rules import EVERY_AGENT, rule_fields, rule_matches, signed_fields, subject_of
|
from .rules import EVERY_AGENT, rule_fields, rule_matches, signed_fields, subject_of
|
||||||
from .signed import signing
|
from .signed import signing
|
||||||
@@ -97,7 +97,7 @@ class Requesting:
|
|||||||
def rule_request_wait(self, arguments: dict) -> dict:
|
def rule_request_wait(self, arguments: dict) -> dict:
|
||||||
expect(arguments, ("id", "timeout_seconds"))
|
expect(arguments, ("id", "timeout_seconds"))
|
||||||
request_id = field(arguments, "id")
|
request_id = field(arguments, "id")
|
||||||
record = self.rule_requests.wait(request_id, seconds(arguments, "timeout_seconds", WAIT_CAP))
|
record = self.rule_requests.wait(request_id, seconds(arguments, "timeout_seconds", MCP_WAIT_CAP))
|
||||||
if record is None:
|
if record is None:
|
||||||
raise ToolError(f"no rule request {request_id}")
|
raise ToolError(f"no rule request {request_id}")
|
||||||
return request_state(record, time.time())
|
return request_state(record, time.time())
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from .diffs import (
|
|||||||
valid_sealed,
|
valid_sealed,
|
||||||
)
|
)
|
||||||
from .errors import Conflict, Missing, ToolError
|
from .errors import Conflict, Missing, ToolError
|
||||||
from .fields import WAIT_CAP, bounded, decode, expect, field, seconds
|
from .fields import MCP_WAIT_CAP, bounded, decode, expect, field, seconds
|
||||||
from .review_page import review_files
|
from .review_page import review_files
|
||||||
from .signed import limits, review_signed
|
from .signed import limits, review_signed
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ class Reviewing:
|
|||||||
def wait(self, arguments: dict) -> dict:
|
def wait(self, arguments: dict) -> dict:
|
||||||
expect(arguments, ("id", "timeout_seconds"))
|
expect(arguments, ("id", "timeout_seconds"))
|
||||||
review_id = field(arguments, "id")
|
review_id = field(arguments, "id")
|
||||||
timeout = seconds(arguments, "timeout_seconds", WAIT_CAP)
|
timeout = seconds(arguments, "timeout_seconds", MCP_WAIT_CAP)
|
||||||
return proven(found(self.reviews.wait(review_id, timeout), review_id))
|
return proven(found(self.reviews.wait(review_id, timeout), review_id))
|
||||||
|
|
||||||
def pending(self, arguments: dict) -> dict:
|
def pending(self, arguments: dict) -> dict:
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ signature verifies here. Placeholders, fallbacks and lifetime:
|
|||||||
python3 ~/.local/share/kvb-orchestrator/client/approval.py request --port 8737 --title "<subject>" --page <pages>/<repo>-<branch>.html --notes <table> --gate <gate> --score "<score line>" --agent "<agent>"
|
python3 ~/.local/share/kvb-orchestrator/client/approval.py request --port 8737 --title "<subject>" --page <pages>/<repo>-<branch>.html --notes <table> --gate <gate> --score "<score line>" --agent "<agent>"
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Call `review_wait` with its `id` and `timeout_seconds` 240 until the
|
3. Call `review_wait` with its `id` and `timeout_seconds` 50 (the hub caps
|
||||||
status is no longer `pending`.
|
it there, below the MCP client's timeout) until the status is no longer
|
||||||
|
`pending`.
|
||||||
4. `approved`: verify in the worktree:
|
4. `approved`: verify in the worktree:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ class TestHubReviews(HubCase):
|
|||||||
def test_review_wait_times_out_at_the_cap(self):
|
def test_review_wait_times_out_at_the_cap(self):
|
||||||
review_id = self.request("feat: slow", "")
|
review_id = self.request("feat: slow", "")
|
||||||
started = time.monotonic()
|
started = time.monotonic()
|
||||||
with mock.patch.object(reviewing, "WAIT_CAP", 0.2):
|
with mock.patch.object(reviewing, "MCP_WAIT_CAP", 0.2):
|
||||||
result = self.tool("review_wait", {"id": review_id, "timeout_seconds": 10**6})
|
result = self.tool("review_wait", {"id": review_id, "timeout_seconds": 10**6})
|
||||||
self.assertLess(time.monotonic() - started, 5)
|
self.assertLess(time.monotonic() - started, 5)
|
||||||
self.assertEqual(result["structuredContent"]["status"], "pending")
|
self.assertEqual(result["structuredContent"]["status"], "pending")
|
||||||
|
|||||||
Reference in new issue
Block a user