# CLAUDE.md — agent runbook for agent-cwm / CodeWorld GYM Read this before touching anything. It encodes the project's hard rules, the working setup, and the exact commands to reproduce or extend every result. ## What this project is Rubric-grounded code world models. `swe-rubrics/` mines verifiable code-quality rubrics (OpenRubrics adapted to code); `codeworld-gym/` uses them in a loop where a prompted **Code World Model** predicts per-rubric 0/1 rewards for candidate code and **races the real interpreter** — whichever finishes first feeds the generator's next revision. Mistake logs (WM-vs-execution disagreements) evolve the rubric database. ## HARD RULES 1. **LiveCodeBench, SWE-bench, and MLE-bench are HELD OUT.** Never mine rubrics from them; they are evaluation-only. Mining sources: GitHub PRs, CodeContests, HLCE-ICPC, SWE-Gym, Claude Code traces. 2. **Report only official-grader numbers**: LCB via `lcb_runner` (`codeworld-gym/scripts/official_lcb_grade.py`), SWE-bench via the `swebench` Docker harness, MLE-bench via `mlebench.grade.grade_csv`. 3. Same generator model across arms within an experiment; arms are `base` (zero-shot) / `selfrepair` (interpreter loop) / `framework` (race). ## Environment - Python venv: `swe-rubrics/.venv` (`pip install -e "swe-rubrics[openai,anthropic,gemini]"`, plus `pytest matplotlib swebench mlebench "kaggle<1.7"`). - ML runtime for MLE-bench agent scripts: `~/.venvs/ml` (`pandas scikit-learn xgboost lightgbm numpy torch torchvision`). - Keys: `ANTHROPIC_API_KEY`, `OPENAI_API_KEY` (rubric gen = `claude-opus-4-8`, judge = `gpt-5.6-sol`), `GEMINI_API_KEY` (backend fixed for google-genai 2.x; bare "gemini" → gemini-3.5-flash), `GITHUB_TOKEN` (PR mining), `~/.kaggle/kaggle.json` (old-style; mlebench pins kaggle<1.7 which ignores KGAT tokens). - Known env quirks: `datasets>=3` killed script-based HF loaders — LCB and HLCE are loaded from raw Hub files (already handled in scripts); LCB `private_test_cases` are zlib+b64+pickle (handled). ## Pipelines (exact commands, run from `swe-rubrics/`) **Mine GitHub PRs at scale** (writes prepared → rubrics → judged): `GITHUB_TOKEN=... ./scripts/full_generation.sh` **Benchmark task workspaces for trace generation / eval:** - `python scripts/make_benchmark_tasks.py --bench codecontests --min-rating 1500 --max-tasks N` - `python scripts/make_benchmark_tasks.py --bench hlce --max-tasks N` (needs `/tmp/mlebench_lite.txt`-style split file? no — that's MLE; HLCE pulls `HumanLastCodeExam/icpc-world-finals` automatically) - `python scripts/make_swegym_tasks.py --repos getmoto/moto --max-tasks N` (mining) or `--dataset princeton-nlp/SWE-bench_Verified` (EVAL ONLY) - LCB eval workspaces: `python scripts/make_benchmark_tasks.py --bench livecodebench --lcb-file test6.jsonl --difficulty '' --max-tasks 175 --include-functional --hidden-tests --out-dir /tmp/lcb-full` **Mine agent traces:** run agents on the workspaces, then `python scripts/prepare_claude_traces.py --benchmark-mode --include-stub --sessions ` (pooled per task, rescored on tests) or `--taskdir-requests` for SWE-Gym-style repo tasks. Merge with `scripts/merge_judgements.py`; final dataset `data/code_rubrics.jsonl`. **Build the rubric DB** (from `codeworld-gym/`): `python scripts/build_db.py ../swe-rubrics/data/code_rubrics.jsonl --out data/rubric_db_full.jsonl` **LCB eval (three arms + official grading):** ``` python scripts/eval_lcb_bench.py --tasks-dir /tmp/lcb-full --db data/rubric_db_full.jsonl \ --arms all --gen-model claude-haiku-4-5-20251001 --out data/lcb_bench.jsonl python scripts/official_lcb_grade.py --rows data/lcb_bench.jsonl --lcb-file test6.jsonl ``` Rows checkpoint per task; reruns resume (`--fresh` to override). **SWE-bench eval (official Docker harness):** ``` python scripts/eval_swebench.py --tasks-dir /tmp/swebench-eval \ --db data/rubric_db_full.jsonl --gen-model claude-sonnet-5 --arms all --grade ``` Notes: haiku is below the SEARCH/REPLACE floor — use sonnet+. The WM must see the post-edit STATE (handled: `wm_view`). Local test feedback is gated on the unpatched repo genuinely failing (`signal_trusted`). Keep-best patch guard on. **MLE-bench (the storage-heavy one — full Lite ≈ tens of GB):** ``` # one-time on a new machine: kaggle.json at ~/.kaggle (chmod 600); accept each # competition's rules on kaggle.com (Join Competition -> accept). Lite list: curl -s https://raw.githubusercontent.com/openai/mle-bench/main/experiments/splits/low.txt > /tmp/mlebench_lite.txt python scripts/make_mlebench_tasks.py --lite --max-tasks 22 --out-dir /tmp/mlebench-tasks \ --data-dir /mle-bench/data cd ../codeworld-gym python scripts/eval_mlebench.py --tasks-dir /tmp/mlebench-tasks --db data/rubric_db_full.jsonl \ --ml-python ~/.venvs/ml/bin/python --run-cap 1800 --out data/mlebench_eval.jsonl ``` Grading is official (`mlebench.grade_csv`, medal thresholds). Give training scripts a GPU if available; raise `--run-cap` for image competitions. **Plots:** `python scripts/make_report_plots.py` (from `codeworld-gym/`; writes `reports/plots/*.png`; palette is the validated reference set). **GKE eval fleet (massive parallelism, `gke/`, runbook in `gke/README.md`):** GCP project `edward-sun`, region `us-east1` — deliberately DISJOINT from the probe-factory/qd-bloom deployment (us-central1); never point these at each other. Cluster `agent-cwm-evals`, bucket `gs://edward-sun-agent-cwm-evals` (all MLE-bench comps prepared as per-comp tarballs), coordinator venv `gke/.venv` (ADC auth, no kubectl/docker needed). ``` V=gke/.venv/bin/python $V gke/prep_datasets.py status # dataset inventory $V gke/submit_eval.py submit --run X --competitions-from-split both \ --arms all --repeats 10 --repeat-chunk 2 --parallelism 50 # 100 pods $V gke/submit_eval.py collect --run X # -> data/gke_runs/X.jsonl ``` GPUs: `--gpu nvidia-tesla-t4|nvidia-l4` (quota: 8 T4 + 16 L4 + same in spot; each shard gets its own GPU; LD_LIBRARY_PATH for the driver is auto-wired). Repeats are 1-based inclusive. Size `--parallelism` to API rate limits, not CPUs. Noise floors must be re-measured on this hardware before trusting causal-precision numbers from fleet runs. `--shared-initials` does not coordinate across pods — keep all arms of one (task, repeat) in one shard. ## Results so far (2026-07-16/17, details in memory + reports/) - LCB test6 official pass@1 (haiku gen): base 33.7 | selfrepair 43.4 | framework 202-rubric DB 43.4 | framework 7k DB **45.1**. cwm mode: ~85% of solve at 1.0 vs 3.4 executions/task. - SWE-bench 24-instance subset (sonnet gen, pre-fix run): base 13/24 > selfrepair 10/24 > framework 8/24 → diagnosed noisy local venv signal + WM judging bare diffs; fixes landed (state view, trust gate, asymmetric verdicts, keep-best) — **fixes are committed but UNVALIDATED: the validation rerun was killed for machine migration. Run it first (open thread #0).** - WM calibration probe (34 LCB solutions): catches 15/17 failing, false-flags 7/17 passing; self-reported confidence uninformative → never gate on it. - MLE-bench validated end-to-end on dog-breed-identification (framework made a valid graded submission; base did not). ## Open threads 0. **Validate the SWE-bench fixes** (state view, trust gate, asymmetric verdicts, keep-best): re-materialize the 24-instance Verified subset and run `eval_swebench.py --arms all --grade`. Success = framework ≥ base resolved, wm_wins > 0. NOTE: official grading needs Docker — if the machine has none (e.g. the RunPod box), generate patches there and grade the predictions files on a Docker-capable host. 1. Full MLE-bench Lite run on a big-storage machine (this file's MLE section). On the RunPod box use `--data-dir /workspace-vast/edwardosunny/mle-bench/data` (the 176TB network volume — home overlay is nearly full). 2. Evolution experiment with randomized task order (eval_lcb.py) — evolution fires but its effect on scores is unproven. 3. Statistical power: n=3-5 samples per LCB problem; grow SWE-bench subset (django needs per-repo test commands, not pytest). 4. Train the WM calibration head / selector MLP from logged verdicts+outcomes (`scripts/make_cwm_labels.py` not yet written). 5. Remaining audit fixes in swe-rubrics: parse_winner leniency, gen_rubric checkpointing, CodeContests py2/timeout label noise.