Skip to content

Keep a completed batch CSV on rerun - #314

Draft
MaxGhenis wants to merge 2 commits into
mainfrom
lane/batch-rerun-keeps-completed-csv
Draft

MaxGhenis wants to merge 2 commits into
mainfrom
lane/batch-rerun-keeps-completed-csv

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #102.

What changes

Rerunning eval-no-tools-batch on an output directory whose by_model/<model>.csv already existed replayed the stored batches from round 0, stopped at the current repair cap and overwrote the CSV. A rerun could leave more missing predictions than the run it replaced. This takes option (a) from the issue: a completed model is a no-op, but only after the run proves the CSV belongs to the same evaluation.

  • Publishing a model writes by_model/<model>.batch.json after the spend mirror and the CSV. It records the model id, provider, resolved programs, scenario hash (scenario ids and serialized inputs), row count and CSV sha256.
  • run_batch_eval returns the persisted CSV only when that record matches the current evaluation, the CSV's sha256 matches and the spend mirror exists. It logs the row and missing-prediction counts and makes no provider call.
  • Otherwise it raises, and the CLI exits with a message naming the mismatch (programs, scenario hash, missing record, CSV checksum or missing mirror). The message says to use a new --output-dir, or to remove the CSV to resume polling an interrupted run with the original inputs.
  • One per-model flock (by_model/.<model>.lock) covers the existing-output check, the mirror, the CSV and the record. A second writer that finishes later returns the first writer's CSV without touching the mirror.
  • Publication stages files inside by_model/ and uses os.replace, so it needs no hard-link support.
  • The repair log says "scheduling repair round" only when the cap allows another round.
  • docs/runbook.md describes the verified skip, the refusal and the new-directory redo.

Behaviour to note

  • Raising POLICYBENCH_MAX_REPAIR_ROUNDS and rerunning on the same directory no longer adds repair rounds; it returns the existing CSV. Option (b) in the issue would continue from the last round, but this PR doesn't implement it.
  • A CSV written before this change has no record, so a rerun refuses it instead of treating it as complete. Removing the CSV re-polls the saved batches and publishes again.
  • That re-poll still trusts the saved round state, which checks only the model id and provider. Removing the CSV after changing the manifest or programs would replay old results for new inputs, as on main.
  • by_model/ gains a .batch.json record and a hidden .lock file per batch model. Export and reparse read only *.csv there.
  • The lock is advisory and POSIX-only (fcntl); it coordinates batch writers that use it.

Tests

  • test_completed_batch_keeps_repairs_when_rerun_with_lower_cap: round 0 returns no predictions and round 1 repairs one. A rerun with the cap at 0 leaves the CSV bytes unchanged and makes no status call. On main, the rerun rewrites the CSV with the repair lost.
  • test_batch_cli_refuses_unverified_output: through the CLI, a changed program list, a changed scenario input under the same id, a missing record, an edited CSV and a missing mirror each exit with the mismatch named, leave the CSV bytes unchanged and make no status call.
  • test_batch_publication_keeps_first_writer: publication holds the model lock, writes the mirror, CSV and record in that order with os.replace from by_model/, and a second publisher with a different frame and a stale ledger changes none of the three files.
  • The interrupted-resume test deletes the CSV and its record first, so it still covers re-polling and ledger deduplication.
  • The randomized test compares a rerun with the saved CSV, then removes the CSV and record and checks that replaying the saved rounds rebuilds the full frame (usage and provider columns included) in both chunking modes.

The patch and its fix commit came from read-only Codex lanes that could not run pytest. CI runs the tests (-m "not slow"). ruff check and ruff format --check pass on the changed files.

🤖 Generated with Claude Code

A rerun of eval-no-tools-batch on an output dir whose by_model/<model>.csv
exists replayed the stored batches from round 0, stopped at the current
repair cap and overwrote the CSV, discarding later rounds' repairs (#102).

- run_batch_eval returns the persisted CSV when it exists, logs its row
  and missing-prediction counts, and makes no provider call. A redo uses
  a new --output-dir.
- A new CSV is written to a staging file and hard-linked into place only
  if the destination is still absent, after the spend ledger is mirrored.
- The repair log announces another round only when the cap allows one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
policybench-site Ready Ready Preview Dec 3, 2026 3:54am UTC

Request Review

Fixes from review round 1:
- Publishing a model writes by_model/<model>.batch.json after the spend
  mirror and the CSV. It records the model id, provider, resolved
  programs, scenario hash, row count and CSV sha256.
- A rerun returns the saved CSV only when that record matches the current
  evaluation, the CSV checksum matches and the spend mirror exists.
  Otherwise it refuses (SystemExit from the CLI) and says to use a new
  --output-dir, or to remove the CSV to resume polling an interrupted run
  with the original inputs. A legacy CSV without a record is refused, not
  accepted as complete.
- One per-model flock covers the existing-output check, the mirror, the
  CSV and the record, so a losing writer returns the winner's output
  without touching the mirror.
- Publication stages files in by_model and uses os.replace, so it no
  longer needs hard links.
- The randomized test replays saved rounds with the CSV removed and
  compares the full reconstructed frame again.
- The runbook's batch section describes the verified skip, the refusal
  and the new-directory redo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active (outdated) deployment
Preview — d2c89fae Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Batch rerun on a completed run dir replays early rounds and regresses the CSV

1 participant