File size: 5,834 Bytes
5d12f8c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #!/usr/bin/env python3
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 Protocol Company
"""Send a row's two requests to the address again and compare what comes back with what the row holds.
python3 scripts/replay.py edge-0123456789ab # one row, by id
python3 scripts/replay.py --model energy/reactor_spert3 # every row of one model
python3 scripts/replay.py --sample 5 # the first 5 rows of each file
The address is open to any agent: https://mcp.zerotrustphysics.com/mcp. It is asked one
request at a time, with a pause between requests, and asked again after a wait when it
answers HTTP 429 or "Too many concurrent physics tasks.". Another address is given with
--address. Standard library only.
For each of a row's two requests the script reports one of:
same bytes the answer is the text the row holds, byte for byte;
same proof the text differs and the proof (run_seal or solution_seal) is the same:
the physics is the same and something outside the seal differs, such as
the engine_version string of a later release;
same stop a request stopped before any computing gives the same stop name, in
other words;
differs the engine now answers this request differently: the model, or its
limit, has changed since the row was made. That is news, not a fault
in the row, and each model's own description at the address is the
current word.
Exit code 0: nothing differs. 1: something differs.
"""
import json
import os
import re
import sys
import time
import urllib.error
import urllib.request
ADDRESS = "https://mcp.zerotrustphysics.com/mcp"
BUSY = "Too many concurrent physics tasks."
NAME = re.compile(r"\(([A-Z][A-Za-z0-9]+)\)")
def ask(address, tool, arguments, tries=40):
"""One tools/call. Returns (text, is_error)."""
body = json.dumps({"jsonrpc": "2.0", "id": 1, "method": "tools/call",
"params": {"name": tool, "arguments": arguments}}).encode("utf-8")
wait = 2.0
for _ in range(tries):
req = urllib.request.Request(address, data=body, method="POST", headers={
"content-type": "application/json", "accept": "application/json, text/event-stream",
"mcp-protocol-version": "2025-06-18", "user-agent": "zero-trust-physics-edges-replay/1"})
try:
with urllib.request.urlopen(req, timeout=120) as res:
raw = res.read().decode("utf-8")
except urllib.error.HTTPError as e:
if e.code in (429, 502, 503, 504):
after = e.headers.get("Retry-After", "")
time.sleep(max(float(after) if after.isdigit() else wait, 1.0))
wait = min(wait * 1.5, 30.0)
continue
raise
line = next((l for l in raw.split("\n") if l.startswith("data:")), None)
msg = json.loads(line[5:] if line else raw)
if "error" in msg:
return json.dumps(msg["error"]), True
text = "".join(c.get("text", "") for c in msg["result"]["content"])
if msg["result"].get("isError") and text.strip() == BUSY:
time.sleep(wait)
wait = min(wait * 1.5, 30.0)
continue
return text, bool(msg["result"].get("isError"))
raise RuntimeError("the address stayed busy")
def proof_of(text):
try:
a = json.loads(text)
except ValueError:
return None
if not isinstance(a, dict):
return None
return a.get("run_seal") or a.get("solution_seal")
def compare(held, now):
if held == now:
return "same bytes"
ph, pn = proof_of(held), proof_of(now)
if ph is not None and ph == pn:
return "same proof"
if ph is None and pn is None:
nh, nn = NAME.findall(held), NAME.findall(now)
if nh and nn and nh[-1] == nn[-1]:
return "same stop"
return "differs"
def rows(files):
for path in files:
with open(path, encoding="utf-8") as f:
for line in f:
if line.strip():
yield path, json.loads(line)
def main(argv):
here = os.path.dirname(os.path.abspath(__file__))
files = [os.path.join(here, "..", "data", "cards.jsonl"), os.path.join(here, "..", "data", "solvers.jsonl")]
address, ids, model, sample = ADDRESS, [], None, None
it = iter(argv)
for arg in it:
if arg == "--address":
address = next(it)
elif arg == "--model":
model = next(it)
elif arg == "--sample":
sample = int(next(it))
elif arg in ("-h", "--help"):
print(__doc__)
return 0
else:
ids.append(arg)
if not ids and model is None and sample is None:
print(__doc__)
return 2
seen, differs, count = {}, 0, 0
for path, row in rows(files):
seen[path] = seen.get(path, 0) + 1
if ids and row["id"] not in ids:
continue
if model and row["model"] != model:
continue
if sample is not None and not ids and not model and seen[path] > sample:
continue
count += 1
result = []
for side in ("inside", "outside"):
text, _ = ask(address, row["tool"], json.loads(row[side + "_request"]))
verdict = compare(row[side + "_answer"], text)
differs += verdict == "differs"
result.append("%s: %s" % (side, verdict))
time.sleep(0.5)
print("%s %s %s %s" % (row["id"], row["model"], row["input"], "; ".join(result)))
print("result: %d rows asked again, %d answers differ" % (count, differs))
return 1 if differs or not count else 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
|