HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
fix(runner): surface Goose MCP startup failures on successful turns (#290)
Yominma756a9261dd70
diff --git a/docs/harness-verification.md b/docs/harness-verification.mdindex d693c83b..9ae22e2b 100644--- a/docs/harness-verification.md+++ b/docs/harness-verification.md@@ -177,6 +177,11 @@ which fails the type-check, and that is the only one a compiler will find for yoof it rather than the last lines — a turn that dies in seconds and is then retried toexhaustion ends with `SIGTERM … Shutting down`, and putting that in the record is worse thansilence, because it reads like a reason.+ A successful turn can also lose a configured MCP server. Goose 1.50.0 logs `Failed to start+ extension 'name' ..., continuing without it` on stderr, then emits a successful stream-json+ result. The runner must preserve this as `system/mcp_unavailable` so the gateway can tell the+ user which tools were absent. Do not copy the extension's raw stderr into that event; it may+ contain credentials.7. `CHECKPOINT_EXCLUDE` and `_git_ensure`'s ignore list: any file the CLI writes that can hold acredential.diff --git a/runner/server.py b/runner/server.pyindex 93fa180f..a2992ef9 100644--- a/runner/server.py+++ b/runner/server.py@@ -5750,6 +5750,19 @@ def _goose_eof(state: dict, rc: int) -> list[dict]:_goose_to_claude.eof = _goose_eof # type: ignore[attr-defined]+# Goose 1.50.0 sends extension startup failures to stderr, not stream-json. The+# turn can still complete successfully without that extension, so the generic+# failure-only stderr tail would otherwise hide the missing MCP tools.+_GOOSE_EXTENSION_START_FAILURE = re.compile(+ r"Failed to start extension '([^'\r\n]{1,80})' \(.*\), continuing without it$"+)+++def _goose_mcp_startup_failure(line: str) -> str:+ match = _GOOSE_EXTENSION_START_FAILURE.search(line)+ return match.group(1) if match else ""++# aider has NO conversation id of ANY kind — its continuation is the chat-history FILE — so the# runner announces a synthetic one. Without it the gateway never records a conversation id, never# treats a later turn as a follow-up, and every turn is a fresh thread: measured as the support@@ -6563,6 +6576,7 @@ def _run_turn_bg(turn_id: str, cmd: list[str], env: dict, cwd: str, normalize, mkiller.daemon = Truekiller.start()errbuf: list[str] = [] # non-JSON output (CLI stderr is merged into stdout) — the REAL error text+ goose_mcp_down: set[str] = set()try:for raw in proc.stdout: # type: ignore[union-attr]raw = raw.strip()@@ -6574,6 +6588,15 @@ def _run_turn_bg(turn_id: str, cmd: list[str], env: dict, cwd: str, normalize, merrbuf.append(raw)if len(errbuf) > 80:del errbuf[0]+ if normalize is _goose_to_claude:+ name = _goose_mcp_startup_failure(raw)+ if name and name not in goose_mcp_down:+ goose_mcp_down.add(name)+ # Include only the extension name. Its raw stderr may contain secrets,+ # and the gateway only needs the name to explain the missing tools.+ with _turns_lock:+ rec["events"].append({"type": "system", "subtype": "mcp_unavailable",+ "servers": [{"name": name}], "_ts": time.time()})continuetry:obj = json.loads(raw)diff --git a/runner/tests/test_goose_build.py b/runner/tests/test_goose_build.pyindex 3dff2eb2..0432636f 100644--- a/runner/tests/test_goose_build.py+++ b/runner/tests/test_goose_build.py@@ -17,17 +17,22 @@ Source anchors (all v1.50.0):get_or_create_session_id crates/goose-cli/src/cli.rsskill discovery roots crates/goose/src/skills/mod.rs"""+import json+import osimport pathlibimport sqlite3import sysimport tempfile+import time+import uuidimport yamlsys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))from server import (Auth, ALL_GOOSE_TOOLS, BACKENDS, _agent_doc_path, _build_goose, # noqa: E402_goose_extensions, _goose_has_session, _goose_root, _goose_split_base,- _goose_to_claude, _goose_usage, _norm_token_usage, _resume_lost,+ _goose_mcp_startup_failure, _goose_to_claude, _goose_usage,+ _norm_token_usage, _resume_lost, _run_turn_bg, _turns,_GOOSE_SESSION_NAME)@@ -445,6 +450,40 @@ def test_notifications_render_nothing():assert out == []+def test_real_goose_startup_warning_survives_successful_turn(tmp_path):+ """Goose 1.50.0 logs this warning on stderr, then emits a successful stream-json turn.++ The runner must surface the missing MCP tool even when the answer itself succeeded. Only+ the extension name is exposed; subprocess stderr in the reason may contain credentials.+ """+ warning = " ⚠ Failed to start extension 'broken-mcp' (process quit before initialization: stderr = secret-token), continuing without it"+ another = " ⚠ Failed to start extension 'other-mcp' (process quit before initialization: stderr = ), continuing without it"+ assert _goose_mcp_startup_failure(warning) == "broken-mcp"+ assert not _goose_mcp_startup_failure("ordinary CLI stderr")+ script = tmp_path / "goose_stream.py"+ script.write_text(+ "import json,sys\n"+ f"for line in {[warning, warning, another, 'unrelated stderr']!r}:\n"+ " sys.stderr.write(line + '\\n'); sys.stderr.flush()\n"+ f"print(json.dumps({_msg({'type': 'text', 'text': 'hello'})!r}), flush=True)\n"+ "print(json.dumps({'type':'complete','input_tokens':1,'output_tokens':1}), flush=True)\n"+ )+ turn_id = "goose-warning-" + uuid.uuid4().hex+ _turns[turn_id] = {"events": [], "done": False, "started": time.time()}+ try:+ _run_turn_bg(turn_id, [sys.executable, str(script)], os.environ.copy(), str(tmp_path),+ _goose_to_claude, "gpt-test", timeout_seconds=10)+ rec = _turns[turn_id]+ warnings = [ev for ev in rec["events"] if ev.get("subtype") == "mcp_unavailable"]+ assert rec["status"] == "done" and rec["result"] == "hello"+ assert [ev["servers"] for ev in warnings] == [+ [{"name": "broken-mcp"}], [{"name": "other-mcp"}]]+ assert all(ev["type"] == "system" and isinstance(ev["_ts"], float) for ev in warnings)+ assert "secret-token" not in json.dumps(rec["events"])+ finally:+ _turns.pop(turn_id, None)++def test_complete_suppresses_the_eof_result():"""Both would otherwise emit a result and the turn would carry two."""state: dict = {"model": "gpt-5.4"}