Skip to content

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.

codex: a turn on a custom Responses endpoint is told that file edits go through the shell, not an apply_patch tool (#346)

github-actions[bot]dd5d600f14a5
diff --git a/docs/self-hosting-guide.md b/docs/self-hosting-guide.md
index 081e9b0e..79c231f7 100644
--- a/docs/self-hosting-guide.md
+++ b/docs/self-hosting-guide.md
@@ -283,6 +283,12 @@ often reject those tool types. Set `namespace_tools` or `web_search` to `"1"` in
configuration (or turn the corresponding console switch on) when the endpoint supports them;
`disabled_tools` still takes precedence for `web_search`.
+Codex offers no `apply_patch` tool on a custom endpoint (measured on 0.154.0: no model gets it, known
+or not; it exists only inside Codex's own multi-environment executors), so a Codex turn on a custom
+Responses connection tells the model that file edits go through the shell tool and that a call to a
+tool named `apply_patch` is refused. A model that otherwise loops on "unsupported call: apply_patch"
+(issue #202) stops at that instruction.
+
</details>
<details>
diff --git a/runner/server.py b/runner/server.py
index 4df1f16e..13c6da68 100644
--- a/runner/server.py
+++ b/runner/server.py
@@ -1985,6 +1985,30 @@ def _codex_custom_responses(auth: Auth) -> bool:
return str(auth.api_format or "").strip().lower() == "responses"
+_CODEX_CUSTOM_EDITING = (
+ "## Editing files on this connection\n\n"
+ "There is no `apply_patch` tool here: Codex offers none on a custom endpoint (measured on Codex "
+ "0.154.0: no model gets it, known or not). A call to a tool named `apply_patch` is refused with "
+ "\"unsupported call\"; do not make it and do not retry it. Edit files through the shell tool: write "
+ "a file with a heredoc, change lines with sed or a short python script, or use an editor command, "
+ "then read the file back to check the change.")
+
+
+def _codex_custom_editing_note(backend: str, auth: Auth | None) -> str:
+ """The instruction a Codex turn on a custom Responses endpoint carries about editing files.
+
+ Issue #202 (lab1207's investigation, PR #332): a model Codex does not know called a tool named
+ apply_patch and looped on "unsupported call". The tool is registered only inside Codex's own
+ multi-environment executors (spec_plan.rs: has_environment() and the catalog's
+ apply_patch_tool_type), never for a config.toml key, and never on a custom provider in our
+ deployments: with a stub endpoint recording the request, gpt-5-codex and an unknown model sent
+ the same tool list, without apply_patch, with or without a model catalog declaring it. So the
+ remedy is what the model is told, not a switch: edits go through the shell tool."""
+ if backend != "codex" or auth is None or not _codex_custom_responses(auth):
+ return ""
+ return _CODEX_CUSTOM_EDITING
+
+
def _codex_namespace_tools_off(auth: Auth) -> bool:
"""Keep Codex's multi-agent namespace out of custom endpoints unless opted in."""
return _codex_custom_responses(auth) and _codex_flag(auth.namespace_tools) is not True
@@ -7721,6 +7745,9 @@ def turn(req: TurnReq, identifier: str = "") -> dict:
if _off:
agent_doc = ((agent_doc + "\n\n") if agent_doc.strip() else "") + \
f"## Disabled tools\n\nDo NOT use these tools — they are disabled for this harness: {_off}."
+ note = _codex_custom_editing_note(backend, req.auth)
+ if note:
+ agent_doc = ((agent_doc + "\n\n") if agent_doc.strip() else "") + note
turn_environment = environments.resolve(req.environment) # 409 when nothing is built: before any process starts
_write_agent_doc(cwd, backend, agent_doc, installed_skills, environment=turn_environment)
# The harness's own variables under the runner's, so nothing a caller names shadows the
diff --git a/runner/tests/test_codex_custom_editing.py b/runner/tests/test_codex_custom_editing.py
new file mode 100644
index 00000000..6cc65083
--- /dev/null
+++ b/runner/tests/test_codex_custom_editing.py
@@ -0,0 +1,21 @@
+"""Issue #202 (lab1207's PR #332 started this): a model Codex does not know, on a custom Responses
+endpoint, called a tool named apply_patch and looped on "unsupported call". Codex 0.154 registers
+that tool only inside its own multi-environment executors and never on a custom provider here, so
+the turn tells the model how files are edited instead of offering a switch that registers nothing."""
+import pathlib
+import sys
+
+sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
+import server as rs # noqa: E402
+
+
+def test_a_codex_turn_on_a_custom_responses_endpoint_is_told_how_to_edit():
+ custom = rs.Auth(api_key="k", base_url="https://bridge.internal/v1", api_format="responses")
+ note = rs._codex_custom_editing_note("codex", custom)
+ assert note.startswith("## Editing files on this connection")
+ assert "no `apply_patch` tool" in note and "unsupported call" in note and "shell tool" in note
+ # the same connection on another base, a Codex turn on a first-party provider, and no auth at all: nothing added
+ assert rs._codex_custom_editing_note("hermes", custom) == ""
+ assert rs._codex_custom_editing_note("codex", rs.Auth(api_key="k", base_url="https://api.openai.com/v1")) == ""
+ assert rs._codex_custom_editing_note("codex", rs.Auth(api_key="k", api_format="openai")) == ""
+ assert rs._codex_custom_editing_note("codex", None) == ""