Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions bench/accuracy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,18 @@ SQL actually ran through the production `run_sql` tool. Missing definitions are
not silently seeded or bypassed. The default model is left to Codex; no resolved
model identifier is asserted. Internal API calls are not observable, so report
CLI invocations and captured usage separately from API-harness measurements.
# Failed-case-only Codex iterations

Add `--failures-from /path/to/previous-run` to the existing
`python -m bench.accuracy.codex_mcp` command to run only that completed run's
score-zero cases. The source directory must contain `manifest.json` and
`codex-mcp/{status,scores}.json`. Every source case must have exactly one binary
grade and must match the current selected input; incomplete grading or changed
questions abort before model calls. No remaining failures means no model calls.

Selection reads grades locally, but passes only unchanged input cases to Codex.
`--review-source` is independent and adds only prior answers/tool observations.
Settings record the selection source and score-file hash. Use a fresh output
directory and the unchanged official scoring command after generation. Report
the result as a repair rate on prior failures, never as full benchmark accuracy
or a best-of-runs combined score. Correct cases are not replayed by this option.
31 changes: 31 additions & 0 deletions bench/accuracy/codex_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ def review_evidence(record):
)


def failed_cases(cases, source):
"""Select failures from one completed run; never pass grading data to inference."""
prior = json.loads((source / "manifest.json").read_text())["cases"]
status = json.loads((source / "codex-mcp/status.json").read_text())
if status.get("status") != "completed":
raise ValueError("Failure selection requires a completed source run")
scores = json.loads((source / "codex-mcp/scores.json").read_text())
by_id = {row["instance_id"]: row for row in scores}
prior_ids = {case["instance_id"] for case in prior}
if len(by_id) != len(scores) or set(by_id) != prior_ids:
raise ValueError("Source scores must cover every source case exactly once")
if any(row["score"] not in (0, 1) for row in scores):
raise ValueError("Source scores must be binary execution grades")
current = {case["instance_id"]: case for case in cases}
if any(current.get(case["instance_id"]) != case for case in prior):
raise ValueError("Source cases must match current questions and inputs")
return [case for case in prior if by_id[case["instance_id"]]["score"] == 0]


async def run(args):
repo = Path(__file__).resolve().parents[2]
manifest = json.loads(args.manifest.read_text())
Expand All @@ -102,6 +121,12 @@ async def run(args):
manifest["cases"] = [
c for c in manifest["cases"] if selected is None or c["instance_id"] in selected
]
if args.failures_from:
manifest["cases"] = failed_cases(manifest["cases"], args.failures_from)
logger.info("Failed-case selection source=%s selected=%d", args.failures_from, len(manifest["cases"]))
if not manifest["cases"]:
logger.info("No failed cases remain in the source run; no model calls made")
return
if args.output.exists():
raise ValueError("Use a fresh output directory; never overwrite attempts")
args.output.mkdir(parents=True)
Expand Down Expand Up @@ -142,6 +167,11 @@ async def run(args):
},
"schema_document_sha256": digest(args.schema_docs),
"review_source": str(args.review_source) if args.review_source else None,
"failure_selection": {
"source": str(args.failures_from),
"scores_sha256": digest(args.failures_from / "codex-mcp/scores.json"),
"metric": "repair rate on prior failures, not full benchmark accuracy",
} if args.failures_from else None,
"split": args.split,
"concurrency": args.concurrency,
"case_timeout": args.case_timeout,
Expand Down Expand Up @@ -340,6 +370,7 @@ def main():
"--split", choices=["development", "all"], default="development"
)
parser.add_argument("--review-source", type=Path, help="Prior run directory; pass only prior model answer/tool observations, never scores")
parser.add_argument("--failures-from", type=Path, help="Run only score=0 cases from this completed run; grades select cases but never enter model prompts")
parser.add_argument("--model", required=True)
parser.add_argument("--reasoning-effort", default="high")
parser.add_argument("--concurrency", type=int, default=2)
Expand Down
33 changes: 33 additions & 0 deletions tests/test_codex_mcp_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,36 @@ def test_review_evidence_excludes_evaluation_feedback():
data = json.loads(payload)
assert set(data) == {"previous_answer", "tool_observations"}
assert data["tool_observations"][0]["arguments"]["sql"] == "SELECT 1"


@pytest.mark.parametrize("invalid", [None, "incomplete", "missing_score", "duplicate_score", "changed_question", "unknown_case", "nonbinary"])
def test_failed_case_selection_preserves_inputs_and_rejects_incomplete_grades(tmp_path, invalid):
from bench.accuracy.codex_mcp import failed_cases
from bench.spider2.evaluate import write_json

cases = [{"instance_id": name, "question": "question " + name, "db": "demo"}
for name in ("correct", "wrong", "execution_failed")]
scores = [{"instance_id": case["instance_id"], "score": int(i == 0)}
for i, case in enumerate(cases)]
write_json(tmp_path / "manifest.json", {"cases": cases})
write_json(tmp_path / "codex-mcp/status.json", {"status": "running" if invalid == "incomplete" else "completed"})
if invalid == "missing_score":
scores.pop()
elif invalid == "duplicate_score":
scores.append(scores[0])
elif invalid == "unknown_case":
scores[-1]["instance_id"] = "other"
elif invalid == "nonbinary":
scores[-1]["score"] = 0.5
elif invalid == "changed_question":
cases[-1]["question"] = "different question"
write_json(tmp_path / "codex-mcp/scores.json", scores)
if invalid:
with pytest.raises(ValueError):
failed_cases(cases, tmp_path)
else:
selected = failed_cases(cases, tmp_path)
assert selected == cases[1:]
assert all(set(case) == {"instance_id", "question", "db"} for case in selected)
write_json(tmp_path / "codex-mcp/scores.json", [{**row, "score": 1} for row in scores])
assert failed_cases(cases, tmp_path) == []