Official Codebase of 3DCodeVerse
Python
compare_backends: one outage, two verdicts — the one-shot arm took a hard zero
gaoypeng25ea7027ae9e
diff --git a/harness/bench/_compare_report.py b/harness/bench/_compare_report.pyindex fe05a618..bb470ef9 100644--- a/harness/bench/_compare_report.py+++ b/harness/bench/_compare_report.py@@ -52,6 +52,10 @@ class CellResult(BaseModel):glb: str = ""workspace: str = ""error: str = ""+ error_is_infra: bool = Field(default=False, description=(+ "set at the raise site, where the exception still carries .status/.__cause__. "+ "run_cell's string fallback cannot recover those, so without this the one-shot "+ "arm scored 0.0 for the same outage that dropped the harness arm."))def natural_key(self) -> tuple[str, ...]:"""Row identity: one cell is one (prompt, arm). results.jsonl is append-only, sodiff --git a/harness/bench/_infra.py b/harness/bench/_infra.pyindex 2853ee00..68c09572 100644--- a/harness/bench/_infra.py+++ b/harness/bench/_infra.py@@ -32,6 +32,11 @@ INFRA_MARKERS: tuple[str, ...] = ("deadline exceeded","connection reset","connection aborted",+ # the provider adapters' own wording for a socket/TLS failure with no HTTP status:+ # ModelError("Gemini transport error: ..."), ("Anthropic connection error: ...") and+ # ("OpenAI connection error: ...") matched nothing here, so BOTH arms scored them 0.+ "transport error",+ "connection error","remote end closed connection","keypoolexhausted","resource has been exhausted",@@ -40,7 +45,10 @@ INFRA_MARKERS: tuple[str, ...] = ()#: HTTP statuses that mean "the provider could not serve this", not "the model was bad".-INFRA_STATUSES: frozenset[int] = frozenset({429, 500, 502, 503, 504, 529})+#: 408 is the adapters' own code for a request timeout (gemini.py:117, openai.py:40,+#: anthropic.py:43) — the exception path must agree with the "request timed out" marker+#: the string path already had.+INFRA_STATUSES: frozenset[int] = frozenset({408, 429, 500, 502, 503, 504, 529})def is_infra_failure(err: object) -> bool:diff --git a/harness/bench/_oneshot.py b/harness/bench/_oneshot.pyindex fed279a8..ad6faede 100644--- a/harness/bench/_oneshot.py+++ b/harness/bench/_oneshot.py@@ -33,6 +33,7 @@ from typing import Any, Protocolfrom pydantic import BaseModel, Field+from bench._infra import is_infra_failurefrom codeverse.agents.claude_code import parse_claude_json, usage_from_envelopefrom codeverse.agents.cli_common import is_secret_env, tailfrom codeverse.agents.codex import effort_overrides, parse_codex_jsonl, split_model_effort@@ -111,6 +112,11 @@ class OneShotResult(BaseModel):usage: Usage = Field(default_factory=Usage)tool_calls: int = Field(default=0, description="tool/command calls the CLI reported (should be 0)")notes: str = ""+ infra_failed: bool = Field(default=False, description=(+ "the provider, not the model, failed. Decided at the raise site because only "+ "there does the exception still carry .status and .__cause__: stringifying it "+ "into `notes` first threw both away, so the one-shot arm scored a hard 0.0 for "+ "the same outage that dropped the harness arm (see bench/_infra.py)."))duration_s: float = 0.0transcript_dir: str = ""@@ -305,8 +311,8 @@ class ApiOneShot:try:resp = self.model.generate(req)except Exception as e: # noqa: BLE001 — a model outage is a recorded failure, not a crash- return OneShotResult(ok=False, notes=f"{type(e).__name__}: {e}", duration_s=round(time.time() - t0, 2),- transcript_dir=str(out_dir))+ return OneShotResult(ok=False, notes=f"{type(e).__name__}: {e}", infra_failed=is_infra_failure(e),+ duration_s=round(time.time() - t0, 2), transcript_dir=str(out_dir))text = resp.text or ""(out_dir / "response.md").write_text(text)return OneShotResult(ok=bool(text.strip()), text=text, usage=resp.usage, duration_s=round(time.time() - t0, 2),diff --git a/harness/bench/compare_backends.py b/harness/bench/compare_backends.pyindex 18129b24..416fe54a 100644--- a/harness/bench/compare_backends.py+++ b/harness/bench/compare_backends.py@@ -192,6 +192,7 @@ def _generate_oneshot(arm: Arm, spec: Spec, cell: Path, eval_ws: Workspace, optsres.gen_seconds += gen.duration_sif not gen.ok:res.error = gen.notes or "empty answer"+ res.error_is_infra = gen.infra_failedreturntry:write_model_file(eval_ws, gen.text)@@ -254,7 +255,7 @@ def run_cell(battery: Battery, item: BenchPrompt, arm: Arm, out: Path, opts: Com# nothing was ever built, so there is no score to average — but the arm# DID fail to deliver, so this still counts against its build rateres.status, res.score, res.passed, res.build_ok = "budget_exhausted", None, False, False- elif is_infra_failure(res.error):+ elif res.error_is_infra or is_infra_failure(res.error):# a provider outage is not a capability result: drop the cell (score# None) instead of scoring the model 0 for someone else's downtimeres.status, res.score, res.passed, res.build_ok = "infra_failed", None, None, Falsediff --git a/harness/tests/compare_bench/test_infra_failures.py b/harness/tests/compare_bench/test_infra_failures.pyindex 6d38065f..243e91c5 100644--- a/harness/tests/compare_bench/test_infra_failures.py+++ b/harness/tests/compare_bench/test_infra_failures.py@@ -72,15 +72,75 @@ def test_outage_cells_leave_every_rate_alone():assert b.infra_failed == 1 and b.n_evaluated == 4 and b.n == 5, "the loss must stay visible"-def test_both_failure_paths_classify_the_same_way():- """The asymmetry itself: whichever path records the outage, the verdict matches."""- from bench import compare_backends as cb-- src = cb.run_cell.__code__.co_consts- assert any(c == "infra_failed" for c in src if isinstance(c, str)), \- "the no-code path must be able to record infra_failed"- outage = "Gemini API error 503: This model is currently experiencing high demand."- assert is_infra_failure(outage) == is_infra_failure(RuntimeError(outage))+def test_both_failure_paths_classify_the_same_way(tmp_path):+ """CQ-1, the asymmetry itself: ONE error hits both arms, both must reach one verdict.++ The previous version of this test could not fail — it grepped run_cell's code+ constants for the literal "infra_failed" and then compared a single 503 string that+ DOES contain one of the 14 INFRA_MARKERS. It therefore passed straight through the+ real bug: gemini's actual 500 prose ("An internal error has occurred") matches no+ marker, and bench/_oneshot.py stringified the exception into `notes`, throwing away+ the .status the harness path classifies on. Same outage, harness dropped+ (infra_failed / score None), one-shot scored a hard 0.0 — biasing every+ harness-vs-one-shot mean in the harness's favour, which is precisely what this+ module was written to end.+ """+ import tempfile+ from pathlib import Path++ from bench._oneshot import ApiOneShot+ from bench.compare_backends import CompareDeps, CompareOptions, parse_arm, run_cell+ from bench.run_bench import Battery+ from codeverse.models.base import ModelError+ from tests.compare_bench.conftest import BATTERY, FakeEvaluator++ for outage in (+ ModelError("Gemini API error 500: An internal error has occurred.", retryable=True, status=500),+ ModelError("Gemini transport error: [Errno 104] Connection reset by peer", retryable=True),+ ModelError("Anthropic connection error: TLS handshake failed", retryable=True),+ ModelError("Gemini request timed out: 600s", retryable=True, status=408),+ ):+ class DeadModel: # the real ApiOneShot around a model that raises the outage+ provider, model = "gemini", "gemini-3.7-flash"++ def supports_vision(self):+ return True++ def generate(self, request):+ raise outage++ def dying_track(spec, ws, resume):+ raise outage++ battery = Battery.load(BATTERY)+ deps = CompareDeps(FakeEvaluator(), run_track=dying_track,+ oneshot_backend=lambda t: ApiOneShot("gemini:gemini-3.7-flash", chat_model=DeadModel()))+ opts = CompareOptions(judge="gemini:x", loop_judge="gemini:x")+ out = Path(tempfile.mkdtemp(dir=tmp_path))+ got = {}+ for raw in ("harness:api-agent:gemini:gemini-3.7-flash", "oneshot:gemini:gemini-3.7-flash"):+ arm = parse_arm(raw)+ r = run_cell(battery, battery.prompts[0], arm, out, opts, deps)+ got[arm.kind] = (r.status, r.score)+ assert got["harness"] == ("infra_failed", None), f"{outage} / harness -> {got}"+ assert got["oneshot"] == got["harness"], (+ f"one error, two verdicts for {outage!s}: {got} — the one-shot arm takes a hard "+ f"zero for the same downtime that drops the harness arm")+++def test_a_real_capability_failure_still_keeps_its_zero():+ """The other half of the contract: widening the classifier must not start excusing+ models. Prose, unparseable code and a refusal are results, not outages."""+ from codeverse.models.base import ModelError++ for not_an_outage in (+ "unparseable answer: no code fence found",+ ModelError("Gemini finish_reason=SAFETY", retryable=True),+ ModelError("Gemini returned no candidates", retryable=True),+ ModelError("Anthropic refused the request: None", retryable=False),+ "empty answer",+ ):+ assert not is_infra_failure(not_an_outage), not_an_outagedef test_budget_exhaustion_is_scoreless_but_still_counts_against_build_rate():