Official Codebase of 3DCodeVerse
Python
models: constructor knobs nobody passes, a restated budget helper, a json mode only a test used
gaoypenga79d1e2f513d
diff --git a/eval/bench/concurrency_probe.py b/eval/bench/concurrency_probe.pyindex d46d69a7..efcaded2 100644--- a/eval/bench/concurrency_probe.py+++ b/eval/bench/concurrency_probe.py@@ -116,8 +116,8 @@ def run_level(pool = KeyPool(keys, rpm_per_key=rpm_per_key, tpm_per_key=tpm_per_key)gate = StormGate(f"probe:{model}:c{level}") if storm_gate else Nonem = GeminiModel(model, pool=pool)- # assign directly: passing storm_gate=None to the constructor means "use the- # process-wide gate", and this probe has to be able to switch it off entirely+ # assign directly: the constructor takes the process-wide gate (Settings.rate.storm_gate)+ # and has no parameter for it, and this probe has to be able to switch it off entirelym.storm_gate = gatebody = filler(in_tokens)gauge = _Gauge()diff --git a/harness/codeverse3d/models/anthropic.py b/harness/codeverse3d/models/anthropic.pyindex c43d5867..f7f3a41a 100644--- a/harness/codeverse3d/models/anthropic.py+++ b/harness/codeverse3d/models/anthropic.py@@ -36,7 +36,7 @@ from codeverse3d.models.parts import (with_logged_retries,)from codeverse3d.models.pricing import cache_write_surcharge, estimate_cost-from codeverse3d.models.retry import MAX_WAIT_S, cause_for+from codeverse3d.models.retry import cause_forfrom codeverse3d.models.schema_utils import (JsonParseError,parse_json_lenient,@@ -120,10 +120,9 @@ def submit_tool(schema: dict[str, Any]) -> dict[str, Any]:# ------------------------------------------------------------------- request-def build_kwargs(request: ChatRequest, model: str, *, json_mode: str = "tool") -> dict[str, Any]:- """Build ``client.messages.create(**kwargs)`` (without ``model``/``timeout``).- ``json_mode``: ``"tool"`` forces a ``submit`` tool; ``"output_config"`` uses- ``output_config.format`` json_schema."""+def build_kwargs(request: ChatRequest, model: str) -> dict[str, Any]:+ """Build ``client.messages.create(**kwargs)`` (without ``model``/``timeout``); a+ response schema becomes a forced ``submit`` tool."""kw: dict[str, Any] = {"messages": to_messages(request.messages),"max_tokens": request.max_output_tokens,@@ -148,21 +147,15 @@ def build_kwargs(request: ChatRequest, model: str, *, json_mode: str = "tool") -kw["temperature"] = request.temperatureif request.response_schema is not None:- if json_mode == "output_config":- kw.setdefault("output_config", {})["format"] = {- "type": "json_schema",- "schema": to_anthropic_schema(request.response_schema),- }+ kw["tools"] = [submit_tool(request.response_schema)]+ if not thinking_on:+ kw["tool_choice"] = {"type": "tool", "name": SUBMIT_TOOL}else:- kw["tools"] = [submit_tool(request.response_schema)]- if not thinking_on:- kw["tool_choice"] = {"type": "tool", "name": SUBMIT_TOOL}- else:- # forced tool_choice is incompatible with thinking; nudge instead- system = (- (system + "\n\n" if system else "")- + f"When you have the final answer, call the `{SUBMIT_TOOL}` tool exactly once with the complete JSON object."- )+ # forced tool_choice is incompatible with thinking; nudge instead+ system = (+ (system + "\n\n" if system else "")+ + f"When you have the final answer, call the `{SUBMIT_TOOL}` tool exactly once with the complete JSON object."+ )if system:kw["system"] = systemreturn kw@@ -206,24 +199,16 @@ class AnthropicModel:self,model: str,*,- api_key: str | None = None,timeout_s: float = 600.0,max_attempts: int = 6,- base_delay: float = 1.0,- max_delay: float = MAX_WAIT_S,- json_mode: str = "tool",sleep: Callable[[float], None] = time.sleep,client: Any | None = None,) -> None:self.model = modelself.timeout_s = timeout_sself.max_attempts = max(1, max_attempts)- self.base_delay = base_delay- self.max_delay = max_delay- self.json_mode = json_modeself._sleep = sleepself._client = client- self._api_key = api_keyself._lock = threading.Lock()@property@@ -238,7 +223,7 @@ class AnthropicModel:from codeverse3d.config import get_settings- key = self._api_key or get_settings().anthropic_api_key+ key = get_settings().anthropic_api_keyif not key:raise ModelError("ANTHROPIC_API_KEY is not configured")self._client = anthropic.Anthropic(@@ -248,7 +233,7 @@ class AnthropicModel:# -------------------------------------------------------------- generatedef generate(self, request: ChatRequest) -> ChatResponse:- kwargs = build_kwargs(request, self.model, json_mode=self.json_mode)+ kwargs = build_kwargs(request, self.model)deadline = time.monotonic() + retry_budget_s(request.max_wait_s)def attempt() -> ChatResponse:@@ -258,10 +243,8 @@ class AnthropicModel:err = classify_exception(exc)raise err from cause_for(err, exc)- return with_logged_retries(attempt, label="anthropic", model=self.model,- attempts=self.max_attempts, base_delay=self.base_delay,- max_delay=self.max_delay, sleep=self._sleep, log=log,- max_wait_s=request.max_wait_s)+ return with_logged_retries(attempt, label="anthropic", model=self.model, attempts=self.max_attempts,+ sleep=self._sleep, log=log, max_wait_s=request.max_wait_s)def _once(self, kwargs: dict[str, Any], request: ChatRequest, deadline: float) -> ChatResponse:client = self.client()diff --git a/harness/codeverse3d/models/gemini.py b/harness/codeverse3d/models/gemini.pyindex bfb5e03d..d180aeb8 100644--- a/harness/codeverse3d/models/gemini.py+++ b/harness/codeverse3d/models/gemini.py@@ -37,16 +37,13 @@ from codeverse3d.contracts.chat import ()from codeverse3d.contracts.common import Usagefrom codeverse3d.models.base import ModelError-from codeverse3d.models.parts import Stopwatch, image_bytes+from codeverse3d.models.parts import Stopwatch, attempt_timeout_s, image_bytes, retry_budget_sfrom codeverse3d.models.pricing import estimate_cost, per_image_usdfrom codeverse3d.models.retry import (- MAX_WAIT_S,- RETRY_DEADLINE_S,KeyPool,KeyPoolExhausted,OnAttempt,Outcome,- StormGate,_Try,request_tokens,rotate_with_retries,@@ -199,15 +196,6 @@ log = logging.getLogger(__name__)_RETRY_DELAY_RE = re.compile(r"retryDelay['\"]?\s*:\s*['\"]?(\d+(?:\.\d+)?)s")-#: floor of the per-attempt HTTP read timeout derived from the remaining retry-#: budget (``ChatRequest.max_wait_s``): a call that starts near its deadline still-#: gets ONE real attempt instead of an instant socket timeout. 20 s matches the-#: judge's own floor (``judges.vlm_judge.SAMPLE_MIN_WAIT_S`` = 20 s), so an in-flight-#: attempt may overshoot the deadline by at most this floor — never by the full-#: ``timeout_s`` read timeout, which was the dominant overshoot (audit 2026-08-27,-#: when that ceiling was 300 s).-HTTP_TIMEOUT_FLOOR_S = 20.0-#: ceiling of the per-READ (inter-chunk) HTTP timeout under streaming. Five runs#: died tonight (drill/vise/clamp x2, one plan hang) because a hung NON-streaming#: read holds the socket for the whole attempt budget — up to model_timeout_s@@ -443,11 +431,6 @@ class GeminiModel:pool: KeyPool | None = None,timeout_s: float | None = None,max_attempts: int = 6,- base_delay: float = 1.0,- max_delay: float = MAX_WAIT_S,- rpm_per_key: int | None = None,- tpm_per_key: int | None = None,- storm_gate: StormGate | None = None,storm_attempts: int | None = None,hedge: int | None = None,sleep: Callable[[float], None] = time.sleep,@@ -462,14 +445,10 @@ class GeminiModel:#: 2; 1 = off) — see ``rotate_with_retries`` and docs/COST.md §27self.hedge = max(1, int(_rate().hedge if hedge is None else hedge))keys = _keys_or_raise(keys, pool)- self.pool = pool or shared_pool(keys, rpm_per_key=rpm_per_key, tpm_per_key=tpm_per_key)- self.storm_gate = storm_gate if storm_gate is not None else (- storm_gate_for(f"gemini:{model}") if _rate().storm_gate else None- )+ self.pool = pool or shared_pool(keys)+ self.storm_gate = storm_gate_for(f"gemini:{model}") if _rate().storm_gate else Noneself.timeout_s = _default_timeout_s() if timeout_s is None else timeout_sself.max_attempts = max(1, max_attempts)- self.base_delay = base_delay- self.max_delay = max_delayself._sleep = sleepself._client_factory = client_factoryself._thinking_ok = True # flipped when the model rejects ThinkingConfig@@ -496,8 +475,7 @@ class GeminiModel:state["config"] = self._config(request)return True- # the caller's budget clips the retry deadline, never extends it- budget = RETRY_DEADLINE_S if request.max_wait_s is None else min(RETRY_DEADLINE_S, float(request.max_wait_s))+ budget = retry_budget_s(request.max_wait_s)deadline = time.monotonic() + budget # mirrors rotate_with_retries' own deadlinestats: dict[str, Any] = {}wasted: list[Usage] = [] # discarded round-trips the provider still billed@@ -511,8 +489,6 @@ class GeminiModel:classify=classify_exception,outcome_of=failure_outcome,max_attempts=self.max_attempts,- base_delay=self.base_delay,- max_delay=self.max_delay,max_total_s=budget,hedge=self.hedge,sleep=self._sleep,@@ -550,11 +526,9 @@ class GeminiModel:) -> types.GenerateContentConfig:"""The config for ONE attempt: its HTTP read timeout is the remaining retrybudget, capped at ``self.timeout_s`` and floored at- :data:`HTTP_TIMEOUT_FLOOR_S`. A 20 s-budget turn used to hand the provider+ :data:`parts.SDK_TIMEOUT_FLOOR_S`. A 20 s-budget turn used to hand the providera 300 s socket — the dominant deadline overshoot (audit 2026-08-27)."""- remaining = deadline - time.monotonic()- want_s = min(self.timeout_s, max(HTTP_TIMEOUT_FLOOR_S, remaining))- return clip_timeout(config, int(want_s * 1000))+ return clip_timeout(config, int(attempt_timeout_s(deadline, self.timeout_s) * 1000))def _attempt_hook(self, wasted: list[Usage]) -> OnAttempt:"""Per-round-trip observer. It collects every DISCARDED round-trip that still@@ -707,8 +681,6 @@ class GeminiImageModel:pool: KeyPool | None = None,timeout_s: float = 180.0,max_attempts: int = 4,- base_delay: float = 1.0,- max_delay: float = MAX_WAIT_S,hedge: int = 1,sleep: Callable[[float], None] = time.sleep,client_factory: Callable[[str], Any] | None = None,@@ -723,8 +695,6 @@ class GeminiImageModel:self.storm_gate = storm_gate_for(f"gemini:{model}") if _rate().storm_gate else Noneself.timeout_s = timeout_sself.max_attempts = max(1, max_attempts)- self.base_delay = base_delay- self.max_delay = max_delayself._sleep = sleepself._client_factory = client_factoryself._lock = threading.Lock()@@ -772,8 +742,6 @@ class GeminiImageModel:order = [self.model] if not dead else []if self.fallback:order.append(self.fallback)- if not order:- order = [self.model]return orderdef _one(@@ -816,12 +784,11 @@ class GeminiImageModel:# attempt's HTTP read timeout is the REMAINING budget, floored like# GeminiModel._attempt_config — a 60 s image budget no longer holds a# 180 s socket past its deadline.- budget = RETRY_DEADLINE_S if max_wait_s is None else min(RETRY_DEADLINE_S, float(max_wait_s))+ budget = retry_budget_s(max_wait_s)deadline = time.monotonic() + budgetdef _attempt_config() -> types.GenerateContentConfig:- remaining = max(HTTP_TIMEOUT_FLOOR_S, deadline - time.monotonic())- return clip_timeout(config, int(min(self.timeout_s, remaining) * 1000))+ return clip_timeout(config, int(attempt_timeout_s(deadline, self.timeout_s) * 1000))return rotate_with_retries(self.pool,@@ -829,8 +796,6 @@ class GeminiImageModel:classify=classify_exception,outcome_of=failure_outcome,max_attempts=self.max_attempts,- base_delay=self.base_delay,- max_delay=self.max_delay,max_total_s=budget,hedge=self.hedge,sleep=self._sleep,diff --git a/harness/codeverse3d/models/health.py b/harness/codeverse3d/models/health.pyindex 411817a1..99be9edf 100644--- a/harness/codeverse3d/models/health.py+++ b/harness/codeverse3d/models/health.py@@ -212,7 +212,7 @@ _AB_PLAN = ("ab_plan.py", "bench.ab_plan")def _is_delegating_driver(args: list[str]) -> bool:"""Does this process spend its in-flight budget only through capped CHILDREN?- ``bench/ab_plan.py`` in driver mode spawns one ``… cell`` child per arm and makes no+ ``eval/bench/ab_plan.py`` in driver mode spawns one ``… cell`` child per arm and makes nomodel calls of its own past a 6-key preflight probe; the children carry the caps andare counted in their own right. Charging the driver as well would double-count thesame traffic — and since ``--max-in-flight`` is the cap it hands its children, not onediff --git a/harness/codeverse3d/models/openai.py b/harness/codeverse3d/models/openai.pyindex d507cd71..b443b725 100644--- a/harness/codeverse3d/models/openai.py+++ b/harness/codeverse3d/models/openai.py@@ -31,7 +31,7 @@ from codeverse3d.models.parts import (with_logged_retries,)from codeverse3d.models.pricing import estimate_cost-from codeverse3d.models.retry import MAX_WAIT_S, cause_for+from codeverse3d.models.retry import cause_forfrom codeverse3d.models.schema_utils import (JsonParseError,inline_refs,@@ -161,24 +161,16 @@ class OpenAIModel:self,model: str,*,- api_key: str | None = None,- base_url: str | None = None,timeout_s: float = 600.0,max_attempts: int = 6,- base_delay: float = 1.0,- max_delay: float = MAX_WAIT_S,sleep: Callable[[float], None] = time.sleep,client: Any | None = None,) -> None:self.model = modelself.timeout_s = timeout_sself.max_attempts = max(1, max_attempts)- self.base_delay = base_delay- self.max_delay = max_delayself._sleep = sleepself._client = client- self._api_key = api_key- self._base_url = base_urlself._strict_ok = True # flipped when the endpoint rejects strict schemasself._lock = threading.Lock()@@ -195,8 +187,8 @@ class OpenAIModel:from codeverse3d.config import get_settingss = get_settings()- key = self._api_key or s.openai_api_key- base_url = self._base_url or s.openai_base_url or None+ key = s.openai_api_key+ base_url = s.openai_base_url or Noneif not key and not base_url:raise ModelError("OPENAI_API_KEY is not configured")self._client = openai.OpenAI(@@ -234,10 +226,8 @@ class OpenAIModel:raise err2 from cause_for(err2, exc2)raise err from cause_for(err, exc)- return with_logged_retries(attempt, label="openai", model=self.model,- attempts=self.max_attempts, base_delay=self.base_delay,- max_delay=self.max_delay, sleep=self._sleep, log=log,- max_wait_s=request.max_wait_s)+ return with_logged_retries(attempt, label="openai", model=self.model, attempts=self.max_attempts,+ sleep=self._sleep, log=log, max_wait_s=request.max_wait_s)def _once(self, kwargs: dict[str, Any], request: ChatRequest, deadline: float) -> ChatResponse:client = self.client()diff --git a/harness/codeverse3d/models/parts.py b/harness/codeverse3d/models/parts.pyindex 25f8901b..3ee0793c 100644--- a/harness/codeverse3d/models/parts.py+++ b/harness/codeverse3d/models/parts.py@@ -70,7 +70,7 @@ def classify_sdk_exception(exc: BaseException, sdk: Any, label: str,``.message`` are the same names on both — this ladder was written out twice,differing only in the module, the label and anthropic's extra 529.- The MESSAGE WORDING IS LOAD-BEARING: bench/_infra.py string-matches "request timed+ The MESSAGE WORDING IS LOAD-BEARING: eval/bench/_infra.py string-matches "request timedout" and "connection error" to tell a provider outage from a model failure, so thef"{label} …" forms below must stay byte-identical to what each adapter emitted."""@@ -89,11 +89,11 @@ def classify_sdk_exception(exc: BaseException, sdk: Any, label: str,return ModelError(f"{label} unexpected error: {type(exc).__name__}: {exc}", retryable=False)-#: floor of the per-attempt SDK timeout derived from what is left of the call's-#: ``max_wait_s`` budget: a call that starts near its deadline still gets ONE real-#: attempt instead of an instant timeout. Same 20 s as gemini's ``HTTP_TIMEOUT_FLOOR_S``-#: and the judge's own ``SAMPLE_MIN_WAIT_S``, so an attempt in flight overshoots the-#: deadline by at most this floor.+#: floor of the per-attempt SDK / HTTP read timeout (gemini's too) derived from what is+#: left of the call's ``max_wait_s`` budget: a call that starts near its deadline still gets+#: ONE real attempt instead of an instant timeout. Same 20 s as the judge's own+#: ``SAMPLE_MIN_WAIT_S``, so an attempt in flight overshoots the deadline by at most this+#: floor — never by the full read timeout (audit 2026-08-27, when that ceiling was 300 s).SDK_TIMEOUT_FLOOR_S = 20.0@@ -112,14 +112,13 @@ def attempt_timeout_s(deadline: float, ceiling: float) -> float:built once with a fixed ``timeout`` (600 s), so a judge told it had 20 s of budgetleft held a socket for 600 s (audit 2026-08-29). The floor is what keeps a legitimatelong completion (the 930 s plan budget) on its full ``timeout_s`` — this shortens an- attempt, it never lengthens one. Gemini clips the same way (``_attempt_config``).+ attempt, it never lengthens one. Gemini's ``_attempt_config`` clips through it too."""return min(ceiling, max(SDK_TIMEOUT_FLOOR_S, deadline - time.monotonic()))def with_logged_retries(attempt: Any, *, label: str, model: str, attempts: int,- base_delay: float, max_delay: float, sleep: Any, log: Any,- max_wait_s: float | None = None) -> Any:+ sleep: Any, log: Any, max_wait_s: float | None = None) -> Any:"""``with_retries`` plus the one log line both SDK adapters write.``max_wait_s`` is the request's ``ChatRequest.max_wait_s`` deadline (retries and@@ -134,5 +133,4 @@ def with_logged_retries(attempt: Any, *, label: str, model: str, attempts: int,budget = retry_budget_s(max_wait_s)return with_retries(attempt, is_retryable=lambda e: isinstance(e, ModelError) and e.retryable,- attempts=attempts, base_delay=base_delay, max_delay=max_delay, max_total_s=budget,- on_retry=on_retry, sleep=sleep)+ attempts=attempts, max_total_s=budget, on_retry=on_retry, sleep=sleep)diff --git a/harness/codeverse3d/models/retry.py b/harness/codeverse3d/models/retry.pyindex 5b9f773d..7f2acb95 100644--- a/harness/codeverse3d/models/retry.py+++ b/harness/codeverse3d/models/retry.py@@ -476,10 +476,6 @@ class StormGate:self.parked_s = 0.0# ------------------------------------------------------------------ public- @property- def storming(self) -> bool:- return self._storm-def enter(self, deadline: float | None = None) -> float:"""Block until this thread may issue a call; returns the seconds waited.@@ -500,7 +496,7 @@ class StormGate:elif now >= self._probe_until:# the window elapsed and no probe is in flight: this thread is itself._probe_until = now + self._probe_lease- self._n_probe_hit()+ self.n_probes += 1return now - t0else:wait = min(self._max_wait, self._probe_until - now)@@ -550,10 +546,6 @@ class StormGate:"parked_s": round(self.parked_s, 1),}- # ----------------------------------------------------------------- private- def _n_probe_hit(self) -> None:- self.n_probes += 1-_gates: dict[str, StormGate] = {}_gates_lock = threading.Lock()@@ -610,7 +602,7 @@ def cause_for(err: BaseException, exc: BaseException | None) -> BaseException |unchanged (gemini.py, openai.py, anthropic.py), so ``raise err from exc`` below isoften ``raise e from e``, and CPython's ``raise ... from ...`` does NOT check for acycle the way it does for ``__context__``. The result — ``e.__cause__ is e`` — is a- chain no naive walker survives: on 2026-08-27 it took ``bench/_infra.py`` to a+ chain no naive walker survives: on 2026-08-27 it took ``eval/bench/_infra.py`` to aRecursionError inside ``run_cell``'s except handler and a compare matrix lost 11finished cells. Dropping the self-cause is invisible otherwise: none of theseraises sits inside an ``except`` block, and ``__suppress_context__`` is already set.@@ -1080,11 +1072,6 @@ def _discard_loser(# ===================================================================== tokens-#: longest edge we assume for an image part whose size we do not measure; the-#: harness caps judge payloads at ``Settings.judge.max_px`` = 1024 (docs/COST.md §3)-DEFAULT_IMAGE_PX = 1024--def request_parts(request: ChatRequest) -> tuple[list[str], int]:"""``(text blocks, number of image parts)`` of a request, system prompt andresponse schema included — everything the provider will count as prompt."""@@ -1103,10 +1090,11 @@ def request_parts(request: ChatRequest) -> tuple[list[str], int]:return blocks, images-def request_tokens(request: ChatRequest, *, model_id: str = "", image_px: int = DEFAULT_IMAGE_PX) -> int:- """Estimated **input** tokens of ``request`` (never negative)."""+def request_tokens(request: ChatRequest, *, model_id: str = "") -> int:+ """Estimated **input** tokens of ``request`` (never negative). An image part is+ counted at 1024 px, the judge payload cap ``Settings.judge.max_px`` (docs/COST.md §3)."""from codeverse3d.cost.guard import estimate_callblocks, images = request_parts(request)- est = estimate_call(model_id or "gemini:unknown", prompt=blocks, n_images=images, image_px=image_px)+ est = estimate_call(model_id or "gemini:unknown", prompt=blocks, n_images=images)return max(0, est.input_tokens)diff --git a/harness/docs/INTERFACES.md b/harness/docs/INTERFACES.mdindex c2322db3..df21ac8a 100644--- a/harness/docs/INTERFACES.md+++ b/harness/docs/INTERFACES.md@@ -78,8 +78,8 @@ from codeverse3d.models.schema_utils import ask_structured # (model, Schema, *# -> (obj | None, Usage, err): one schema-bound call; call failure and parse failure are the same `err` family```Backends: `GeminiModel(model, *, keys=None, pool=None, ...)` (one shared KeyPool per-key list), `AnthropicModel(model, *, json_mode="tool"|"output_config")`,-`OpenAIModel(model, *, base_url=None)` (Chat Completions; `C3D_OPENAI_BASE_URL`).+key list), `AnthropicModel(model)` (a response schema is a forced `submit` tool),+`OpenAIModel(model)` (Chat Completions; key and `C3D_OPENAI_BASE_URL` from Settings).Rules that callers must know:* **Δ** Gemini key handling: auth/permission errors (401/403, or 400 withAPI_KEY_INVALID / expired / PERMISSION_DENIED / suspended markers) classify asdiff --git a/harness/tests/models/test_anthropic.py b/harness/tests/models/test_anthropic.pyindex 6ee8c95d..9fdd0f16 100644--- a/harness/tests/models/test_anthropic.py+++ b/harness/tests/models/test_anthropic.py@@ -163,15 +163,6 @@ def test_structured_output_with_thinking_uses_auto_and_text_fallback():assert "tool_choice" not in kw and "submit" in kw["system"]-def test_output_config_json_mode():- m, fc = make([msg([text('{"c": 3}')])], json_mode="output_config")- r = m.generate(- ChatRequest(messages=[ChatMessage.user("x")], response_schema={"type": "object"})- )- assert r.parsed == {"c": 3}- assert fc.calls[0]["output_config"]["format"]["type"] == "json_schema"--def test_images_base64_and_message_merging():msgs = to_messages([diff --git a/harness/tests/models/test_gemini_scheduling.py b/harness/tests/models/test_gemini_scheduling.pyindex d06c4fc5..2a416601 100644--- a/harness/tests/models/test_gemini_scheduling.py+++ b/harness/tests/models/test_gemini_scheduling.py@@ -104,7 +104,7 @@ def test_a_503_closes_the_shared_gate_and_the_call_still_succeeds():r = m.generate(ChatRequest(messages=[ChatMessage.user("hi")]))assert r.text == "ok"assert gate.n_hits == 1 and gate.n_storms == 1- assert not gate.storming, "the success must reopen the gate"+ assert not gate.snapshot()["storming"], "the success must reopen the gate"def test_rate_settings_control_the_shared_gate_and_hedge(monkeypatch):@@ -183,7 +183,7 @@ def test_a_clean_call_reports_one_attempt_and_a_failed_call_carries_its_count():# ------------------------------------------ per-attempt HTTP timeout (audit 2026-08-27)def test_retry_budget_bounds_http_timeout_without_raising_an_explicit_ceiling():- from codeverse3d.models.gemini import HTTP_TIMEOUT_FLOOR_S+ from codeverse3d.models.parts import SDK_TIMEOUT_FLOOR_Sm, log, _ = make_model([text_response("a"), text_response("b"), text_response("c")], timeout_s=300.0@@ -195,7 +195,7 @@ def test_retry_budget_bounds_http_timeout_without_raising_an_explicit_ceiling():m.generate(ChatRequest(messages=[ChatMessage.user("x")], max_wait_s=60))assert 55_000 <= log[1]["config"].http_options.timeout <= 60_000m.generate(ChatRequest(messages=[ChatMessage.user("x")], max_wait_s=5))- assert log[2]["config"].http_options.timeout == int(HTTP_TIMEOUT_FLOOR_S * 1000)+ assert log[2]["config"].http_options.timeout == int(SDK_TIMEOUT_FLOOR_S * 1000)small, small_log, _ = make_model([text_response("d")], timeout_s=8.0)small.generate(ChatRequest(messages=[ChatMessage.user("x")], max_wait_s=5))assert small_log[0]["config"].http_options.timeout == 8_000diff --git a/harness/tests/models/test_retry.py b/harness/tests/models/test_retry.pyindex c7d1b152..6e269565 100644--- a/harness/tests/models/test_retry.py+++ b/harness/tests/models/test_retry.py@@ -10,7 +10,7 @@ import pytestfrom codeverse3d.contracts.common import Usagefrom codeverse3d.models.base import ModelError-from codeverse3d.models.gemini import HTTP_TIMEOUT_FLOOR_S+from codeverse3d.models.parts import SDK_TIMEOUT_FLOOR_Sfrom codeverse3d.models.retry import (ACQUIRE_TIMEOUT_S,MAX_WAIT_S,@@ -343,8 +343,8 @@ def test_one_call_cannot_retry_for_hours():clock = Clock()def call(_key):- # gemini.py _attempt_config: min(300 s, remaining), floored at HTTP_TIMEOUT_FLOOR_S- clock.t += min(300.0, max(HTTP_TIMEOUT_FLOOR_S, RETRY_DEADLINE_S - clock.t))+ # gemini.py _attempt_config: min(300 s, remaining), floored at SDK_TIMEOUT_FLOOR_S+ clock.t += min(300.0, max(SDK_TIMEOUT_FLOOR_S, RETRY_DEADLINE_S - clock.t))raise RuntimeError("503 high demand")with pytest.raises(ModelError):@@ -360,7 +360,7 @@ def test_one_call_cannot_retry_for_hours():)# bounded by the clock: the ONLY legal overshoot is the one floored attempt that was# already in flight when the deadline passed- assert clock.t <= RETRY_DEADLINE_S + HTTP_TIMEOUT_FLOOR_S, (+ assert clock.t <= RETRY_DEADLINE_S + SDK_TIMEOUT_FLOOR_S, (f"one call burned {clock.t / 3600:.2f} h; the deadline is {RETRY_DEADLINE_S / 60:.0f} min")assert clock.t < 5 * 3600, "this is the 5.1-hour regression"@@ -419,7 +419,7 @@ def test_503_rotates_through_every_untried_key_before_it_is_a_storm():# one key per round-trip, never twice: 9 free rotations, then the 10th key landsassert out == "ok" and len(calls) == len(keys) and set(calls) == set(keys)assert naps == [], "rotation to a fresh key costs no sleep"- assert gate.n_storms == 0 and not gate.storming, "an untried key remains: not a storm"+ assert gate.n_storms == 0 and not gate.snapshot()["storming"], "an untried key remains: not a storm"@pytest.mark.parametrize(diff --git a/harness/tests/models/test_storm.py b/harness/tests/models/test_storm.pyindex d98209bd..fb36beeb 100644--- a/harness/tests/models/test_storm.py+++ b/harness/tests/models/test_storm.py@@ -31,7 +31,7 @@ def test_a_hit_closes_the_gate_and_the_next_worker_parks():gate, clock = make(base_delay=4.0)closed = gate.hit()assert closed == min(4.0, MAX_WAIT_S) # the house cap clips the gate's own delay- assert gate.storming+ assert gate.snapshot()["storming"]waited = gate.enter()assert waited >= closedassert gate.parked_s >= closed@@ -75,7 +75,7 @@ def test_a_success_reopens_the_gate_for_everybody():gate, clock = make(base_delay=4.0)gate.hit()gate.ok()- assert not gate.storming+ assert not gate.snapshot()["storming"]assert gate.enter() == 0.0assert clock.t == 100.0@@ -142,4 +142,4 @@ def test_enter_returns_at_the_deadline_even_mid_storm():gate.hit()waited = gate.enter(deadline=clock.t + 1.5)assert waited == pytest.approx(1.5)- assert gate.storming, "the storm is still on; only this caller's budget ended"+ assert gate.snapshot()["storming"], "the storm is still on; only this caller's budget ended"