Skip to content

Commit 16f583a

Browse files
committed
fix(benchmark): reject explicit null semantic_unit_fold_sha256 in report export and verify
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
1 parent 52c2799 commit 16f583a

2 files changed

Lines changed: 64 additions & 9 deletions

File tree

‎benchmark/edgebench/export_report.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ def _validate_turn_validator(runner, profile):
4444

4545
def _validate_semantic_unit_fold(runner, profile):
4646
key = "semantic_unit_fold_sha256"
47-
if runner.get("worker") != "turn-resume":
48-
if key in runner or key in profile:
49-
raise ValueError("Unexpected semantic_unit_fold_sha256 on non-turn-resume worker")
50-
return
51-
runner_digest = runner.get(key)
52-
profile_digest = profile.get(key)
53-
if runner_digest is None and profile_digest is None:
47+
has_runner = key in runner
48+
has_profile = key in profile
49+
if not has_runner and not has_profile:
5450
return
55-
if runner_digest is None or profile_digest is None:
51+
if runner.get("worker") != "turn-resume":
52+
raise ValueError("Unexpected semantic_unit_fold_sha256 on non-turn-resume worker")
53+
if not has_runner or not has_profile:
5654
raise ValueError("Semantic unit fold digest missing on one side")
55+
runner_digest = runner[key]
56+
profile_digest = profile[key]
5757
for digest_value in (runner_digest, profile_digest):
5858
if not isinstance(digest_value, str) or not re.fullmatch("[0-9a-f]{64}", digest_value):
5959
raise ValueError("Invalid semantic_unit_fold_sha256 digest")
@@ -383,7 +383,7 @@ def export(runs_root: Path, selection: list, output: Path, *, observed_at: str):
383383
if "stride_strategy" in receipt:
384384
config["runner"]["stride_strategy"] = receipt["stride_strategy"]
385385
config["worker_profile"]["stride_strategy"] = profile["stride_strategy"]
386-
if receipt.get("semantic_unit_fold_sha256") is not None:
386+
if "semantic_unit_fold_sha256" in receipt:
387387
config["runner"]["semantic_unit_fold_sha256"] = receipt["semantic_unit_fold_sha256"]
388388
config["worker_profile"]["semantic_unit_fold_sha256"] = profile["semantic_unit_fold_sha256"]
389389
row["status"], row["observed_at"] = "completed", observed_at

‎benchmark/tests/test_edgebench_report.py‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,3 +840,58 @@ def test_report_rejects_semantic_unit_fold_digest_on_non_turn_worker(trial):
840840
with pytest.raises(ValueError, match="non-turn-resume"):
841841
export(runs, selection, bad_output, observed_at="2026-12-01T00:00:00+00:00")
842842
assert not bad_output.exists()
843+
844+
845+
@pytest.mark.parametrize(
846+
"runner_value,profile_value",
847+
[
848+
(None, "OMIT"),
849+
("OMIT", None),
850+
(None, None),
851+
],
852+
)
853+
def test_report_rejects_explicit_null_semantic_unit_fold_digest_in_export_and_verify(
854+
trial, runner_value, profile_value
855+
):
856+
runs, selection, output, _ = trial
857+
task = runs / "run" / "case"
858+
for name, role_key in (("runtime-receipt", "worker"), ("worker-profile", "profile")):
859+
path = task / (name + ".json")
860+
record = json.loads(path.read_text())
861+
record[role_key] = "turn-resume"
862+
record["validation_argv_sha256"] = "a" * 64
863+
write(path, record)
864+
865+
# 1. Valid baseline turn-resume export without fold digest succeeds; resealing explicit null fails --verify.
866+
export(runs, selection, output, observed_at="2026-12-01T00:00:00+00:00")
867+
assert verify(output)["verified"] is True
868+
settings_path = output / "settings/run.json"
869+
tampered = json.loads(settings_path.read_text())
870+
if runner_value != "OMIT":
871+
tampered["runner"]["semantic_unit_fold_sha256"] = runner_value
872+
if profile_value != "OMIT":
873+
tampered["worker_profile"]["semantic_unit_fold_sha256"] = profile_value
874+
write(settings_path, tampered)
875+
reseal(output, "settings/run.json")
876+
with pytest.raises(ValueError, match="semantic_unit_fold_sha256|Semantic unit fold digest"):
877+
verify(output)
878+
cli_verify = subprocess.run(
879+
[sys.executable, "-m", "benchmark.edgebench.export_report", "--verify", str(output)],
880+
capture_output=True,
881+
text=True,
882+
)
883+
assert cli_verify.returncode != 0
884+
assert "semantic_unit_fold_sha256" in cli_verify.stderr or "Semantic unit fold digest" in cli_verify.stderr
885+
886+
# 2. Exporting turn-resume with explicit null on one or both sides rejects upfront.
887+
for name, val in (("runtime-receipt", runner_value), ("worker-profile", profile_value)):
888+
if val == "OMIT":
889+
continue
890+
path = task / (name + ".json")
891+
record = json.loads(path.read_text())
892+
record["semantic_unit_fold_sha256"] = val
893+
write(path, record)
894+
bad_output = output.parent / "out-explicit-null-fold"
895+
with pytest.raises(ValueError, match="semantic_unit_fold_sha256|Semantic unit fold digest"):
896+
export(runs, selection, bad_output, observed_at="2026-12-01T00:00:00+00:00")
897+
assert not bad_output.exists()

0 commit comments

Comments
 (0)