File size: 3,875 Bytes
7415d8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
from __future__ import annotations

import csv
import gzip
import hashlib
import json
import re
from pathlib import Path


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


def sha256(path: Path) -> str:
    digest = hashlib.sha256()
    with path.open("rb") as handle:
        for block in iter(lambda: handle.read(1024 * 1024), b""):
            digest.update(block)
    return digest.hexdigest()


errors: list[str] = []

tasks = list(
    csv.DictReader(
        (ROOT / "task_pool/TASK_INVENTORY_47.csv").open(encoding="utf-8-sig")
    )
)
runs = list(
    csv.DictReader(
        (ROOT / "trajectories/TRAJECTORY_INDEX.csv").open(encoding="utf-8")
    )
)

project_ids = {row["project_id"] for row in tasks}
task_ids = {row["task_id"] for row in runs}
settings = {(row["base_model"], row["agent"]) for row in runs}

if len(tasks) != 47 or len(project_ids) != 47:
    errors.append("task inventory is not 47 unique projects")
if len(runs) != 423 or len(task_ids) != 423:
    errors.append("trajectory index is not 423 unique assignments")
if len(settings) != 9:
    errors.append("trajectory index is not nine unique model-agent settings")
if {row["project"] for row in runs} != project_ids:
    errors.append("trajectory projects do not match the task inventory")

strong_patterns = {
    "local_path": re.compile(r"/Users/ssp|/lustre/prod_glm_volumes"),
    "api_key": re.compile(r"(?<![A-Za-z0-9])sk-(?:ant-)?[A-Za-z0-9_-]{12,}"),
    "service_token": re.compile(
        r"(?<![A-Za-z0-9])(?:ghp_[A-Za-z0-9]{20,}|"
        r"github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{20,}|"
        r"hf_[A-Za-z0-9]{30,})"
    ),
    "authorization": re.compile(
        r"(?i)authorization\s*[:=]\s*(?:bearer|basic)\s+"
        r"(?!<REDACTED>)[A-Za-z0-9][A-Za-z0-9._~+/-]{7,}"
    ),
    "private_key": re.compile(r"BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY"),
}

for row in runs:
    log = ROOT / row["trajectory_path"]
    if not log.is_file():
        errors.append(f"missing trajectory: {row['task_id']}")
        continue
    if log.name != "agent.log.gz":
        errors.append(f"unexpected trajectory filename: {row['task_id']}")
    if sha256(log) != row["released_log_sha256"]:
        errors.append(f"trajectory hash mismatch: {row['task_id']}")
        continue
    try:
        with gzip.open(log, "rt", encoding="utf-8", errors="replace") as handle:
            for line_number, line in enumerate(handle, 1):
                matched = False
                for name, pattern in strong_patterns.items():
                    if pattern.search(line):
                        errors.append(
                            f"residual {name}: {row['task_id']}:{line_number}"
                        )
                        matched = True
                        break
                if matched:
                    break
    except (OSError, EOFError) as exc:
        errors.append(f"unreadable gzip: {row['task_id']}: {exc}")

manifest = json.loads((ROOT / "DATASET_MANIFEST.json").read_text(encoding="utf-8"))
if manifest.get("task_count") != 47:
    errors.append("manifest task count is not 47")
if manifest.get("model_agent_setting_count") != 9:
    errors.append("manifest setting count is not nine")
if manifest.get("trajectory_file_count") != 423:
    errors.append("manifest trajectory count is not 423")

checksum_file = ROOT / "DATASET_SHA256SUMS"
for raw in checksum_file.read_text(encoding="utf-8").splitlines():
    expected, relative = raw.split("  ", 1)
    path = ROOT / relative
    if not path.is_file() or sha256(path) != expected:
        errors.append(f"dataset checksum mismatch: {relative}")

if errors:
    print("verification FAILED")
    for error in errors[:50]:
        print("-", error)
    raise SystemExit(1)

print(
    "verification OK: "
    f"tasks={len(tasks)} settings={len(settings)} trajectories={len(runs)}"
)