tailot's picture
thinking-python: reference implementation, corpus and gates
4bc63c7 verified
Raw History Blame Contribute Delete
1.85 kB
"""Node: arbiter. Derives the verdict from what the two checkers said.
Assurance is a property of the run, not of the claim: level 3 needs both independent
checkers to agree, and they must not have read each other.
"""
import json
import sys
LEVELS = ("REFUSED", "UNKNOWN", "SINGLE_PROVER", "VERIFIED")
def combine(nodes):
"""nodes: list of envelopes in pipeline order. Returns verdict, assurance, reasons."""
reasons = []
for node in nodes:
reasons.extend(node.get("reasons") or [])
if node.get("reason"):
reasons.append(node["reason"])
reasons = sorted(set(r for r in reasons if r))
by_name = {node.get("node", ""): node for node in nodes}
intent = by_name.get("intent", {})
locator = by_name.get("locator", {})
planner = by_name.get("planner", {})
executor = by_name.get("executor", {})
checker = by_name.get("gate_checker", {})
adversary = by_name.get("adversary", {})
if intent.get("status") == "refused" or locator.get("status") == "refused":
return "REFUSED", 0, reasons
if executor.get("status") == "refused" or planner.get("status") == "refused":
return "REFUSED", 0, reasons
passed = checker.get("status") == "pass"
survived = adversary.get("status") == "survived"
if passed and survived:
return "VERIFIED", 3, reasons
if passed or survived:
return "SINGLE_PROVER", 2, reasons
return "REFUSED", 1, reasons + ["CHECKER_ABSTAIN"]
def main() -> int:
task = json.load(sys.stdin)
verdict, assurance, reasons = combine(task.get("nodes") or [])
print(json.dumps({"node": "arbiter", "status": verdict.lower(), "verdict": verdict,
"assurance": assurance, "reasons": reasons}))
return 0 if verdict == "VERIFIED" else 1
if __name__ == "__main__":
raise SystemExit(main())