agent-bios 0.19.3 → 0.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEPENDENCIES.md +62 -20
- package/INSTALL.md +1 -1
- package/README.md +16 -21
- package/claude/agents/frontier.md +1 -1
- package/claude/agents/sweep.md +2 -1
- package/claude/agents/workhorse.md +2 -2
- package/claude/guides/claude-prompting.md +494 -167
- package/claude/guides/cli-multi-model-workflow.md +8 -7
- package/claude/guides/gpt-prompting.md +241 -111
- package/claude/guides/session-distill-workflow.md +93 -43
- package/claude/guides/tooling-gotchas.md +3 -1
- package/codex/agents/reviewer.toml +2 -2
- package/codex/agents/sweep.toml +1 -1
- package/codex/agents/workhorse.toml +2 -2
- package/codex/guides/claude-prompting.md +494 -167
- package/codex/guides/cli-multi-model-workflow.md +8 -7
- package/codex/guides/gpt-prompting.md +241 -111
- package/codex/guides/session-distill-workflow.md +93 -43
- package/codex/guides/tooling-gotchas.md +3 -1
- package/compose/assemble.py +4 -1
- package/compose/canary.sh +8 -6
- package/compose/host_platform.py +158 -15
- package/compose/instructions-state.py +183 -41
- package/compose/instructions_app.py +2 -2
- package/compose/instructions_install.py +222 -27
- package/compose/instructions_session.py +250 -75
- package/compose/instructions_setup.py +6 -6
- package/compose/instructions_setup_cli.py +2 -36
- package/compose/instructions_setup_i18n.py +3 -3
- package/compose/instructions_store.py +160 -3
- package/compose/instructions_transaction.py +29 -5
- package/compose/instructions_ui_runtime.py +2 -2
- package/compose/setup/START.md +1 -1
- package/docs/advanced-launch.md +4 -0
- package/docs/releases/0.19.4.md +99 -0
- package/docs/releases/0.20.0.md +102 -0
- package/docs/setup.md +4 -4
- package/install.sh +54 -20
- package/launch/agent-launch.py +171 -22
- package/launch/agent-launch.toml +64 -29
- package/launch/agent-launch.zsh +104 -13
- package/launch/claude_subcommands.py +179 -0
- package/launch/provision-venv.sh +1 -1
- package/launch/shell_integration.py +7 -1
- package/learn/collect-learning.py +60 -9
- package/learn/migrate-learnings.py +70 -4
- package/learn/redact.py +2 -1
- package/package.json +37 -4
- package/provenance.json +1 -1
- package/session-cost.py +141 -18
- package/session-distill/coverage.json +6 -0
- package/session-distill/distill.py +2575 -0
- package/session-distill/grammar/__init__.py +0 -0
- package/session-distill/grammar/owner_lines.py +874 -0
- package/session-distill/originators.json +9 -0
- package/session-distill/packets/cross_review.md +31 -0
- package/session-distill/packets/form.md +86 -0
- package/session-distill/packets/judge.md +81 -0
- package/session-distill/packets/placement_contract.md +90 -0
- package/session-distill/packets/propose.md +124 -0
- package/session-distill/packets/read.md +57 -0
- package/session-distill/packets/reconsider.md +53 -0
- package/session-distill/packets/s7b.md +65 -0
- package/session-distill/packets/s9b.md +39 -0
- package/session-distill/packets/stitch.md +35 -0
- package/session-distill/packets/sweep.md +33 -0
- package/session-distill/runlib/__init__.py +0 -0
- package/session-distill/runlib/bound.py +1102 -0
- package/session-distill/runlib/breaker.py +467 -0
- package/session-distill/runlib/census.py +2347 -0
- package/session-distill/runlib/claims.py +420 -0
- package/session-distill/runlib/controls.py +902 -0
- package/session-distill/runlib/coverage.py +881 -0
- package/session-distill/runlib/declare.py +888 -0
- package/session-distill/runlib/delivery_evidence.py +1145 -0
- package/session-distill/runlib/derive.py +812 -0
- package/session-distill/runlib/destinations.py +3072 -0
- package/session-distill/runlib/dispatch.py +7939 -0
- package/session-distill/runlib/drift.py +1077 -0
- package/session-distill/runlib/entry.py +401 -0
- package/session-distill/runlib/evidence.py +890 -0
- package/session-distill/runlib/exposure.py +1162 -0
- package/session-distill/runlib/gate.py +2727 -0
- package/session-distill/runlib/gitread.py +79 -0
- package/session-distill/runlib/inventory.py +19624 -0
- package/session-distill/runlib/journal.py +1919 -0
- package/session-distill/runlib/ledger.py +3210 -0
- package/session-distill/runlib/ledger_compat.py +101 -0
- package/session-distill/runlib/ledger_migration.py +190 -0
- package/session-distill/runlib/lifecycle_intake.py +693 -0
- package/session-distill/runlib/lineage.py +454 -0
- package/session-distill/runlib/measures.py +249 -0
- package/session-distill/runlib/monitor.py +1180 -0
- package/session-distill/runlib/operations.py +522 -0
- package/session-distill/runlib/packet.py +838 -0
- package/session-distill/runlib/placement.py +1769 -0
- package/session-distill/runlib/projection.py +4090 -0
- package/session-distill/runlib/ranking.py +740 -0
- package/session-distill/runlib/receipts.py +200 -0
- package/session-distill/runlib/records.py +1965 -0
- package/session-distill/runlib/search.py +249 -0
- package/session-distill/runlib/sequencing.py +829 -0
- package/session-distill/runlib/sources.py +641 -0
- package/session-distill/runlib/stage_adjudicate.py +845 -0
- package/session-distill/runlib/stage_apply.py +1378 -0
- package/session-distill/runlib/stage_approvals.py +758 -0
- package/session-distill/runlib/stage_close.py +1220 -0
- package/session-distill/runlib/stage_confirm.py +929 -0
- package/session-distill/runlib/stage_delivery.py +3080 -0
- package/session-distill/runlib/stage_form.py +2576 -0
- package/session-distill/runlib/stage_judge.py +4248 -0
- package/session-distill/runlib/stage_propose.py +3307 -0
- package/session-distill/runlib/stage_read.py +5179 -0
- package/session-distill/runlib/stage_render.py +2739 -0
- package/session-distill/runlib/stage_retrieve.py +924 -0
- package/session-distill/runlib/stage_review_korean.py +1002 -0
- package/session-distill/runlib/stage_review_proposals.py +1292 -0
- package/session-distill/runlib/stagelock.py +412 -0
- package/session-distill/runlib/stop.py +1061 -0
- package/session-distill/runlib/targets.py +809 -0
- package/session-distill/runlib/usage.py +280 -0
- package/session-distill/runlib/validate.py +319 -0
- package/session-distill/runlib/views.py +4327 -0
- package/session-distill/schemas/adjudication.schema.json +35 -0
- package/session-distill/schemas/approval.schema.json +35 -0
- package/session-distill/schemas/census.schema.json +128 -0
- package/session-distill/schemas/checks.schema.json +207 -0
- package/session-distill/schemas/claim.schema.json +16 -0
- package/session-distill/schemas/confirmation.schema.json +24 -0
- package/session-distill/schemas/coverage.schema.json +66 -0
- package/session-distill/schemas/cross_review.schema.json +24 -0
- package/session-distill/schemas/event.schema.json +20 -0
- package/session-distill/schemas/evidence.schema.json +20 -0
- package/session-distill/schemas/expected_observation.schema.json +18 -0
- package/session-distill/schemas/form.schema.json +103 -0
- package/session-distill/schemas/intake.schema.json +71 -0
- package/session-distill/schemas/inventory.schema.json +872 -0
- package/session-distill/schemas/judge.schema.json +77 -0
- package/session-distill/schemas/ledger.schema.json +313 -0
- package/session-distill/schemas/observation.schema.json +16 -0
- package/session-distill/schemas/propose.schema.json +555 -0
- package/session-distill/schemas/read.schema.json +76 -0
- package/session-distill/schemas/reconsider.schema.json +122 -0
- package/session-distill/schemas/run.schema.json +150 -0
- package/session-distill/schemas/s7b.schema.json +200 -0
- package/session-distill/schemas/s9b.schema.json +28 -0
- package/session-distill/schemas/stitch.schema.json +25 -0
- package/session-distill/schemas/sweep.schema.json +25 -0
- package/session-distill/seats.json +149 -0
- package/session-distill/tables/allowed_pairs.json +257 -0
- package/session-distill/tables/controls.json +30 -0
- package/session-distill/tables/delivery_evidence.json +36 -0
- package/session-distill/tables/delivery_evidence_fixtures.json +731 -0
- package/session-distill/tables/destinations.json +684 -0
- package/session-distill/tables/drift_layers.json +68 -0
- package/session-distill/tables/exposure_rules.json +192 -0
- package/session-distill/tables/placement_rules.json +148 -0
- package/session-distill/tables/propose_fixtures.json +154 -0
- package/session-distill/tables/ranking.json +194 -0
- package/session-distill/tables/redundancy.json +10 -0
- package/session-distill/tables/structural_rules.json +44 -0
- package/session-distill/tables/transition_fixtures.json +398 -0
- package/session-distill/tables/transitions.json +69 -0
- package/session-distill/tables/unit_outcome.json +67 -0
- package/session-distill/tables/unit_outcome_fixtures.json +2364 -0
- package/wrappers/claude-run.sh +481 -33
- package/wrappers/claude_hermetic_evidence.py +1423 -0
- package/wrappers/codex-helm.sh +44 -13
- package/wrappers/codex-run.sh +183 -20
- package/wrappers/codex_frame_filter.py +1199 -0
- package/wrappers/codex_protocol.py +737 -0
- package/wrappers/jsonl_lines.py +65 -0
|
@@ -0,0 +1,902 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Design §6.5's planted controls (plan WP-10 done-when 4; F27): planted into every run under ordinary ids, judged like
|
|
3
|
+
any candidate, and held to the verdicts `tables/controls.json` gives them.
|
|
4
|
+
|
|
5
|
+
`plant` builds the §6.5 population for S5 from the run's own material: each control borrows a natural formed
|
|
6
|
+
candidate - its events, sessions and quotes - and changes exactly what its kind plants:
|
|
7
|
+
|
|
8
|
+
- **paraphrase_covered** (two): a paraphrase of an operative unit of the current library, as its lesson, situation
|
|
9
|
+
and action; S5 must retrieve the unit for it, and both judges must find the unit covers it;
|
|
10
|
+
- **temporal_order_cause**: the borrowed candidate whose causal support states temporal order as its only reason;
|
|
11
|
+
both judges must mark causal_support unmet, so admission is rejected;
|
|
12
|
+
- **task_specific_requirement**: a requirement specific to the task at hand (the purpose record's "not a learning");
|
|
13
|
+
admission must be rejected;
|
|
14
|
+
- **altered_quote**: one quote whose text differs from the span of the immutable copy it names; S5's quote check must
|
|
15
|
+
fail it (QUOTE_MISMATCH);
|
|
16
|
+
- **fabricated_session**: a session id no census row holds; S5's session check must fail it (SESSION_UNKNOWN).
|
|
17
|
+
|
|
18
|
+
A control's id is `k-` and sixteen hex digits, as a formed candidate's is, derived from a nonce drawn per run; its record
|
|
19
|
+
has exactly the fields of the natural candidate it borrows. What marks it a control - its kind, what it borrowed and
|
|
20
|
+
its expected verdict - is written only to `controls.json` (CONTROLS_FILE), which no packet carries and S6 never reads:
|
|
21
|
+
`reader_problems` names every site that names the file, and S6 runs with the file `sealed`, so a read that does not
|
|
22
|
+
name it (a glob, a computed name, a link) is refused where it opens. The §3.2 gate controls are
|
|
23
|
+
declared beside them; the gate judges them over planted call directories of the stage that dispatches calls.
|
|
24
|
+
|
|
25
|
+
`check_s5` holds S5's checks to the S5 verdicts, and a control S5 does not give its verdict stops the run at S5;
|
|
26
|
+
`evaluate` holds the judgments and the gate's verdicts to the rest, and the natural candidates to the rejection share,
|
|
27
|
+
apart from the controls: CONTROLS_INCOMPLETE (a kind not planted, or a control with no verdict), CONTROL_FAILED (a
|
|
28
|
+
control accepted as natural or not given its verdict), REJECTION_SHARE_ZERO (more than twenty natural candidates and
|
|
29
|
+
none rejected; O4). `evaluation_of` is that evaluation as a run records it after S6 (D-20261115-18d56b): it never
|
|
30
|
+
stops the run; S9's review header and S12's close report show how many controls got their expected verdict, and a
|
|
31
|
+
control whose verdict needs a complete reference point is counted not applicable at an incomplete one.
|
|
32
|
+
|
|
33
|
+
controls.py --self-test
|
|
34
|
+
"""
|
|
35
|
+
import ast
|
|
36
|
+
import contextlib
|
|
37
|
+
import copy
|
|
38
|
+
import hashlib
|
|
39
|
+
import json
|
|
40
|
+
import os
|
|
41
|
+
import pathlib
|
|
42
|
+
import random
|
|
43
|
+
import re
|
|
44
|
+
import secrets
|
|
45
|
+
import sys
|
|
46
|
+
|
|
47
|
+
if __package__ in (None, ""): # run as a script: put session-distill/ on the import path
|
|
48
|
+
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
49
|
+
from runlib import lifecycle_intake
|
|
50
|
+
from runlib.records import Refused
|
|
51
|
+
|
|
52
|
+
HERE = pathlib.Path(__file__).resolve().parents[1]
|
|
53
|
+
TABLE_PATH = HERE / "tables" / "controls.json"
|
|
54
|
+
CONTROLS_FILE = "controls.json"
|
|
55
|
+
ID = re.compile(r"k-[0-9a-f]{16}")
|
|
56
|
+
# design 2026-10-20T1942--9684f05--mechanism-design.md §6.5 lines 510-513, copied once and held against the table
|
|
57
|
+
DESIGN_6_5 = ("two paraphrases of covered units (must match their unit)", "two admission failures (cause by temporal "
|
|
58
|
+
"order only; a task-specific requirement)", "one altered quote", "one fabricated session id",
|
|
59
|
+
"the model-call gate controls of §3.2")
|
|
60
|
+
DESIGN_6_5_COUNTS = {"paraphrase_covered": 2, "temporal_order_cause": 1, "task_specific_requirement": 1,
|
|
61
|
+
"altered_quote": 1, "fabricated_session": 1}
|
|
62
|
+
# §3.2 lines 150-158: the rehearsal controls, each rejected by name and each clean counterpart accepted
|
|
63
|
+
DESIGN_3_2 = ("a truncated output", "a real aborted stream", "a planted `response.incomplete` frame", "a refusal",
|
|
64
|
+
"a nonzero exit", "a stale receipt", "a mismatched result hash", "an inherited profile",
|
|
65
|
+
"a contaminated working directory", "an unattested model")
|
|
66
|
+
# §6.5 line 513: "More than twenty natural candidates with no rejection fails O4."
|
|
67
|
+
DESIGN_REJECTION_SHARE = 20
|
|
68
|
+
PARAPHRASE_MIN_KEYS = 6
|
|
69
|
+
PARAPHRASE_LAYERS = ("catalog", "overlays", "native_global", "native_project", "native_memory")
|
|
70
|
+
# what a control of its kind says in place of the borrowed candidate's words; the paraphrase is made from the unit
|
|
71
|
+
TEMPORAL_BASIS = "The outcome came right after this step, so this step is what produced the outcome."
|
|
72
|
+
TASK_SPECIFIC = {"lesson": "Name the output file exactly as this task's request spelled it.",
|
|
73
|
+
"situation": "When this task's request names the file its output goes to",
|
|
74
|
+
"action": "Write the output to that file name, spelled as the request spelled it",
|
|
75
|
+
"exception": "Unless this task's request is changed"}
|
|
76
|
+
|
|
77
|
+
_TABLES = {}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def table():
|
|
81
|
+
"""The controls table, read once per process; a control may hold a scratch copy in `_TABLES["t"]`."""
|
|
82
|
+
if "t" not in _TABLES:
|
|
83
|
+
_TABLES["t"] = json.loads(TABLE_PATH.read_text(encoding="utf-8"))
|
|
84
|
+
return _TABLES["t"]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def table_problems(held=None):
|
|
88
|
+
"""The table against design §6.5 and §3.2 (CONTRACT_DRIFT) and against itself."""
|
|
89
|
+
held = held or table()
|
|
90
|
+
problems = []
|
|
91
|
+
counts = {row["kind"]: row["count"] for row in held["planted"]}
|
|
92
|
+
if counts != DESIGN_6_5_COUNTS:
|
|
93
|
+
problems.append(f"CONTRACT_DRIFT planted: the table plants {counts}, §6.5 {DESIGN_6_5_COUNTS}")
|
|
94
|
+
kinds = [row["kind"] for row in held["gate"]]
|
|
95
|
+
if len(kinds) != len(set(kinds)) or len(kinds) != len(DESIGN_3_2):
|
|
96
|
+
problems.append(f"CONTRACT_DRIFT gate: {len(kinds)} gate controls ({len(set(kinds))} distinct), §3.2 lists "
|
|
97
|
+
f"{len(DESIGN_3_2)}")
|
|
98
|
+
for row, phrase in zip(held["gate"], DESIGN_3_2):
|
|
99
|
+
if phrase.replace("`", "") not in row["design"].replace("`", ""):
|
|
100
|
+
problems.append(f"CONTRACT_DRIFT gate {row['kind']}: its design text does not hold §3.2's {phrase!r}")
|
|
101
|
+
if held["rejection_share"]["natural_more_than"] != DESIGN_REJECTION_SHARE:
|
|
102
|
+
problems.append(f"CONTRACT_DRIFT rejection_share: {held['rejection_share']['natural_more_than']}, §6.5 "
|
|
103
|
+
f"{DESIGN_REJECTION_SHARE}")
|
|
104
|
+
for row in held["planted"]:
|
|
105
|
+
if not set(row["expected"]) == set(row["checked_at"]) <= {"S5", "S6"}:
|
|
106
|
+
problems.append(f"TABLE_INVALID planted {row['kind']}: its expected verdicts are not one per stage it is "
|
|
107
|
+
"checked at (S5, S6)")
|
|
108
|
+
continue
|
|
109
|
+
for stage, verdict in row["expected"].items():
|
|
110
|
+
rule = verdict.get("rule") if isinstance(verdict, dict) else None
|
|
111
|
+
if not isinstance(verdict, dict) or not verdict.get("text") or not isinstance(rule, dict) or not rule \
|
|
112
|
+
or set(rule) - RULE_KEYS[stage] or ("problem" in rule) != ("of" in rule and "in" in rule):
|
|
113
|
+
problems.append(f"TABLE_INVALID planted {row['kind']} {stage}: an expected verdict is its design text "
|
|
114
|
+
f"and a rule of {sorted(RULE_KEYS[stage])} (`problem` with `of` and `in`)")
|
|
115
|
+
return problems
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
# what each stage's evaluator applies of an expected verdict's rule (tables/controls.json)
|
|
119
|
+
RULE_KEYS = {"S5": {"retrieved", "problem", "of", "in", "fields"}, "S6": {"unit_diagnosis", "admission", "requirements"}}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def s5_holds(rule, entry, row):
|
|
123
|
+
"""Whether S5's row of a planted candidate is the table's verdict: the unit it names retrieved for it, the problem
|
|
124
|
+
it names reported on its subject, and the row's fields as the rule gives them."""
|
|
125
|
+
ok = True
|
|
126
|
+
if "retrieved" in rule:
|
|
127
|
+
ok = ok and entry[rule["retrieved"]] in {u["unit_id"] for u in row["retrieved_units"]}
|
|
128
|
+
if "problem" in rule:
|
|
129
|
+
ok = ok and f"{rule['problem']} {entry[rule['of']]}" in row[rule["in"]]
|
|
130
|
+
return ok and all(row.get(k) == v for k, v in (rule.get("fields") or {}).items())
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def s6_holds(rule, entry, verdict):
|
|
134
|
+
"""Whether S6's verdict on a planted candidate is the table's: its unit diagnosis at the current point, its
|
|
135
|
+
admission, and both judges' marks on the requirements the rule names."""
|
|
136
|
+
ok = True
|
|
137
|
+
if "unit_diagnosis" in rule:
|
|
138
|
+
of = rule["unit_diagnosis"]
|
|
139
|
+
ok = (verdict["outcome"]["unit_diagnosis"].get("current") or {}).get(entry[of["of"]]) == of["is"]
|
|
140
|
+
if "admission" in rule:
|
|
141
|
+
ok = ok and verdict["outcome"]["admission"]["admission"] == rule["admission"]
|
|
142
|
+
return ok and all(verdict["requirements"][w].get(name) == mark for w in ("A", "B")
|
|
143
|
+
for name, mark in (rule.get("requirements") or {}).items())
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def planted_id(nonce, kind, n):
|
|
147
|
+
return "k-" + hashlib.sha256(f"{nonce}\x00{kind}\x00{n}".encode("utf-8")).hexdigest()[:16]
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def fabricated_session(nonce, host):
|
|
151
|
+
"""A session id of the host's shape that no census holds (a UUID drawn from the nonce)."""
|
|
152
|
+
h = hashlib.sha256(f"{nonce}\x00session".encode("utf-8")).hexdigest()
|
|
153
|
+
return f"{host}:{h[:8]}-{h[8:12]}-4{h[13:16]}-8{h[17:20]}-{h[20:32]}"
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def alter(text):
|
|
157
|
+
"""The altered quote: one character changed, the length kept, so only the bytes say it was altered."""
|
|
158
|
+
if not text:
|
|
159
|
+
return "x"
|
|
160
|
+
return text[:-1] + ("y" if text[-1] == "x" else "x")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def paraphrase(text):
|
|
164
|
+
"""A unit's rule in other order: its clauses rotated, so the words stay the unit's and the sentence is not."""
|
|
165
|
+
parts = [p.strip(" .;,:") for p in re.split(r"[;,:]|\.\s", text.strip()) if p.strip(" .;,:")]
|
|
166
|
+
if len(parts) > 1:
|
|
167
|
+
parts = parts[1:] + parts[:1]
|
|
168
|
+
body = "; ".join(parts) if parts else text.strip()
|
|
169
|
+
return body[:1].upper() + body[1:] + ("" if body.endswith(".") else ".")
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def paraphrasable(unit_index):
|
|
173
|
+
"""The units a paraphrase control may name: operative, standing for their text in a layer the owner writes, with
|
|
174
|
+
enough distinct words to be recognisable (PARAPHRASE_MIN_KEYS)."""
|
|
175
|
+
out = []
|
|
176
|
+
for rep, layer in sorted(unit_index.layer_of.items()):
|
|
177
|
+
unit = unit_index.units[rep]
|
|
178
|
+
if layer in PARAPHRASE_LAYERS and len(lifecycle_intake.keys_tf(unit["text"])[0]) >= PARAPHRASE_MIN_KEYS:
|
|
179
|
+
out.append(rep)
|
|
180
|
+
return out
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def plant(natural, unit_index, cited_of, evidence_of, known_sessions, nonce=None):
|
|
184
|
+
"""`(planted candidates, their evidence records by id, controls.json's document)`.
|
|
185
|
+
|
|
186
|
+
`natural` are S4's candidates; `cited_of(candidate)` the evidence ids it cites; `evidence_of(id)` the record of an
|
|
187
|
+
id or None; `known_sessions` the census's session keys. A kind that cannot be planted from the run's material is
|
|
188
|
+
listed `incomplete` with its reason, and S5 refuses the run CONTROLS_INCOMPLETE.
|
|
189
|
+
|
|
190
|
+
A planted id is drawn from the nonce and a planted label follows S4's last, so on disk the two kinds differ in form,
|
|
191
|
+
as S4's own candidates.json already tells them apart. What must not tell them apart is what a judge is sent, and no
|
|
192
|
+
model is sent either: S6 hides the id and the label from every packet and names a candidate's calls by one digest of
|
|
193
|
+
its id (stage_judge's CANDIDATE_HIDDEN and `item_of`), which S6's self-test holds on every packet its golden sends
|
|
194
|
+
(Codex WP-10 X r1 #4)."""
|
|
195
|
+
nonce = nonce or secrets.token_hex(8)
|
|
196
|
+
rng = random.Random(nonce)
|
|
197
|
+
formed = sorted((k for k in natural if k["source"] == "formed" and k.get("event_ids")), key=lambda k: k["candidate_id"])
|
|
198
|
+
numbers = [int(k["label"][1:]) for k in natural if re.fullmatch(r"k[1-9][0-9]*", str(k.get("label")))]
|
|
199
|
+
label = max(numbers, default=0)
|
|
200
|
+
doc = {"nonce": nonce, "planted": [], "incomplete": [],
|
|
201
|
+
"gate": [{"kind": row["kind"], "code": row["code"]} for row in table()["gate"]]}
|
|
202
|
+
planted, evidence = [], {}
|
|
203
|
+
units = paraphrasable(unit_index)
|
|
204
|
+
wanted = next((spec["count"] for spec in table()["planted"] if spec["kind"] == "paraphrase_covered"), 0)
|
|
205
|
+
chosen_units = rng.sample(units, min(len(units), wanted)) # the table's count (Codex WP-10 r1 #5), not §6.5's copy
|
|
206
|
+
for spec in table()["planted"]:
|
|
207
|
+
for n in range(spec["count"]):
|
|
208
|
+
kind = spec["kind"]
|
|
209
|
+
if not formed:
|
|
210
|
+
doc["incomplete"].append({"kind": kind, "reason": "no formed candidate with events to borrow from"})
|
|
211
|
+
continue
|
|
212
|
+
base = rng.choice(formed)
|
|
213
|
+
record = copy.deepcopy(base)
|
|
214
|
+
label += 1
|
|
215
|
+
record["candidate_id"], record["label"] = planted_id(nonce, kind, n), f"k{label}"
|
|
216
|
+
entry = {"candidate_id": record["candidate_id"], "kind": kind, "borrowed_from": base["candidate_id"],
|
|
217
|
+
"checked_at": list(spec["checked_at"]), "expected": dict(spec["expected"])}
|
|
218
|
+
if kind == "paraphrase_covered":
|
|
219
|
+
if n >= len(chosen_units):
|
|
220
|
+
doc["incomplete"].append({"kind": kind, "reason": f"the library has {len(units)} paraphrasable units, "
|
|
221
|
+
f"and {spec['count']} are needed"})
|
|
222
|
+
label -= 1
|
|
223
|
+
continue
|
|
224
|
+
unit = unit_index.units[chosen_units[n]]
|
|
225
|
+
text = paraphrase(unit["text"])
|
|
226
|
+
record.update(lesson=text, situation=text, action=text)
|
|
227
|
+
entry["unit_id"] = unit["unit_id"]
|
|
228
|
+
elif kind == "temporal_order_cause":
|
|
229
|
+
# only the stated reason changes: the claims it cites still show the event, and no cause beyond its order
|
|
230
|
+
record["admission"]["causal_support"]["basis"] = TEMPORAL_BASIS
|
|
231
|
+
elif kind == "task_specific_requirement":
|
|
232
|
+
record.update(TASK_SPECIFIC)
|
|
233
|
+
elif kind == "altered_quote":
|
|
234
|
+
source = next((evidence_of(i) for i in cited_of(base) if evidence_of(i) is not None), None)
|
|
235
|
+
if source is None:
|
|
236
|
+
doc["incomplete"].append({"kind": kind, "reason": "the borrowed candidate cites no quote a store holds"})
|
|
237
|
+
label -= 1
|
|
238
|
+
continue
|
|
239
|
+
new_id = "e-" + hashlib.sha256(f"{nonce}\x00quote".encode("utf-8")).hexdigest()[:16]
|
|
240
|
+
evidence[new_id] = {**copy.deepcopy(source), "evidence_id": new_id, "redacted_text": alter(source["redacted_text"])}
|
|
241
|
+
record["admission"]["observed_event"]["evidence_ids"] = (
|
|
242
|
+
list(record["admission"]["observed_event"]["evidence_ids"]) + [new_id])
|
|
243
|
+
entry["evidence_id"] = new_id
|
|
244
|
+
elif kind == "fabricated_session":
|
|
245
|
+
host = (base.get("sessions") or ["claude:"])[0].split(":", 1)[0]
|
|
246
|
+
session = fabricated_session(nonce, host)
|
|
247
|
+
if session in known_sessions:
|
|
248
|
+
doc["incomplete"].append({"kind": kind, "reason": "the drawn session id is a census row"})
|
|
249
|
+
label -= 1
|
|
250
|
+
continue
|
|
251
|
+
record["sessions"] = [session]
|
|
252
|
+
entry["session"] = session
|
|
253
|
+
planted.append(record)
|
|
254
|
+
doc["planted"].append(entry)
|
|
255
|
+
return planted, evidence, doc
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def check_s5(doc, rows_by_id):
|
|
259
|
+
"""`(problems)` of S5's checks against the S5 verdicts, each entry of `doc` given its `S5` observation."""
|
|
260
|
+
problems = [f"CONTROLS_INCOMPLETE {i['kind']}: {i['reason']}" for i in doc["incomplete"]]
|
|
261
|
+
for entry in doc["planted"]:
|
|
262
|
+
if "S5" not in entry["checked_at"]:
|
|
263
|
+
continue
|
|
264
|
+
row = rows_by_id.get(entry["candidate_id"])
|
|
265
|
+
if row is None:
|
|
266
|
+
problems.append(f"CONTROLS_INCOMPLETE {entry['kind']} {entry['candidate_id']}: S5 checked no such candidate")
|
|
267
|
+
continue
|
|
268
|
+
kind = entry["kind"]
|
|
269
|
+
# the rule the table gave this control when it was planted (Codex WP-10 r1 #5: each kind's verdict was
|
|
270
|
+
# restated here, so a table that changed it was not obeyed)
|
|
271
|
+
ok = s5_holds(entry["expected"]["S5"]["rule"], entry, row)
|
|
272
|
+
entry["S5"] = {"ok": ok}
|
|
273
|
+
if not ok:
|
|
274
|
+
problems.append(f"CONTROL_FAILED {entry['candidate_id']} {kind}: S5 did not give it its verdict "
|
|
275
|
+
f"({entry['expected']['S5']['text']})")
|
|
276
|
+
return problems
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def evaluate(doc, verdicts, gate_verdicts, natural_ids, s5_rows):
|
|
280
|
+
"""The controls after S6, and the natural candidates apart from them.
|
|
281
|
+
|
|
282
|
+
`verdicts`: `{candidate_id: {"outcome": derive.unit_outcome(...), "requirements": {"A": {...}, "B": {...}}}}`;
|
|
283
|
+
`gate_verdicts`: `{gate kind: {"planted": gate.accept(...), "clean": gate.accept(...)}}`; `natural_ids` the natural
|
|
284
|
+
candidates; `s5_rows` S5's rows by id. Returns `{controls, gate, natural, problems}`."""
|
|
285
|
+
problems = [f"CONTROLS_INCOMPLETE {i['kind']}: {i['reason']}" for i in doc["incomplete"]]
|
|
286
|
+
controls = []
|
|
287
|
+
for entry in doc["planted"]:
|
|
288
|
+
if "S6" not in entry["checked_at"]:
|
|
289
|
+
continue
|
|
290
|
+
v = verdicts.get(entry["candidate_id"])
|
|
291
|
+
if v is None:
|
|
292
|
+
problems.append(f"CONTROLS_INCOMPLETE {entry['kind']} {entry['candidate_id']}: no judgment of it")
|
|
293
|
+
controls.append({"candidate_id": entry["candidate_id"], "kind": entry["kind"], "ok": False})
|
|
294
|
+
continue
|
|
295
|
+
admitted = v["outcome"]["admission"]["admission"]
|
|
296
|
+
ok = s6_holds(entry["expected"]["S6"]["rule"], entry, v)
|
|
297
|
+
controls.append({"candidate_id": entry["candidate_id"], "kind": entry["kind"], "ok": ok})
|
|
298
|
+
if not ok:
|
|
299
|
+
why = "accepted as natural" if admitted == "admitted" else "not given its verdict"
|
|
300
|
+
problems.append(f"CONTROL_FAILED {entry['candidate_id']} {entry['kind']}: {why} "
|
|
301
|
+
f"({entry['expected']['S6']['text']})")
|
|
302
|
+
gate = []
|
|
303
|
+
for row in doc["gate"]:
|
|
304
|
+
got = gate_verdicts.get(row["kind"])
|
|
305
|
+
if got is None:
|
|
306
|
+
problems.append(f"CONTROLS_INCOMPLETE gate {row['kind']}: no verdict of the gate over its planted call")
|
|
307
|
+
gate.append({"kind": row["kind"], "ok": False})
|
|
308
|
+
continue
|
|
309
|
+
planted_ok = got["planted"]["ok"] is False and row["code"] in got["planted"]["codes"]
|
|
310
|
+
clean_ok = got["clean"]["ok"] is True
|
|
311
|
+
gate.append({"kind": row["kind"], "ok": planted_ok and clean_ok})
|
|
312
|
+
if not planted_ok:
|
|
313
|
+
problems.append(f"CONTROL_FAILED gate {row['kind']}: the planted call was not rejected {row['code']}")
|
|
314
|
+
if not clean_ok:
|
|
315
|
+
problems.append(f"CONTROL_FAILED gate {row['kind']}: its clean counterpart was not accepted")
|
|
316
|
+
judged = [i for i in natural_ids if i in verdicts or i in s5_rows]
|
|
317
|
+
rejected = [i for i in judged if (i in verdicts and verdicts[i]["outcome"]["admission"]["admission"] == "rejected")
|
|
318
|
+
or (i in s5_rows and (s5_rows[i]["quote_ok"] is False or s5_rows[i]["session_problems"]))]
|
|
319
|
+
limit = table()["rejection_share"]["natural_more_than"]
|
|
320
|
+
if len(judged) > limit and not rejected:
|
|
321
|
+
problems.append(f"REJECTION_SHARE_ZERO: {len(judged)} natural candidates and none rejected; more than {limit} "
|
|
322
|
+
"with no rejection fails O4 (the controls are counted apart)")
|
|
323
|
+
return {"controls": controls, "gate": gate, "natural": {"candidates": len(judged), "rejected": len(rejected)},
|
|
324
|
+
"problems": problems}
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
EVALUATION_INPUTS = ({"artifact": CONTROLS_FILE, "producer_stage": "S5"},
|
|
328
|
+
{"artifact": "checks.json", "producer_stage": "S5"},
|
|
329
|
+
{"artifact": "judgments/derivations.json", "producer_stage": "S6"},
|
|
330
|
+
{"artifact": "judgments/gate-verdicts.json", "producer_stage": "S6"})
|
|
331
|
+
NEEDS_COMPLETE_POINT = ("unit_diagnosis",)
|
|
332
|
+
NOT_APPLICABLE_POINT = ("its expected verdict is a unit diagnosis at the current reference point, and that point is "
|
|
333
|
+
"incomplete, so no diagnosis there is the verdict or its failure")
|
|
334
|
+
NOT_APPLICABLE_GATE = "the gate judged no planted copy of this kind"
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def evaluation_of(planted_doc, derivations, gate_doc, checks_doc):
|
|
338
|
+
"""The planted controls evaluated after S6, as a run records them (D-20261115-18d56b): never a stop. Each control
|
|
339
|
+
is `expected` (given its verdict), `failed`, or `not_applicable` with why: a control whose S6 rule reads a unit
|
|
340
|
+
diagnosis at an incomplete current point (the point decides the diagnosis, so a verdict there proves nothing either
|
|
341
|
+
way), and a gate control the gate judged no planted copy of (S6 copied no call: `gate-verdicts.json` says why).
|
|
342
|
+
S5's controls are read too: a run that reached S6 had every one of them given its verdict, or S5 stopped it.
|
|
343
|
+
|
|
344
|
+
`planted_doc` is S5's `controls.json`, `derivations` S6's `judgments/derivations.json`, `gate_doc` S6's
|
|
345
|
+
`judgments/gate-verdicts.json`, `checks_doc` S5's `checks.json`. Returns `{controls, gate, natural, counts,
|
|
346
|
+
problems}`; `problems` are `evaluate`'s, over the applicable controls only."""
|
|
347
|
+
complete = (((derivations or {}).get("points") or {}).get("current") or {}).get("complete") is True
|
|
348
|
+
verdicts = (derivations or {}).get("verdicts") or {}
|
|
349
|
+
gate_verdicts = (gate_doc or {}).get("gate_verdicts") or {}
|
|
350
|
+
s5_rows = {r["candidate_id"]: r for r in (checks_doc or {}).get("candidates") or []}
|
|
351
|
+
planted = list((planted_doc or {}).get("planted") or [])
|
|
352
|
+
planted_ids = {e["candidate_id"] for e in planted}
|
|
353
|
+
rows, applicable = [], []
|
|
354
|
+
for entry in planted:
|
|
355
|
+
if "S5" in entry["checked_at"]:
|
|
356
|
+
row = s5_rows.get(entry["candidate_id"])
|
|
357
|
+
rows.append({"candidate_id": entry["candidate_id"], "kind": entry["kind"], "stage": "S5",
|
|
358
|
+
"state": "expected" if row is not None and s5_holds(entry["expected"]["S5"]["rule"], entry, row)
|
|
359
|
+
else "failed"})
|
|
360
|
+
if "S6" not in entry["checked_at"]:
|
|
361
|
+
continue
|
|
362
|
+
rule = entry["expected"]["S6"]["rule"]
|
|
363
|
+
if not complete and any(key in rule for key in NEEDS_COMPLETE_POINT):
|
|
364
|
+
rows.append({"candidate_id": entry["candidate_id"], "kind": entry["kind"], "stage": "S6",
|
|
365
|
+
"state": "not_applicable", "why": NOT_APPLICABLE_POINT})
|
|
366
|
+
else:
|
|
367
|
+
applicable.append(entry)
|
|
368
|
+
gate_rows = [row for row in (planted_doc or {}).get("gate") or [] if row["kind"] in gate_verdicts]
|
|
369
|
+
gate_absent = [{"kind": row["kind"], "state": "not_applicable",
|
|
370
|
+
"why": (gate_doc or {}).get("why") or NOT_APPLICABLE_GATE}
|
|
371
|
+
for row in (planted_doc or {}).get("gate") or [] if row["kind"] not in gate_verdicts]
|
|
372
|
+
held = evaluate({**(planted_doc or {}), "planted": applicable, "gate": gate_rows}, verdicts, gate_verdicts,
|
|
373
|
+
sorted(i for i in s5_rows if i not in planted_ids), s5_rows)
|
|
374
|
+
rows += [{"candidate_id": c["candidate_id"], "kind": c["kind"], "stage": "S6",
|
|
375
|
+
"state": "expected" if c["ok"] else "failed"} for c in held["controls"]]
|
|
376
|
+
gate = [{"kind": g["kind"], "state": "expected" if g["ok"] else "failed"} for g in held["gate"]] + gate_absent
|
|
377
|
+
counts = {state: sum(1 for r in rows + gate if r["state"] == state)
|
|
378
|
+
for state in ("expected", "failed", "not_applicable")}
|
|
379
|
+
counts["kinds_not_planted"] = len((planted_doc or {}).get("incomplete") or [])
|
|
380
|
+
return {"controls": rows, "gate": gate, "natural": held["natural"], "counts": counts, "problems": held["problems"]}
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def evaluation_in(run_dir):
|
|
384
|
+
"""`evaluation_of` over the run's own four artifacts (`EVALUATION_INPUTS`), S6's derivations as S6 wrote them:
|
|
385
|
+
an owner's adjudication changes what the owner decides, never what the controls were given."""
|
|
386
|
+
from runlib import records
|
|
387
|
+
run_dir = pathlib.Path(run_dir)
|
|
388
|
+
held = [records.read_json(run_dir / spec["artifact"]) for spec in EVALUATION_INPUTS]
|
|
389
|
+
return evaluation_of(*held)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
def korean_line(evaluation):
|
|
393
|
+
"""The evaluation in one Korean line, for the review header and the close report: how many controls got their
|
|
394
|
+
expected verdict, how many did not, and how many were not applicable and why, with the run never stopped."""
|
|
395
|
+
counts = evaluation["counts"]
|
|
396
|
+
total = counts["expected"] + counts["failed"] + counts["not_applicable"]
|
|
397
|
+
whys = sorted({r["why"] for r in evaluation["controls"] + evaluation["gate"] if r["state"] == "not_applicable"})
|
|
398
|
+
failed = [f"{r.get('candidate_id') or 'gate'} {r['kind']}" for r in evaluation["controls"] + evaluation["gate"]
|
|
399
|
+
if r["state"] == "failed"]
|
|
400
|
+
line = (f"심어 둔 대조군 {total}개 중 기대한 판정 {counts['expected']}개, 어긋남 {counts['failed']}개, "
|
|
401
|
+
f"해당 없음 {counts['not_applicable']}개")
|
|
402
|
+
if failed:
|
|
403
|
+
line += f" (어긋난 것: {', '.join(failed)})"
|
|
404
|
+
if whys:
|
|
405
|
+
line += f". 해당 없음의 이유: {'; '.join(NOT_APPLICABLE_KO.get(w, w) for w in whys)}"
|
|
406
|
+
if counts["kinds_not_planted"]:
|
|
407
|
+
line += f". 심지 못한 종류 {counts['kinds_not_planted']}개"
|
|
408
|
+
return line + ". 어긋나도 실행은 멈추지 않고, 이 결과만 기록합니다."
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
NOT_APPLICABLE_KO = {
|
|
412
|
+
NOT_APPLICABLE_POINT: "현재 기준점이 불완전해, 단위 진단을 기대하는 대조군은 맞았는지 틀렸는지 판정할 수 없음",
|
|
413
|
+
NOT_APPLICABLE_GATE: "게이트가 이 종류의 심은 호출 사본을 판정하지 않음",
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
# ---- F27: no judge-visible byte marks a control --------------------------------------------------------------------
|
|
418
|
+
|
|
419
|
+
def kind_of(value):
|
|
420
|
+
return "object" if isinstance(value, dict) else "array" if isinstance(value, list) else "null" if value is None \
|
|
421
|
+
else "boolean" if isinstance(value, bool) else "number" if isinstance(value, (int, float)) else "string"
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def marker_problems(control, natural, path=""):
|
|
425
|
+
"""What a field marker would change between a control's record and a natural one of the same shape: MARKER_FIELD for
|
|
426
|
+
a key one object holds and the other does not, MARKER_TYPE for a value of another kind (a null is any kind's value;
|
|
427
|
+
the items of an array are held to the other array's first item, and an empty array to nothing)."""
|
|
428
|
+
if isinstance(control, dict) and isinstance(natural, dict):
|
|
429
|
+
out = [f"MARKER_FIELD {path}/{k}" for k in sorted(set(control) ^ set(natural))]
|
|
430
|
+
for k in sorted(set(control) & set(natural)):
|
|
431
|
+
out += marker_problems(control[k], natural[k], f"{path}/{k}")
|
|
432
|
+
return out
|
|
433
|
+
if isinstance(control, list) and isinstance(natural, list):
|
|
434
|
+
if not control or not natural:
|
|
435
|
+
return []
|
|
436
|
+
out = []
|
|
437
|
+
for item in control:
|
|
438
|
+
out += [p for p in marker_problems(item, natural[0], f"{path}/[]") if p not in out]
|
|
439
|
+
return out
|
|
440
|
+
a, b = kind_of(control), kind_of(natural)
|
|
441
|
+
return [] if "null" in (a, b) or a == b else [f"MARKER_TYPE {path}: {a}, where a natural record holds {b}"]
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
# where the expected verdicts may be named, each with its reason; any other site of non-test code is a reader S6 could be
|
|
445
|
+
READERS = {
|
|
446
|
+
("runlib/stage_retrieve.py", "<module>"): "OUTPUTS declares controls.json as one of S5's outputs",
|
|
447
|
+
("runlib/stage_retrieve.py", "run"): "S5 writes the expected verdicts it planted, outside every packet",
|
|
448
|
+
("runlib/stage_render.py", "<module>"): "INPUTS declares controls.json as one of S9's S5 input artifacts",
|
|
449
|
+
("runlib/stage_render.py", "load"): "S9 reads which candidates S5 planted, so a proposal for one is accounted as a "
|
|
450
|
+
"control and never rendered as a review row; S9 runs after S6 and S7, and the "
|
|
451
|
+
"review is the owner's, read by no judge",
|
|
452
|
+
("runlib/stage_propose.py", "<module>"): "LIVE_INPUTS declares controls.json as one of S7's S5 input artifacts",
|
|
453
|
+
("runlib/stage_propose.py", "live"): "S7 reads which candidates S5 planted, so no proposal call is spent on a "
|
|
454
|
+
"control; S7 runs after S6, whose judges are the only readers the file is "
|
|
455
|
+
"sealed against, and what it reads is the ids, never a verdict",
|
|
456
|
+
("runlib/stage_propose.py", "run"): "S7 over answers in hand with the pinned legacy entries decides who is owed "
|
|
457
|
+
"an answer as the live stage does, so it reads which candidates S5 planted - "
|
|
458
|
+
"the ids, never a verdict - after S6 (Codex WP-12 r3 F7)",
|
|
459
|
+
}
|
|
460
|
+
TEST_CODE = ("self_test", "_self_test", "fx_")
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def reader_sites(texts):
|
|
464
|
+
"""`(module, top-level function)` of every non-test site in `texts` (`{relative path: source}`) that names the
|
|
465
|
+
expected verdicts' file (the literal or CONTROLS_FILE), this module aside."""
|
|
466
|
+
sites = set()
|
|
467
|
+
for rel, source in sorted(texts.items()):
|
|
468
|
+
if rel == "runlib/controls.py":
|
|
469
|
+
continue
|
|
470
|
+
tree = ast.parse(source)
|
|
471
|
+
for top in tree.body:
|
|
472
|
+
name = getattr(top, "name", "<module>")
|
|
473
|
+
if name.startswith(TEST_CODE):
|
|
474
|
+
continue
|
|
475
|
+
for node in ast.walk(top):
|
|
476
|
+
if (isinstance(node, ast.Constant) and node.value == CONTROLS_FILE) or \
|
|
477
|
+
(isinstance(node, (ast.Name, ast.Attribute)) and getattr(node, "id", getattr(node, "attr", None)) == "CONTROLS_FILE"):
|
|
478
|
+
sites.add((rel, name))
|
|
479
|
+
return sites
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
# ---- WP-10 X r1 #7: the expected verdicts' file is sealed while a judging stage runs ------------------------------
|
|
483
|
+
|
|
484
|
+
_SEAL = {"installed": False, "stages": [], "opened": []}
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
def _sealed_open(event, args):
|
|
488
|
+
"""The audit hook `sealed` installs: while a stage holds the seal, opening any file named controls.json - or any
|
|
489
|
+
path that is the run's controls.json under another name (a link) - is refused, the controls table aside, and the
|
|
490
|
+
attempt is recorded so a caller that swallows the refusal is still named when the stage ends."""
|
|
491
|
+
if event != "open" or not _SEAL["stages"] or not args or not isinstance(args[0], (str, bytes, os.PathLike)):
|
|
492
|
+
return
|
|
493
|
+
stage, run_file, table_id, sealed_id = _SEAL["stages"][-1]
|
|
494
|
+
try:
|
|
495
|
+
name = os.fsdecode(args[0])
|
|
496
|
+
st = os.stat(name)
|
|
497
|
+
held = (st.st_dev, st.st_ino)
|
|
498
|
+
except (OSError, TypeError, ValueError):
|
|
499
|
+
held = None
|
|
500
|
+
if held is not None and held == table_id:
|
|
501
|
+
return # the controls TABLE (tables/controls.json), which holds no run's verdicts
|
|
502
|
+
if os.path.basename(name) == CONTROLS_FILE or (held is not None and held == sealed_id):
|
|
503
|
+
_SEAL["opened"].append(name)
|
|
504
|
+
raise Refused(f"CONTROLS_READ {stage}: {name} was opened while {stage} runs; the expected verdicts "
|
|
505
|
+
f"({run_file}) are sealed from every module the stage runs, by name, glob or link alike")
|
|
506
|
+
|
|
507
|
+
|
|
508
|
+
@contextlib.contextmanager
|
|
509
|
+
def sealed(run_dir, stage):
|
|
510
|
+
"""Hold the expected verdicts' file of `run_dir` sealed while the block runs (Codex WP-10 X r1 #7: a scan for the
|
|
511
|
+
file's name cannot see a glob, a computed name or a link, so the boundary is held where every read passes, at
|
|
512
|
+
`open`). An attempt is refused where it is made and, should its caller swallow that, CONTROLS_READ when the block
|
|
513
|
+
ends."""
|
|
514
|
+
if not _SEAL["installed"]:
|
|
515
|
+
sys.addaudithook(_sealed_open)
|
|
516
|
+
_SEAL["installed"] = True
|
|
517
|
+
|
|
518
|
+
def identity(path):
|
|
519
|
+
try:
|
|
520
|
+
st = os.stat(path)
|
|
521
|
+
return st.st_dev, st.st_ino
|
|
522
|
+
except OSError:
|
|
523
|
+
return None
|
|
524
|
+
run_file = pathlib.Path(run_dir) / CONTROLS_FILE
|
|
525
|
+
_SEAL["stages"].append((stage, str(run_file), identity(TABLE_PATH), identity(run_file)))
|
|
526
|
+
before = len(_SEAL["opened"])
|
|
527
|
+
try:
|
|
528
|
+
yield
|
|
529
|
+
finally:
|
|
530
|
+
_SEAL["stages"].pop()
|
|
531
|
+
opened = _SEAL["opened"][before:]
|
|
532
|
+
del _SEAL["opened"][before:]
|
|
533
|
+
if opened:
|
|
534
|
+
raise Refused(f"CONTROLS_READ {stage}: {len(opened)} opens of the sealed expected verdicts' file while it ran "
|
|
535
|
+
f"(the first {opened[0]})")
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def reader_problems(texts):
|
|
539
|
+
sites = reader_sites(texts)
|
|
540
|
+
return ([f"CONTROLS_READ {rel} ({name}): names the expected verdicts' file, and no reason in READERS says why"
|
|
541
|
+
for rel, name in sorted(sites - set(READERS))]
|
|
542
|
+
+ [f"CONTROLS_READ_STALE {rel} ({name}): listed in READERS, and it no longer names the file"
|
|
543
|
+
for rel, name in sorted(set(READERS) - sites)])
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def module_texts(root=HERE):
|
|
547
|
+
root = pathlib.Path(root)
|
|
548
|
+
texts = {f"runlib/{p.name}": p.read_text(encoding="utf-8") for p in sorted((root / "runlib").glob("*.py"))}
|
|
549
|
+
texts["distill.py"] = (root / "distill.py").read_text(encoding="utf-8")
|
|
550
|
+
return texts
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
# ---- self-test -------------------------------------------------------------------------------------------------------
|
|
554
|
+
|
|
555
|
+
def self_test():
|
|
556
|
+
import shutil
|
|
557
|
+
import tempfile
|
|
558
|
+
from runlib import records, stage_retrieve
|
|
559
|
+
failures, ran = [], []
|
|
560
|
+
|
|
561
|
+
def control(name, condition, detail=""):
|
|
562
|
+
ran.append(name)
|
|
563
|
+
if not condition:
|
|
564
|
+
failures.append(f"{name}: {detail}")
|
|
565
|
+
|
|
566
|
+
def guarded(action, default):
|
|
567
|
+
try:
|
|
568
|
+
return action()
|
|
569
|
+
except Exception as exc: # noqa: BLE001 - reported by the control that reads the default
|
|
570
|
+
return default if not callable(default) else default(exc)
|
|
571
|
+
|
|
572
|
+
def refusal(action):
|
|
573
|
+
try:
|
|
574
|
+
action()
|
|
575
|
+
except Refused as exc:
|
|
576
|
+
return str(exc)
|
|
577
|
+
except Exception as exc: # noqa: BLE001 - a control whose subject raises anything else fails by its own name
|
|
578
|
+
return f"RAISED {exc!r}"
|
|
579
|
+
return ""
|
|
580
|
+
|
|
581
|
+
# ---- the table against the design ---------------------------------------------------------------------------
|
|
582
|
+
control("contract fidelity: the planted kinds and counts are §6.5's, the gate controls §3.2's, the share bar 20",
|
|
583
|
+
table_problems() == [], f"{table_problems()}")
|
|
584
|
+
drifted = copy.deepcopy(table())
|
|
585
|
+
drifted["planted"][0]["count"] = 1
|
|
586
|
+
control("control: one paraphrase planted where §6.5 says two is CONTRACT_DRIFT",
|
|
587
|
+
any(p.startswith("CONTRACT_DRIFT planted") for p in table_problems(drifted)), f"{table_problems(drifted)}")
|
|
588
|
+
dropped = copy.deepcopy(table())
|
|
589
|
+
dropped["gate"] = dropped["gate"][:-1]
|
|
590
|
+
control("control: a gate control dropped from the table is CONTRACT_DRIFT",
|
|
591
|
+
any(p.startswith("CONTRACT_DRIFT gate") for p in table_problems(dropped)), f"{table_problems(dropped)}")
|
|
592
|
+
|
|
593
|
+
# ---- planting over a golden run's material ------------------------------------------------------------------
|
|
594
|
+
root = pathlib.Path(tempfile.mkdtemp(prefix="controls-"))
|
|
595
|
+
try:
|
|
596
|
+
run_dir = guarded(lambda: stage_retrieve.fx_gold(root / "base"), lambda exc: exc)
|
|
597
|
+
if isinstance(run_dir, Exception):
|
|
598
|
+
failures.append(f"the golden run through S4 could not be made: {run_dir!r}")
|
|
599
|
+
run_dir = None
|
|
600
|
+
if run_dir is not None:
|
|
601
|
+
from runlib import census, evidence as evidences, stage_form
|
|
602
|
+
cands = records.read_json(run_dir / "candidates.json")
|
|
603
|
+
natural = cands["candidates"]
|
|
604
|
+
current = records.read_json(run_dir / "inventory" / "current.json")
|
|
605
|
+
index = stage_retrieve.UnitIndex(current["units"])
|
|
606
|
+
subject_of = stage_form.subject(run_dir)
|
|
607
|
+
names = [t["name"] for t in records.read_json(run_dir / "views.json")["transcripts"]]
|
|
608
|
+
stored = stage_retrieve.stored_evidence(run_dir, names)
|
|
609
|
+
extra = cands.get("origin_evidence") or {}
|
|
610
|
+
known = {census.key_of(r) for r in census.rows(census.load(run_dir))}
|
|
611
|
+
|
|
612
|
+
def cited_of(k):
|
|
613
|
+
return stage_retrieve.cited(k, subject_of)[0]
|
|
614
|
+
|
|
615
|
+
def evidence_of(i):
|
|
616
|
+
return stored.get(i) or extra.get(i)
|
|
617
|
+
planted, planted_ev, doc = plant(natural, index, cited_of, evidence_of, known, nonce="0123456789abcdef")
|
|
618
|
+
kinds = [e["kind"] for e in doc["planted"]]
|
|
619
|
+
control("done-when 4: the full §6.5 population is planted: two paraphrases, two admission failures, one "
|
|
620
|
+
"altered quote, one fabricated session id, and the §3.2 gate controls declared beside them",
|
|
621
|
+
sorted(kinds) == sorted(k for k, n in DESIGN_6_5_COUNTS.items() for _ in range(n))
|
|
622
|
+
and not doc["incomplete"] and len(doc["gate"]) == len(DESIGN_3_2), f"{kinds} {doc['incomplete']}")
|
|
623
|
+
natural_ids = {k["candidate_id"] for k in natural}
|
|
624
|
+
control("F27: every control has an ordinary id - k- and sixteen hex digits, as a formed candidate's - none of "
|
|
625
|
+
"them a natural candidate's", all(ID.fullmatch(k["candidate_id"]) for k in planted)
|
|
626
|
+
and not natural_ids & {k["candidate_id"] for k in planted}
|
|
627
|
+
and all(ID.fullmatch(k["candidate_id"]) for k in natural if k["source"] == "formed"),
|
|
628
|
+
f"{[k['candidate_id'] for k in planted]}")
|
|
629
|
+
by_id = {k["candidate_id"]: k for k in natural}
|
|
630
|
+
marks = {e["candidate_id"]: marker_problems(k, by_id[e["borrowed_from"]])
|
|
631
|
+
for k, e in zip(planted, doc["planted"])}
|
|
632
|
+
control("F27 (structural): a control's record against the natural candidate it borrowed shows no marker field "
|
|
633
|
+
"- the same paths and types", all(not m for m in marks.values()), f"{marks}")
|
|
634
|
+
control("control: a planted field would show as MARKER_FIELD",
|
|
635
|
+
marker_problems({**planted[0], "planted": True}, by_id[doc["planted"][0]["borrowed_from"]])
|
|
636
|
+
== ["MARKER_FIELD /planted"], "unmarked")
|
|
637
|
+
control("control: a field holding another kind of value would show as MARKER_TYPE",
|
|
638
|
+
marker_problems({**planted[0], "lesson": ["x"]}, by_id[doc["planted"][0]["borrowed_from"]])
|
|
639
|
+
== ["MARKER_TYPE /lesson: array, where a natural record holds string"], "unmarked")
|
|
640
|
+
raw = json.dumps(planted, sort_keys=True)
|
|
641
|
+
words = [e["kind"] for e in doc["planted"]] + [CONTROLS_FILE, doc["nonce"], "borrowed_from", "expected"]
|
|
642
|
+
control("F27: no planted record holds its kind, the nonce, or the expected-verdicts file's words",
|
|
643
|
+
not [w for w in words if w in raw], f"{[w for w in words if w in raw]}")
|
|
644
|
+
control("the same nonce plants the same controls; another draws other ids",
|
|
645
|
+
plant(natural, index, cited_of, evidence_of, known, nonce="0123456789abcdef")[0] == planted
|
|
646
|
+
and {k["candidate_id"] for k in plant(natural, index, cited_of, evidence_of, known, nonce="fedcba9876543210")[0]}
|
|
647
|
+
.isdisjoint({k["candidate_id"] for k in planted}), "differs")
|
|
648
|
+
altered = next(e for e in doc["planted"] if e["kind"] == "altered_quote")
|
|
649
|
+
rec = planted_ev[altered["evidence_id"]]
|
|
650
|
+
control("the altered quote's record differs from its source by one character of its text and keeps every field",
|
|
651
|
+
len(rec["redacted_text"]) == len(next(evidence_of(i) for i in cited_of(by_id[altered["borrowed_from"]])
|
|
652
|
+
if evidence_of(i))["redacted_text"])
|
|
653
|
+
and evidences.verify(run_dir, rec) and evidences.verify(run_dir, rec)[0].startswith("QUOTE_MISMATCH"),
|
|
654
|
+
f"{evidences.verify(run_dir, rec)[:1]}")
|
|
655
|
+
fab = next(e for e in doc["planted"] if e["kind"] == "fabricated_session")
|
|
656
|
+
control("the fabricated session id has its host's shape and is no census row",
|
|
657
|
+
fab["session"] not in known and fab["session"].startswith("claude:"), f"{fab['session']}")
|
|
658
|
+
para = [e for e in doc["planted"] if e["kind"] == "paraphrase_covered"]
|
|
659
|
+
control("the two paraphrases name two distinct operative units the library holds",
|
|
660
|
+
len({e["unit_id"] for e in para}) == 2 and all(e["unit_id"] in index.units for e in para), f"{para}")
|
|
661
|
+
# incomplete populations
|
|
662
|
+
_p, _e, none_doc = plant([k for k in natural if k["source"] != "formed"], index, cited_of, evidence_of, known, "aa")
|
|
663
|
+
control("CONTROLS_INCOMPLETE: a run with no formed candidate to borrow from plants none, and says why per kind",
|
|
664
|
+
len(none_doc["incomplete"]) == sum(DESIGN_6_5_COUNTS.values())
|
|
665
|
+
and check_s5(none_doc, {})[0].startswith("CONTROLS_INCOMPLETE"), f"{none_doc['incomplete'][:1]}")
|
|
666
|
+
small = stage_retrieve.UnitIndex([u for u in current["units"] if u["unit_id"] == "u-tests"])
|
|
667
|
+
_p, _e, small_doc = plant(natural, small, cited_of, evidence_of, known, "bb")
|
|
668
|
+
control("CONTROLS_INCOMPLETE: a library with one paraphrasable unit plants one paraphrase, and names the second",
|
|
669
|
+
[i["kind"] for i in small_doc["incomplete"]] == ["paraphrase_covered"]
|
|
670
|
+
and sum(1 for e in small_doc["planted"] if e["kind"] == "paraphrase_covered") == 1, f"{small_doc['incomplete']}")
|
|
671
|
+
fewer = copy.deepcopy(table())
|
|
672
|
+
fewer["planted"] = [r for r in fewer["planted"] if r["kind"] != "fabricated_session"]
|
|
673
|
+
_TABLES["t"] = fewer
|
|
674
|
+
try:
|
|
675
|
+
_p, _e, fewer_doc = plant(natural, index, cited_of, evidence_of, known, "cc")
|
|
676
|
+
finally:
|
|
677
|
+
_TABLES.pop("t", None)
|
|
678
|
+
control("CONTROLS_INCOMPLETE: a population with fewer than the six listed is refused against §6.5 by the table "
|
|
679
|
+
"check", table_problems(fewer) and len(fewer_doc["planted"]) == 5, f"{table_problems(fewer)}")
|
|
680
|
+
|
|
681
|
+
# ---- S5's verdicts --------------------------------------------------------------------------------------
|
|
682
|
+
def row(k, **over):
|
|
683
|
+
base = {"retrieved_units": [], "quote_ok": True, "quote_problems": [], "session_problems": []}
|
|
684
|
+
return {**base, **over}
|
|
685
|
+
good = {}
|
|
686
|
+
for e in doc["planted"]:
|
|
687
|
+
if e["kind"] == "paraphrase_covered":
|
|
688
|
+
good[e["candidate_id"]] = row(e, retrieved_units=[{"unit_id": e["unit_id"]}])
|
|
689
|
+
elif e["kind"] == "altered_quote":
|
|
690
|
+
good[e["candidate_id"]] = row(e, quote_ok=False, quote_problems=[f"QUOTE_MISMATCH {e['evidence_id']}"])
|
|
691
|
+
elif e["kind"] == "fabricated_session":
|
|
692
|
+
good[e["candidate_id"]] = row(e, session_problems=[f"SESSION_UNKNOWN {e['session']}"])
|
|
693
|
+
control("S5: each S5 control given its verdict passes", check_s5(copy.deepcopy(doc), good) == [],
|
|
694
|
+
f"{check_s5(copy.deepcopy(doc), good)}")
|
|
695
|
+
for kind, change in (("altered_quote", dict(quote_ok=True, quote_problems=[])),
|
|
696
|
+
("fabricated_session", dict(session_problems=[])),
|
|
697
|
+
("paraphrase_covered", dict(retrieved_units=[]))):
|
|
698
|
+
bent = copy.deepcopy(good)
|
|
699
|
+
target = next(e["candidate_id"] for e in doc["planted"] if e["kind"] == kind)
|
|
700
|
+
bent[target] = {**bent[target], **change}
|
|
701
|
+
control(f"CONTROL_FAILED: {kind} accepted by S5 as a natural candidate would be is named",
|
|
702
|
+
any(p.startswith(f"CONTROL_FAILED {target} {kind}") for p in check_s5(copy.deepcopy(doc), bent)),
|
|
703
|
+
f"{check_s5(copy.deepcopy(doc), bent)}")
|
|
704
|
+
|
|
705
|
+
# Codex WP-10 r1 #5: the verdict a control is held to is the table's rule, read where it was planted
|
|
706
|
+
swapped = copy.deepcopy(doc)
|
|
707
|
+
for e in swapped["planted"]:
|
|
708
|
+
if e["kind"] == "altered_quote":
|
|
709
|
+
e["expected"]["S5"]["rule"] = {"problem": "SESSION_UNKNOWN", "of": "evidence_id",
|
|
710
|
+
"in": "quote_problems"}
|
|
711
|
+
aq = next(e["candidate_id"] for e in doc["planted"] if e["kind"] == "altered_quote")
|
|
712
|
+
control("Codex WP-10 r1 #5: S5's verdict on a control follows its rule: the altered quote's row passes its "
|
|
713
|
+
"own rule and fails one that names another problem",
|
|
714
|
+
check_s5(copy.deepcopy(doc), good) == []
|
|
715
|
+
and any(p.startswith(f"CONTROL_FAILED {aq} altered_quote") for p in check_s5(swapped, good)),
|
|
716
|
+
f"{check_s5(swapped, good)}")
|
|
717
|
+
# one more than §6.5's two, from a library that holds that many: a count read from §6.5's copy samples two
|
|
718
|
+
# units and names the third incomplete
|
|
719
|
+
more = DESIGN_6_5_COUNTS["paraphrase_covered"] + 1
|
|
720
|
+
ruled = copy.deepcopy(table())
|
|
721
|
+
for r in ruled["planted"]:
|
|
722
|
+
if r["kind"] == "paraphrase_covered":
|
|
723
|
+
r["count"] = more
|
|
724
|
+
_TABLES["t"] = ruled
|
|
725
|
+
try:
|
|
726
|
+
_p, _e, ruled_doc = plant(natural, index, cited_of, evidence_of, known, "dd")
|
|
727
|
+
finally:
|
|
728
|
+
_TABLES.pop("t", None)
|
|
729
|
+
control("Codex WP-10 r1 #5: the paraphrases planted are the table's count, not §6.5's copy of it",
|
|
730
|
+
len(paraphrasable(index)) >= more
|
|
731
|
+
and sum(1 for e in ruled_doc["planted"] if e["kind"] == "paraphrase_covered") == more
|
|
732
|
+
and not [i for i in ruled_doc["incomplete"] if i["kind"] == "paraphrase_covered"],
|
|
733
|
+
f"{len(paraphrasable(index))} paraphrasable {[e['kind'] for e in ruled_doc['planted']]} "
|
|
734
|
+
f"{ruled_doc['incomplete']}")
|
|
735
|
+
invalid = copy.deepcopy(table())
|
|
736
|
+
invalid["planted"][0]["expected"]["S5"]["rule"] = {"judged": "unit_id"}
|
|
737
|
+
control("Codex WP-10 r1 #5: a rule no evaluator applies is TABLE_INVALID",
|
|
738
|
+
any(p.startswith("TABLE_INVALID planted paraphrase_covered S5") for p in table_problems(invalid)),
|
|
739
|
+
f"{table_problems(invalid)}")
|
|
740
|
+
|
|
741
|
+
# ---- after S6: the judge controls, the gate controls, the natural share -----------------------------------
|
|
742
|
+
def outcome(admission, covers=None):
|
|
743
|
+
return {"outcome": {"admission": {"admission": admission}, "unit_diagnosis": {"current": covers or {}}},
|
|
744
|
+
"requirements": {"A": {"causal_support": "unmet"}, "B": {"causal_support": "unmet"}}}
|
|
745
|
+
verdicts = {}
|
|
746
|
+
for e in doc["planted"]:
|
|
747
|
+
if e["kind"] == "paraphrase_covered":
|
|
748
|
+
verdicts[e["candidate_id"]] = outcome("disputed", {e["unit_id"]: "covers"})
|
|
749
|
+
elif "S6" in e["checked_at"]:
|
|
750
|
+
verdicts[e["candidate_id"]] = outcome("rejected")
|
|
751
|
+
gates = {r["kind"]: {"planted": {"ok": False, "codes": [r["code"]]}, "clean": {"ok": True, "codes": []}}
|
|
752
|
+
for r in doc["gate"]}
|
|
753
|
+
nat = sorted(natural_ids)
|
|
754
|
+
some = {i: outcome("admitted") for i in nat}
|
|
755
|
+
some[nat[0]] = outcome("rejected")
|
|
756
|
+
clean = evaluate(doc, {**verdicts, **some}, gates, nat, {})
|
|
757
|
+
control("after S6: every control given its verdict, every gate control rejected by name with its clean "
|
|
758
|
+
"counterpart accepted, passes", clean["problems"] == [], f"{clean['problems']}")
|
|
759
|
+
temporal = next(e["candidate_id"] for e in doc["planted"] if e["kind"] == "temporal_order_cause")
|
|
760
|
+
accepted = evaluate(doc, {**verdicts, **some, temporal: outcome("admitted")}, gates, nat, {})
|
|
761
|
+
control("CONTROL_FAILED: a planted control accepted as natural is named",
|
|
762
|
+
any(p.startswith(f"CONTROL_FAILED {temporal} temporal_order_cause: accepted as natural") for p in accepted["problems"]),
|
|
763
|
+
f"{accepted['problems']}")
|
|
764
|
+
|
|
765
|
+
# ---- as a run records it after S6, never a stop (D-20261115-18d56b) -------------------------------------
|
|
766
|
+
s5_ok = {e["candidate_id"]: {"candidate_id": e["candidate_id"], "retrieved_units": [{"unit_id": e.get("unit_id")}],
|
|
767
|
+
"quote_problems": [f"QUOTE_MISMATCH {e.get('evidence_id')}"],
|
|
768
|
+
"session_problems": [f"SESSION_UNKNOWN {e.get('session')}"], "quote_ok": False}
|
|
769
|
+
for e in doc["planted"]}
|
|
770
|
+
checks_ok = {"candidates": list(s5_ok.values()) + [{"candidate_id": i, "retrieved_units": [], "quote_problems": [],
|
|
771
|
+
"session_problems": [], "quote_ok": True} for i in nat]}
|
|
772
|
+
gate_ok = {"gate_verdicts": gates}
|
|
773
|
+
point = lambda complete: {"current": {"complete": complete}} # noqa: E731
|
|
774
|
+
whole = evaluation_of(doc, {"points": point(True), "verdicts": {**verdicts, **some}}, gate_ok, checks_ok)
|
|
775
|
+
planted_count = sum(len(e["checked_at"]) for e in doc["planted"]) + len(doc["gate"])
|
|
776
|
+
control("the evaluation over a complete point: every control expected, counted once per stage it is checked "
|
|
777
|
+
"at, gate controls included",
|
|
778
|
+
whole["counts"] == {"expected": planted_count, "failed": 0, "not_applicable": 0,
|
|
779
|
+
"kinds_not_planted": len(doc["incomplete"])} and whole["problems"] == [],
|
|
780
|
+
f"{whole['counts']} {whole['problems']}")
|
|
781
|
+
failing = evaluation_of(doc, {"points": point(True), "verdicts": {**verdicts, **some, temporal: outcome("admitted")}},
|
|
782
|
+
gate_ok, checks_ok)
|
|
783
|
+
control("a control accepted as natural is failed in the evaluation, named in its problems, and nothing raises",
|
|
784
|
+
[(r["candidate_id"], r["state"]) for r in failing["controls"] if r["state"] == "failed"]
|
|
785
|
+
== [(temporal, "failed")] and failing["counts"]["failed"] == 1
|
|
786
|
+
and any(p.startswith(f"CONTROL_FAILED {temporal}") for p in failing["problems"]),
|
|
787
|
+
f"{failing['counts']} {failing['problems']}")
|
|
788
|
+
partial = evaluation_of(doc, {"points": point(False), "verdicts": {**verdicts, **some}}, gate_ok, checks_ok)
|
|
789
|
+
para_ids = sorted(e["candidate_id"] for e in doc["planted"] if e["kind"] == "paraphrase_covered")
|
|
790
|
+
control("at an incomplete current point a unit-diagnosis control is not applicable, with why, and not failed",
|
|
791
|
+
sorted(r["candidate_id"] for r in partial["controls"] if r["state"] == "not_applicable") == para_ids
|
|
792
|
+
and all(r.get("why") == NOT_APPLICABLE_POINT for r in partial["controls"] if r["state"] == "not_applicable")
|
|
793
|
+
and partial["counts"]["failed"] == 0 and partial["counts"]["not_applicable"] == len(para_ids),
|
|
794
|
+
f"{partial['counts']}")
|
|
795
|
+
covered_wrong = evaluation_of(doc, {"points": point(False), "verdicts": {**verdicts, **some,
|
|
796
|
+
para_ids[0]: outcome("disputed", {})}},
|
|
797
|
+
gate_ok, checks_ok)
|
|
798
|
+
control("and its verdict there is not read either way: a paraphrase the judges did not find covering is still "
|
|
799
|
+
"not applicable", covered_wrong["counts"]["failed"] == 0, f"{covered_wrong['counts']}")
|
|
800
|
+
ungated = evaluation_of(doc, {"points": point(True), "verdicts": {**verdicts, **some}},
|
|
801
|
+
{"gate_verdicts": {}, "why": "no candidate has both judges' calls accepted"}, checks_ok)
|
|
802
|
+
control("a gate the gate judged no copy of is not applicable with the gate's own why, not failed",
|
|
803
|
+
[g["state"] for g in ungated["gate"]] == ["not_applicable"] * len(doc["gate"])
|
|
804
|
+
and {g["why"] for g in ungated["gate"]} == {"no candidate has both judges' calls accepted"}
|
|
805
|
+
and ungated["counts"]["failed"] == 0, f"{ungated['gate'][:2]}")
|
|
806
|
+
s5_failed = evaluation_of(doc, {"points": point(True), "verdicts": {**verdicts, **some}}, gate_ok,
|
|
807
|
+
{"candidates": [r for r in checks_ok["candidates"] if r["candidate_id"] != para_ids[0]]})
|
|
808
|
+
control("an S5 control with no S5 row is failed at S5, not dropped",
|
|
809
|
+
("S5", "failed") in {(r["stage"], r["state"]) for r in s5_failed["controls"]
|
|
810
|
+
if r["candidate_id"] == para_ids[0]},
|
|
811
|
+
f"{[r for r in s5_failed['controls'] if r['candidate_id'] == para_ids[0]]}")
|
|
812
|
+
other = {**verdicts[temporal], "requirements": {"A": {"causal_support": "met"}, "B": {"causal_support": "unmet"}}}
|
|
813
|
+
loose = copy.deepcopy(doc)
|
|
814
|
+
for e in loose["planted"]:
|
|
815
|
+
if e["kind"] == "temporal_order_cause":
|
|
816
|
+
e["expected"]["S6"]["rule"] = {"admission": "rejected"}
|
|
817
|
+
control("Codex WP-10 r1 #5: S6's verdict on a control follows its rule: the temporal-order control rejected "
|
|
818
|
+
"for another requirement fails its own rule and passes one that asks only for the rejection",
|
|
819
|
+
any(p.startswith(f"CONTROL_FAILED {temporal}") for p in
|
|
820
|
+
evaluate(doc, {**verdicts, **some, temporal: other}, gates, nat, {})["problems"])
|
|
821
|
+
and not any(p.startswith(f"CONTROL_FAILED {temporal}") for p in
|
|
822
|
+
evaluate(loose, {**verdicts, **some, temporal: other}, gates, nat, {})["problems"]),
|
|
823
|
+
"the rule was not followed")
|
|
824
|
+
control("CONTROL_FAILED: a temporal-order control rejected for another requirement is not its verdict",
|
|
825
|
+
any(p.startswith(f"CONTROL_FAILED {temporal}") for p in
|
|
826
|
+
evaluate(doc, {**verdicts, **some, temporal: other}, gates, nat, {})["problems"]), "passed")
|
|
827
|
+
p0 = para[0]["candidate_id"]
|
|
828
|
+
control("CONTROL_FAILED: a paraphrase whose unit the judges do not find covering is named",
|
|
829
|
+
any(p.startswith(f"CONTROL_FAILED {p0} paraphrase_covered") for p in
|
|
830
|
+
evaluate(doc, {**verdicts, **some, p0: outcome("disputed", {})}, gates, nat, {})["problems"]), "passed")
|
|
831
|
+
missing = {k: v for k, v in verdicts.items() if k != temporal}
|
|
832
|
+
control("CONTROLS_INCOMPLETE: a control with no judgment is named",
|
|
833
|
+
any(p.startswith("CONTROLS_INCOMPLETE temporal_order_cause") for p in
|
|
834
|
+
evaluate(doc, {**missing, **some}, gates, nat, {})["problems"]), "passed")
|
|
835
|
+
no_gate = {k: v for k, v in gates.items() if k != "stale_receipt"}
|
|
836
|
+
control("CONTROLS_INCOMPLETE: a gate control with no verdict of the gate is named",
|
|
837
|
+
any(p.startswith("CONTROLS_INCOMPLETE gate stale_receipt") for p in
|
|
838
|
+
evaluate(doc, {**verdicts, **some}, no_gate, nat, {})["problems"]), "passed")
|
|
839
|
+
slipped = {**gates, "refusal": {"planted": {"ok": True, "codes": []}, "clean": {"ok": True, "codes": []}}}
|
|
840
|
+
wrong = {**gates, "nonzero_exit": {"planted": {"ok": False, "codes": ["SCHEMA_INVALID"]}, "clean": {"ok": True, "codes": []}}}
|
|
841
|
+
spoiled = {**gates, "inherited_profile": {"planted": {"ok": False, "codes": ["PROFILE_INHERITED"]},
|
|
842
|
+
"clean": {"ok": False, "codes": ["SCHEMA_INVALID"]}}}
|
|
843
|
+
control("CONTROL_FAILED: a planted gate fault accepted, or rejected under another code, or a clean counterpart "
|
|
844
|
+
"rejected, is named",
|
|
845
|
+
any("gate refusal: the planted call was not rejected" in p for p in evaluate(doc, verdicts, slipped, [], {})["problems"])
|
|
846
|
+
and any("gate nonzero_exit: the planted call" in p for p in evaluate(doc, verdicts, wrong, [], {})["problems"])
|
|
847
|
+
and any("gate inherited_profile: its clean counterpart" in p for p in evaluate(doc, verdicts, spoiled, [], {})["problems"]),
|
|
848
|
+
"passed")
|
|
849
|
+
|
|
850
|
+
def share(n, rejected=0, s5=None):
|
|
851
|
+
ids = [f"k-{i:016x}" for i in range(n)]
|
|
852
|
+
vs = {i: outcome("rejected" if j < rejected else "admitted") for j, i in enumerate(ids)}
|
|
853
|
+
return evaluate(doc, {**verdicts, **vs}, gates, ids, s5 or {})
|
|
854
|
+
control("done-when 4: 21 natural candidates all admitted fail O4 (REJECTION_SHARE_ZERO)",
|
|
855
|
+
any(p.startswith("REJECTION_SHARE_ZERO: 21 natural") for p in share(21)["problems"]), f"{share(21)['problems']}")
|
|
856
|
+
control("control: 20 natural candidates all admitted pass", share(20)["problems"] == [], f"{share(20)['problems']}")
|
|
857
|
+
control("control: 21 natural candidates with one rejected pass", share(21, 1)["problems"] == [], f"{share(21, 1)['problems']}")
|
|
858
|
+
ids21 = [f"k-{i:016x}" for i in range(21)]
|
|
859
|
+
control("a natural candidate S5 failed is a rejection of the natural share",
|
|
860
|
+
share(21, 0, {ids21[0]: {"quote_ok": False, "session_problems": []}})["problems"] == [], "failed")
|
|
861
|
+
control("the controls are counted apart: their rejections do not lift a natural share of zero",
|
|
862
|
+
share(21)["natural"] == {"candidates": 21, "rejected": 0}
|
|
863
|
+
and any(p.startswith("REJECTION_SHARE_ZERO") for p in share(21)["problems"]), f"{share(21)['natural']}")
|
|
864
|
+
|
|
865
|
+
# ---- the expected verdicts are read nowhere S6 could ---------------------------------------------------------
|
|
866
|
+
texts = guarded(module_texts, {})
|
|
867
|
+
control("F27: outside this module only S5's writer names the expected verdicts' file, each site with its reason",
|
|
868
|
+
texts and reader_problems(texts) == [], f"{reader_problems(texts) if texts else 'no texts'}")
|
|
869
|
+
planted_text = dict(texts)
|
|
870
|
+
planted_text["runlib/stage_form.py"] = texts.get("runlib/stage_form.py", "") + (
|
|
871
|
+
'\n\ndef sneak(run_dir):\n return (run_dir / "controls.json").read_text()\n')
|
|
872
|
+
held_readers = dict(READERS)
|
|
873
|
+
READERS[("runlib/stage_form.py", "run")] = "a reason for a site that does not name the file"
|
|
874
|
+
try:
|
|
875
|
+
stale = reader_problems(texts)
|
|
876
|
+
finally:
|
|
877
|
+
READERS.clear()
|
|
878
|
+
READERS.update(held_readers)
|
|
879
|
+
control("control: a listed site that no longer names the file is CONTROLS_READ_STALE",
|
|
880
|
+
"CONTROLS_READ_STALE runlib/stage_form.py (run): listed in READERS, and it no longer names the file" in stale,
|
|
881
|
+
f"{stale}")
|
|
882
|
+
control("control: a stage that reads the expected verdicts is CONTROLS_READ by site",
|
|
883
|
+
"CONTROLS_READ runlib/stage_form.py (sneak): names the expected verdicts' file, and no reason in READERS "
|
|
884
|
+
"says why" in reader_problems(planted_text), f"{reader_problems(planted_text)}")
|
|
885
|
+
finally:
|
|
886
|
+
shutil.rmtree(root, ignore_errors=True)
|
|
887
|
+
for failure in failures:
|
|
888
|
+
print(f"controls --self-test [FAIL] {failure}")
|
|
889
|
+
if failures:
|
|
890
|
+
return 1
|
|
891
|
+
print(f"controls --self-test: OK ({len(ran)} controls: §6.5's population planted from a golden run's material under "
|
|
892
|
+
"ordinary ids with no marker field (F27), CONTROLS_INCOMPLETE, S5's verdicts and CONTROL_FAILED, the judge and "
|
|
893
|
+
"gate controls after S6, REJECTION_SHARE_ZERO at 21 and not at 20, the controls apart from the natural share, "
|
|
894
|
+
"and the expected verdicts read nowhere else)")
|
|
895
|
+
return 0
|
|
896
|
+
|
|
897
|
+
|
|
898
|
+
if __name__ == "__main__":
|
|
899
|
+
if sys.argv[1:] == ["--self-test"]:
|
|
900
|
+
sys.exit(self_test())
|
|
901
|
+
print("usage: controls.py --self-test", file=sys.stderr)
|
|
902
|
+
sys.exit(2)
|