A scratch copy is one run's working store. The video harness defaults to bench/runs/video_audio and copy_store() copies straight over it, so a smoke run started while the full run was mid-ingest replaced the database under it: the full run's after-arm would have scored a store whose speech atoms had been swapped out, and the smoke itself died on "database is locked" inside text_index. Six harnesses share that copy path, so the claim lives in bench/scratch.py: a live pid in held_by refuses the path, a stale one is taken over, and the same process may re-copy per arm. The reviewer's smoke knob also measured nothing instead of saying so. With --limit the probe sample narrows to video only, and a small --probes strides past that modality entirely, so the run crashed in aggregate() after the ingest. probe_sample() now switches the arm off at --probes 0 and fails in half a second otherwise. The frozen-report guard had two holes found by running it: it compared cwd-relative parents, so an absolute path to the frozen file passed, and it refused the harness's own default destination once that file existed, which would have stopped the shipped run. It now compares resolved paths and refuses only committed evidence. Record fixes from review round 3: the round-2 line credited a reproduction to the wrong round and quoted a git log -S hit for a string that never existed in code; the suite counts now name the commit each was measured on (401 at83dfc14, 406 ateab6bd7, 410 atcf2de31, 411 at92237c8). Gates: pytest -q 418 passed; ruff clean; bench.filesize_check OK; mypy cold cache and pyright clean on the four touched files.
56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
"""Every harness measures a copy. The frozen baseline store is cited evidence, and the product
|
|
migrates whatever database it opens."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import atexit
|
|
import os
|
|
import shutil
|
|
import time
|
|
from pathlib import Path
|
|
|
|
HELD = "held_by"
|
|
|
|
|
|
def _alive(pid: str) -> bool:
|
|
"""A live process holds the copy. Without /proc there is nothing to check, so a stale lock cannot block a run."""
|
|
return pid.isdigit() and Path(f"/proc/{pid}").exists()
|
|
|
|
|
|
def claim(scratch: Path) -> None:
|
|
"""Refuse a copy another run is already using: two harnesses on one scratch overwrite each other's store mid-measurement."""
|
|
lock = scratch / HELD
|
|
if lock.exists():
|
|
holder = lock.read_text(encoding="utf-8").strip()
|
|
if _alive(holder) and holder != str(os.getpid()):
|
|
raise SystemExit(
|
|
f"{scratch} is held by pid {holder}; wait for that run or pass a different scratch path"
|
|
)
|
|
scratch.mkdir(parents=True, exist_ok=True)
|
|
lock.write_text(str(os.getpid()), encoding="utf-8")
|
|
atexit.register(_release, scratch)
|
|
|
|
|
|
def _release(scratch: Path) -> None:
|
|
"""Drop the claim, but only if it is still ours."""
|
|
lock = scratch / HELD
|
|
if lock.exists() and lock.read_text(encoding="utf-8").strip() == str(os.getpid()):
|
|
lock.unlink(missing_ok=True)
|
|
|
|
|
|
def copy_store(home: Path, scratch: Path) -> tuple[Path, float]:
|
|
"""Work on a copy: the baseline store is frozen evidence and must not be migrated in place."""
|
|
source = home / "data" / "ely_eye.sqlite"
|
|
if not source.is_file():
|
|
raise SystemExit(
|
|
f"{source}: no product database, build it with python -m bench.ingest_baseline"
|
|
)
|
|
claim(scratch)
|
|
data = scratch / "data"
|
|
data.mkdir(parents=True, exist_ok=True)
|
|
began = time.perf_counter()
|
|
for suffix in ("", "-wal", "-shm"):
|
|
if (path := Path(str(source) + suffix)).is_file():
|
|
shutil.copyfile(path, data / (source.name + suffix))
|
|
return scratch, time.perf_counter() - began
|