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 never sends a thinking level the model refuses (#925)

Ruben Lütkec27824a90431
diff --git a/docs/agent-runtimes.md b/docs/agent-runtimes.md
index 8856f17d82..ce2cd2276d 100644
--- a/docs/agent-runtimes.md
+++ b/docs/agent-runtimes.md
@@ -374,7 +374,22 @@ replayed during `session/load` is swallowed because the chat already shows it.
names the conversation in its `_meta` (`sessionKey: agent:main:main`, and
`resetSession: true` for a fresh conversation), and each `session/prompt`
carries the agent's thinking level (`_meta.thinking`), so one bridge serves
- every turn and a changed effort never restarts the Gateway. No hand-written
+ every turn and a changed effort never restarts the Gateway. OpenClaw checks
+ that level against the model as its config declares it and fails the whole
+ turn for one outside that set, so Dodaios declares what the catalog knows:
+ `reasoning: true` when the catalog says the model reasons (or lists effort
+ levels; the ChatGPT subscription lists them per model) and
+ `compat.supportedReasoningEfforts` with the listed levels. OpenClaw then
+ offers `off`..`high` plus each listed `xhigh` / `max`; a model not declared
+ to reason gets `off` only. The agent's effort folds onto that set before it
+ is sent (`openclaw.prompt_meta`): `none` -> `off`; a listed level passes;
+ any other level -> the highest offered level below it (`ultra` -> `max`,
+ `max` without a listed `max` -> `high`); a model not declared to reason
+ gets no level at all. The upstream model still runs on the agent's own
+ effort, which Dodaios' gateway applies per turn and snaps to the model's
+ levels. A failure notice OpenClaw posts as the assistant's reply (an
+ unsupported level, `[OpenClaw interruption] ...`) ends the turn as an error
+ (`acp.AcpTurn.failure_replies`), never as an answer. No hand-written
Gateway WebSocket client: its wire protocol requires an exact version match.
- **Warm-up run.** A fresh Gateway sets its agent loop up on its first run
(session lifecycle, SQLite store, harness and context assembly, the MCP
diff --git a/dodaios/agent_chat/runner_acp.py b/dodaios/agent_chat/runner_acp.py
index 43c3dd5b00..1e359bdc35 100644
--- a/dodaios/agent_chat/runner_acp.py
+++ b/dodaios/agent_chat/runner_acp.py
@@ -87,6 +87,25 @@ def model_capabilities(provider: str, model: str) -> tuple[bool | None, bool | N
return reasons, vision
+def runtime_effort(provider: str, picked: str, model_efforts: tuple[str, ...] | None) -> str:
+ """The level a runtime turn runs on: the provider's fold, then the model's own.
+
+ ``model_efforts`` is the model's ladder from its catalog (``None`` = not
+ listed: the provider ladder alone applies). A level the model lists passes
+ as is; any other folds to the highest one it lists below, else its
+ lightest. ``""`` stays the model's own default.
+ """
+ from dodaios.agent_chat.effort import normalize_effort, snap_to_ladder
+
+ level = (picked or "").strip().lower()
+ if model_efforts is not None and level in model_efforts:
+ return level
+ effort = normalize_effort(provider, level)
+ if model_efforts is None or not effort:
+ return effort
+ return snap_to_ladder(effort, model_efforts)
+
+
def _denied_native(agent: Any, plan_mode: bool) -> frozenset[str]:
grants = set(agent.grants or [])
denies = set(agent.denies or [])
@@ -146,7 +165,6 @@ async def _runtime_turn(
) -> RuntimeTurn:
"""The runtime's view of one turn; raises ``RouteUnavailable``."""
from dodaios.agent_chat import dodaios_harness
- from dodaios.agent_chat.effort import normalize_effort
route = await prepare_route(
_config(), session.provider, session.model,
@@ -156,6 +174,11 @@ async def _runtime_turn(
)
plan_mode = session.permission_mode in ("plan", "read-only")
reasoning, vision = await asyncio.to_thread(model_capabilities, route.provider, route.model)
+ if route.efforts is not None:
+ # The provider's own per-model effort list is the stronger statement:
+ # a model listing a level above "none" reasons; one listing none (or
+ # only "none") does not.
+ reasoning = any(level and level != "none" for level in route.efforts)
return RuntimeTurn(
agent_id=agent.agent_id,
agent_name=agent.name,
@@ -167,8 +190,11 @@ async def _runtime_turn(
mcp_url=dodaios_harness.endpoint() if tools else None,
control_key=dodaios_harness.control_key() if tools else None,
denied_native=_denied_native(agent, plan_mode),
- effort=normalize_effort(session.provider, getattr(session, "effort", "") or ""),
+ effort=runtime_effort(
+ session.provider, getattr(session, "effort", "") or "", route.efforts
+ ),
reasoning=reasoning,
+ efforts=route.efforts,
vision=vision,
warm=warm,
)
@@ -346,6 +372,7 @@ def _plan(
report_session=launch.vendor_session,
session_meta=launch.session_meta,
prompt_meta=launch.prompt_meta,
+ failure_replies=tuple(getattr(launch, "failure_replies", ()) or ()),
)
if launch.proc is not None:
# The agent's warm process: initialized, maybe with the session open.
diff --git a/dodaios/agent_runtimes/acp.py b/dodaios/agent_runtimes/acp.py
index b1c301c0da..abeeccdc86 100644
--- a/dodaios/agent_runtimes/acp.py
+++ b/dodaios/agent_runtimes/acp.py
@@ -178,6 +178,11 @@ class AcpTurn:
#: (OpenClaw: this prompt's thinking level).
session_meta: dict[str, Any] | None = None
prompt_meta: dict[str, Any] | None = None
+ #: Replies the runtime posts as the assistant's message when the turn
+ #: failed before any model call (OpenClaw: an unsupported thinking level,
+ #: an interruption). The first group of a match is the reason; such a
+ #: reply ends the turn as an error instead of showing as the answer.
+ failure_replies: tuple[re.Pattern[str], ...] = ()
# --- fields the CLI runner reads after the turn ---
vendor_session: str | None = None
@@ -205,6 +210,7 @@ class AcpTurn:
_tool_names: dict[str, str] = field(default_factory=dict, init=False)
_tool_started: dict[str, float] = field(default_factory=dict, init=False)
_finished_tools: set[str] = field(default_factory=set, init=False)
+ _failure_reply: str = field(default="", init=False)
# ------------------------------------------------------------------ frames
@@ -346,6 +352,9 @@ class AcpTurn:
res = result if isinstance(result, dict) else {}
self.stop_reason = str(res.get("stopReason") or "")
self._take_usage(res.get("usage"))
+ if self._failure_reply:
+ self._fail(self._failure_reply.strip())
+ return
if self.stop_reason == "refusal" and not self.emitted_text:
self._fail("The model refused this request.")
elif self.stop_reason in _STOPPED_EARLY and not self.emitted_text:
@@ -435,6 +444,15 @@ class AcpTurn:
if kind == "agent_message_chunk":
await self._flush_thought(io)
text = _content_text(update.get("content"))
+ if self._failure_reply:
+ # The rest of a failure notice that arrived in several chunks.
+ self._failure_reply += text
+ return
+ reason = _failure_reason(text, self.failure_replies)
+ if reason:
+ # The runtime's own failure notice, not the model's answer.
+ self._failure_reply = reason
+ return
if text:
if not self._text_id:
self._text_id = f"acp-{self.turn_id}-{uuid.uuid4().hex[:8]}"
@@ -617,6 +635,16 @@ def _tool_name(update: dict[str, Any]) -> str:
return str(update.get("kind") or "tool")
+def _failure_reason(text: str, patterns: tuple[re.Pattern[str], ...]) -> str:
+ """The reason in ``text`` when it is one of the runtime's failure replies ("" otherwise)."""
+ stripped = text.strip()
+ for pattern in patterns:
+ match = pattern.match(stripped)
+ if match:
+ return (match.group(1) if match.groups() else stripped).strip()
+ return ""
+
+
def _error_text(error: dict[str, Any]) -> str:
message = str(error.get("message") or "error")
data = error.get("data")
diff --git a/dodaios/agent_runtimes/base.py b/dodaios/agent_runtimes/base.py
index 6b8dbc40db..be36fc19fa 100644
--- a/dodaios/agent_runtimes/base.py
+++ b/dodaios/agent_runtimes/base.py
@@ -166,6 +166,9 @@ class RuntimeTurn:
#: it reasons / it reads images. Never inferred from a provider or model name.
reasoning: bool | None = None
vision: bool | None = None
+ #: The model's own effort levels as its provider's catalog lists them
+ #: (``ModelRoute.efforts``); ``None`` = the catalog lists none.
+ efforts: tuple[str, ...] | None = None
#: Run on the agent's warm process (``warm.WarmPool``). ``False`` for a
#: turn whose process runs elsewhere (another computer over SSH).
warm: bool = True
@@ -196,6 +199,9 @@ class RuntimeLaunch:
#: ``_meta`` for ``session/new`` and for ``session/prompt``.
session_meta: dict[str, Any] | None = None
prompt_meta: dict[str, Any] | None = None
+ #: Replies the runtime itself posts as the assistant's message when a turn
+ #: fails before any model call (``acp.AcpTurn.failure_replies``).
+ failure_replies: tuple[re.Pattern[str], ...] = ()
class AgentRuntimeDriver(Protocol):
diff --git a/dodaios/agent_runtimes/gateway.py b/dodaios/agent_runtimes/gateway.py
index 34f8d387db..d247f10de9 100644
--- a/dodaios/agent_runtimes/gateway.py
+++ b/dodaios/agent_runtimes/gateway.py
@@ -274,6 +274,20 @@ async def refresh_model_limits(grant: Grant, model: str, config: Any) -> ModelLi
return resolve_limits(config, grant.provider, model, metadata)
+def declared_efforts(grant: Grant, model: str) -> tuple[str, ...] | None:
+ """The effort levels the provider's catalog lists for ``model`` (``None`` = none listed).
+
+ Read from the facts :func:`refresh_model_limits` just remembered; no
+ request of its own. A runtime that validates levels per model (OpenClaw)
+ needs them, or it refuses every level but "off".
+ """
+ cached = _METADATA.get((grant.provider, grant.account_id, model))
+ efforts = getattr(cached[1], "efforts", None) if cached is not None else None
+ if not isinstance(efforts, list | tuple):
+ return None
+ return tuple(str(level) for level in efforts if isinstance(level, str))
+
+
def _metadata_refreshed(key: tuple[str, str, str], task: asyncio.Task[Any]) -> None:
_METADATA_REFRESH.pop(key, None)
if not task.cancelled() and task.exception() is not None:
diff --git a/dodaios/agent_runtimes/model_map.py b/dodaios/agent_runtimes/model_map.py
index 147b30226e..05f27cd58e 100644
--- a/dodaios/agent_runtimes/model_map.py
+++ b/dodaios/agent_runtimes/model_map.py
@@ -97,6 +97,10 @@ class ModelRoute:
#: ``claude_cli`` only: the environment that selects the agent's Claude
#: account (its config directory). Never a credential.
claude_env: tuple[tuple[str, str], ...] = ()
+ #: The model's own reasoning-effort levels as the provider's catalog lists
+ #: them (the ChatGPT subscription names them per model). ``None`` = the
+ #: catalog lists none; ``()`` = the model has no effort knob.
+ efforts: tuple[str, ...] | None = None
def env(self) -> dict[str, str]:
"""The child environment: the key (empty when keyless), or for the
@@ -460,5 +464,8 @@ async def prepare_route(
limits = await gateway.refresh_model_limits(grant, route.model, config)
gateway.register_model(route.api_key, route.model, limits)
return replace(
- route, context_window=limits.context_window, max_output_tokens=limits.max_output_tokens
+ route,
+ context_window=limits.context_window,
+ max_output_tokens=limits.max_output_tokens,
+ efforts=gateway.declared_efforts(grant, route.model),
)
diff --git a/dodaios/agent_runtimes/openclaw.py b/dodaios/agent_runtimes/openclaw.py
index ee0ba091c3..5419b328d9 100644
--- a/dodaios/agent_runtimes/openclaw.py
+++ b/dodaios/agent_runtimes/openclaw.py
@@ -30,6 +30,7 @@ import hashlib
import json
import logging
import os
+import re
import secrets
import socket
import time
@@ -38,6 +39,7 @@ from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Final
+from dodaios.agent_chat.effort import ORDER, snap_to_ladder
from dodaios.agent_runtimes import base, versions
from dodaios.agent_runtimes.base import (
DetectCache,
@@ -155,6 +157,21 @@ _CONTROL_KEY_ENV: Final[str] = "JARVIS_CONTROL_API_KEY"
_THINKING_LEVELS: Final[frozenset[str]] = frozenset(
{"off", "minimal", "low", "medium", "high", "xhigh", "max"}
)
+#: The levels OpenClaw (2026.9) offers a model of a provider it has no
+#: policy for, as Dodaios' ``jarvis`` provider is: ``off`` .. ``high`` when the
+#: model is declared to reason, plus each of ``xhigh`` / ``max`` the model's
+#: ``compat.supportedReasoningEfforts`` names; ``off`` alone otherwise. A
+#: per-prompt level outside that set fails the turn ("Thinking level ... is not
+#: supported"), so :func:`prompt_meta` never sends one.
+_BASE_THINKING: Final[tuple[str, ...]] = ("none", "minimal", "low", "medium", "high")
+_DECLARED_EFFORTS: Final[tuple[str, ...]] = ("minimal", "low", "medium", "high", "xhigh", "max")
+#: What OpenClaw posts as the assistant's reply when a turn fails before any
+#: model call (no tokens, no answer): shown as the turn's error, not as an
+#: answer. The first group is the reason.
+FAILURE_REPLIES: Final[tuple[re.Pattern[str], ...]] = (
+ re.compile(r"^\[OpenClaw interruption\]\s*(.+)$", re.DOTALL),
+ re.compile(r"^(Thinking level \"[^\"]*\" is not supported for \S+\. Use one of: .*)$"),
+)
_INSTALL_URL_PS1: Final[str] = "https://openclaw.ai/install.ps1"
_INSTALL_URL_SH: Final[str] = "https://openclaw.ai/install.sh"
@@ -512,6 +529,7 @@ class OpenClawRuntime:
# (no reasoning, text only) stand for an unknown model.
"input": ["text", "image"] if turn.vision else ["text"],
**({"reasoning": True} if turn.reasoning else {}),
+ **_declared_efforts(turn),
"contextWindow": route.context_window,
**({"maxTokens": route.max_output_tokens}
if route.max_output_tokens is not None else {}),
@@ -783,6 +801,7 @@ class OpenClawRuntime:
"resetSession": turn.resume is None,
},
prompt_meta=prompt_meta(turn),
+ failure_replies=FAILURE_REPLIES,
)
return launch, gateway
@@ -1040,12 +1059,51 @@ def _use_claude_cli(config: dict[str, Any], turn: RuntimeTurn) -> None:
tools["deny"] = [*tools["deny"], "exec", "process"]
+def _declared_efforts(turn: RuntimeTurn) -> dict[str, Any]:
+ """The model's ``compat`` entry: the effort levels its catalog lists.
+
+ Without it OpenClaw offers a reasoning model ``off`` .. ``high`` only and
+ refuses ``xhigh`` / ``max`` although the model takes them."""
+ if not turn.reasoning or not turn.efforts:
+ return {}
+ levels = [level for level in _DECLARED_EFFORTS if level in turn.efforts]
+ return {"compat": {"supportedReasoningEfforts": levels}} if levels else {}
+
+
+def thinking_levels(turn: RuntimeTurn) -> tuple[str, ...]:
+ """The levels OpenClaw accepts for this turn's model, on Dodaios' ladder
+ (``none`` = OpenClaw's ``off``), as :meth:`OpenClawRuntime.config_for`
+ declares the model."""
+ if turn.route.transport == "claude_cli":
+ # OpenClaw's own Claude policy answers for the Claude CLI route.
+ return ("none", *sorted(_THINKING_LEVELS - {"off"}, key=ORDER.index))
+ if not turn.reasoning:
+ return ("none",)
+ declared = _declared_efforts(turn).get("compat", {}).get("supportedReasoningEfforts", [])
+ return (*_BASE_THINKING, *(level for level in ("xhigh", "max") if level in declared))
+
+
def prompt_meta(turn: RuntimeTurn) -> dict[str, Any] | None:
"""``session/prompt`` ``_meta``: the agent's thinking level for this prompt.
Per prompt, not ``thinkingDefault`` in the config: a changed effort then
- never restarts the Gateway. No level = the model's own default."""
- thinking = "off" if turn.effort == "none" else turn.effort
+ never restarts the Gateway. No level = the model's own default.
+
+ OpenClaw refuses the whole turn for a level the model does not offer (in
+ its view), so the effort folds onto :func:`thinking_levels` first: the
+ highest level at or below the pick (``ultra`` -> the highest one), never
+ a level outside the set. A model not declared to reason gets no level
+ unless the pick is "none". The upstream model still runs on the agent's
+ own effort: Dodaios' gateway applies it per turn (``watch_failure``).
+ """
+ effort = (turn.effort or "").strip().lower()
+ if effort not in ORDER:
+ return None
+ levels = thinking_levels(turn)
+ if levels == ("none",) and effort != "none":
+ return None
+ level = snap_to_ladder(effort, levels)
+ thinking = "off" if level == "none" else level
return {"thinking": thinking} if thinking in _THINKING_LEVELS else None
diff --git a/tests/unit/agent_runtimes/test_acp_failure_replies.py b/tests/unit/agent_runtimes/test_acp_failure_replies.py
new file mode 100644
index 0000000000..14ea77baf4
--- /dev/null
+++ b/tests/unit/agent_runtimes/test_acp_failure_replies.py
@@ -0,0 +1,107 @@
+"""A runtime's own failure notice ends the turn as an error, never as the answer.
+
+Live 2026-10-27: OpenClaw refused a thinking level and posted the refusal as
+the assistant's reply ("Thinking level "medium" is not supported for
+jarvis/gpt-6-luna. Use one of: off, ultra."); the chat showed it as an
+ordinary answer bubble.
+"""
+
+from __future__ import annotations
+
+import asyncio
+from typing import Any
+
+from dodaios.agent_runtimes.acp import AcpTurn
+from dodaios.agent_runtimes.openclaw import FAILURE_REPLIES
+
+_REFUSAL = (
+ 'Thinking level "medium" is not supported for jarvis/gpt-6-luna. Use one of: off, ultra.'
+)
+
+
+class _IO:
+ def __init__(self) -> None:
+ self.events: list[dict[str, Any]] = []
+
+ async def write(self, frame: dict[str, Any]) -> None:
+ pass
+
+ async def emit(self, event: dict[str, Any]) -> None:
+ self.events.append(event)
+
+ async def ask(self, call_id: str, name: str, args: dict[str, Any], summary: str) -> str:
+ return "deny"
+
+
+def _chunk(text: str) -> dict[str, Any]:
+ return {
+ "jsonrpc": "2.0",
+ "method": "session/update",
+ "params": {
+ "sessionId": "s",
+ "update": {
+ "sessionUpdate": "agent_message_chunk",
+ "content": {"type": "text", "text": text},
+ },
+ },
+ }
+
+
+_RESULT = {"jsonrpc": "2.0", "id": 3, "result": {"stopReason": "end_turn"}}
+
+
+def _run(*texts: str, patterns=FAILURE_REPLIES) -> tuple[AcpTurn, _IO]:
+ turn = AcpTurn(turn_id="t", cwd=".", prompt_text="hi", failure_replies=patterns)
+ io = _IO()
+
+ async def go() -> None:
+ for text in texts:
+ await turn.on_message(_chunk(text), io)
+ await turn.on_message(_RESULT, io)
+
+ asyncio.run(go())
+ return turn, io
+
+
+def _texts(io: _IO) -> list[str]:
+ return [
+ str(e["payload"].get("text", ""))
+ for e in io.events
+ if e.get("kind") in {"text_delta", "assistant_text"}
+ ]
+
+
+def test_an_unsupported_thinking_level_reply_is_the_turns_error():
+ turn, io = _run(_REFUSAL)
+ assert turn.status == "error"
+ assert turn.error == _REFUSAL
+ assert not turn.emitted_text
+ assert _texts(io) == []
+
+
+def test_an_interruption_notice_is_an_error_and_keeps_the_partial_answer():
+ turn, io = _run("Half an answer", "[OpenClaw interruption] The Gateway disconnected.")
+ assert turn.status == "error"
+ assert turn.error == "The Gateway disconnected."
+ assert any("Half an answer" in text for text in _texts(io))
+ assert not any("interruption" in text for text in _texts(io))
+
+
+def test_an_answer_that_merely_mentions_thinking_levels_stays_an_answer():
+ answer = 'You asked about the "medium" thinking level: it is supported here.'
+ turn, io = _run(answer)
+ assert turn.status == "done"
+ assert turn.emitted_text
+
+
+def test_a_runtime_without_failure_replies_shows_every_text():
+ turn, io = _run(_REFUSAL, patterns=())
+ assert turn.status == "done"
+ assert turn.emitted_text
+
+
+def test_a_failure_notice_split_over_chunks_never_leaks_into_the_answer():
+ turn, io = _run("[OpenClaw interruption] The Gateway", " disconnected.")
+ assert turn.status == "error"
+ assert turn.error == "The Gateway disconnected."
+ assert _texts(io) == []
diff --git a/tests/unit/agent_runtimes/test_runtime_configs.py b/tests/unit/agent_runtimes/test_runtime_configs.py
index 7d1bda8d5a..50f8d66c08 100644
--- a/tests/unit/agent_runtimes/test_runtime_configs.py
+++ b/tests/unit/agent_runtimes/test_runtime_configs.py
@@ -545,7 +545,7 @@ def test_hermes_writes_the_agents_effort(tmp_path, effort, expected):
def test_openclaw_sends_the_agents_thinking_with_each_prompt(tmp_path, effort, expected):
from dodaios.agent_runtimes import openclaw
- turn = _turn(tmp_path, effort=effort)
+ turn = _turn(tmp_path, effort=effort, reasoning=True)
meta = openclaw.prompt_meta(turn)
assert (meta or {}).get("thinking") == expected
# Never in the config: a changed effort must not restart the Gateway.
@@ -595,3 +595,117 @@ def test_capabilities_come_from_the_catalog_never_the_name(monkeypatch):
assert runner_acp.model_capabilities("ollama", "plain") == (False, False)
# A name that "sounds" capable but has no catalog entry stays unknown.
assert runner_acp.model_capabilities("openai", "gpt-vision-reasoner") == (None, None)
+
+
+def _codex_turn(tmp_path: Path, **overrides) -> RuntimeTurn:
+ """An OpenClaw turn on the ChatGPT subscription seat (``gpt-6-luna``)."""
+ route = ModelRoute(
+ provider="openai-codex",
+ model="gpt-6-luna",
+ base_url=_GATEWAY,
+ transport="responses",
+ api_key=_TOKEN,
+ efforts=("low", "medium", "high", "xhigh", "max"),
+ )
+ values = {"route": route, "efforts": route.efforts, "reasoning": True}
+ values.update(overrides)
+ return _turn(tmp_path, **values)
+
+
[email protected]("effort", ["low", "medium", "high", "xhigh", "max"])
+def test_openclaw_accepts_every_level_the_subscription_model_lists(tmp_path, effort):
+ """Live 2026-10-27: gpt-6-luna on the ChatGPT seat refused "medium" and
+ "max" (OpenClaw offered "off, ultra") because the model was not declared
+ to reason. Every level the model's catalog lists is declared and sent."""
+ from dodaios.agent_runtimes import openclaw
+
+ turn = _codex_turn(tmp_path, effort=effort)
+ model = OpenClawRuntime().config_for(turn, port=1, token=_TOKEN)["models"]["providers"][
+ "jarvis"
+ ]["models"][0]
+ assert model["reasoning"] is True
+ assert model["compat"] == {
+ "supportedReasoningEfforts": ["low", "medium", "high", "xhigh", "max"]
+ }
+ assert openclaw.prompt_meta(turn) == {"thinking": effort}
+
+
+ ("effort", "efforts", "expected"),
+ [
+ ("max", None, "high"), # reasoning, no listed ladder: off..high only
+ ("xhigh", ("low", "medium", "high"), "high"),
+ ("ultra", ("low", "medium", "high", "xhigh", "max", "ultra"), "max"),
+ ("none", ("low", "medium"), "off"),
+ ],
+)
+def test_openclaw_folds_a_level_it_would_refuse(tmp_path, effort, efforts, expected):
+ from dodaios.agent_runtimes import openclaw
+
+ turn = _codex_turn(tmp_path, effort=effort, efforts=efforts)
+ meta = openclaw.prompt_meta(turn)
+ assert meta == {"thinking": expected}
+
+
[email protected]("effort", ["low", "medium", "high", "max"])
+def test_openclaw_sends_no_level_to_a_model_not_declared_to_reason(tmp_path, effort):
+ """OpenClaw offers such a model only "off" (and its own ultra mode): any
+ other level fails the turn. The gateway still applies the agent's effort."""
+ from dodaios.agent_runtimes import openclaw
+
+ for reasoning in (None, False):
+ turn = _turn(tmp_path, effort=effort, reasoning=reasoning)
+ assert openclaw.thinking_levels(turn) == ("none",)
+ assert openclaw.prompt_meta(turn) is None
+ assert openclaw.prompt_meta(_turn(tmp_path, effort="none")) == {"thinking": "off"}
+
+
+def test_openclaw_never_sends_a_level_outside_what_it_offers(tmp_path):
+ """Exhaustive: whatever the pick and the model's listed levels, the level
+ sent is one OpenClaw offers for the model as Dodaios declares it."""
+ from itertools import combinations
+
+ from dodaios.agent_chat.effort import ORDER
+ from dodaios.agent_runtimes import openclaw
+
+ ladders = [None, ()] + [
+ tuple(combo) for size in (1, 2, 3) for combo in combinations(ORDER, size)
+ ]
+ for reasoning in (None, False, True):
+ for efforts in ladders:
+ for effort in ("", *ORDER):
+ turn = _codex_turn(tmp_path, effort=effort, efforts=efforts, reasoning=reasoning)
+ meta = openclaw.prompt_meta(turn)
+ if meta is None:
+ continue
+ levels = openclaw.thinking_levels(turn)
+ offered = {"off" if lvl == "none" else lvl for lvl in levels}
+ assert meta["thinking"] in offered, (reasoning, efforts, effort, meta)
+
+
+def test_runtime_effort_folds_onto_the_models_own_levels():
+ from dodaios.agent_chat.runner_acp import runtime_effort
+
+ luna = ("low", "medium", "high", "xhigh", "max")
+ assert runtime_effort("openai-codex", "medium", luna) == "medium"
+ assert runtime_effort("openai-codex", "ultra", luna) == "max"
+ assert runtime_effort("openai-codex", "", luna) == ""
+ assert runtime_effort("openai-codex", "max", ("low", "medium", "high")) == "high"
+ assert runtime_effort("openai-codex", "high", ()) == "" # no effort knob
+ # Not listed: the provider ladder alone applies, as before.
+ assert runtime_effort("openai-codex", "max", None) == "max"
+ assert runtime_effort("gemini", "xhigh", None) == "high"
+
+
+def test_the_route_carries_the_subscription_models_listed_levels(gateway_up):
+ from dodaios.agent_runtimes.gateway import Grant
+
+ grant = Grant(agent_id="a", provider="openai-codex", account_id="acct")
+ gateway_up._METADATA[("openai-codex", "acct", "gpt-6-luna")] = (
+ 0.0,
+ SimpleNamespace(id="gpt-6-luna", efforts=["low", "medium", "max"]),
+ )
+ assert gateway_up.declared_efforts(grant, "gpt-6-luna") == ("low", "medium", "max")
+ assert gateway_up.declared_efforts(grant, "unknown") is None
+ gateway_up._METADATA[("openai-codex", "acct", "bare")] = (0.0, SimpleNamespace(id="bare"))
+ assert gateway_up.declared_efforts(grant, "bare") is None