fix(sdk): close the runtime when the MCP wait overflows and expect the SDK manager row

Converting `mcp_startup_timeout_seconds` to milliseconds raised
`OverflowError` for `inf` or `1e308` before `initialize` entered its failure
path, leaving the started runtime running. The conversion now runs inside
that path, so it closes the runtime like any failed initialization.

`apps/cli/tests/profile-mcp.spec.ts` still expected only the `web` profile to
mount `mcp-manager`; it now expects the `web` and `sdk` profiles to.
This commit is contained in:
sjw1231 committed 2026-11-24 14:49:12 +08:00
1 parent 3e0f80c608
commit 2da97e9f3a
3 files changed
+26 -6

No files matched your search

+6 -4
View File
@@ -172,8 +172,9 @@ class HarnessClient:
handshake for MCP manager servers in their first connection attempt;
omission or 0 answers without waiting. Keep it shorter than
initialize_timeout_seconds, which also covers runtime startup, or a
hanging MCP server makes the handshake time out. A negative value
closes the runtime like any failed initialization.
hanging MCP server makes the handshake time out. A negative value, or
one too large to convert to milliseconds, closes the runtime like any
failed initialization.
"""
if mcp_startup_timeout_seconds is not None and not mcp_startup_timeout_seconds >= 0:
self.close()
@@ -189,11 +190,12 @@ class HarnessClient:
payload["reasoningEffort"] = reasoning_effort
if max_tokens is not None:
payload["maxTokens"] = max_tokens
if mcp_startup_timeout_seconds is not None:
payload["mcpStartupTimeoutMs"] = round(mcp_startup_timeout_seconds * 1000)
if self._user_question_handler is not None:
payload["capabilities"] = {"userQuestions": True}
try:
if mcp_startup_timeout_seconds is not None:
# An infinite or overflowing product raises here, so the failure path below closes the runtime.
payload["mcpStartupTimeoutMs"] = round(mcp_startup_timeout_seconds * 1000)
return self.request(
"initialize",
payload,
+18
View File
@@ -1047,6 +1047,24 @@ def test_initialize_rejects_a_negative_mcp_startup_wait(tmp_path: Path, seconds:
assert not init_dump.exists()
@pytest.mark.parametrize("seconds", [float("inf"), 1e308])
def test_initialize_closes_the_runtime_when_the_mcp_startup_wait_overflows(tmp_path: Path, seconds: float) -> None:
script = tmp_path / "recording_runtime.py"
script.write_text(_INIT_RECORDING_RUNTIME)
init_dump = tmp_path / "init.jsonl"
client = HarnessClient(HarnessConfig(env={"INIT_DUMP": str(init_dump)}), _launch_args=(sys.executable, str(script)))
client.start()
proc = client._proc
assert proc is not None
with pytest.raises(OverflowError):
client.initialize(cwd=".", provider="deepseek-official", model="dsagent", mcp_startup_timeout_seconds=seconds)
assert proc.wait(timeout=1) is not None
assert client._proc is None
assert not init_dump.exists()
def test_public_signatures_omit_unsupported_wire_parameters() -> None:
from deepseek_harness import DeepSeekHarnessConfig, Session