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(goose): override saved provider on every turn (#450)
02Ychasea14330b3db4c
diff --git a/runner/server.py b/runner/server.pyindex 930c3717..34556539 100644--- a/runner/server.py+++ b/runner/server.py@@ -8581,13 +8581,16 @@ def _build_goose(provider: str, auth: Auth, model: str, prompt: str, cwd: str, e# Otherwise every turn pays an extra background model call to invent a session name we never# read — the name is ours, set with -n below.env["GOOSE_DISABLE_SESSION_NAMING"] = "true"- _goose_config(root, model, mcp_servers, tools_disabled, provider="anthropic" if native else "openai")+ goose_provider = "anthropic" if native else "openai"+ _goose_config(root, model, mcp_servers, tools_disabled, provider=goose_provider)# -n names the session on a fresh run and selects it on a resume (get_or_create_session_id# matches s.name == name || s.id == name), so it is the handle in both directions and nothing# has to be read back out of the stream. --session-id is NOT usable here: it sits in the same# clap group, which is multiple = false, and it is rejected outright without --resume.+ # Goose prefers the session's saved provider to config.yaml on resume. Override it on every+ # turn so a switch of connection uses the provider matching this turn's endpoint and key.cmd = ["goose", "run", "--output-format", "stream-json", "--model", model,- "-n", _GOOSE_SESSION_NAME, "-t", prompt]+ "-n", _GOOSE_SESSION_NAME, "-t", prompt, "--provider", goose_provider]if max_turns:# The harness's step budget, which the gateway sends as max_turns (its max_step, default# 40). goose's own default is 1000, so without this the budget an operator set is ignoreddiff --git a/runner/tests/test_goose_build.py b/runner/tests/test_goose_build.pyindex 0432636f..0b2282fd 100644--- a/runner/tests/test_goose_build.py+++ b/runner/tests/test_goose_build.py@@ -26,6 +26,7 @@ import tempfileimport timeimport uuid+import pytestimport yamlsys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))@@ -244,6 +245,42 @@ def test_resume_only_once_the_session_is_in_this_workspace():assert "-r" in cmd2[email protected]("provider,api_format,expected", [+ ("anthropic", None, "anthropic"),+ ("openai-api", "anthropic", "anthropic"),+ ("openai-api", "openai", "openai"),+ ("tokenrouter", None, "openai"),+])[email protected]("session", ["new", "resumed", "missing"])+def test_turn_provider_overrides_the_saved_session(tmp_path, provider, api_format, expected, session):+ """#375: Goose 1.50.0 prefers a saved provider to config.yaml on resume. The CLI+ override must name this turn's wire provider, including for a custom Messages endpoint.+ A new or lost session must use the same provider as a resumed one."""+ cwd = str(tmp_path)+ previous = "openai" if expected == "anthropic" else "anthropic"+ if session == "resumed":+ db_path = _sessions_db(cwd, ("existing-session", _GOOSE_SESSION_NAME))+ with sqlite3.connect(db_path) as db:+ db.execute("ALTER TABLE sessions ADD COLUMN provider_name TEXT")+ db.execute("UPDATE sessions SET provider_name = ?", (previous,))+ env = {}+ cmd = _build_goose(provider, Auth(api_key="sk-test", base_url="https://up.example/v1",+ api_format=api_format),+ "test-model", "continue", cwd, env,+ resume_session_id=_GOOSE_SESSION_NAME if session != "new" else None)+ cfg = yaml.safe_load((_goose_root(cwd) / "config" / "config.yaml").read_text())+ assert cfg["GOOSE_PROVIDER"] == expected+ assert "--provider" in cmd, "config.yaml cannot override a resumed session's provider"+ assert cmd[cmd.index("--provider") + 1] == expected+ assert ("-r" in cmd) == (session == "resumed")+ key = "ANTHROPIC_API_KEY" if expected == "anthropic" else "OPENAI_API_KEY"+ assert env[key].startswith("hr-relay-")+ if session == "resumed":+ # The runner selects the provider through the CLI, without rewriting Goose's database.+ with sqlite3.connect(db_path) as db:+ assert db.execute("SELECT provider_name FROM sessions").fetchone() == (previous,)++def test_session_lookup_asks_the_database():"""THE check, and it must be exact in both directions.