Viewing files at commit fcd8a785ee1aCommit detailsView latest

Browse files
scripts/oakbench/public_output.py 101 lines · 5.8 KB · python
1
"""Evidence requirements for publishing output-usefulness measurements.
2
3
Legacy structural markers remain diagnostic data. They cannot certify that
4
standard patch tooling reconstructs the intended repository tree.
5
"""
6
7
from __future__ import annotations
8
9
from typing import Any
10
import math
11
import re
12
13
from oakbench.output_semantics import OUTPUT_ORACLE_VERSION, PATCH_ORACLE_VERSION
14
from oakbench.workflow_oracles import SCENARIOS as TRUSTED_WORKFLOWS, VERSION as WORKFLOW_ORACLE_VERSION
15
16
17
def output_evidence_failures(row: dict[str, Any]) -> list[str]:
18
    failures: list[str] = []
19
    for flag in ("pipe_compatible_unified", "patch_apply_ok", "patch_tree_matches", "patch_application_required"):
20
        if row.get(flag) is not None and type(row[flag]) is not bool:
21
            failures.append(f"{flag} is not a nullable boolean")
22
    for metric, source in (
23
        ("information_recall", "information_recall_source"),
24
        ("information_precision", "information_precision_source"),
25
    ):
26
        value = row.get(metric)
27
        if value is not None and (
28
            type(value) not in (int, float) or not math.isfinite(value) or not 0 <= value <= 1
29
        ):
30
            failures.append(f"{metric} is not a finite fraction")
31
        if row.get(metric) is not None and (
32
            row.get("output_oracle_version") != OUTPUT_ORACLE_VERSION
33
            or row.get(source) != "exact_metadata_path_set"
34
        ):
35
            failures.append(f"{metric} lacks versioned exact-path evidence")
36
37
    claims_applicability = row.get("patch_application_required") is True or row.get("patch_apply_ok") is True
38
    if claims_applicability and not (
39
        row.get("patch_apply_ok") is True
40
        and row.get("patch_tree_matches") is True
41
        and row.get("patch_apply_returncode") == 0
42
        and type(row.get("patch_apply_returncode")) is int
43
        and row.get("patch_oracle_version") == PATCH_ORACLE_VERSION
44
        and row.get("patch_apply_source") == "git_apply_exact_tree"
45
        and isinstance(row.get("patch_instrument_sha256"), str)
46
        and re.fullmatch(r"[0-9a-f]{64}", row["patch_instrument_sha256"])
47
        and isinstance(row.get("patch_instrument_version"), str)
48
        and row["patch_instrument_version"].strip()
49
        and not row.get("patch_skip_reason")
50
        and not row.get("patch_failure_reason")
51
        and not row.get("probe_output_truncated")
52
        and not row.get("output_truncated")
53
    ):
54
        failures.append("structural/applicability success lacks a successful exact-tree patch application")
55
    return failures
56
57
58
def workflow_evidence_failures(rows: list[dict[str, Any]]) -> list[str]:
59
    """Require independent persisted-state evidence for trusted payload tasks.
60
61
    Source labels describe how observations were obtained; they are not
62
    equivalence classes. Every workflow summary must pass its measured oracle.
63
    In particular, this rule does not certify bugfix_test_loop persistence.
64
    """
65
    groups = {}
66
    failures = []
67
    for row in rows:
68
        if row.get("operation") in {"agent.workflow", "workflow.total"}:
69
            if (row.get("workflow_integrity_passed") is not True or row.get("returncode") != 0
70
                    or row.get("skipped") or row.get("success") is False
71
                    or row.get("correctness_passed") is False):
72
                failures.append(f"{row.get('subject')}/{row.get('scenario')}: workflow correctness is failed, skipped or unmeasured")
73
        if row.get("operation") in {"agent.workflow", "workflow.total"} and row.get("workflow_integrity_evidence_class") == "independent_committed_tree":
74
            instrument = row.get("git_head_instrument_sha256")
75
            subject = row.get("workflow_subject_binary_sha256")
76
            if (not all(isinstance(value, str) and re.fullmatch(r"[0-9a-f]{64}", value) for value in (instrument, subject))
77
                    or instrument == subject or "subject_produced" in str(row.get("workflow_integrity_source", ""))):
78
                failures.append("independent reader lacks distinct observed subject/instrument identities or uses subject-produced evidence")
79
        if row.get("operation") not in {"agent.workflow", "workflow.total"} or row.get("scenario") not in TRUSTED_WORKFLOWS:
80
            continue
81
        agent = row.get("agent") if isinstance(row.get("agent"), dict) else {}
82
        key = (row.get("scenario"), row.get("operation"), row.get("benchmark_track"),
83
               row.get("instruction_level", agent.get("instruction_level")),
84
               agent.get("name"), agent.get("model"), agent.get("provider"),
85
               agent.get("environment"))
86
        groups.setdefault(key, []).append(row)
87
    for key, items in groups.items():
88
        if len({item.get("subject") for item in items}) < 2:
89
            continue
90
        if any(item.get("oracle_version") != WORKFLOW_ORACLE_VERSION for item in items):
91
            failures.append(f"{key}: trusted task validator version is incompatible or missing")
92
        if any(item.get("workflow_integrity_evidence_class") != "independent_committed_tree" for item in items):
93
            failures.append(f"{key}: trusted persisted-state comparison requires independent committed-tree readers; subject-produced exports and metadata are insufficient")
94
        if any(not isinstance(item.get("workflow_integrity_source"), str) or not item["workflow_integrity_source"].strip() for item in items):
95
            failures.append(f"{key}: correctness evidence source is missing")
96
        if any("subject_produced" in str(item.get("workflow_integrity_source", ""))
97
               and item.get("workflow_integrity_evidence_class") == "independent_committed_tree" for item in items):
98
            failures.append(f"{key}: subject-produced evidence cannot declare an independent reader class")
99
        if any(item.get("workflow_integrity_passed") is not True for item in items):
100
            failures.append(f"{key}: correctness evidence is failed or unmeasured")
101
    return failures