Viewing files at commit 2735d7f5558eCommit detailsView latest

Browse files
scripts/oakbench/public_output.py 90 lines · 4.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. Non-trusted workflows retain their existing gates.
63
    In particular, this rule does not certify bugfix_test_loop persistence.
64
    """
65
    groups = {}
66
    for row in rows:
67
        if row.get("operation") not in {"agent.workflow", "workflow.total"} or row.get("scenario") not in TRUSTED_WORKFLOWS:
68
            continue
69
        agent = row.get("agent") if isinstance(row.get("agent"), dict) else {}
70
        key = (row.get("scenario"), row.get("operation"), row.get("benchmark_track"),
71
               row.get("instruction_level", agent.get("instruction_level")),
72
               agent.get("name"), agent.get("model"), agent.get("provider"),
73
               agent.get("environment"))
74
        groups.setdefault(key, []).append(row)
75
    failures = []
76
    for key, items in groups.items():
77
        if len({item.get("subject") for item in items}) < 2:
78
            continue
79
        if any(item.get("oracle_version") != WORKFLOW_ORACLE_VERSION for item in items):
80
            failures.append(f"{key}: trusted task validator version is incompatible or missing")
81
        if any(item.get("workflow_integrity_evidence_class") != "independent_committed_tree" for item in items):
82
            failures.append(f"{key}: trusted persisted-state comparison requires independent committed-tree readers; subject-produced exports and metadata are insufficient")
83
        if any(not isinstance(item.get("workflow_integrity_source"), str) or not item["workflow_integrity_source"].strip() for item in items):
84
            failures.append(f"{key}: correctness evidence source is missing")
85
        if any("subject_produced" in str(item.get("workflow_integrity_source", ""))
86
               and item.get("workflow_integrity_evidence_class") == "independent_committed_tree" for item in items):
87
            failures.append(f"{key}: subject-produced evidence cannot declare an independent reader class")
88
        if any(item.get("workflow_integrity_passed") is not True for item in items):
89
            failures.append(f"{key}: correctness evidence is failed or unmeasured")
90
    return failures