Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

Bind prefill evidence to the bundle's original graph

Claude8c7f185af472
diff --git a/scripts/models/bonsai/build_vision.py b/scripts/models/bonsai/build_vision.py
index 09262c0f0..8e7afb762 100644
--- a/scripts/models/bonsai/build_vision.py
+++ b/scripts/models/bonsai/build_vision.py
@@ -339,7 +339,8 @@ optional check. {ocr_limit}
Apache 2.0; see LICENSE and NOTICE.txt. Original context capacity is 262,144 tokens;
WebBrain applies a smaller browser context budget. Model weights and processor
files are downloaded once; inference runs locally.
-""" + model_card_section([], language_graph["output_sha256"], language_graph["chunk_tokens"]), encoding="utf-8")
+""" + model_card_section(
+ [], language_graph["output_sha256"], language_graph["chunk_tokens"], language_graph["source_sha256"]), encoding="utf-8")
total = seal_manifest(output)
print(json.dumps({"output": str(output.resolve()), "vision_tensors": len(records),
"total_bytes": total, "vision_inference": validation}), flush=True)
diff --git a/scripts/models/bonsai/chunk_gdn_prefill.py b/scripts/models/bonsai/chunk_gdn_prefill.py
index 14baab322..dba42420a 100644
--- a/scripts/models/bonsai/chunk_gdn_prefill.py
+++ b/scripts/models/bonsai/chunk_gdn_prefill.py
@@ -75,19 +75,23 @@ def _require(condition, message):
raise ValueError(f"Prefill evidence rejected: {message}")
-def verify_prefill_evidence(reports, graph_sha256, chunk_tokens):
+def verify_prefill_evidence(reports, graph_sha256, chunk_tokens, source_sha256):
"""Check attached reports and return the verified ones by kind.
Raises on an unknown report kind or any failed comparison, so a bundle can
never be sealed with evidence that contradicts its model card. CPU parity
must cover the rewrite's own chunk size: a prompt ending exactly on a chunk
boundary and one spanning several chunks (which exercises the prefix scan).
+ Every report must name both the rewritten graph and the original (Scan)
+ graph it was compared against.
"""
verified = {}
for report in reports:
kind = report.get("kind")
if kind == CPU_EVIDENCE_KIND:
_require(report.get("rewritten_graph_sha256") == graph_sha256, "CPU report is for a different graph")
+ _require(report.get("original_graph_sha256") == source_sha256,
+ "CPU report did not compare against this bundle's original graph")
rows = list(report.get("fresh_prefill") or [])
continuation = report.get("continuation_from_cache")
_require(rows and continuation, "CPU report needs fresh prefills and a cached continuation")
@@ -116,6 +120,8 @@ def verify_prefill_evidence(reports, graph_sha256, chunk_tokens):
_require(row.get("decode_step_top1_equal") is True, f"decode step differs ({row})")
elif kind == WEBGPU_EVIDENCE_KIND:
_require(report.get("rewritten_graph_sha256") == graph_sha256, "WebGPU report is for a different graph")
+ _require(report.get("original_graph_sha256") == source_sha256,
+ "WebGPU report did not time this bundle's original graph")
rewritten = [row for row in report.get("prefill") or [] if row.get("variant") == "rewritten"]
original = [row for row in report.get("prefill") or [] if row.get("variant") == "original"]
comparisons = list(report.get("webgpu_logit_comparison") or [])
@@ -138,8 +144,8 @@ def rewritten_chunk_tokens(graph_path):
raise ValueError(f"{graph_path} was not rewritten by chunk_gdn_prefill.py")
-def model_card_section(reports, graph_sha256, chunk_tokens=128):
- verified = verify_prefill_evidence(reports, graph_sha256, chunk_tokens)
+def model_card_section(reports, graph_sha256, chunk_tokens, source_sha256):
+ verified = verify_prefill_evidence(reports, graph_sha256, chunk_tokens, source_sha256)
text = MODEL_CARD_INTRO.format(chunk=chunk_tokens) + "\n"
if CPU_EVIDENCE_KIND in verified:
text += ("`chunked-prefill-validation.json` records CPU comparisons with the original\n"
diff --git a/scripts/models/bonsai/make_chunked_bundle.py b/scripts/models/bonsai/make_chunked_bundle.py
index 6330adef0..6e714e190 100644
--- a/scripts/models/bonsai/make_chunked_bundle.py
+++ b/scripts/models/bonsai/make_chunked_bundle.py
@@ -109,7 +109,8 @@ def build_bundle(source, output, manifest, args):
scratch.rename(output / GRAPH)
evidence = [read_json(path) for path in args.evidence]
- card_section = model_card_section(evidence, report["output_sha256"], report["chunk_tokens"]) # rejects failed evidence
+ card_section = model_card_section(evidence, report["output_sha256"], report["chunk_tokens"],
+ report["source_sha256"]) # rejects failed evidence
write_json(output / DERIVED_MARKER, {
"rewrite": report,
"external_data_unchanged": "onnx/decoder_model_merged_q2f16.onnx_data",