File size: 7,749 Bytes
c406af5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
from __future__ import annotations

import hashlib
import json
import re
from pathlib import Path

from pypdf import PdfReader


ROOT = Path(__file__).resolve().parents[1]
RESULTS = ROOT / "results"
PAPER_SOURCE = ROOT / "paper" / "paper.md"
PAPER_PDF = ROOT / "paper" / "paper.pdf"
EXPECTED_STUDY = "permission-safe-planning-locked-v2-2026-09"
CONDITIONS = {"no_wiki", "flat_history", "persistent_wiki"}


class VerificationError(RuntimeError):
    pass


def load_object(path: Path) -> dict:
    value = json.loads(path.read_text(encoding="utf-8"))
    if not isinstance(value, dict):
        raise VerificationError(f"object expected: {path}")
    return value


def sha_text(value: str) -> str:
    return "sha256:" + hashlib.sha256(value.encode("utf-8")).hexdigest()


def semantic_material(entry: dict) -> dict:
    return {
        "id": entry["entry_id"],
        "proposalId": entry["proposal_id"],
        "comparisonId": entry["comparison_id"],
        "action": entry["action"],
        "decision": entry["decision"],
        "targetKind": entry["target_kind"],
        "targetPath": entry["target_path"],
        "previousDigest": entry["previous_digest"],
        "candidateDigest": entry["candidate_digest"],
        "metrics": entry["metrics"],
        "context": entry["context"],
        "evidenceRefs": entry["evidence_refs"],
        "patternIds": entry["pattern_ids"],
        "securityAttestationDigest": entry["security_attestation_digest"],
        "note": entry["note"],
        "previousEntryDigest": entry["previous_entry_digest"],
        "createdAt": entry["created_at"],
    }


def verify_summary() -> tuple[dict, dict[str, dict]]:
    summary = load_object(RESULTS / "summary.json")
    manifest = load_object(RESULTS / "manifest.json")
    if summary.get("study_id") != EXPECTED_STUDY or manifest.get("study_id") != EXPECTED_STUDY:
        raise VerificationError("study identity mismatch")
    if not manifest.get("completed_at"):
        raise VerificationError("manifest is incomplete")
    if manifest.get("result_rows") != 9 or manifest.get("ledger_entries") != 36:
        raise VerificationError("manifest counts changed")

    rows = summary.get("rows")
    if not isinstance(rows, list) or len(rows) != 9:
        raise VerificationError("expected nine result rows")
    keys = {(row["condition"], row["replicate"]) for row in rows}
    expected = {(condition, replicate) for condition in CONDITIONS for replicate in (1, 2, 3)}
    if keys != expected:
        raise VerificationError("condition-replicate matrix is incomplete")
    if sum(row["model_calls"] for row in rows) + summary["shared_baseline_transfer_costs"]["model_calls"] != 87:
        raise VerificationError("completed model-call count changed")
    if any(row["tool_calls"] != 0 for row in rows):
        raise VerificationError("tool-call claim changed")

    aggregates = {row["condition"]: row for row in summary["aggregates"]}
    if set(aggregates) != CONDITIONS:
        raise VerificationError("aggregate conditions changed")
    persistent = aggregates["persistent_wiki"]
    flat = aggregates["flat_history"]
    computed = {
        "persistent_minus_flat_task_quality": round(
            persistent["mean_task_quality"] - flat["mean_task_quality"], 4
        ),
        "persistent_minus_flat_input_tokens": round(
            persistent["mean_input_tokens"] - flat["mean_input_tokens"], 4
        ),
        "persistent_minus_flat_rollbacks": round(
            persistent["mean_rollback_count"] - flat["mean_rollback_count"], 4
        ),
        "persistent_minus_flat_target_skill_gain": round(
            persistent["mean_target_skill_gain"] - flat["mean_target_skill_gain"], 4
        ),
    }
    if computed != summary["contrasts"]:
        raise VerificationError("registered contrasts do not recompute")
    return summary, aggregates


def verify_ledger() -> None:
    ledger = load_object(RESULTS / "skill-impact-ledger.json")
    if ledger.get("schema_version") != "rew.skill-impact-ledger.v1":
        raise VerificationError("ledger schema changed")
    entries = ledger.get("entries")
    if not isinstance(entries, list) or len(entries) != 36:
        raise VerificationError("expected 36 ledger entries")
    previous = None
    for entry in entries:
        material_text = entry.get("digest_material")
        if not isinstance(material_text, str):
            raise VerificationError("ledger entry has no canonical digest material")
        if json.loads(material_text) != semantic_material(entry):
            raise VerificationError(f"ledger semantic mismatch: {entry.get('entry_id')}")
        if entry.get("previous_entry_digest") != previous:
            raise VerificationError(f"ledger chain mismatch: {entry.get('entry_id')}")
        digest = sha_text(material_text)
        if entry.get("entry_digest") != digest:
            raise VerificationError(f"ledger digest mismatch: {entry.get('entry_id')}")
        previous = digest
    if ledger.get("last_entry_digest") != previous:
        raise VerificationError("ledger terminal digest mismatch")

    skillops = load_object(RESULTS / "skillops" / "runtime-evolution-summary.json")
    if skillops.get("chain_verified") is not True or skillops.get("entries_verified") != 36:
        raise VerificationError("SkillOps verification is incomplete")
    if skillops.get("last_entry_digest") != previous:
        raise VerificationError("SkillOps terminal digest differs")


def verify_public_cleanliness() -> None:
    patterns = [
        re.compile(r"[A-Za-z]:\\"),
        re.compile(r"/Users/"),
        re.compile(r"\\Users\\"),
    ]
    for path in list(RESULTS.rglob("*")) + [PAPER_SOURCE, ROOT / "README.md", ROOT / "REPRODUCIBILITY.md"]:
        if not path.is_file():
            continue
        text = path.read_text(encoding="utf-8")
        for pattern in patterns:
            if pattern.search(text):
                raise VerificationError(f"non-public marker in {path}: {pattern.pattern}")
        if re.search(r"\bdraft\b", text, re.IGNORECASE):
            raise VerificationError(f"prohibited status marker in {path}")


def verify_paper(aggregates: dict[str, dict]) -> None:
    source = PAPER_SOURCE.read_text(encoding="utf-8")
    required = [
        "Governed Skill Evolution from Persistent Agent Experience",
        "-2.2867",
        "-10,495.7",
        "+0.3333",
        "+1.9685",
        "87 model calls",
        "36 impact entries",
    ]
    for value in required:
        if value not in source:
            raise VerificationError(f"paper is missing required evidence: {value}")
    for condition, label in (
        ("no_wiki", "87.4158"),
        ("flat_history", "89.6189"),
        ("persistent_wiki", "87.3322"),
    ):
        if f"{aggregates[condition]['mean_task_quality']:.4f}" != label or label not in source:
            raise VerificationError(f"paper table differs for {condition}")
    if not PAPER_PDF.is_file():
        raise VerificationError("paper PDF is absent")
    reader = PdfReader(str(PAPER_PDF))
    if len(reader.pages) < 6:
        raise VerificationError("paper PDF is unexpectedly short")
    metadata = reader.metadata or {}
    if metadata.get("/Author") != "Song Luo":
        raise VerificationError("paper PDF author metadata changed")
    if "Governed Skill Evolution" not in (metadata.get("/Title") or ""):
        raise VerificationError("paper PDF title metadata changed")


def main() -> int:
    _, aggregates = verify_summary()
    verify_ledger()
    verify_public_cleanliness()
    verify_paper(aggregates)
    print("verified 9 result rows, 87 model calls, 36 ledger entries, and paper PDF")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())