spiderpilot89's picture
Edges: the two runs either side of where each model stops (936 rows, asked 2026-10-13 UTC)
5d12f8c verified
Raw History Blame Contribute Delete
5.83 kB
#!/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:]))