interplane-mv
INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.
Brought by drakestapleton
GitHub aien-dev/interplane-mv#64 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/interplane-mv/patches/e8708d3936e2f9eb.bundle -o e8708d3936e2f9eb.bundle git fetch e8708d3936e2f9eb.bundle refs/pull/64/head
Provenance
github-import 1
aien-dev/interplane-mv
64
34303eabdcc878138409191ed91c9c28a511f3be
{"kind":"github-import","owner":"aien-dev","repo":"interplane-mv","number":64,"url":"https://github.com/aien-dev/interplane-mv/pull/64","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:09Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/bench/tools/analyze.py b/bench/tools/analyze.py index 6e0c7c2..d4c8791 100644 --- a/bench/tools/analyze.py +++ b/bench/tools/analyze.py @@ -106,17 +106,30 @@ def boot_ci(deltas: list, seed: int = BOOT_SEED, n_boot: int = BOOT_N) -> dict: # ------------------------------------------------------------------------------- loading +R1_REQUIRED = ("B5",) # conditions whose receipts must carry the R1 fields (bench_eval.r1_problems) + + def load_run(run_dir: Path, tasks_dir: Path) -> dict: manifest = json.loads((run_dir / "manifest.json").read_text(encoding="utf-8")) if (run_dir / "manifest.json").exists() else {} - rec = {} + rec, r1_invalid = {}, [] for p in sorted((run_dir / "receipts").glob("*.json")): r = json.loads(p.read_text(encoding="utf-8")) rec.setdefault(r["task"]["id"], {})[r["condition"]] = r + if r["condition"] in R1_REQUIRED and not bench_eval.r1_valid(r): # PREREG-0.2y: B5 without R1 fields is invalid + r1_invalid.append({"task": r["task"]["id"], "condition": r["condition"], "problems": bench_eval.r1_problems(r)}) tasks = {} for p in sorted(tasks_dir.glob("*.json")): t = json.loads(p.read_text(encoding="utf-8")) tasks[t["id"]] = t - return {"manifest": manifest, "receipts": rec, "tasks": tasks} + return {"manifest": manifest, "receipts": rec, "tasks": tasks, "r1_invalid": r1_invalid} + + +def refuse_r1_invalid(data: dict, label: str) -> None: + """PREREG-0.2y validity: no run with an unrecorded query or text counts. The analyzer refuses the + whole run rather than scoring around it.""" + if data["r1_invalid"]: + raise SystemExit(f"{label}: {len(data['r1_invalid'])} B5 receipt(s) without valid R1 fields, run not scored: " + + json.dumps(data["r1_invalid"][:5])) def pair_class(a: bool, b: bool) -> str: @@ -251,6 +264,7 @@ def gates(rows: list, expected_n: int) -> dict: def build(run_dir: Path, tasks_dir: Path, exclude: list, exclude_reason: str) -> dict: data = load_run(run_dir, tasks_dir) + refuse_r1_invalid(data, run_dir.name) tasks, rec = data["tasks"], data["receipts"] rows = [] for tid in sorted(rec): @@ -590,6 +604,8 @@ def build_campaign(gate_dir: Path, stab_dirs: list, tasks_dir: Path) -> dict: for i, d in enumerate(stab_dirs): runs[f"stability{i + 1}"] = load_run(d, tasks_dir) labels[f"stability{i + 1}"] = d.name + for k, r in runs.items(): + refuse_r1_invalid(r, labels[k]) out: dict = {"kind": "interplane_bench_campaign_summary", "gate_seed_dir": labels["gate"], "stability_dirs": [labels[k] for k in labels if k != "gate"], "arms": {}} out["blocks"] = {k: {"seed": (r["manifest"].get("campaign") or {}).get("seed"), diff --git a/bench/tools/bench_eval.py b/bench/tools/bench_eval.py index ed3b7fa..683c3c9 100644 --- a/bench/tools/bench_eval.py +++ b/bench/tools/bench_eval.py @@ -203,3 +203,30 @@ def run_metrics(task: dict, condition: str, run: dict) -> dict: "tool_schema_bytes_per_round_mean": (sum(r["tools_bytes"] for r in rounds) / n_rounds) if n_rounds else None, "infra_failure": bool(run.get("infra_failure")), } + + +def r1_problems(receipt: dict) -> list: + """R1 receipt fields (PREREG-0.2y section 2): the full assistant text of every round and the + query string of every discovery call. Returns the problems found; an empty list means valid. + A B5 receipt with any problem is invalid (the analyzer must exclude the run).""" + bad = [] + if not receipt.get("rounds"): + bad.append("no rounds recorded") + for r in receipt.get("rounds") or []: + if not isinstance(r.get("text"), str): + bad.append(f"round {r.get('round')}: no text") + for c in receipt.get("calls") or []: + if not c.get("discovery"): + continue + where = f"round {c.get('round')} call {c.get('index')}" + if "query" not in c: + bad.append(f"{where}: discovery call without query") + elif not isinstance(c["query"], str) and c.get("error_code") != "invalid_arguments": + # a non-string query is valid only as the model's own malformed call, which the + # runner records as an invalid_arguments error; anything else is a recording fault + bad.append(f"{where}: query is not a string and the call is not an invalid_arguments error") + return bad + + +def r1_valid(receipt: dict) -> bool: + return not r1_problems(receipt) diff --git a/bench/tools/run_bench.py b/bench/tools/run_bench.py index ffe056b..828a963 100644 --- a/bench/tools/run_bench.py +++ b/bench/tools/run_bench.py @@ -70,6 +70,22 @@ from interplane_adapter_odysseus.mapping import mapping_table # noqa: E402 RECEIPT_VERSION = "0.2.0" DISCOVERY = bench_eval.DISCOVERY_TOOL ALWAYS_INCLUDE = ["ask_user"] +# PREREG-0.2y section 2 (F1): condition B5 pins this frozen base set instead of ALWAYS_INCLUDE. +B5_ALWAYS_INCLUDE = ["ask_user", "ls", "glob", "grep", "read_file"] +BASE_SETS = {"B5": B5_ALWAYS_INCLUDE} # condition id -> always_include; every other condition uses ALWAYS_INCLUDE + + +def always_include_for(cond: str) -> list: + return BASE_SETS.get(cond, ALWAYS_INCLUDE) + + +def check_base_sets(catalog, conds) -> None: + """Refuse to start when a pinned base set names a tool the catalog does not have.""" + names = {c.name for c in catalog.capabilities} + for cond in conds: + missing = [n for n in BASE_SETS.get(cond, []) if n not in names] + if missing: + raise SystemExit(f"condition {cond}: base set names not in the catalog: {missing}") FROZEN_PROMPT_SHA = "207dd449409bacd6260943a1d918087334d9601586c1e2f069bf9336aaf647f5" ODYSSEUS_COMMIT = "2992bf6" DISCOVERY_SPEC = { @@ -280,11 +296,13 @@ EXPANSION_POLICIES = ("0.2", RUNTIME_POLICY) # PROTOCOL-0.2x.md section 4: one id per condition. The id fixes family (judge, rendering), prompt # addendum, reasoning switch and expansion policy. "B" is the 0.2 id (policy from --expansion-policy). CAMPAIGN_CONDITIONS = ("A", "A2", "A4", "B1", "B2", "B3", "B4") # canonical order, section 8 -CONDITION_IDS = ("A", "B") + CAMPAIGN_CONDITIONS[1:] +# B5 (PREREG-0.2y) is explicit only: never part of CAMPAIGN_CONDITIONS, so "all" and the rotation are unchanged. +EXPLICIT_CONDITIONS = ("B5",) +CONDITION_IDS = ("A", "B") + CAMPAIGN_CONDITIONS[1:] + EXPLICIT_CONDITIONS _SPECS = { "A": (False, False, None), "A2": (True, False, None), "A4": (False, True, None), "B": (False, False, "flag"), "B1": (False, False, "0.2"), "B2": (True, False, "0.2"), - "B3": (False, False, RUNTIME_POLICY), "B4": (False, True, "0.2"), + "B3": (False, False, RUNTIME_POLICY), "B4": (False, True, "0.2"), "B5": (False, False, RUNTIME_POLICY), } REASONING_FIELDS = ("reasoning_effort", "chat_template_kwargs") ADDENDUM_REL = Path("prompts") / "discovery-addendum.md" # under the held-out root @@ -296,8 +314,11 @@ def condition_spec(cx: dict, cond: str) -> dict: addendum, off, policy = _SPECS[cond] if policy == "flag": policy = cx["expansion_policy"] - return {"id": cond, "family": cond[0], "addendum": addendum, "reasoning_off": off, + spec = {"id": cond, "family": cond[0], "addendum": addendum, "reasoning_off": off, "expansion_policy": policy if cond[0] == "B" else None} + if cond in BASE_SETS: # only conditions with a pinned base set carry the field: other identities are unchanged + spec["always_include"] = list(BASE_SETS[cond]) + return spec def rotated(conds: list, idx: int) -> list: @@ -462,7 +483,7 @@ def _run(cx: dict, task: dict, cond: str, run_id: str, ws: str) -> dict: all_names = [c.name for c in catalog.capabilities] selection = None if fam == "B": - selection, _ = select(catalog, task["requested_domains"], always_include=ALWAYS_INCLUDE, + selection, _ = select(catalog, task["requested_domains"], always_include=always_include_for(cond), renderer=openai_tools_renderer) def current_names() -> list: @@ -523,6 +544,7 @@ def _run(cx: dict, task: dict, cond: str, run_id: str, ws: str) -> dict: "reasoning_present": bool(msg.get("reasoning") or msg.get("reasoning_content")), "outcome": outcome, "text_digest": text_sha(text) if text else None, + "text": text, # R1 (PREREG-0.2y section 2): the full assistant text of the round "n_tool_calls": len(orig), }) if out is not None and out.outcome != "tool_request": @@ -583,7 +605,8 @@ def _run(cx: dict, task: dict, cond: str, run_id: str, ws: str) -> dict: "argument_keys": keys, "arguments_digest": adig, "request_id": rid, "decision": None, "status": "ok", "error_code": None, "executed": False, "result_digest": None, "result_trust": "trusted_runtime", "result_content_kind": "discovery", "exposed": None, - "synthetic": None, "discovery": True} + "synthetic": None, "discovery": True, + "query": q} # R1: the discovery query exactly as the model sent it (None if absent) if not isinstance(q, str) or not q.strip(): content = {"error": "query must be a non-empty string"} rec["status"], rec["error_code"] = "error", "invalid_arguments" @@ -679,7 +702,7 @@ def make_receipt(cx: dict, task: dict, cond: str, run: dict, attempt: int, prior sel = run["selection"] selection_block = None if sel is not None: - r1 = select(cx["catalog"], task["requested_domains"], always_include=ALWAYS_INCLUDE, renderer=openai_tools_renderer)[0] + r1 = select(cx["catalog"], task["requested_domains"], always_include=always_include_for(cond), renderer=openai_tools_renderer)[0] d = r1.to_dict() d["kind"] = "selection" selection_block = {"round1": d, "round1_digest": selection_digest(r1), "final_digest": selection_digest(sel), @@ -710,6 +733,8 @@ def make_receipt(cx: dict, task: dict, cond: str, run: dict, attempt: int, prior sp = run["spec"] rec["condition_spec"] = {"id": cond, "family": sp["family"], "prompt_addendum": sp["addendum"], "reasoning_off": sp["reasoning_off"], "expansion_policy": sp["expansion_policy"]} + if "always_include" in sp: + rec["condition_spec"]["always_include"] = sp["always_include"] present = sum(1 for r in run["rounds"] if r["reasoning_present"]) rec["reasoning"] = {"off_requested": sp["reasoning_off"], "field": cx["client"].reasoning_field if sp["reasoning_off"] else None, @@ -843,9 +868,18 @@ def build_identity(cx: dict, tasks: list) -> dict: ident["campaign"] = {"corpus": cx["corpus"], "conditions": {c: condition_spec(cx, c) for c in cx["conditions"]}, "addendum_prompt_digest": text_sha(cx["system_prompt_addendum"]), "reasoning_off_field": cx["client"].reasoning_off_fields()} - if cx["expansion_policy"] != "0.2" or "B3" in cx["conditions"]: - ident["expansion_policy"] = {"name": RUNTIME_POLICY if "B3" in cx["conditions"] else cx["expansion_policy"], - **({"applies_to": ["B3"]} if "B3" in cx["conditions"] else {}), "schema_budget_ratio": SCHEMA_BUDGET_RATIO, + rt_conds = [c for c in ("B3", "B5") if c in cx["conditions"]] # B5 is B3 with another base set + base_conds = [c for c in cx["conditions"] if c in BASE_SETS] + if base_conds: # additive: identities of runs without B5 are byte-identical to before + ident["base_sets"] = {c: list(BASE_SETS[c]) for c in base_conds} + for t in tasks: + sel5, caps5 = select(catalog, t["requested_domains"], always_include=BASE_SETS[base_conds[0]], renderer=openai_tools_renderer) + b5_tools = openai_tools_renderer(caps5) + [DISCOVERY_SPEC] + per[t["id"]]["base_set_round1"] = {"selection_digest": selection_digest(sel5), "selected": [c.name for c in caps5], + "tools_digest": digest_of(b5_tools), "tools_bytes": len(jcs(b5_tools).encode())} + if cx["expansion_policy"] != "0.2" or rt_conds: + ident["expansion_policy"] = {"name": RUNTIME_POLICY if rt_conds else cx["expansion_policy"], + **({"applies_to": rt_conds} if rt_conds else {}), "schema_budget_ratio": SCHEMA_BUDGET_RATIO, "full_tools_bytes": cx["full_tools_bytes"], "discover_limit": DISCOVER_LIMIT, "triggers": ["T1", "T2", "T3"], "suppressed": sorted(SUPPRESSED.values())} ident["identity_digest"] = digest_of(ident) @@ -938,7 +972,8 @@ def main(argv=None) -> int: ap.add_argument("--condition", choices=list(CONDITION_IDS) + ["both", "all"], default="both", help="A/B/both = 0.2. A2, A4, B1..B4 = the PROTOCOL-0.2x.md conditions; all = the seven, in order " "A A2 A4 B1 B2 B3 B4 rotated left by (task index mod 7). B3 is arm 3 (runtime-v1), " - "A2/B2 add the discovery addendum, A4/B4 turn reasoning off") + "A2/B2 add the discovery addendum, A4/B4 turn reasoning off. B5 (PREREG-0.2y) = B3 with the " + "base set ask_user ls glob grep read_file; explicit only, never part of all") ap.add_argument("--reasoning-field", choices=list(REASONING_FIELDS), default="reasoning_effort", help="request field that turns reasoning off for A4/B4: reasoning_effort=none (Ollama) or " "chat_template_kwargs.enable_thinking=false (SGLang, llama.cpp)") @@ -995,6 +1030,7 @@ def main(argv=None) -> int: if not ody_commit.startswith(ODYSSEUS_COMMIT) and not args.allow_nonfrozen: raise SystemExit(f"Odysseus is at {ody_commit}, expected {ODYSSEUS_COMMIT}") cx = make_cx(args, tasks_dir, root, conds) + check_base_sets(cx["catalog"], conds) if text_sha(cx["system_prompt"]) != "sha256:" + FROZEN_PROMPT_SHA and not args.allow_nonfrozen: raise SystemExit("prompts/system.md does not match the digest every task pins") corpus = check_corpus(not args.allow_nonfrozen, args.corpus) diff --git a/bench/tools/test_runner_offline.py b/bench/tools/test_runner_offline.py index baa9bc5..35b10b9 100644 --- a/bench/tools/test_runner_offline.py +++ b/bench/tools/test_runner_offline.py @@ -415,6 +415,97 @@ def main() -> int: r = json.loads((hout / "receipts" / f"{tid}.{c}.json").read_text()) assert r["task"]["split"] == "qual" and r["fixture"]["name"].startswith("fixtures/") and r["fixture"]["digest"] assert hm["order_rule"].startswith("tasks in id order; canonical condition order") + # ---- condition B5 (PREREG-0.2y F1) and the R1 receipt fields + base5 = ["ask_user", "ls", "glob", "grep", "read_file"] + assert run_bench.B5_ALWAYS_INCLUDE == base5 and run_bench.ALWAYS_INCLUDE == ["ask_user"] + # existing conditions, order and rotation are untouched: B5 is explicit only + assert run_bench.CAMPAIGN_CONDITIONS == ("A", "A2", "A4", "B1", "B2", "B3", "B4") + assert "B5" in run_bench.CONDITION_IDS and "B5" not in run_bench.CAMPAIGN_CONDITIONS + assert run_bench.always_include_for("B3") == ["ask_user"] and run_bench.always_include_for("B5") == base5 + assert [run_bench.rotated(list(run_bench.CAMPAIGN_CONDITIONS), k) for k in range(3)] == \ + [["A", "A2", "A4", "B1", "B2", "B3", "B4"], ["A2", "A4", "B1", "B2", "B3", "B4", "A"], ["A4", "B1", "B2", "B3", "B4", "A", "A2"]] + assert "always_include" not in run_bench.condition_spec({"expansion_policy": "0.2"}, "B3") + assert all(c in cm["campaign"]["conditions"] and "always_include" not in cm["campaign"]["conditions"][c] for c in conds7) # all: identity has no base set + assert "base_sets" not in cm["deterministic_identity"] and cm["deterministic_identity"]["expansion_policy"]["applies_to"] == ["B3"] + b5dir = Path(td) / "b5tasks" + b5dir.mkdir() + b5t = [task_from("ambiguous-925", "ambiguous-004", "DISCO calendar question", split="dev", requested_domains=["calendar"], + judge={"expected_answer": "x", "checks": [{"kind": "answer_contains_all", "values": ["tide-small"]}]}), + task_from("ambiguous-926", "ambiguous-004", "RT-T2 calendar question", split="dev", requested_domains=["calendar"])] + for t in b5t: + (b5dir / f"{t['id']}.json").write_text(json.dumps(t)) + + def run_b5(cond, name, *extra): + o = Path(td) / name + assert run_bench.main(["--tasks", "dev", "--condition", cond, "--endpoint", ep, "--out", str(o), "--tasks-dir", str(b5dir), + "--allow-nonfrozen", "--no-warmup", "--backends", "sim-1", *extra]) == 0 + return o, json.loads((o / "manifest.json").read_text()) + o5, m5 = run_b5("B5", "b5run") + o3, m3 = run_b5("B3", "b3run") + assert m5["conditions"] == ["B5"] and m5["campaign"]["conditions"]["B5"]["always_include"] == base5 + assert m5["deterministic_identity"]["base_sets"] == {"B5": base5} and m5["expansion_policy"]["applies_to"] == ["B5"] + assert "base_sets" not in m3["deterministic_identity"] + assert m3["deterministic_identity"]["identity_digest"] != m5["deterministic_identity"]["identity_digest"] + for tid in ("ambiguous-925", "ambiguous-926"): + r5 = json.loads((o5 / "receipts" / f"{tid}.B5.json").read_text()) + r3 = json.loads((o3 / "receipts" / f"{tid}.B3.json").read_text()) + assert r5["condition_spec"]["expansion_policy"] == "runtime-v1" and r5["condition_spec"]["always_include"] == base5 + assert "always_include" not in r3["condition_spec"] + ex5, ex3 = r5["rounds"][0]["exposed_names"], r3["rounds"][0]["exposed_names"] + assert set(base5) <= set(ex5) and r5["discovery_tool"] == run_bench.DISCOVERY, ex5 + assert not ({"ls", "glob", "grep"} & set(ex3)), ex3 # B3 keeps the ask_user-only base set + assert set(ex3) < set(ex5) # B5 is B3 plus the base set and nothing else + assert r5["selection"]["round1"]["selected"] and set(base5) <= {e["name"] for e in r5["selection"]["round1"]["selected"]} + # R1: full assistant text of every round, query of every discovery call; existing fields unchanged + r5 = json.loads((o5 / "receipts" / "ambiguous-925.B5.json").read_text()) + assert r5["rounds"][-1]["text"] == "tide-small, tide-large, whisper-batch" + assert all(isinstance(r["text"], str) and "text_digest" in r for r in r5["rounds"]) + dq = [c for c in r5["calls"] if c["discovery"]] + assert dq and dq[0]["query"] == "serve preset" and "arguments_digest" in dq[0], r5["calls"] + assert bench_eval.r1_valid(r5) and bench_eval.r1_problems(r5) == [] + for rr in (json.loads(p.read_text()) for p in (out / "receipts").glob("*.B.json")): # the 0.2 path carries R1 too + assert bench_eval.r1_valid(rr) + # a receipt missing R1 fields is invalid (the analyzer drops it for B5) + stripped = copy.deepcopy(r5) + for r in stripped["rounds"]: + del r["text"] + for c in stripped["calls"]: + c.pop("query", None) + assert not bench_eval.r1_valid(stripped) and len(bench_eval.r1_problems(stripped)) == len(stripped["rounds"]) + len(dq) + import analyze + shutil_copy = Path(td) / "b5bad" + (shutil_copy / "receipts").mkdir(parents=True) + (shutil_copy / "receipts" / "ambiguous-925.B5.json").write_text(json.dumps(stripped)) + (shutil_copy / "receipts" / "ambiguous-926.B5.json").write_text((o5 / "receipts" / "ambiguous-926.B5.json").read_text()) + ld = analyze.load_run(shutil_copy, b5dir) + assert [x["task"] for x in ld["r1_invalid"]] == ["ambiguous-925"] and ld["r1_invalid"][0]["condition"] == "B5" + assert analyze.load_run(o5, b5dir)["r1_invalid"] == [] + # the analyzer refuses a run holding an invalid B5 receipt instead of scoring around it + try: + analyze.build(shutil_copy, b5dir, [], "") + raise AssertionError("build scored a run with an invalid B5 receipt") + except SystemExit as e: + assert "without valid R1 fields" in str(e), e + # no rounds is invalid; a non-string query is valid only as a recorded invalid_arguments call + assert bench_eval.r1_problems({"rounds": [], "calls": []}) == ["no rounds recorded"] + assert not bench_eval.r1_valid({k: v for k, v in r5.items() if k != "rounds"}) + nullq = copy.deepcopy(r5) + nc = [c for c in nullq["calls"] if c["discovery"]][0] + nc["query"] = None + assert not bench_eval.r1_valid(nullq), "a null query on an ok call must be invalid" + nc["status"], nc["error_code"] = "error", "invalid_arguments" + assert bench_eval.r1_valid(nullq), "the model's own malformed call, recorded as such, is valid" + # the base set is verified against the catalog: a name the catalog lacks refuses the run + saved_sets = dict(run_bench.BASE_SETS) + run_bench.BASE_SETS["B5"] = base5 + ["no_such_tool"] + try: + run_b5("B5", "b5bad") + raise AssertionError("accepted a base set naming a tool the catalog lacks") + except SystemExit as e: + assert "no_such_tool" in str(e), e + finally: + run_bench.BASE_SETS.clear() + run_bench.BASE_SETS.update(saved_sets) # resume: nothing is rerun before = len(Handler.log) run_bench.main(["--tasks", "dev", "--condition", "both", "--endpoint", f"http://127.0.0.1:{srv.server_port}/v1",