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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(dictation): negotiate low-reasoning polish requests
rubenluetke10-beep2e3398fb6836
diff --git a/jarvis/dictation/polish_client.py b/jarvis/dictation/polish_client.pyindex e16400e385..1e1158b511 100644--- a/jarvis/dictation/polish_client.py+++ b/jarvis/dictation/polish_client.py@@ -748,6 +748,12 @@ class OpenAIChatPolishClient:"max_tokens": max_output_tokens,"temperature": temperature,"stream": False,+ # A polish pass is a deterministic rewrite, so OpenAI-compatible+ # transports should spend their budget on visible text rather than+ # hidden reasoning. This is an optional wire-level intent, not a+ # provider/model capability claim: a 400 naming the field removes+ # it for the single schema-negotiation retry below.+ "reasoning_effort": "low",}data = await self._post(payload, timeout_s=timeout_s)choices = data.get("choices") or []@@ -760,11 +766,10 @@ class OpenAIChatPolishClient:async def _post(self, payload: dict[str, Any], *, timeout_s: float) -> dict[str, Any]:"""POST the payload, retrying ONCE against a schema-shape rejection.- Newer OpenAI-schema endpoints renamed ``max_tokens`` to- ``max_completion_tokens`` and pin ``temperature`` to 1 on some models.- Both show up as a 400 naming the offending field, so the retry is driven- by what the SERVER said rather than by a model-id allowlist that would- rot with every release (AP-21).+ OpenAI-compatible endpoints can rename ``max_tokens``, pin+ ``temperature``, or reject the optional low-reasoning intent. These+ show up as a 400 naming the offending field, so the retry is driven by+ what the SERVER said rather than by a provider/model allowlist (AP-21)."""import httpx@@ -833,6 +838,9 @@ def _relax_payload(payload: dict[str, Any], body: str) -> dict[str, Any] | None:if "temperature" in lowered and "temperature" in adjusted:adjusted.pop("temperature")changed = True+ if "reasoning_effort" in lowered and "reasoning_effort" in adjusted:+ adjusted.pop("reasoning_effort")+ changed = Truereturn adjusted if changed else Nonediff --git a/jarvis/dictation/polish_probe.py b/jarvis/dictation/polish_probe.pyindex 8e41686004..cacdbd496f 100644--- a/jarvis/dictation/polish_probe.py+++ b/jarvis/dictation/polish_probe.py@@ -136,7 +136,11 @@ async def probe_polish_family(client.complete(PROBE_SYSTEM,PROBE_USER,- max_output_tokens=64,+ # Reasoning-capable providers count hidden work against this+ # ceiling too. 64 tokens can therefore yield HTTP 200 with no+ # visible text; 256 remains small for a one-sentence probe while+ # leaving room for the final answer.+ max_output_tokens=256,temperature=0.0,timeout_s=ceiling_s,),diff --git a/tests/unit/dictation/test_polish_chain.py b/tests/unit/dictation/test_polish_chain.pyindex 9f15f6ec9f..b121ad1cc7 100644--- a/tests/unit/dictation/test_polish_chain.py+++ b/tests/unit/dictation/test_polish_chain.py@@ -50,6 +50,7 @@ from jarvis.dictation.polish_client import ()GROQ: PolishFamily = POLISH_FAMILIES[0]+OPENAI: PolishFamily = next(f for f in POLISH_FAMILIES if f.id == "openai")GEMINI: PolishFamily = next(f for f in POLISH_FAMILIES if f.transport == "gemini")RAW = "so we should probably move the meeting to the morning and tell the team"@@ -448,6 +449,64 @@ async def test_the_openai_chat_transport_returns_the_message_content(assert seen[0]["max_tokens"] == 1200+async def test_openai_compatible_transport_requests_low_reasoning_cross_provider(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """The rewrite intent is a transport option, never a family/model allowlist."""+ import httpx++ seen: list[dict[str, Any]] = []++ def handler(request: httpx.Request) -> httpx.Response:+ seen.append(json.loads(request.content.decode("utf-8")))+ return httpx.Response(+ 200, json={"choices": [{"message": {"content": POLISHED}}]}+ )++ _mock_http(monkeypatch, handler)+ client = OpenAIChatPolishClient(OPENAI, model="arbitrary-future-model", api_key="k")++ text = await client.complete(+ "system", "user", max_output_tokens=256, temperature=0.0, timeout_s=1.0+ )++ assert text == POLISHED+ assert seen[0]["max_tokens"] == 256+ assert seen[0]["reasoning_effort"] == "low"+++async def test_low_reasoning_intent_is_stripped_after_explicit_400_rejection(+ monkeypatch: pytest.MonkeyPatch,+) -> None:+ """An incompatible endpoint gets one honest retry without the option."""+ import httpx++ bodies: list[dict[str, Any]] = []++ def handler(request: httpx.Request) -> httpx.Response:+ body = json.loads(request.content.decode("utf-8"))+ bodies.append(body)+ if "reasoning_effort" in body:+ return httpx.Response(+ 400, text="Unsupported parameter: 'reasoning_effort'."+ )+ return httpx.Response(+ 200, json={"choices": [{"message": {"content": POLISHED}}]}+ )++ _mock_http(monkeypatch, handler)+ client = OpenAIChatPolishClient(GROQ, model="any-model", api_key="k")++ text = await client.complete(+ "system", "user", max_output_tokens=256, temperature=0.0, timeout_s=1.0+ )++ assert text == POLISHED+ assert len(bodies) == 2+ assert bodies[0]["reasoning_effort"] == "low"+ assert "reasoning_effort" not in bodies[1]++async def test_a_rate_limited_transport_reports_its_status_and_retry_after(monkeypatch: pytest.MonkeyPatch,) -> None:diff --git a/tests/unit/dictation/test_polish_probe.py b/tests/unit/dictation/test_polish_probe.pyindex 8d6936f693..c22678d128 100644--- a/tests/unit/dictation/test_polish_probe.py+++ b/tests/unit/dictation/test_polish_probe.py@@ -53,6 +53,16 @@ class _Answers:return self._text+class _RecordsAnswer(_Answers):+ def __init__(self) -> None:+ super().__init__()+ self.max_output_tokens = 0++ async def complete(self, _system: str, _user: str, **kw: Any) -> str:+ self.max_output_tokens = int(kw["max_output_tokens"])+ return await super().complete(_system, _user, **kw)++class _Raises:def __init__(self, message: str):self._message = message@@ -73,6 +83,18 @@ def test_a_provider_that_answers_in_time_is_ok() -> None:assert res.provider == "groq-polish"+def test_probe_reserves_room_for_reasoning_models_final_text() -> None:+ client = _RecordsAnswer()++ _run(+ probe_polish_family(+ _family("groq"), _cfg(), make_client=lambda _f, _m: client+ )+ )++ assert client.max_output_tokens == 256++def test_a_provider_slower_than_the_budget_is_not_reported_healthy() -> None:"""Reached, authenticated, answered — and still useless HERE.