DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
fix(codex): normalize cached Luna reasoning levels
NoxsMedia9e053f129884
diff --git a/deeptutor/services/codex_auth/catalog.py b/deeptutor/services/codex_auth/catalog.pyindex a22efb08d..7c3d4cb7d 100644--- a/deeptutor/services/codex_auth/catalog.py+++ b/deeptutor/services/codex_auth/catalog.py@@ -18,7 +18,13 @@ from .constants import (CODEX_MODELS_URL,CODEX_STALE_CACHE_SECONDS,)-from .contracts import CatalogSnapshot, CodexAuthError, CodexCredentials, CodexModel+from .contracts import (+ CatalogSnapshot,+ CodexAuthError,+ CodexCredentials,+ CodexModel,+ normalize_codex_reasoning_levels,+)from .storage import CodexCredentialStore@@ -107,12 +113,7 @@ def _reasoning_levels(value: object, *, model_slug: str) -> tuple[str, ...]:if isinstance(effort, str) and effort and effort not in efforts:efforts.append(effort)- # The Codex catalog can lag the Luna API contract: ``none`` is accepted by- # the provider even when omitted here. Remove this compatibility entry once- # the catalog advertises it consistently.- if model_slug == "gpt-5.6-luna" and "none" not in efforts:- efforts.insert(0, "none")- return tuple(efforts)+ return normalize_codex_reasoning_levels(model_slug, efforts)def _summary_support(raw_model: Mapping[str, Any]) -> bool:diff --git a/deeptutor/services/codex_auth/contracts.py b/deeptutor/services/codex_auth/contracts.pyindex 754b7180b..75f2944bc 100644--- a/deeptutor/services/codex_auth/contracts.py+++ b/deeptutor/services/codex_auth/contracts.py@@ -3,7 +3,7 @@from __future__ import annotationsimport base64-from collections.abc import Mapping+from collections.abc import Iterable, Mappingfrom dataclasses import dataclass, fieldimport jsonfrom typing import Any, Literal@@ -11,6 +11,17 @@ from typing import Any, LiteralCatalogSource = Literal["live", "fresh-cache", "revalidated-cache", "stale-cache"]+def normalize_codex_reasoning_levels(+ model_slug: str,+ levels: Iterable[str],+) -> tuple[str, ...]:+ """Apply the provider compatibility contract to live and stored catalogs."""+ normalized = tuple(dict.fromkeys(level for level in levels if level))+ if model_slug == "gpt-5.6-luna" and "none" not in normalized:+ return ("none", *normalized)+ return normalized++class CodexAuthError(RuntimeError):"""An OAuth error whose string form is safe to expose to a user."""@@ -149,8 +160,9 @@ class CodexModel:reasoning_levels = payload["supported_reasoning_levels"]if not isinstance(reasoning_levels, list):raise TypeError+ slug = str(payload["slug"])return cls(- slug=str(payload["slug"]),+ slug=slug,display_name=str(payload["display_name"]),priority=int(payload["priority"]),visibility=str(payload["visibility"]),@@ -159,7 +171,10 @@ class CodexModel:if payload.get("default_reasoning_level") is not Noneelse None),- supported_reasoning_levels=tuple(str(item) for item in reasoning_levels),+ supported_reasoning_levels=normalize_codex_reasoning_levels(+ slug,+ (str(item) for item in reasoning_levels),+ ),supports_reasoning_summary=bool(payload["supports_reasoning_summary"]),supports_parallel_tool_calls=bool(payload["supports_parallel_tool_calls"]),use_responses_lite=bool(payload["use_responses_lite"]),diff --git a/deeptutor/services/codex_auth/service.py b/deeptutor/services/codex_auth/service.pyindex 1555a905b..d285c5e04 100644--- a/deeptutor/services/codex_auth/service.py+++ b/deeptutor/services/codex_auth/service.py@@ -33,6 +33,7 @@ from .contracts import (CodexModel,CodexToken,decode_codex_jwt,+ normalize_codex_reasoning_levels,)from .oauth import (CodexOAuthClient,@@ -171,6 +172,17 @@ def _reasoning_efforts(profile: Mapping[str, Any]) -> dict[str, str]:return overrides+def _managed_reasoning_levels(model: Mapping[str, Any]) -> list[str]:+ slug = model.get("model")+ supported = model.get("codex_supported_reasoning_levels")+ levels = (+ (level for level in supported if isinstance(level, str))+ if isinstance(supported, list)+ else ()+ )+ return list(normalize_codex_reasoning_levels(slug if isinstance(slug, str) else "", levels))++def reconcile_codex_catalog_update(current_catalog: Mapping[str, Any],proposed_catalog: Mapping[str, Any],@@ -227,9 +239,10 @@ def reconcile_codex_catalog_update(continuemodel.pop("reasoning_effort", None)slug = model.get("model")- supported = model.get("codex_supported_reasoning_levels")+ supported = _managed_reasoning_levels(model)+ model["codex_supported_reasoning_levels"] = supportedeffort = requested.get(slug) if isinstance(slug, str) else None- if isinstance(supported, list) and effort in supported:+ if effort in supported:model["reasoning_effort"] = effortinsert_at = proposed_indexes[0] if proposed_indexes else current_indexes[0]@@ -769,15 +782,14 @@ class CodexOAuthService:for model in profile.get("models", []):if not isinstance(model, dict) or model.get("model") != model_slug:continue- supported = model.get("codex_supported_reasoning_levels")- if reasoning_effort is not None and (- not isinstance(supported, list) or reasoning_effort not in supported- ):+ supported = _managed_reasoning_levels(model)+ if reasoning_effort is not None and reasoning_effort not in supported:raise CodexAuthError("reasoning_effort_unsupported","The selected Codex model does not support that reasoning effort.",422,)+ model["codex_supported_reasoning_levels"] = supportedif reasoning_effort is None:model.pop("reasoning_effort", None)else:@@ -907,12 +919,7 @@ class CodexOAuthService:if not isinstance(slug, str) or not slug:continuename = model.get("name")- supported = model.get("codex_supported_reasoning_levels")- levels = (- [level for level in supported if isinstance(level, str)]- if isinstance(supported, list)- else []- )+ levels = _managed_reasoning_levels(model)effort = model.get("reasoning_effort")result.append({diff --git a/tests/services/codex_auth/test_contracts.py b/tests/services/codex_auth/test_contracts.pyindex 913ad613a..8ad98f492 100644--- a/tests/services/codex_auth/test_contracts.py+++ b/tests/services/codex_auth/test_contracts.py@@ -192,3 +192,14 @@ def test_codex_model_accepts_cache_without_context_windows() -> None:assert restored.context_window is Noneassert restored.max_context_window is None+++def test_codex_model_normalizes_legacy_luna_reasoning_cache() -> None:+ payload = _model().to_dict()+ payload["slug"] = "gpt-5.6-luna"+ payload["display_name"] = "GPT-5.6-Luna"+ payload["supported_reasoning_levels"] = ["low", "medium"]++ restored = CodexModel.from_dict(payload)++ assert restored.supported_reasoning_levels == ("none", "low", "medium")diff --git a/tests/services/codex_auth/test_service.py b/tests/services/codex_auth/test_service.pyindex 1086f3e86..bc8824ac0 100644--- a/tests/services/codex_auth/test_service.py+++ b/tests/services/codex_auth/test_service.py@@ -790,6 +790,35 @@ async def test_owner_persists_none_for_managed_luna(tmp_path: Path) -> None:assert resolve_llm_runtime_config(catalog=model_catalog.load()).reasoning_effort == "none"+async def test_owner_persists_none_for_managed_luna_with_legacy_profile(+ tmp_path: Path,+) -> None:+ snapshot = _snapshot(+ "live",+ _model("gpt-5.6-luna", supported_reasoning_levels=("none", "low")),+ )+ service, model_catalog = _bound_reasoning_service(tmp_path, snapshot)+ synced = model_catalog.load()+ synced["services"]["llm"]["active_profile_id"] = CODEX_PROFILE_ID+ synced["services"]["llm"]["active_model_id"] = codex_model_id("gpt-5.6-luna")+ legacy_model = _managed_profile(synced)["models"][0]+ legacy_model["codex_supported_reasoning_levels"] = ["low"]+ model_catalog.save(synced)++ assert service.public_status()["models"][0]["supported_reasoning_levels"] == [+ "none",+ "low",+ ]++ status = await service.set_reasoning_effort("gpt-5.6-luna", "none")++ model = _managed_profile(model_catalog.load())["models"][0]+ assert model["codex_supported_reasoning_levels"] == ["none", "low"]+ assert model["reasoning_effort"] == "none"+ assert status["models"][0]["reasoning_effort"] == "none"++@pytest.mark.asyncioasync def test_runtime_validation_accepts_any_effort_for_a_bound_model(tmp_path: Path) -> None:"""Effort is a per-request knob, not part of what binds a config to a token.