diff --git a/orchestrator/kvb_orchestrator/asking.py b/orchestrator/kvb_orchestrator/asking.py index 3d27edb..8d3abe3 100644 --- a/orchestrator/kvb_orchestrator/asking.py +++ b/orchestrator/kvb_orchestrator/asking.py @@ -9,6 +9,7 @@ from .errors import Conflict, Missing, ToolError from .fields import ( COMMAND_LIMIT, DESCRIPTION_LIMIT, + MCP_WAIT_CAP, OPTION_LIMIT, PATH_LIMIT, WAIT_CAP, @@ -233,7 +234,7 @@ class Asking: def decision_wait(self, arguments: dict) -> dict: expect(arguments, ("id", "timeout_seconds")) 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: raise ToolError(f"no decision {decision_id}") return decision_state(record) diff --git a/orchestrator/kvb_orchestrator/fields.py b/orchestrator/kvb_orchestrator/fields.py index ef96f47..cbe94b2 100644 --- a/orchestrator/kvb_orchestrator/fields.py +++ b/orchestrator/kvb_orchestrator/fields.py @@ -8,6 +8,8 @@ from .errors import ToolError from .signed import limits, signing 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 COMMAND_LIMIT = 4000 PATH_LIMIT = limits.PATH_LIMIT diff --git a/orchestrator/kvb_orchestrator/mcp.py b/orchestrator/kvb_orchestrator/mcp.py index b12ccfc..f27456b 100644 --- a/orchestrator/kvb_orchestrator/mcp.py +++ b/orchestrator/kvb_orchestrator/mcp.py @@ -6,7 +6,7 @@ from http import HTTPStatus from . import NAME from .choosing import CHOICE_REQUEST 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 .reviewing import GATES from .rules import RULE_KINDS @@ -30,7 +30,7 @@ def rpc_error(request_id: object, code: int, message: str) -> dict: class Mcp: def tools(self) -> list[dict]: 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 = { "type": "object", "properties": { @@ -63,7 +63,7 @@ class Mcp: tool( "review_wait", 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}, ), 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 " "(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) " - 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}, ), tool( @@ -106,7 +106,7 @@ class Mcp: tool( "rule_request_wait", 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}, ), tool( diff --git a/orchestrator/kvb_orchestrator/requesting.py b/orchestrator/kvb_orchestrator/requesting.py index 50981f5..fce077e 100644 --- a/orchestrator/kvb_orchestrator/requesting.py +++ b/orchestrator/kvb_orchestrator/requesting.py @@ -4,7 +4,7 @@ import time from .denying import request_status, request_words, requester_of 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 .rules import EVERY_AGENT, rule_fields, rule_matches, signed_fields, subject_of from .signed import signing @@ -97,7 +97,7 @@ class Requesting: def rule_request_wait(self, arguments: dict) -> dict: expect(arguments, ("id", "timeout_seconds")) 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: raise ToolError(f"no rule request {request_id}") return request_state(record, time.time()) diff --git a/orchestrator/kvb_orchestrator/reviewing.py b/orchestrator/kvb_orchestrator/reviewing.py index f9f3b18..5f8e95f 100644 --- a/orchestrator/kvb_orchestrator/reviewing.py +++ b/orchestrator/kvb_orchestrator/reviewing.py @@ -16,7 +16,7 @@ from .diffs import ( valid_sealed, ) 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 .signed import limits, review_signed @@ -127,7 +127,7 @@ class Reviewing: def wait(self, arguments: dict) -> dict: expect(arguments, ("id", "timeout_seconds")) 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)) def pending(self, arguments: dict) -> dict: diff --git a/skills/kvb-git-diff/SKILL.md b/skills/kvb-git-diff/SKILL.md index 01d70fb..4b79e30 100644 --- a/skills/kvb-git-diff/SKILL.md +++ b/skills/kvb-git-diff/SKILL.md @@ -24,8 +24,9 @@ signature verifies here. Placeholders, fallbacks and lifetime: python3 ~/.local/share/kvb-orchestrator/client/approval.py request --port 8737 --title "" --page /-.html --notes --gate --score "" --agent "" ``` -3. Call `review_wait` with its `id` and `timeout_seconds` 240 until the - status is no longer `pending`. +3. Call `review_wait` with its `id` and `timeout_seconds` 50 (the hub caps + it there, below the MCP client's timeout) until the status is no longer + `pending`. 4. `approved`: verify in the worktree: ```bash diff --git a/tests/test_hub_reviews.py b/tests/test_hub_reviews.py index e3f911f..c220a86 100644 --- a/tests/test_hub_reviews.py +++ b/tests/test_hub_reviews.py @@ -150,7 +150,7 @@ class TestHubReviews(HubCase): def test_review_wait_times_out_at_the_cap(self): review_id = self.request("feat: slow", "") 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}) self.assertLess(time.monotonic() - started, 5) self.assertEqual(result["structuredContent"]["status"], "pending")