Official Codebase of 3DCodeVerse
Python
bench one-shot: its CLI end is read by the harness's claude_end/codex_end; why it stays off AgentJob and llm.extract is written down
gaoypeng03a58daeb497
diff --git a/eval/bench/_oneshot.py b/eval/bench/_oneshot.pyindex 284945eb..0459ac19 100644--- a/eval/bench/_oneshot.py+++ b/eval/bench/_oneshot.py@@ -22,6 +22,25 @@ Every call runs in a scratch directory *outside* the repository so the CLIscannot pick up CLAUDE.md / AGENTS.md context, and with secrets stripped from theenvironment (``cli_common.clean_env``: no git ceiling — it runs outside any repo),keeping only the CLI's own auth variable.++Why the CLI one-shots are NOT an ``AgentJob`` through ``codeverse3d.agents`` (owner, 2026-09-24,+N82b): that route was taken only if the argv and the prompt stayed byte-identical, and they cannot.+The harness sessions pass the prompt on stdin, allow a tool list (``--allowedTools`` /+``--dangerously-skip-permissions``, codex ``--sandbox workspace-write`` + skill and MCP overrides)+and run in a Workspace; the one-shot passes ``-p <prompt>`` with ``--tools "" --max-turns 1``, runs+codex ``--sandbox read-only -o <last message>``, in an empty scratch dir. Moving them changes the+one-shot arm itself, and its recorded history would stop being comparable. So only the READING is+shared: usage from ``ClaudeStream`` / ``CodexEvents.estimated_usage`` (N82a) and the provider verdict+from ``claude_end`` / ``codex_end`` — the harness's own end rule (N76).++Why the answer is read by :func:`extract_model_file` and not ``eval/llm/extract.py`` (N86): the two+answer different questions and each keeps its own history comparable. ``llm.extract`` is the+finetune/paper extractor (scored candidates, think blocks, the LAST good block), copied so the bare-LLM+numbers stay comparable with the paper's; this one is ``parse_multifile`` — the parser the harness+reads a single-shot answer with — so the one-shot arm is read the way the harness reads its own.+They disagree on some answers (a "variant" second block; unfenced code after a prose line), so a+model's one-shot number is not portable between the two stacks. Revisit only if the one-shot+``no_code`` rate matters."""from __future__ import annotations@@ -39,6 +58,8 @@ from bench._infra import is_infra_failurefrom codeverse3d.agents.backends import (CLAUDE_SETTING_SOURCES,ClaudeStream,+ claude_end,+ codex_end,effort_overrides,parse_claude_json,parse_codex_jsonl,@@ -415,8 +436,12 @@ class ClaudeOneShot:elif env.get("is_error"):notes = f"claude is_error subtype={env.get('subtype', '')}: {text[-400:]}"ok = False+ # the provider's failure, by the harness's own reading of the same stream (N76): a 529 or a spent+ # usage limit drops the cell instead of scoring the arm 0 for someone else's outage+ end = claude_end(proc, env, stream, text)(out_dir / "response.md").write_text(text)return OneShotResult(ok=ok, text=text, usage=usage, tool_calls=usage.tool_calls, notes=notes,+ infra_failed=not ok and (end.transient or end.quota),duration_s=round(proc.duration_s, 2), transcript_dir=str(out_dir))@@ -473,8 +498,10 @@ class CodexOneShot:elif proc.rc != 0 or events.n_events == 0:notes = f"rc={proc.rc}; events={events.n_events}; stderr: {proc.stderr[-800:]}"ok = ok and events.n_events > 0+ end = codex_end(proc, events, text) # the provider's failure, read as the harness reads it (N76)(out_dir / "response.md").write_text(text)return OneShotResult(ok=ok, text=text, usage=usage, tool_calls=events.tool_calls, notes=notes,+ infra_failed=not ok and (end.transient or end.quota),duration_s=round(proc.duration_s, 2), transcript_dir=str(out_dir))diff --git a/eval/llm/extract.py b/eval/llm/extract.pyindex 514a2444..515e5e81 100644--- a/eval/llm/extract.py+++ b/eval/llm/extract.py@@ -20,6 +20,11 @@ extract(text, dialect) -> (code, meta)* ties are broken toward the LAST high-scoring block (models put the final program last), then length.meta keys: n_blocks, chosen, score, lang, had_think, think_chars, from_think, no_fence, valid, markers.++Not shared with the bench one-shot arm (``eval/bench/_oneshot.extract_model_file``, which reads an+answer with the harness's own ``parse_multifile``): owner, 2026-09-24 (N86) — each extractor keeps its+own history comparable (this one the paper's, that one the one-shot arm's). They score some answers+differently; the reasons are in ``bench/_oneshot.py``'s module docstring."""import astimport jsondiff --git a/eval/tests/test_oneshot.py b/eval/tests/test_oneshot.pyindex 32eb127d..26de3746 100644--- a/eval/tests/test_oneshot.py+++ b/eval/tests/test_oneshot.py@@ -183,3 +183,19 @@ def test_a_session_that_never_finished_books_what_it_spent_not_zero(tmp_path: Pafake.chmod(0o755)r = backend(str(fake)).generate("brief", out_dir=tmp_path / "o", timeout_s=30)assert r.usage.input_tokens > 0 and r.usage.cost_usd > 0, r.usage++[email protected]("said, infra", [+ ("API Error: 529 {\"type\":\"overloaded_error\"}", True), # matched no marker: scored 0.0 before+ ("You've hit your usage limit. Try again later.", True),+ ("TypeError: cannot read properties of undefined", False), # the CLI's own crash stays a zero+])[email protected]("backend", [lambda b: ClaudeOneShot("claude-sonnet-5", binary=b),+ lambda b: CodexOneShot("gpt-5.5", binary=b)], ids=["claude", "codex"])+def test_a_provider_failure_drops_the_one_shot_cell(tmp_path: Path, backend, said, infra):+ """N76: the one-shot reads its CLI's end the way the harness session does (claude_end / codex_end)."""+ fake = tmp_path / "cli"+ fake.write_text(f"#!{sys.executable}\nimport sys\nsys.stdin.read()\nprint({said!r}, file=sys.stderr)\nsys.exit(1)\n")+ fake.chmod(0o755)+ r = backend(str(fake)).generate("brief", out_dir=tmp_path / "o", timeout_s=30)+ assert not r.ok and r.infra_failed is infra, rdiff --git a/harness/codeverse3d/agents/backends.py b/harness/codeverse3d/agents/backends.pyindex f32c65f8..7febd908 100644--- a/harness/codeverse3d/agents/backends.py+++ b/harness/codeverse3d/agents/backends.py@@ -678,6 +678,21 @@ def primary_served_model(env: dict[str, Any], model: str) -> str:return max(served, key=lambda n: float((served[n] or {}).get("costUSD") or 0.0))+def claude_end(proc: CompletedProc, env: dict[str, Any] | None, stream: ClaudeStream, text: str) -> SessionEnd:+ """How a ``claude -p`` process ended (``cli_common.classify_end`` with claude's evidence: its+ ``api_retry`` events, its result envelope) — the harness session and the bench one-shot alike."""+ sub = str((env or {}).get("subtype", ""))+ if proc.timed_out:+ return classify_end(proc, ok=False, text=text, provider_retried=bool(stream.retries))+ if env is None or proc.rc != 0:+ # a 529 / overloaded exit is the provider's, not the task's (AgentResult.transient)+ return classify_end(proc, ok=False, text=text, said=(proc.stderr, proc.stdout))+ if env.get("is_error") or sub.startswith("error"):+ # the turn cap is the task's budget, never the provider's+ return SessionEnd("budget") if "max_turns" in sub else classify_end(proc, ok=False, text=text, said=(text,))+ return classify_end(proc, ok=True, text=text)++class ClaudeCodeAgent(_CliAgent):kind = "claude-code"cli_label = "claude"@@ -740,19 +755,13 @@ class ClaudeCodeAgent(_CliAgent):turns = int((env or {}).get("num_turns") or 0)errors: list[str] = []sub = str((env or {}).get("subtype", ""))+ end = claude_end(proc, env, stream, text)if proc.timed_out:- end = classify_end(proc, ok=False, text=text, provider_retried=bool(stream.retries))errors.append(watchdog_error(proc))elif env is None or proc.rc != 0:- # a 529 / overloaded exit is the provider's, not the task's (AgentResult.transient)- end = classify_end(proc, ok=False, text=text, said=(proc.stderr, proc.stdout))errors.append(f"rc={proc.rc}; no result envelope; stderr tail: {proc.stderr[-1500:]}")- elif env.get("is_error") or sub.startswith("error"):- # the turn cap is the task's budget, never the provider's- end = SessionEnd("budget") if "max_turns" in sub else classify_end(proc, ok=False, text=text, said=(text,))+ elif end.exit_reason != "completed":errors.append(f"claude reported {sub or 'is_error'}: {text[-800:]}")- else:- end = classify_end(proc, ok=True, text=text)return finish_session(s, ok=end.exit_reason == "completed", exit_reason=end.exit_reason, text=text, usage=usage,tool_calls=n_calls, turns=turns, errors=errors, transient=end.transient, quota=end.quota,@@ -896,6 +905,15 @@ def parse_codex_jsonl(stdout: str) -> CodexEvents:return ev+def codex_end(proc: CompletedProc, events: CodexEvents, text: str) -> SessionEnd:+ """How a ``codex exec --json`` process ended (``cli_common.classify_end`` with codex's evidence:+ its own error events — a dropped stream, a 5xx it gave up on) — the harness session and the+ bench one-shot alike."""+ ok = not proc.timed_out and proc.rc == 0 and events.n_events > 0 and not (events.errors and events.turns_completed == 0)+ return classify_end(proc, ok=ok, text=text, said=(*events.errors, proc.stderr),+ provider_retried=is_transient_failure(*events.errors))++class CodexAgent(_CliAgent):kind = "codex"cli_label = "codex"@@ -947,10 +965,8 @@ class CodexAgent(_CliAgent):errors.append(watchdog_error(proc))elif proc.rc != 0 or events.n_events == 0:errors.append(f"rc={proc.rc}; events={events.n_events}; stderr tail: {proc.stderr[-1500:]}")- ok = not proc.timed_out and proc.rc == 0 and events.n_events > 0 and not (events.errors and events.turns_completed == 0)- # codex's provider record is its own error events (a dropped stream, a 5xx it gave up on)- end = classify_end(proc, ok=ok, text=text, said=(*events.errors, proc.stderr),- provider_retried=is_transient_failure(*events.errors))+ end = codex_end(proc, events, text)+ ok = end.exit_reason == "completed"return finish_session(s, ok=ok, exit_reason=end.exit_reason, text=text, usage=usage, tool_calls=events.tool_calls,turns=events.turns_completed, errors=errors, transient=end.transient, quota=end.quota,