Expand description
Directory-based resumable checkpoint storage for long benchmark runs.
Port of benchmarks/checkpoint.py. A checkpoint is a directory:
<checkpoint-dir>/
manifest.json pretty (indent 2), sorted-key JSON + trailing "\n",
written atomically (tmp file + rename)
observations.jsonl one compact, sorted-key JSON row per completed
agreement observation, appended + flushed per line
h2h.jsonl one compact, sorted-key JSON row per completed
head-to-head game, appended + flushed per lineBoth JSONL files use crate::bench::canonical::canonical_json, the
same byte-exact encoder used for dataset/bundle artifacts, so a
checkpoint directory written by this crate loads and rehydrates
(bundle_from_checkpoint) correctly in Python’s benchmarks.checkpoint
module and vice versa. manifest.json uses
crate::bench::canonical::canonical_json_pretty, matching Python’s
json.dumps(manifest, indent=2, sort_keys=True) + "\n".
Resume validation is intra-language only. validate_resume_manifest
compares the run’s config dict against the manifest’s stored config
dict, but the two languages’ CLI argument dicts have different key sets
and shapes (e.g. track_memory/skip_agreement exist only in the
Python CLI) — a checkpoint directory started by one language’s run is
not expected to --resume cleanly in the other. Loading and reporting
(bundle_from_checkpoint, report --input <dir>) work identically in
both languages regardless of which one wrote the directory.
Unlike the single-file .ckpt format this module replaces (PR #10),
an invalid JSONL line is a hard error (file path + 1-based line
number) — there is no truncated-tail tolerance here, because
manifest.json’s atomic tmp+rename write is the integrity anchor: a
crash mid-write of an observation/h2h line can only ever leave a
trailing partial line (never a torn manifest), and callers that always
flush after append_jsonl should not see one in practice, but Python
chose to raise rather than silently drop, so this port matches that.
Structs§
- Checkpoint
Paths - The paths that make up one checkpoint directory.
Constants§
Functions§
- append_
jsonl - Append one JSON object as one compact, sorted-key JSONL row, flushing to the OS immediately.
- build_
manifest - Build a fresh checkpoint manifest (mirrors Python CLI’s
_checkpoint_manifestinexamples/cross_engine_benchmark.py, not the library-level_build_manifestinbenchmarks/checkpoint.py— the CLI manifest intentionally omitsschema_version; that key only lives on the bundle produced bybundle_from_checkpoint, from thebundle::SCHEMA_VERSIONconstant). - bundle_
from_ checkpoint - Rehydrate a checkpoint directory into the standard benchmark bundle,
including a partial state — an in-progress or preflight-failed
checkpoint rehydrates fine, with whatever rows/records/aggregates are
available so far. The bundle gains a
"checkpoint": {status, counts}block (andh2h_pairswhen the manifest carries one). - checkpoint_
paths - Resolve the manifest/observations/h2h file paths under
root. - key_set
- Build the set of stable resume keys already present in checkpoint rows.
- load_
jsonl - Load a JSONL file; a missing file behaves like an empty stream. Blank lines are skipped. An invalid line is a hard error naming the file and its 1-based line number (no truncated-tail tolerance — see the module doc).
- load_
manifest - Load the checkpoint manifest, or an empty object if it doesn’t exist
yet (mirrors Python’s
load_manifestreturning{}). - normalize_
run_ config - Drop volatile fields that must not participate in resume validation.
- update_
manifest_ counts - Update checkpoint progress counters in place (
counts, optionallystatus, alwaysupdated_at) and return the resulting manifest. - validate_
resume_ manifest - Raise a clear error when a resume checkpoint does not match this run:
dataset checksum must be equal, and the normalized config signature
must be equal (per-key diff in the error message otherwise).
allow_skip_h2h_mismatchadditionally dropsskip_h2hfrom the signature — the CLI only sets this when the checkpoint’s existing h2h records already equal the expected count, so a differing--skip-h2hthis run genuinely doesn’t matter. - write_
manifest - Atomically write the checkpoint manifest (tmp file + rename), pretty
(indent 2), sorted-key JSON + trailing newline, matching Python’s
json.dumps(manifest, indent=2, sort_keys=True) + "\n".