Python
Handle effort "none" on every provider: Anthropic omits it, OpenAI-compat sends it
Devika Verma26884bb764a0
diff --git a/coworker/providers/effort.py b/coworker/providers/effort.pyindex 816b77b9..31d3abe0 100644--- a/coworker/providers/effort.py+++ b/coworker/providers/effort.py@@ -26,6 +26,12 @@ from ..config import EFFORT_LEVELS_RANK = {level: i for i, level in enumerate(EFFORT_LEVELS)}+# "No thinking, just answer." The auto-title request sends this so a reasoning model does+# not spend its 64-token cap on hidden reasoning. It is not one of the five user-selectable+# levels and never goes through the rank table: Anthropic has no such value (the effort+# field is omitted), and OpenAI-vocabulary endpoints accept it on the wire (#676, #702).+NO_EFFORT = "none"+@dataclass(frozen=True)class EffortPlan:@@ -123,7 +129,10 @@ def _anthropic_supported(model: str) -> Optional[tuple[str, ...]]:def anthropic_effort(model: str, level: str, *, budget_mode: bool) -> EffortPlan:"""`output_config.effort` on adaptive-thinking models; `thinking.budget_tokens` onbudget-mode models. Unknown adaptive models get the level as-is (the 400 fallback- covers a wrong guess); the mapping is recorded either way."""+ covers a wrong guess); the mapping is recorded either way. `"none"` has no Anthropic+ equivalent, so nothing is sent and the API default applies."""+ if level == NO_EFFORT:+ return unsupported(level, "Anthropic has no effort value 'none'; no effort parameter sent")if budget_mode:budget = BUDGET_TOKENS_BY_LEVEL[level]return EffortPlan(@@ -161,10 +170,19 @@ _OPENAI_DEFAULT = ("low", "medium", "high")def openai_compat_effort(model: str, level: str) -> EffortPlan:supported = _OPENAI_COMPAT.get(model) or _OPENAI_COMPAT.get(model.lower()) or _OPENAI_DEFAULT+ verified = model in _OPENAI_COMPAT or model.lower() in _OPENAI_COMPAT+ if level == NO_EFFORT:+ # Send it as-is where the OpenAI vocabulary is assumed (it includes "none"). A+ # verified row that documents no such value gets its lowest level instead — "none"+ # ranks below "low", so that is the nearest accepted one, per this module's rule.+ # A rejection is dropped by the provider's param-fix retry like any other.+ if verified and NO_EFFORT not in supported:+ lowest = min(supported, key=_RANK.__getitem__)+ return EffortPlan(level, lowest, {"reasoning_effort": lowest}, f"{model} has no 'none'; sent its lowest level {lowest}")+ return EffortPlan(level, level, {"reasoning_effort": level}, "no-thinking request; OpenAI vocabulary assumed")effective = nearest_supported(level, supported)if effective is None:return unsupported(level, f"effort level {level!r} unknown for {model}; no effort parameter sent")- verified = model in _OPENAI_COMPAT or model.lower() in _OPENAI_COMPATnote = ""if effective != level:note = f"{level} not accepted by {model}; sent {effective}"diff --git a/coworker/providers/openai_provider.py b/coworker/providers/openai_provider.pyindex 72636ff1..4e268de2 100644--- a/coworker/providers/openai_provider.py+++ b/coworker/providers/openai_provider.py@@ -14,7 +14,7 @@ import jsonimport refrom typing import Any, Optional-from .effort import EffortPlan, mentions_effort, openai_compat_effort+from .effort import NO_EFFORT, EffortPlan, mentions_effort, openai_compat_effortfrom .base import (AssistantTurn,ModelCapabilities,@@ -137,13 +137,10 @@ def _param_fix_retry(kwargs: dict[str, Any], exc: Exception) -> dict[str, Any]:msg = str(exc).lower()if _EFFORT_ERROR in msg and kwargs.get("reasoning_effort") != "none":return {**kwargs, "reasoning_effort": "none"}- if (- "reasoning_effort" in kwargs- and kwargs.get("reasoning_effort") != "none"- and ("reasoning_effort" in msg or "effort" in msg)- ):- # OPE-176: the endpoint has no effort knob under that name — drop it and run on- # the server default; the reply's `effort` record says it was rejected.+ if "reasoning_effort" in kwargs and ("reasoning_effort" in msg or "effort" in msg):+ # OPE-176: the endpoint has no effort knob under that name (or, for the auto-title+ # request, no "none" value) — drop it and run on the server default; the reply's+ # `effort` record says it was rejected.fixed = dict(kwargs)fixed.pop("reasoning_effort")return fixed@@ -329,7 +326,13 @@ class OpenAIProvider(ProviderClient):self, model: str, plan: Optional[EffortPlan], kwargs: dict[str, Any]) -> Optional[dict[str, Any]]:record = _effort_record(plan, kwargs)- if plan is not None and plan.params and kwargs.get("reasoning_effort") is None:+ if (+ plan is not None+ and plan.params+ and kwargs.get("reasoning_effort") is None+ # A rejected "none" says nothing about the real levels; keep sending those.+ and plan.requested != NO_EFFORT+ ):self.__dict__.setdefault("_effort_rejected", set()).add(model)return recorddiff --git a/coworker/server/manager.py b/coworker/server/manager.pyindex 6270aa31..61894734 100644--- a/coworker/server/manager.py+++ b/coworker/server/manager.py@@ -7251,8 +7251,10 @@ class SessionManager:temperature=0.2,# Reasoning-routed models spend hidden tokens BEFORE emitting text; a# tight cap plus default effort yields an empty completion and a silent- # no-op. Effort "none" reaches only the OpenAI-compat path (the native- # providers whitelist their settings), and 64 leaves headroom either way.+ # no-op. Effort "none" means "no thinking": every provider's effort+ # mapper handles it (OpenAI-vocabulary endpoints get it on the wire,+ # Anthropic omits the field; see effort.NO_EFFORT), and 64 leaves+ # headroom either way.max_tokens=64,reasoning_effort="none",)diff --git a/tests/test_reasoning_effort.py b/tests/test_reasoning_effort.pyindex 102108d8..be1c86de 100644--- a/tests/test_reasoning_effort.py+++ b/tests/test_reasoning_effort.py@@ -178,35 +178,62 @@ def test_nearest_supported_unknown_level_returns_none():assert nearest_supported("none", ("low", "medium", "high")) is None-def test_openai_compat_unknown_level_sends_no_parameter():- """Effort "none" (used by the compaction summariser) and unlisted model ids- (Ollama, any OpenAI-compatible endpoint) must omit the parameter rather- than crash the turn — see #676."""+def test_openai_compat_none_is_sent_where_openai_vocabulary_is_assumed():+ """The auto-title request asks for "none" (no thinking). Unlisted model ids (Ollama,+ any OpenAI-compatible endpoint) get the OpenAI vocabulary, which includes "none", so it+ goes on the wire as-is — omitting it would let a reasoning model spend the 64-token+ title cap on hidden thinking (#702)."""plan = openai_compat_effort("ollama:glm-5.3:cloud", "none")- assert plan.effective is None- assert plan.params == {}- assert "unknown" in plan.note+ assert plan.effective == "none"+ assert plan.params == {"reasoning_effort": "none"}+ assert "no-thinking" in plan.note- # Known models behave identically — "none" omits the parameter there too++def test_openai_compat_none_maps_to_the_lowest_level_on_a_verified_row_without_it():+ """Kimi K3 documents low/high/max only. "none" ranks below "low", so the nearest+ accepted level is "low" — the least thinking the model offers (#702)."""plan = openai_compat_effort("moonshotai/Kimi-K3", "none")- assert plan.effective is None- assert plan.params == {}+ assert plan.effective == "low"+ assert plan.params == {"reasoning_effort": "low"}+ assert "sent its lowest level low" in plan.note+++def test_openai_compat_other_unknown_level_sends_no_parameter():+ """Any other value outside the rank table still omits the parameter rather than raise."""+ plan = openai_compat_effort("ollama:glm-5.3:cloud", "turbo")+ assert plan.effective is None and plan.params == {} and "unknown" in plan.note+ "model, budget",+ [("claude-sonnet-5", False), ("claude-opus-4-5", False), ("claude-unknown-9", False), ("claude-3-7-sonnet", True)],+)+def test_anthropic_none_sends_nothing(model, budget):+ """Anthropic has no "none" value: adaptive, budget-thinking and unknown models all+ omit the effort field instead of raising (#702)."""+ plan = anthropic_effort(model, "none", budget_mode=budget)+ assert plan.requested == "none" and plan.effective is None and plan.params == {}+ assert "no effort parameter sent" in plan.note+def test_every_curated_model_resolves_every_level():- """No level on any curated row may raise; providers without a knob are simply skipped."""+ """No level on any curated row may raise, and neither may the auto-title's "none";+ providers without a knob are simply skipped."""for mid in MATRIX:provider, _, bare = mid.partition(":") if ":" in mid else ("openai", "", mid)- for level in EFFORT_LEVELS:+ for level in (*EFFORT_LEVELS, "none"):if provider == "anthropic":plan = anthropic_effort(bare, level, budget_mode=_uses_budget_thinking(bare))elif provider in ("gemini", "bedrock", "vertex", "ark", "ark-agent-plan-cn", "openai-codex", "openai"):continue # no chat-completions effort knob on these paths (recorded as such)else:plan = openai_compat_effort(bare, level)- assert plan.requested == level and plan.effective in EFFORT_LEVELS, (mid, level)+ assert plan.requested == level, (mid, level)+ if level == "none":+ assert plan.effective in (None, "none", "low"), (mid, level)+ else:+ assert plan.effective in EFFORT_LEVELS, (mid, level)# -- Anthropic provider ---------------------------------------------------------------@@ -260,6 +287,17 @@ def test_anthropic_unset_sends_no_effort_field():assert turn.effort is None+def test_anthropic_none_sends_no_effort_field_and_records_it():+ """The auto-title's "none" must not raise on the Anthropic path (#702): nothing is+ sent, and the reply records that nothing was sent."""+ fake = _FakeAnthropic(response=_anthropic_response())+ turn = AnthropicProvider(client=fake).complete(+ model="claude-sonnet-5", messages=[{"role": "user", "content": "x"}], reasoning_effort="none"+ )+ assert "output_config" not in fake.kwargs and "thinking" not in fake.kwargs+ assert turn.effort["requested"] == "none" and turn.effort["effective"] is None++def test_anthropic_complete_and_stream_send_output_config():fake = _FakeAnthropic(response=_anthropic_response(), events=_anthropic_events())provider = AnthropicProvider(client=fake)@@ -361,6 +399,25 @@ def test_openai_compat_rejection_drops_the_parameter_and_records_it():assert len(fake.calls) == 3 and "reasoning_effort" not in fake.calls[-1]+def test_openai_compat_none_goes_on_the_wire_for_unlisted_models():+ fake = _FakeOpenAI(response=_openai_response())+ turn = OpenAIProvider(client=fake).complete(model="ollama:glm-5.3:cloud", messages=[{"role": "user", "content": "x"}], reasoning_effort="none")+ assert fake.calls[-1]["reasoning_effort"] == "none"+ assert turn.effort == {"requested": "none", "effective": "none", "param": {"reasoning_effort": "none"}, "note": "no-thinking request; OpenAI vocabulary assumed"}+++def test_openai_compat_rejected_none_is_dropped_but_not_remembered():+ """An endpoint that rejects "none" gets the retry without it, like any other rejected+ value — but that rejection must not stop the real levels from being sent afterwards."""+ fake = _FakeOpenAI(response=_openai_response(), reject_effort=True)+ provider = OpenAIProvider(client=fake)+ turn = provider.complete(model="some/other-model", messages=[{"role": "user", "content": "x"}], reasoning_effort="none")+ assert len(fake.calls) == 2 and "reasoning_effort" not in fake.calls[-1]+ assert turn.effort["effective"] is None and "rejected" in turn.effort["note"]+ provider.complete(model="some/other-model", messages=[{"role": "user", "content": "y"}], reasoning_effort="high")+ assert fake.calls[2]["reasoning_effort"] == "high" # still attempted, not pre-emptively skipped++# -- engine record --------------------------------------------------------------------