File size: 4,006 Bytes
3b92b73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Derive the graph-free direct GPT-OSS baseline from saved model choices.

This script performs no inference and loads no benchmark labels.  It releases a
case iff the frozen primary GPT-OSS choice is NONE; otherwise it reviews only
the selected component.  Governance actions use the benchmark's public,
deterministic authority/event router shared by the open-weight reference arms.
"""

from __future__ import annotations

import argparse
import json
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]


def load_jsonl(path: Path) -> list[dict]:
    return [json.loads(line) for line in path.read_text().splitlines() if line.strip()]


def default_measurements() -> Path:
    released = ROOT / "results/open_weight/gptoss20b_direct_measurements.jsonl"
    if released.exists():
        return released
    return ROOT / "results/open_weight_full_archive/gptoss20b_open_weight_token_sseg_measurements.jsonl"


def input_rows() -> list[dict]:
    base = ROOT / "closed_loop_inputs" if (ROOT / "closed_loop_inputs").exists() else ROOT / "hf/closed_loop_inputs"
    return sorted(
        (row for split in ("development", "validation", "test") for row in load_jsonl(base / f"{split}.jsonl")),
        key=lambda row: row["case_id"],
    )


def action_for(row: dict, release: bool) -> str:
    if release:
        return "release"
    trigger = row["event"]["trigger_category"]
    tier = row["workflow_context"]["authority_tier"]
    if any(c.get("status") == "failed" and not c.get("compensable", True) for c in row.get("red_line_controls", [])):
        return "suspend"
    if trigger == "tool_permission":
        return "restrict" if tier.startswith("C") else "scoped_revalidation"
    if trigger == "incident_near_miss":
        return "withhold"
    if trigger in {"performance_behaviour", "model_vendor"}:
        return "escalate"
    if trigger == "prompt_policy_orchestration":
        return "withhold"
    if trigger == "purpose_population":
        return "scoped_revalidation"
    if trigger == "memory_data":
        return "rollback" if tier.startswith("A") else ("withhold" if row["domain"] == "market_data" else "scoped_revalidation")
    return "escalate"


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("--measurements", type=Path, default=default_measurements())
    parser.add_argument("--output", type=Path, default=ROOT / "results/open_weight/direct_llm.jsonl")
    args = parser.parse_args()
    measurements = {row["case_id"]: row for row in load_jsonl(args.measurements)}
    predictions = []
    for row in input_rows():
        measurement = measurements[row["case_id"]]
        primary = measurement["observed_primary"]
        selected = primary.get("selected_node") or "NONE"
        release = selected == "NONE"
        scope = [] if release else [selected]
        predictions.append({
            "case_id": row["case_id"],
            "method": "direct_llm",
            "model": measurement.get("model_requested", "openai/gpt-oss-20b"),
            "measurement_channel": "frozen primary model choice; no probability gate or graph propagation",
            "iceberg_detected": not release,
            "governance_action": action_for(row, release),
            "affected_components": scope,
            "revalidation_components": scope,
            "reviewed_components": scope,
            "release_permitted": release,
            "diagnostic": {"selected_code": primary.get("selected_code"), "selected_node": selected},
        })
    args.output.parent.mkdir(parents=True, exist_ok=True)
    args.output.write_text("".join(json.dumps(row, sort_keys=True) + "\n" for row in predictions))
    print(json.dumps({
        "method": "direct_llm",
        "predictions": len(predictions),
        "model_calls": 0,
        "uses_probability_gate": False,
        "uses_graph_propagation": False,
        "output": str(args.output),
    }, indent=2))


if __name__ == "__main__":
    main()