Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(agent-runtimes): OpenClaw on the ChatGPT subscription defers its tool schemas (#933)

Ruben Lütke87b2a0a1c063
diff --git a/docs/agent-runtimes.md b/docs/agent-runtimes.md
index ce2cd2276d..22955f3e1c 100644
--- a/docs/agent-runtimes.md
+++ b/docs/agent-runtimes.md
@@ -356,8 +356,23 @@ replayed during `session/load` is swallowed because the chat already shows it.
model to search, describe and call through `tool_search` / `tool_describe` /
`tool_call` and to answer greetings directly; a resumed session's pinned
eager tool catalog is invalidated first (`tool_snapshot.py`) so the deferred
- configuration takes effect. OpenClaw still offers the tools directly
- (`tools.toolSearch: false`): a 9B local model never found deferred tools there.
+ configuration takes effect. OpenClaw offers the tools directly
+ (`tools.toolSearch: false`) on every route but the ChatGPT subscription: a
+ 9B local model never found deferred tools there. On the subscription it uses
+ OpenClaw's structured Tool Search (`tools.toolSearch: {mode: "tools"}`):
+ ChatGPT's backend accepted a turn carrying the whole inline catalog (~400
+ tools, ~580 KB of schemas) with HTTP 200 and then ended it as
+ `response.incomplete` (`max_output_tokens`, zero usage) on every retry.
+ Size alone is not the trigger: 400 synthetic tools (~210k tokens) passed,
+ while every failing slice of the live catalog held its only `oneOf` schemas
+ (Linear's `save_*` tools), so deferring keeps third-party schema shapes off
+ the backend's function list.
+- **Subscription stream failures:** a failure the backend reports inside an
+ accepted stream (`error`, `response.failed`, `response.incomplete`) is logged
+ with its event type, code, reason and a short redacted message
+ (`ChatGPT subscription stream failed: ...`, repeated on the gateway's
+ `subscription call failed` line); the runtime only sees fixed wording. An
+ incomplete stream ends the turn (`incomplete`) instead of being resent.
- **Not yet covered:** Hermes discovers ambient credentials (for example the
GitHub CLI's `gh auth token` for Copilot) into each profile's credential
pool. Dodaios' config never routes a model call to them; switching the
diff --git a/dodaios/agent_runtimes/gateway.py b/dodaios/agent_runtimes/gateway.py
index 5481d125c3..f056152d1a 100644
--- a/dodaios/agent_runtimes/gateway.py
+++ b/dodaios/agent_runtimes/gateway.py
@@ -842,8 +842,12 @@ def _subscription_failure(grant: Grant, exc: Exception) -> GatewayError:
if isinstance(exc, GatewayError) or getattr(exc, "status", 0) == 429:
return _failure(grant.provider, exc)
+ detail = getattr(exc, "detail", "")
log.warning(
- "runtime gateway: %s subscription call failed: %s", grant.agent_id, _describe(exc)
+ "runtime gateway: %s subscription call failed: %s%s",
+ grant.agent_id,
+ _describe(exc),
+ f" [{detail}]" if isinstance(detail, str) and detail else "",
)
sign_in = "The ChatGPT subscription needs a new sign-in in Dodaios."
if isinstance(exc, SubscriptionAuthError):
@@ -859,6 +863,16 @@ def _subscription_failure(grant: Grant, exc: Exception) -> GatewayError:
)
if status in (401, 403):
return GatewayError(sign_in, status=401, code="provider_auth")
+ if code in ("max_output_tokens", "incomplete"):
+ # The backend ends the stream as incomplete before any output (live
+ # 2026-10-27: an OpenClaw turn carrying ~400 inline tool schemas, every
+ # retry alike). Terminal: resending the same request cannot succeed.
+ return GatewayError(
+ "ChatGPT stopped this request before answering (incomplete). Resending it "
+ "unchanged will not help; a tool schema it carries can cause this.",
+ status=502,
+ code="incomplete",
+ )
if status == 404 or code == "model_not_found":
return GatewayError(
"The selected model is unavailable on this ChatGPT subscription.",
diff --git a/dodaios/agent_runtimes/openclaw.py b/dodaios/agent_runtimes/openclaw.py
index 5419b328d9..e466bca569 100644
--- a/dodaios/agent_runtimes/openclaw.py
+++ b/dodaios/agent_runtimes/openclaw.py
@@ -583,9 +583,11 @@ class OpenClawRuntime:
"slots": {"memory": "none"},
"entries": {"memory-core": {"enabled": False}},
},
- # Jarvis' tools offered directly, never behind OpenClaw's tool search
- # (on by default for local models; smaller models miss deferred tools).
- "tools": {"deny": denied, "exec": {"mode": exec_mode}, "toolSearch": False},
+ "tools": {
+ "deny": denied,
+ "exec": {"mode": exec_mode},
+ "toolSearch": _tool_search(route.transport),
+ },
# The agent's log stays in its own folder, never in the shared
# temp-folder log every OpenClaw on the machine appends to.
"logging": {"file": str(home / "state" / "logs" / "openclaw.log")},
@@ -1059,6 +1061,25 @@ def _use_claude_cli(config: dict[str, Any], turn: RuntimeTurn) -> None:
tools["deny"] = [*tools["deny"], "exec", "process"]
+def _tool_search(transport: str) -> Any:
+ """``tools.toolSearch``: deferred schemas on the ChatGPT subscription only.
+
+ Every other route gets Jarvis' tools directly (OpenClaw turns tool search
+ on by default for local models; smaller models miss deferred tools). The
+ subscription's backend ends a request carrying the whole inline catalog
+ (live 2026-10-27: ~400 tools, ~580 KB of schemas from the person's
+ connected plugins) as ``response.incomplete`` before any output, on every
+ retry. Size alone is not the trigger (400 synthetic tools at ~210k tokens
+ passed); the failing slices all held the only ``oneOf`` schemas in the
+ catalog, which points at a schema shape the backend refuses inline.
+ Hermes on the same seat defers its tools behind ``tool_search`` and
+ answers. The structured mode keeps every tool callable through
+ ``tool_search`` / ``tool_describe`` / ``tool_call``, and no third-party
+ schema reaches the backend as a function declaration.
+ """
+ return {"mode": "tools"} if transport == "responses" else False
+
+
def _declared_efforts(turn: RuntimeTurn) -> dict[str, Any]:
"""The model's ``compat`` entry: the effort levels its catalog lists.
diff --git a/dodaios/live/subscription_reasoning.py b/dodaios/live/subscription_reasoning.py
index 097d40f4b1..212b0f46c5 100644
--- a/dodaios/live/subscription_reasoning.py
+++ b/dodaios/live/subscription_reasoning.py
@@ -29,6 +29,9 @@ _REQUEST_FAILURES = {
"model_not_found": "The selected model is unavailable on this ChatGPT subscription.",
"invalid_request_error": "ChatGPT rejected this request.",
}
+#: A stream the backend ended as incomplete: retrying the same request
+#: changes nothing.
+_STOPPED_EARLY = frozenset({"max_output_tokens", "incomplete"})
log = logging.getLogger(__name__)
_SAFE_CODE = re.compile(r"^[a-zA-Z0-9_.-]{1,96}$")
_SAFE_EFFORT = re.compile(r"^[a-z][a-z0-9_-]{0,31}$")
@@ -47,11 +50,15 @@ class SubscriptionReasoningError(RuntimeError):
code: str = "subscription_unavailable",
status: int = 0,
retry_after: str | None = None,
+ detail: str = "",
) -> None:
super().__init__(message)
self.code = code
self.status = status
self.retry_after = retry_after
+ #: The backend's own failure (event type, code, short message),
+ #: bounded and redacted: for the log only, never shown to a runtime.
+ self.detail = detail
def _failure(
@@ -81,6 +88,11 @@ def _failure(
"ChatGPT subscription access was rejected. "
"Check the selected account and sign in again if needed."
)
+ elif code in _STOPPED_EARLY:
+ message = (
+ "ChatGPT stopped this request before it finished (incomplete). "
+ "Resending it unchanged will not help; a tool schema it carries can cause this."
+ )
elif status in (400, 404, 413, 422):
if code not in _REQUEST_FAILURES:
code = "invalid_request_error"
@@ -96,6 +108,51 @@ def _failure(
return SubscriptionReasoningError(message, code=code, status=status, retry_after=retry_after)
+#: Key- and token-shaped strings masked in a logged backend failure.
+_SECRET = re.compile(
+ r"(sk-[A-Za-z0-9_\-]{6,}|[Bb]earer\s+[A-Za-z0-9._\-]{10,}|eyJ[A-Za-z0-9._\-]{20,})"
+)
+_MAX_DETAIL_CHARS = 300
+
+
+def _stream_failure(kind: str, event: dict[str, Any]) -> SubscriptionReasoningError:
+ """A failure the backend reported inside an accepted (HTTP 200) stream.
+
+ The three shapes carry their reason in different places: ``error`` at
+ the top level, ``response.failed`` under ``response.error`` and
+ ``response.incomplete`` under ``response.incomplete_details``. The code
+ alone decides the wording; the backend's message only reaches the log.
+ """
+ response = event.get("response") if isinstance(event.get("response"), dict) else {}
+ error: dict[str, Any] = {}
+ code = ""
+ if kind == "error" and not isinstance(event.get("error"), dict):
+ # Top-level shape: its own "type" is the event kind, never a reason.
+ error = event
+ code = str(event.get("code") or "")
+ else:
+ nested = event.get("error") if kind == "error" else response.get("error")
+ if isinstance(nested, dict):
+ error = nested
+ code = str(nested.get("code") or nested.get("type") or "")
+ incomplete = response.get("incomplete_details")
+ reason = incomplete.get("reason") if isinstance(incomplete, dict) else None
+ if not code and (kind == "response.incomplete" or response.get("status") == "incomplete"):
+ code = "max_output_tokens" if reason == "max_output_tokens" else "incomplete"
+ message = error.get("message") if isinstance(error.get("message"), str) else ""
+ message = _SECRET.sub("[redacted]", " ".join(message.split()))[:_MAX_DETAIL_CHARS]
+ shown_code = code if _SAFE_CODE.fullmatch(code) else ("unsafe" if code else "none")
+ detail = f"event={kind} code={shown_code}"
+ if isinstance(reason, str) and _SAFE_CODE.fullmatch(reason):
+ detail += f" reason={reason}"
+ if message:
+ detail += f" message={message!r}"
+ log.warning("ChatGPT subscription stream failed: %s", detail)
+ failure = _failure(payload={"error": {"code": code}})
+ failure.detail = detail
+ return failure
+
+
def _invalid_request(message: str) -> SubscriptionReasoningError:
"""A request this client refuses before sending it: never worth a retry."""
return SubscriptionReasoningError(message, code="invalid_request_error", status=400)
@@ -408,14 +465,14 @@ class SubscriptionReasoning:
raise SubscriptionReasoningError("ChatGPT returned an invalid reasoning event.")
kind = event["type"]
if kind in {"error", "response.failed", "response.incomplete"}:
- raise _failure(payload=event.get("response", event))
+ raise _stream_failure(kind, event)
if kind == "response.completed":
result = event.get("response", {})
if (
not isinstance(result, dict)
or result.get("status", "completed") != "completed"
):
- raise _failure(payload=result)
+ raise _stream_failure("response.completed", {"response": result})
completed = True
yield event
if completed:
diff --git a/tests/unit/agent_runtimes/test_runtime_configs.py b/tests/unit/agent_runtimes/test_runtime_configs.py
index 50f8d66c08..23fa014751 100644
--- a/tests/unit/agent_runtimes/test_runtime_configs.py
+++ b/tests/unit/agent_runtimes/test_runtime_configs.py
@@ -280,6 +280,22 @@ def test_openclaw_subscription_route_uses_the_responses_adapter(tmp_path):
assert config["models"]["providers"]["jarvis"]["api"] == "openai-responses"
+ ("transport", "expected"),
+ [
+ # The ChatGPT backend ends a request carrying the whole inline tool
+ # catalog as incomplete (live 2026-10-27), so its tools are deferred.
+ ("responses", {"mode": "tools"}),
+ ("chat_completions", False),
+ ("anthropic_messages", False),
+ ],
+)
+def test_openclaw_defers_tool_schemas_only_on_the_subscription(tmp_path, transport, expected):
+ route = _route(transport=transport)
+ config = OpenClawRuntime().config_for(_turn(tmp_path, route=route), port=1, token=_TOKEN)
+ assert config["tools"]["toolSearch"] == expected
+
+
def test_openclaw_without_tools_writes_no_mcp_server(tmp_path):
config = OpenClawRuntime().config_for(
_turn(tmp_path, mcp_url=None, control_key=None), port=1, token=_TOKEN
diff --git a/tests/unit/agent_runtimes/test_runtime_gateway.py b/tests/unit/agent_runtimes/test_runtime_gateway.py
index 35f2826c83..6384c4a7b1 100644
--- a/tests/unit/agent_runtimes/test_runtime_gateway.py
+++ b/tests/unit/agent_runtimes/test_runtime_gateway.py
@@ -610,6 +610,38 @@ def test_a_subscription_overflow_mid_stream_keeps_its_code(fake, guarded, monkey
assert failed[0]["response"]["error"]["code"] == "context_length_exceeded"
+def test_an_incomplete_subscription_stream_ends_the_turn_with_its_reason(
+ fake, guarded, monkeypatch, caplog
+):
+ """Live 2026-10-27: ChatGPT accepted an OpenClaw turn (HTTP 200,
+ ``response.created``) and ended it as ``response.incomplete`` before any
+ output; the gateway called that ``subscription_unavailable`` and OpenClaw
+ resent the same request three times."""
+ async def incomplete(**kwargs):
+ yield {"type": "response.created", "response": {"id": "r1"}}
+ raise SubscriptionReasoningError(
+ "ChatGPT stopped this request before it finished.",
+ code="max_output_tokens",
+ detail="event=response.incomplete code=max_output_tokens reason=max_output_tokens",
+ )
+
+ monkeypatch.setattr(fake, "stream", incomplete)
+ token = gateway.grant_token("agent-1", "openai-codex")
+ signal = gateway.watch_failure(token)
+ with caplog.at_level("WARNING"):
+ answer = _post(guarded, token, {"model": "m", "input": "hello", "stream": True})
+ failed = [json.loads(line[5:]) for line in answer.text.splitlines()
+ if line.startswith("data:") and "response.failed" in line]
+ error = failed[0]["response"]["error"]
+ assert error["code"] == "incomplete"
+ assert "will not help" in error["message"]
+ # Terminal: the Jarvis turn ends instead of the runtime resending it.
+ assert signal.done()
+ # The backend's own reason reaches the log.
+ assert "reason=max_output_tokens" in caplog.text
+ gateway.unwatch_failure(token, signal)
+
+
async def test_a_claude_subscription_seat_is_refused_not_billed(monkeypatch) -> None:
"""No API key saved: the seat is the Claude subscription, which only the
Claude CLI may use. The gateway says so instead of sending the login to
diff --git a/tests/unit/live/test_subscription_reasoning.py b/tests/unit/live/test_subscription_reasoning.py
index 1f55b58429..01d6877012 100644
--- a/tests/unit/live/test_subscription_reasoning.py
+++ b/tests/unit/live/test_subscription_reasoning.py
@@ -461,3 +461,61 @@ async def test_a_login_lost_during_the_catalog_check_keeps_the_original_refusal(
assert caught.value.code == "invalid_request_error" and caught.value.status == 400
assert len(calls) == 2
await reasoning.aclose()
+
+
+ ("event", "code", "logged"),
+ [
+ # An "error" event carries its code at the top level, not under "error".
+ (
+ {"type": "error", "code": "invalid_prompt", "message": "Bad input item."},
+ "invalid_prompt",
+ "event=error code=invalid_prompt message='Bad input item.'",
+ ),
+ (
+ {
+ "type": "response.failed",
+ "response": {"error": {"code": "server_error", "message": "Try again."}},
+ },
+ "server_error",
+ "event=response.failed code=server_error message='Try again.'",
+ ),
+ (
+ {
+ "type": "response.incomplete",
+ "response": {"incomplete_details": {"reason": "max_output_tokens"}},
+ },
+ "max_output_tokens",
+ "event=response.incomplete code=max_output_tokens reason=max_output_tokens",
+ ),
+ ],
+)
+async def test_stream_failure_keeps_the_backend_reason_for_the_log(event, code, logged, caplog):
+ reasoning, _ = _reasoning(lambda _request: httpx.Response(200, text=_sse(event)))
+ with caplog.at_level("WARNING"), pytest.raises(SubscriptionReasoningError) as caught:
+ await _collect(reasoning)
+ assert caught.value.code == code
+ assert caught.value.detail == logged
+ # The backend's own words reach the log, never the error a runtime sees.
+ assert logged in caplog.text
+ assert "Bad input item" not in str(caught.value)
+ await reasoning.aclose()
+
+
+async def test_stream_failure_detail_masks_tokens_and_unsafe_codes():
+ event = {
+ "type": "response.failed",
+ "response": {
+ "error": {"code": "has spaces!", "message": "Bearer abcdefghijklmnop leaked " * 30}
+ },
+ }
+ reasoning, _ = _reasoning(lambda _request: httpx.Response(200, text=_sse(event)))
+ with pytest.raises(SubscriptionReasoningError) as caught:
+ await _collect(reasoning)
+ assert caught.value.code == "subscription_unavailable"
+ assert "code=unsafe" in caught.value.detail
+ assert "abcdefghijklmnop" not in caught.value.detail
+ assert len(caught.value.detail) < 400
+ await reasoning.aclose()