bench(unseen): per-commit history cache for ordinary_history; assemble.freeze --history-cache

One append-only JSONL per clone (named by the sha256 of its top-level path), one line per commit
with the row as the walk built it and HISTORY_CACHE_VERSION, flushed after every commit so a
killed run keeps its progress. A cached row is reused only when its parents match the current log;
other versions and torn lines are recomputed. With no cache directory nothing changes. The
7,400-commit trigger.dev walk that took over an hour per freeze becomes a one-time cost.
Implemented by Codex (gpt-6-astra), gated here.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
Marius Ciepluch
2026-10-13 19:40:34 +02:00
co-authored by Claude Fable 5.1
parent dbaaa86d5b
commit 47d0f0fac1
4 changed files with 315 additions and 41 deletions
+7 -2
View File
@@ -51,6 +51,7 @@ def freeze(
seed: int = 0,
ratio: int = 20,
history_heads: dict | None = None,
history_cache: Path | None = None,
fix_index: dict | None = None,
floor: int = extract.ORDINARY_FLOOR,
) -> dict:
@@ -58,7 +59,8 @@ def freeze(
``floor`` is the eligible-commit count a repository needs before its ordinary pushes are drawn. The
held-out benchmark keeps the shipped 40; a training freeze may lower it (never below the ratio) so small
repositories with 20 eligible commits still contribute, and the record carries the floor used."""
repositories with 20 eligible commits still contribute, and the record carries the floor used.
``history_cache`` reuses completed per-commit history rows across freezes of the same clone."""
if type(ratio) is not int or ratio < 20:
raise ValueError("ordinary ratio must be at least 20")
if type(floor) is not int or floor < ratio:
@@ -91,7 +93,8 @@ def freeze(
functions = {(case["path"], case["function"]) for case in all_cases}
head = (history_heads or {}).get(repo) or git.run("rev-parse", "HEAD").strip()
heads[repo] = head
history = sorted(extract.ordinary_history(git, head), key=lambda row: row["head"])
history_options = {"cache_dir": history_cache} if history_cache is not None else {}
history = sorted(extract.ordinary_history(git, head, **history_options), key=lambda row: row["head"])
# Ratio is per positive CHANGE (a fix commit), not per accepted function. Several
# accepted functions in one fix collapse to one vulnerability change below, so the
# negative count must track distinct (commit, parent) pairs.
@@ -177,6 +180,7 @@ def main(argv=None):
parser.add_argument("--used", type=Path, required=True, help="JSON array of used repository identities, including known aliases")
parser.add_argument("--out", type=Path, required=True)
parser.add_argument("--seed", type=int, default=0)
parser.add_argument("--history-cache", type=Path, help="Directory for per-clone commit history caches")
args = parser.parse_args(argv)
result = freeze(
args.out,
@@ -185,6 +189,7 @@ def main(argv=None):
repos={k: local_git(Path(v)) for k, v in json.loads(args.repos.read_text()).items()},
used=json.loads(args.used.read_text()),
seed=args.seed,
history_cache=args.history_cache,
)
print(json.dumps(result, sort_keys=True))
return 0