agent-bios 0.19.4 → 0.20.1
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 +20 -5
- package/README.md +14 -19
- package/claude/agents/frontier.md +1 -1
- package/claude/guides/claude-prompting.md +475 -234
- package/claude/guides/cli-multi-model-workflow.md +8 -7
- package/claude/guides/gpt-prompting.md +319 -144
- package/claude/guides/session-distill-workflow.md +93 -43
- package/claude/guides/tooling-gotchas.md +3 -1
- package/codex/agents/frontier.toml +1 -1
- package/codex/agents/reviewer.toml +1 -1
- package/codex/agents/workhorse.toml +1 -1
- package/codex/guides/claude-prompting.md +475 -234
- package/codex/guides/cli-multi-model-workflow.md +8 -7
- package/codex/guides/gpt-prompting.md +319 -144
- 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_install.py +222 -27
- package/compose/instructions_session.py +250 -75
- package/compose/instructions_setup_cli.py +2 -36
- package/compose/instructions_store.py +160 -3
- package/compose/instructions_transaction.py +29 -5
- package/docs/advanced-launch.md +5 -1
- package/docs/releases/0.20.0.md +102 -0
- package/docs/releases/0.20.1.md +76 -0
- package/install.sh +42 -14
- package/launch/agent-launch.py +152 -18
- package/launch/agent-launch.toml +28 -16
- package/launch/agent-launch.zsh +104 -13
- package/launch/claude_subcommands.py +179 -0
- 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 +36 -3
- package/provenance.json +1 -1
- package/session-cost.py +80 -9
- 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 +7940 -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 +46 -15
- 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,1292 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""S7b review of proposals (WP-12 commit 5): a second reader on each disposition and destination.
|
|
3
|
+
|
|
4
|
+
The review SHOWS disagreement; it does not resolve it. The owner does, by approving, by naming the
|
|
5
|
+
alternative with `수정`, or by rejecting - so this module records the disagreement, holds the
|
|
6
|
+
alternative to the same table the proposal was held to, and refuses to let a review stand in for a
|
|
7
|
+
decision (`REVIEW_DECIDES`, a verdict written as an approval).
|
|
8
|
+
|
|
9
|
+
Two things it checks that only code can. A `faithful_merge` of `n/a` is checked against the
|
|
10
|
+
proposal's own operations, because a reviewer who did not look at a merge would otherwise pass it by
|
|
11
|
+
answering `n/a`. And the `bars` set is checked against the bars the contract text states, because a
|
|
12
|
+
bar left out of a review is not a bar that holds.
|
|
13
|
+
|
|
14
|
+
stage_review_proposals.py --self-test
|
|
15
|
+
"""
|
|
16
|
+
import collections
|
|
17
|
+
import json
|
|
18
|
+
import pathlib
|
|
19
|
+
import re
|
|
20
|
+
import sys
|
|
21
|
+
import tempfile
|
|
22
|
+
|
|
23
|
+
if __package__ in (None, ""): # run as a script: put session-distill/ on the import path
|
|
24
|
+
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
25
|
+
from runlib import packet, placement, records, stage_propose, validate # noqa: E402
|
|
26
|
+
from runlib.records import Refused # noqa: E402
|
|
27
|
+
|
|
28
|
+
HERE = pathlib.Path(__file__).resolve().parents[1]
|
|
29
|
+
STAGE = "S7b"
|
|
30
|
+
SCHEMA_PATH = HERE / "schemas" / "s7b.schema.json"
|
|
31
|
+
TEMPLATE = "s7b"
|
|
32
|
+
INPUTS = ({"artifact": stage_propose.OUTPUT, "producer_stage": "S7"},
|
|
33
|
+
{"artifact": "checked-candidates.json", "producer_stage": "S5"})
|
|
34
|
+
MERGE_TYPES = ("merge",)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def schema_bytes():
|
|
38
|
+
if not SCHEMA_PATH.is_file():
|
|
39
|
+
raise Refused(f"S7B_SCHEMA_ABSENT {SCHEMA_PATH}: a review would be judged by nothing")
|
|
40
|
+
return SCHEMA_PATH.read_bytes()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def packet_for(candidate, proposal_row, units=(), call_id="c1", seat="review"):
|
|
44
|
+
"""The S7b packet for one proposal, with the contract text and digest the proposal was judged by."""
|
|
45
|
+
payload = payload_for(candidate, proposal_row, units)
|
|
46
|
+
return packet.build(call_id, STAGE, seat, payload, schema=schema_bytes(), repo=HERE.parent)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def payload_for(candidate, proposal_row, units=(), judgments=None):
|
|
50
|
+
"""The packet's payload alone: what a supervised call is handed (`packet_for` builds around it). `judgments` are
|
|
51
|
+
S6's two judges' marks on the candidate's requirements, the slot S7's packet fills from the same derivation
|
|
52
|
+
(`stage_propose.payload_for`); S7's proposal row does not carry them, so a live call passes them in (Codex WP-12
|
|
53
|
+
r2 F2: the slot was always empty)."""
|
|
54
|
+
return packet.render(TEMPLATE, {
|
|
55
|
+
"candidate": json.dumps(candidate, ensure_ascii=False, indent=1),
|
|
56
|
+
"judgments": json.dumps(judgments if judgments is not None else (proposal_row.get("judgments") or {}),
|
|
57
|
+
ensure_ascii=False, indent=1),
|
|
58
|
+
"proposal": json.dumps(shown_proposal(proposal_row), ensure_ascii=False, indent=1),
|
|
59
|
+
"units": json.dumps(list(units), ensure_ascii=False, indent=1),
|
|
60
|
+
"placement_contract": f"sha256:{placement.contract_digest()}\n\n{placement.contract_text()}",
|
|
61
|
+
"release": placement.release_packet_text("review"),
|
|
62
|
+
"returns": returns_text(),
|
|
63
|
+
}, template_dir=HERE / "packets")
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def shown_proposal(proposal_row):
|
|
67
|
+
"""The proposal as the reviewer is shown it: without the judgments (their own slot), and with the destination
|
|
68
|
+
the proposal carries (`stage_propose.carried_destination`): a `none` shows none, whatever its answer wrote."""
|
|
69
|
+
held = {k: v for k, v in proposal_row.items() if k != "judgments"}
|
|
70
|
+
if isinstance(held.get("proposal"), dict):
|
|
71
|
+
held["proposal"] = {**held["proposal"], "destination": stage_propose.carried_destination(held["proposal"])}
|
|
72
|
+
return held
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def returns_text():
|
|
76
|
+
"""What the packet asks back, with the bars by name.
|
|
77
|
+
|
|
78
|
+
`review_problems` holds a review's `bars` to the contract text's own list in both directions, and
|
|
79
|
+
the list is a parse of that text (`placement.contract_bars`): the bolded lead-ins of two
|
|
80
|
+
sections. A reviewer reading the text cannot know which of its headings and paragraphs that parse
|
|
81
|
+
takes - the first live S7b got five first answers refused for bars named after other paragraphs,
|
|
82
|
+
and lost one review to it. So the packet spells the names it will be held to."""
|
|
83
|
+
names = "; ".join(f"`{bar}`" for bar in placement.contract_bars())
|
|
84
|
+
return ("Return one JSON object in the schema of this call. `bars` holds exactly one entry for each of these, "
|
|
85
|
+
f"its `bar` spelled exactly as here and no other: {names}.")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def merge_targets(proposal):
|
|
89
|
+
return [op.get("target") for op in proposal.get("operations") or []
|
|
90
|
+
if op.get("type") in MERGE_TYPES]
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _schema_review_blocks():
|
|
94
|
+
"""The schema's `*_review` object fields — the blocks a review can call not-holding.
|
|
95
|
+
|
|
96
|
+
Derived from the schema so the contradiction rule cannot fall behind it; the schema is the
|
|
97
|
+
authority on which blocks exist, and a second list here would be a second authority.
|
|
98
|
+
"""
|
|
99
|
+
schema = json.loads(schema_bytes().decode("utf-8"))
|
|
100
|
+
held = schema.get("properties") or {}
|
|
101
|
+
defs = schema.get("$defs") or {}
|
|
102
|
+
|
|
103
|
+
def names_holds(shape):
|
|
104
|
+
"""Whether this property is an object carrying `holds` — following one `$ref` hop.
|
|
105
|
+
|
|
106
|
+
The blocks are `$ref`s to `#/$defs/judgment`, so reading `properties` off the property
|
|
107
|
+
itself found nothing and the rule judged an EMPTY set: every verdict passed and the control
|
|
108
|
+
was green about nothing. That is the shape this repo calls a check that cannot fire.
|
|
109
|
+
"""
|
|
110
|
+
shape = shape or {}
|
|
111
|
+
ref = shape.get("$ref") or ""
|
|
112
|
+
if ref.startswith("#/$defs/"):
|
|
113
|
+
shape = defs.get(ref.split("/")[-1]) or {}
|
|
114
|
+
return "holds" in (shape.get("properties") or {})
|
|
115
|
+
|
|
116
|
+
return {name for name, shape in held.items()
|
|
117
|
+
if name.endswith("_review") and names_holds(shape)}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def review_problems(review, proposal_row, kind=None, diagnosis=None, legacy_incubating=False):
|
|
121
|
+
"""Every problem of one review, by name: its shape, the merge question, the bars, the alternative."""
|
|
122
|
+
# BEFORE the shape check, and that order is the whole point: the schema's additionalProperties
|
|
123
|
+
# already refuses an unknown field, so this rule was unreachable behind it and said nothing. A
|
|
124
|
+
# review that wrote itself a decision deserves to be told why, not that a property was
|
|
125
|
+
# unexpected.
|
|
126
|
+
# The root type first. REVIEW_DECIDES keeps its precedence over the SHAPE, which is the whole
|
|
127
|
+
# reason it comes before the schema — but only for an object: on a scalar the membership test
|
|
128
|
+
# raised TypeError and the stage ended with a traceback instead of one named invalid row (the
|
|
129
|
+
# WP-12 review).
|
|
130
|
+
if not isinstance(review, dict):
|
|
131
|
+
return (_shape_problems(review)
|
|
132
|
+
or [f"REVIEW_NOT_AN_OBJECT {type(review).__name__}: a review is an object"])
|
|
133
|
+
problems = [f"REVIEW_DECIDES {field}: a review shows disagreement and the owner resolves it; it "
|
|
134
|
+
f"does not carry a decision of its own"
|
|
135
|
+
for field in ("approved", "decision", "applied", "confirmed") if field in review]
|
|
136
|
+
if problems:
|
|
137
|
+
return problems
|
|
138
|
+
problems = _shape_problems(review)
|
|
139
|
+
if problems:
|
|
140
|
+
return problems
|
|
141
|
+
# A verdict of `agree` that carries a NEGATIVE finding is a contradiction, and it reached the
|
|
142
|
+
# owner as agreement with nothing to resolve: `disposition_review.holds=false` with
|
|
143
|
+
# `verdict=agree` and no alternative passed, and the document then counted it as agreement
|
|
144
|
+
# (the WP-12 review). The reviewer's own claims are preserved; what is refused is calling the
|
|
145
|
+
# set of them agreement.
|
|
146
|
+
# The schema's own review blocks, derived from it rather than listed here: a block added to the
|
|
147
|
+
# schema would otherwise be a finding this rule cannot see.
|
|
148
|
+
negative = [name for name in sorted(_schema_review_blocks())
|
|
149
|
+
if isinstance(review.get(name), dict) and review[name].get("holds") is False]
|
|
150
|
+
if review.get("verdict") == "agree" and negative:
|
|
151
|
+
problems.append(f"REVIEW_VERDICT_CONTRADICTS {', '.join(sorted(negative))}: a verdict of "
|
|
152
|
+
f"agree with a finding that does not hold would reach the owner as "
|
|
153
|
+
f"agreement with nothing to resolve")
|
|
154
|
+
# A semantic bar that does not hold is a negative finding too (Codex WP-12 r2 F1): with `agree` it reached the
|
|
155
|
+
# owner beside "agreement" with no resolution asked of anyone.
|
|
156
|
+
failed_bars = sorted({row.get("bar") for row in review.get("bars") or []
|
|
157
|
+
if isinstance(row, dict) and row.get("holds") is False})
|
|
158
|
+
if review.get("verdict") == "agree" and failed_bars:
|
|
159
|
+
problems.append(f"REVIEW_VERDICT_CONTRADICTS bars {', '.join(str(b) for b in failed_bars)}: a verdict of "
|
|
160
|
+
f"agree with a bar that does not hold would reach the owner as agreement with nothing to "
|
|
161
|
+
f"resolve")
|
|
162
|
+
if review.get("verdict") == "agree" and review.get("faithful_merge") == "no":
|
|
163
|
+
problems.append("REVIEW_VERDICT_CONTRADICTS faithful_merge: a verdict of agree with an "
|
|
164
|
+
"unfaithful merge would reach the owner as agreement")
|
|
165
|
+
proposal = proposal_row.get("proposal") or {}
|
|
166
|
+
merges = merge_targets(proposal)
|
|
167
|
+
# The merge question, against the operations rather than against the answer's own word for them.
|
|
168
|
+
if merges and review["faithful_merge"] == "n/a":
|
|
169
|
+
problems.append(f"MERGE_UNJUDGED {proposal_row.get('candidate_id')}: the proposal holds "
|
|
170
|
+
f"{len(merges)} merge operation(s) ({', '.join(str(t) for t in merges)}), so "
|
|
171
|
+
f"the review answers the merge question rather than n/a")
|
|
172
|
+
if not merges and review["faithful_merge"] != "n/a":
|
|
173
|
+
problems.append(f"MERGE_JUDGED_WITHOUT_ONE {proposal_row.get('candidate_id')}: the proposal "
|
|
174
|
+
f"holds no merge operation, and the review answers "
|
|
175
|
+
f"{review['faithful_merge']!r}")
|
|
176
|
+
judged = [row["operation_target"] for row in review.get("merge_findings") or []]
|
|
177
|
+
for target in merges:
|
|
178
|
+
if target not in judged:
|
|
179
|
+
problems.append(f"MERGE_FINDING_ABSENT {target}: every merge is judged for meaning and "
|
|
180
|
+
f"for an obligation neither unit carried")
|
|
181
|
+
for target in judged:
|
|
182
|
+
if target not in merges:
|
|
183
|
+
problems.append(f"MERGE_FINDING_ORPHAN {target}: the proposal holds no such merge")
|
|
184
|
+
# A `yes` that its own findings contradict: the summary may not be kinder than the detail.
|
|
185
|
+
contradicting = [row["operation_target"] for row in review.get("merge_findings") or []
|
|
186
|
+
if not row["meaning_preserved"] or row["unrelated_obligation"]]
|
|
187
|
+
if review["faithful_merge"] == "yes" and contradicting:
|
|
188
|
+
problems.append(f"MERGE_SUMMARY_CONTRADICTED {', '.join(contradicting)}: the review answers "
|
|
189
|
+
f"yes while its own findings report a loss of meaning or an obligation "
|
|
190
|
+
f"introduced")
|
|
191
|
+
# The bars, both ways, against the text's own list.
|
|
192
|
+
stated = set(placement.contract_bars())
|
|
193
|
+
answered = {row["bar"] for row in review["bars"]}
|
|
194
|
+
for bar in sorted(stated - answered):
|
|
195
|
+
problems.append(f"BAR_UNJUDGED {bar!r}: a bar left out of a review is not a bar that holds")
|
|
196
|
+
for bar in sorted(answered - stated):
|
|
197
|
+
problems.append(f"BAR_UNKNOWN {bar!r}: the contract text states no such bar")
|
|
198
|
+
named = [row["bar"] for row in review["bars"]]
|
|
199
|
+
for bar in sorted({b for b in named if named.count(b) > 1}):
|
|
200
|
+
problems.append(f"BAR_REPEATED {bar!r}: {named.count(bar)} entries judge one bar, and a review holds "
|
|
201
|
+
f"exactly one for each")
|
|
202
|
+
# The alternative, held to the same table as the proposal.
|
|
203
|
+
alternative = review.get("alternative")
|
|
204
|
+
if review["verdict"] == "agree" and alternative is not None:
|
|
205
|
+
problems.append(f"ALTERNATIVE_WITH_AGREEMENT {proposal_row.get('candidate_id')}: an agreeing "
|
|
206
|
+
f"review carries no alternative, and this one names "
|
|
207
|
+
f"{alternative.get('disposition')!r}")
|
|
208
|
+
if alternative is not None:
|
|
209
|
+
allowed = placement.allowed_for(kind or proposal_row.get("kind"),
|
|
210
|
+
diagnosis or proposal_row.get("diagnosis"),
|
|
211
|
+
bool(legacy_incubating or proposal_row.get("legacy_incubating")))
|
|
212
|
+
if alternative["disposition"] not in allowed:
|
|
213
|
+
problems.append(f"ALTERNATIVE_DISALLOWED {alternative['disposition']}: §7.2 allows "
|
|
214
|
+
f"{', '.join(sorted(allowed)) or 'nothing'} for this pair, so this is not "
|
|
215
|
+
f"an alternative the owner could take")
|
|
216
|
+
# the owner may adopt it with `수정`, so release 1's refusal holds it as it holds a proposal
|
|
217
|
+
problems.extend(placement.release_problems(alternative["disposition"], (),
|
|
218
|
+
where=f"{proposal_row.get('candidate_id')} alternative: "))
|
|
219
|
+
# The alternative IS a proposal - it is what the owner may take instead - so its destination
|
|
220
|
+
# is held to §7.4's layers and to the carrier rules, through the same function S7's own
|
|
221
|
+
# destination goes through. Both are model output that reaches the owner's review page, where
|
|
222
|
+
# a carrier carrying a newline and a decision-shaped line could forge an owner's line; the
|
|
223
|
+
# render escapes, and the producer refuses at the source.
|
|
224
|
+
problems.extend(placement.destination_problems(
|
|
225
|
+
stage_propose.carried_destination(alternative), where="alternative.destination",
|
|
226
|
+
item=f"{proposal_row.get('candidate_id')}: "))
|
|
227
|
+
return problems
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
_VALIDATOR = []
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def validator():
|
|
234
|
+
"""The review's validator, through `runlib/validate.py`: the pinned dependency and the lint.
|
|
235
|
+
|
|
236
|
+
No fallback, for the reason `stage_propose.validator` states: a validation that falls back to
|
|
237
|
+
the schema's required keys accepts a wrong type, a wrong enum and an extra field, and every
|
|
238
|
+
control over it passes."""
|
|
239
|
+
if not _VALIDATOR:
|
|
240
|
+
_VALIDATOR.append(validate.compile_schema(json.loads(schema_bytes())))
|
|
241
|
+
return _VALIDATOR[0]
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _shape_problems(review):
|
|
245
|
+
"""The review against its schema: every violation, by json path."""
|
|
246
|
+
return [f"REVIEW_INVALID {problem}" for problem in
|
|
247
|
+
validate.validate_instance(validator(), review)]
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def row_of(review, proposal_row):
|
|
251
|
+
"""The `review-s7b.json` row: the plan's shape, plus what the owner needs to resolve it."""
|
|
252
|
+
return {"item_id": proposal_row.get("candidate_id"),
|
|
253
|
+
"verdict": review["verdict"],
|
|
254
|
+
"faithful_merge": review["faithful_merge"],
|
|
255
|
+
"alternative": review.get("alternative"),
|
|
256
|
+
"notes": review["notes"],
|
|
257
|
+
"disposition_holds": review["disposition_review"]["holds"],
|
|
258
|
+
"destination_holds": review["destination_review"]["holds"],
|
|
259
|
+
"bars_failing": sorted(row["bar"] for row in review["bars"] if not row["holds"]),
|
|
260
|
+
"disagreement": review["verdict"] == "disagree",
|
|
261
|
+
"owner_resolves": review["verdict"] == "disagree"}
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
def document(proposals, reviews, candidates=None, only=None, unasked=None):
|
|
265
|
+
"""`review-s7b.json`: one row per proposal, with every unreviewed and returned case named.
|
|
266
|
+
|
|
267
|
+
A proposal with no review is NOT carried as agreed. Silence is not a second reader, and a stage
|
|
268
|
+
that filled it in would make the whole call decorative."""
|
|
269
|
+
rows, returned, unreviewed = [], [], []
|
|
270
|
+
by_id = {p["candidate_id"]: p for p in (proposals or {}).get("proposals") or []}
|
|
271
|
+
problems = stage_propose.subset_problems(only, by_id)
|
|
272
|
+
if problems:
|
|
273
|
+
raise Refused("; ".join(problems))
|
|
274
|
+
# The UPSTREAM population, inherited when this call asks for no narrower one. An S7 document
|
|
275
|
+
# that was itself a subset reached here and came out `subset: null` while reviewing only those
|
|
276
|
+
# rows, so the review read as the whole population; and the CLI has no `only` of its own, which
|
|
277
|
+
# is exactly the path a reader would take (the WP-12 review, D-20261112-f46263: a subset names
|
|
278
|
+
# its population and never narrows silently). `inherited` says where the marker came from, so
|
|
279
|
+
# the provenance is not lost in the inheriting.
|
|
280
|
+
upstream = (proposals or {}).get("subset")
|
|
281
|
+
inherited = only is None and upstream is not None
|
|
282
|
+
if inherited:
|
|
283
|
+
# A narrower request would have to be a subset of what S7 recorded: narrowing past the
|
|
284
|
+
# upstream population is how a review of three rows could claim to be a review of thirty.
|
|
285
|
+
only = sorted(upstream)
|
|
286
|
+
elif only is not None and upstream is not None:
|
|
287
|
+
outside = sorted(set(only) - set(upstream))
|
|
288
|
+
if outside:
|
|
289
|
+
raise Refused(f"SUBSET_OUTSIDE_UPSTREAM {', '.join(outside)}: S7's document is itself a "
|
|
290
|
+
f"subset of {len(upstream)} row(s), so a review cannot ask for a row it "
|
|
291
|
+
f"does not carry")
|
|
292
|
+
if only is not None:
|
|
293
|
+
by_id = {cid: row for cid, row in by_id.items() if cid in set(only)}
|
|
294
|
+
for cid in sorted(by_id):
|
|
295
|
+
review = (reviews or {}).get(cid)
|
|
296
|
+
if review is None:
|
|
297
|
+
# `unasked` is the live stage's: a proposal no review was asked for is unreviewed for
|
|
298
|
+
# that reason, which is not the same sentence as a call that returned nothing.
|
|
299
|
+
unreviewed.append({"item_id": cid, "why": (unasked or {}).get(
|
|
300
|
+
cid, "S7b returned no review for this proposal")})
|
|
301
|
+
continue
|
|
302
|
+
problems = review_problems(review, by_id[cid])
|
|
303
|
+
if problems:
|
|
304
|
+
returned.append({"item_id": cid, "problems": problems})
|
|
305
|
+
continue
|
|
306
|
+
rows.append(row_of(review, by_id[cid]))
|
|
307
|
+
tally = collections.Counter
|
|
308
|
+
return {"stage": STAGE, "reviews": rows,
|
|
309
|
+
"subset": sorted(only) if only is not None else None,
|
|
310
|
+
"subset_inherited": inherited,
|
|
311
|
+
"upstream_subset": sorted(upstream) if upstream is not None else None,
|
|
312
|
+
"returned": sorted(returned, key=lambda r: r["item_id"]),
|
|
313
|
+
"unreviewed": sorted(unreviewed, key=lambda r: r["item_id"]),
|
|
314
|
+
"contract": {"placement_contract_sha256": placement.contract_digest(),
|
|
315
|
+
"bars": list(placement.contract_bars()),
|
|
316
|
+
"schema_sha256": packet.sha256_bytes(schema_bytes())},
|
|
317
|
+
"counts": {"proposals": len(by_id), "reviewed": len(rows), "returned": len(returned),
|
|
318
|
+
"unreviewed": len(unreviewed),
|
|
319
|
+
"verdict": dict(tally(r["verdict"] for r in rows)),
|
|
320
|
+
"disagreements": sum(1 for r in rows if r["disagreement"]),
|
|
321
|
+
"faithful_merge": dict(tally(r["faithful_merge"] for r in rows))}}
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
OUTPUT = "review-s7b.json"
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
def run(run_dir, reviews, only=None):
|
|
328
|
+
"""The stage, through the shared mechanism: nothing is written on refusal.
|
|
329
|
+
|
|
330
|
+
The path is absolute beneath the run and the file is registered with `stage.output`, for the
|
|
331
|
+
reason `stage_propose.run` states: a bare name is refused by the confinement, and an
|
|
332
|
+
unregistered output leaves the next stage's staleness check nothing to read."""
|
|
333
|
+
run_dir = pathlib.Path(run_dir)
|
|
334
|
+
if only is not None:
|
|
335
|
+
# The same refusal as S7's, named by S7 so there is one sentence for one rule.
|
|
336
|
+
raise Refused(stage_propose.SUBSET_IN_RUN.format(stage=STAGE, n=len(list(only))))
|
|
337
|
+
with records.run_stage(run_dir, STAGE, INPUTS) as stage:
|
|
338
|
+
proposals = records.read_json(run_dir / stage_propose.OUTPUT)
|
|
339
|
+
doc = document(proposals, reviews)
|
|
340
|
+
records.write_json(run_dir, run_dir / OUTPUT, doc)
|
|
341
|
+
stage.output(OUTPUT)
|
|
342
|
+
return stage, doc
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
# ---- the supervised call (release 1) --------------------------------------------------------------
|
|
346
|
+
# One call per proposal a MODEL wrote. A legacy entry the owner's default answered in code
|
|
347
|
+
# (D-20261111-e53a01) is not a proposal anybody argued for, so there is nothing for a second reader
|
|
348
|
+
# to disagree with: it is named unreviewed with that reason, which S9 accounts for, and no call is
|
|
349
|
+
# spent on it. Everything else is the dispatcher's, as in S7.
|
|
350
|
+
SEAT_KEY = "S7b"
|
|
351
|
+
CASE = "review"
|
|
352
|
+
OUTPUT_CAP = 20_000
|
|
353
|
+
LIVE_INPUTS = INPUTS + ({"artifact": "checks.json", "producer_stage": "S5"},
|
|
354
|
+
{"artifact": "inventory/current.json", "producer_stage": "S2"},
|
|
355
|
+
{"artifact": "judgments/derivations.json", "producer_stage": "S6"})
|
|
356
|
+
CALLS = "review-proposals/calls.json"
|
|
357
|
+
DRY_RECORD = "review-proposals/dry.json"
|
|
358
|
+
UNASKED_DEFAULT = "the owner's legacy default answered it in code, so there is no proposal of a model's to review"
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def item_of(candidate_id):
|
|
362
|
+
"""A proposal's item name in its call: opaque, since a call directory's name must not be the id."""
|
|
363
|
+
import hashlib
|
|
364
|
+
return "b" + hashlib.sha256(candidate_id.encode("utf-8")).hexdigest()[:12]
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def asked_of(proposals):
|
|
368
|
+
"""`(asked ids, {unasked id: why})` over S7's proposals: a model's proposal is reviewed, a
|
|
369
|
+
defaulted one is not."""
|
|
370
|
+
asked, unasked = [], {}
|
|
371
|
+
for row in (proposals or {}).get("proposals") or []:
|
|
372
|
+
if row.get("answered_by") == "default":
|
|
373
|
+
unasked[row["candidate_id"]] = UNASKED_DEFAULT
|
|
374
|
+
else:
|
|
375
|
+
asked.append(row["candidate_id"])
|
|
376
|
+
return sorted(asked), unasked
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def live_check(proposal_row, capacity):
|
|
380
|
+
"""The stage's check of a review call's attempts (`Supervisor.item(stage_check=)`): the review
|
|
381
|
+
contract's own refusals, so the one retry is told what `document` would return the row for."""
|
|
382
|
+
from runlib import stage_read
|
|
383
|
+
|
|
384
|
+
def judged(call_dir):
|
|
385
|
+
held = ((records.read_json(pathlib.Path(call_dir) / "call.json").get("bound")) or {}).get("context_capacity")
|
|
386
|
+
if held != capacity:
|
|
387
|
+
raise Refused(f"CAPACITY_UNRECORDED {pathlib.Path(call_dir).name}: its call record "
|
|
388
|
+
f"carries the capacity {held!r}, and S7b was admitted against {capacity!r}")
|
|
389
|
+
return review_problems(stage_read.answer_of(call_dir), proposal_row)
|
|
390
|
+
return judged
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def supervisor(run_dir, cells, plan=None, seats_path=None):
|
|
394
|
+
"""The supervisor S7b's calls go through, their cells under `cells` (made mode 700). Live, the
|
|
395
|
+
pinned runner of the seat run.json names. With `plan`, a golden host's plan (`[{match, answer}]`,
|
|
396
|
+
dispatch.FAKE_HOST's): the host answers from the plan and starts no model."""
|
|
397
|
+
from runlib import dispatch
|
|
398
|
+
cells = pathlib.Path(cells)
|
|
399
|
+
cells.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
400
|
+
if plan is None:
|
|
401
|
+
return dispatch.Supervisor(run_dir, cell_root=cells, realization="live", seats_path=seats_path)
|
|
402
|
+
# The golden host is S6's: its seat here is a Codex one, and that host is the one that answers
|
|
403
|
+
# a Codex call from a plan (dispatch's own golden host replays a Codex stream and reads no plan).
|
|
404
|
+
from runlib import stage_judge
|
|
405
|
+
return stage_judge.supervisor(run_dir, cells, plan, seats_path)
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def live(run_dir, supervisor=None, *, dry=False, seats_path=None, tranche="calibration"):
|
|
409
|
+
"""S7b with its supervised calls: `review-s7b.json` over the reviews the calls returned.
|
|
410
|
+
|
|
411
|
+
Dry, it writes `review-proposals/dry.json` (who would be asked, each packet's measure) and
|
|
412
|
+
leaves the record `partial`. Otherwise each asked proposal is one item through `supervisor`; an
|
|
413
|
+
accepted review enters `document`, a call that ends other than accepted leaves its proposal
|
|
414
|
+
unreviewed by name and the record `partial`, and a re-run reuses every accepted attempt.
|
|
415
|
+
`review-proposals/calls.json` says what each call did: counts and codes, never a review's text."""
|
|
416
|
+
from runlib import bound, dispatch, gate, stage_judge
|
|
417
|
+
if not dry and supervisor is None:
|
|
418
|
+
raise Refused("REVIEW_UNSUPERVISED S7b: a review call goes through a supervisor; without one, "
|
|
419
|
+
"run it dry (--dry) or over reviews in hand (--reviews)")
|
|
420
|
+
run_dir = pathlib.Path(run_dir)
|
|
421
|
+
run_id = run_dir.resolve().name
|
|
422
|
+
with records.run_stage(run_dir, STAGE, LIVE_INPUTS) as stage:
|
|
423
|
+
declaration = stage.declaration
|
|
424
|
+
seat = ((declaration or {}).get("seats") or {}).get(SEAT_KEY)
|
|
425
|
+
if not seat:
|
|
426
|
+
raise Refused(f"SEAT_UNDECLARED {SEAT_KEY}: S7b's seat is named by run.json's seats")
|
|
427
|
+
interrupted = [] if dry else supervisor.interrupted(STAGE)
|
|
428
|
+
proposals = records.read_json(run_dir / stage_propose.OUTPUT)
|
|
429
|
+
population = {r["candidate_id"]: r for r in
|
|
430
|
+
records.read_json(run_dir / "checked-candidates.json")["candidates"]}
|
|
431
|
+
checks = {r["candidate_id"]: r for r in records.read_json(run_dir / "checks.json")["candidates"]}
|
|
432
|
+
current = {u["unit_id"]: u for u in records.read_json(run_dir / "inventory" / "current.json")["units"]}
|
|
433
|
+
verdicts = records.read_json(run_dir / "judgments" / "derivations.json").get("verdicts") or {}
|
|
434
|
+
by_id = {p["candidate_id"]: p for p in proposals.get("proposals") or []}
|
|
435
|
+
asked, unasked = asked_of(proposals)
|
|
436
|
+
held_schema = json.loads(schema_bytes().decode("utf-8"))
|
|
437
|
+
limits = stage_judge.limits_of(seat, run_dir, declaration,
|
|
438
|
+
seats_path if dry else supervisor.seats_path,
|
|
439
|
+
case=CASE, output_cap=OUTPUT_CAP, stage=STAGE)
|
|
440
|
+
packets, measured = {}, []
|
|
441
|
+
for cid in asked:
|
|
442
|
+
text = payload_for(population.get(cid) or {"candidate_id": cid}, by_id[cid],
|
|
443
|
+
stage_propose.unit_rows(checks.get(cid), current, None),
|
|
444
|
+
judgments=(verdicts.get(cid) or {}).get("requirements") or {})
|
|
445
|
+
item = item_of(cid)
|
|
446
|
+
built = packet.build(f"{run_id}-{STAGE}-{item}-a1", STAGE, seat, text, schema_bytes())
|
|
447
|
+
size = bound.driver_bytes(built, schema_bytes())[0]
|
|
448
|
+
packets[cid] = (item, text)
|
|
449
|
+
measured.append({"candidate_id": cid, "item": item,
|
|
450
|
+
"payload_bytes": len(text.encode("utf-8")),
|
|
451
|
+
"payload_sha256": packet.sha256_bytes(text.encode("utf-8")),
|
|
452
|
+
"driver_bytes": size,
|
|
453
|
+
"input_at_most": stage_judge.at_most_of(size, limits),
|
|
454
|
+
"over_capacity": bool(stage_judge.beyond_capacity(size, limits))})
|
|
455
|
+
summary = {"stage": STAGE, "declaration_seq": declaration["declaration_seq"], "dry": dry,
|
|
456
|
+
"seat": seat, "limits": limits, "output_cap": OUTPUT_CAP,
|
|
457
|
+
"population": {"proposals": len(by_id), "asked": len(asked), "unasked": len(unasked),
|
|
458
|
+
"unasked_by_reason": dict(sorted(collections.Counter(unasked.values()).items()))},
|
|
459
|
+
"packets": measured,
|
|
460
|
+
"budget": {"per_stage": ((declaration.get("budget") or {}).get("per_stage") or {}).get(STAGE)}}
|
|
461
|
+
if dry:
|
|
462
|
+
records.write_json(run_dir, run_dir / DRY_RECORD, summary)
|
|
463
|
+
stage.output(DRY_RECORD)
|
|
464
|
+
stage.record["status"] = "partial"
|
|
465
|
+
return summary, None
|
|
466
|
+
over = [m["candidate_id"] for m in measured if m["over_capacity"]]
|
|
467
|
+
if over:
|
|
468
|
+
raise Refused(f"REVIEW_OVER_CAPACITY S7b: {len(over)} packets exceed the seat's capacity "
|
|
469
|
+
f"{limits['capacity']} with the output cap and a retry's correction ({over[:3]})")
|
|
470
|
+
episode = declaration["budget"]["per_episode"]
|
|
471
|
+
caps = {"tokens": episode["tokens"], "compactions": episode["compactions"]}
|
|
472
|
+
reviews, calls = {}, []
|
|
473
|
+
for row in measured:
|
|
474
|
+
cid = row["candidate_id"]
|
|
475
|
+
item, text = packets[cid]
|
|
476
|
+
out = supervisor.item(
|
|
477
|
+
STAGE, item, seat, text, held_schema, case_type=CASE, caps=caps, view_window=False,
|
|
478
|
+
tranche=tranche, max_output_tokens=OUTPUT_CAP, resume=True,
|
|
479
|
+
context_capacity=limits["capacity"],
|
|
480
|
+
stage_check=live_check(by_id[cid], limits["capacity"]),
|
|
481
|
+
packet_check=lambda built: stage_judge.attempt_problems(
|
|
482
|
+
built, limits, schema_bytes(), SEAT_KEY, code="REVIEW_OVER_CAPACITY"))
|
|
483
|
+
held = {"candidate_id": cid, "item": item, **stage_judge.call_row(out)}
|
|
484
|
+
if out["outcome"] == "accepted":
|
|
485
|
+
call_dir = pathlib.Path(out["accepted"])
|
|
486
|
+
held["call_id"] = records.read_json(call_dir / "call.json")["call_id"]
|
|
487
|
+
reviews[cid] = gate.accepted(call_dir, judged=True)
|
|
488
|
+
else:
|
|
489
|
+
unasked[cid] = (f"S7b's call ended {out['outcome']}"
|
|
490
|
+
+ (f" ({', '.join(held['codes'])})" if held["codes"] else ""))
|
|
491
|
+
calls.append(held)
|
|
492
|
+
doc = document(proposals, reviews, unasked=unasked)
|
|
493
|
+
records.write_json(run_dir, run_dir / OUTPUT, doc)
|
|
494
|
+
stage.output(OUTPUT)
|
|
495
|
+
outcomes = [c["outcome"] for c in calls]
|
|
496
|
+
summary.update(calls=calls, interrupted=interrupted, tranche=tranche,
|
|
497
|
+
counts={**{o: outcomes.count(o) for o in sorted(set(outcomes))},
|
|
498
|
+
"reused": sum(1 for c in calls if c.get("reused"))},
|
|
499
|
+
document=doc["counts"], density_table=dispatch.measured_table(run_dir))
|
|
500
|
+
records.write_json(run_dir, run_dir / CALLS, summary)
|
|
501
|
+
stage.output(CALLS)
|
|
502
|
+
if any(o != "accepted" for o in outcomes):
|
|
503
|
+
stage.record["status"] = "partial"
|
|
504
|
+
return summary, doc
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
def live_report_lines(summary):
|
|
508
|
+
"""What the driver prints of a live or dry S7b: counts, sizes and codes, never a review's text."""
|
|
509
|
+
pop = summary["population"]
|
|
510
|
+
lines = [f"S7b review-proposals{' (dry)' if summary['dry'] else ''}: declaration_seq "
|
|
511
|
+
f"{summary['declaration_seq']}; {pop['asked']} of {pop['proposals']} proposals asked; not asked: "
|
|
512
|
+
f"{'; '.join(f'{n} ({why})' for why, n in pop['unasked_by_reason'].items()) or 'none'}",
|
|
513
|
+
f"packets: {sum(m['payload_bytes'] for m in summary['packets'])} payload bytes over "
|
|
514
|
+
f"{len(summary['packets'])} calls on {summary['seat']}; output at most "
|
|
515
|
+
f"{len(summary['packets']) * summary['output_cap']} tokens at the cap {summary['output_cap']}; "
|
|
516
|
+
f"budget per_stage S7b {summary['budget']['per_stage']}"]
|
|
517
|
+
if not summary["dry"]:
|
|
518
|
+
counts, held = summary["counts"], summary["document"]
|
|
519
|
+
lines.append("calls: " + (", ".join(f"{k} {v}" for k, v in counts.items() if k != "reused") or "none")
|
|
520
|
+
+ f"; {counts['reused']} answered by an earlier accepted attempt")
|
|
521
|
+
failed = sorted({c for row in summary["calls"] if row["outcome"] != "accepted" for c in row["codes"]})
|
|
522
|
+
if failed:
|
|
523
|
+
lines.append(f"codes of the calls not accepted: {', '.join(failed)}")
|
|
524
|
+
lines.append(f"review-s7b.json: {held['reviewed']} reviewed, {held['disagreements']} disagreements, "
|
|
525
|
+
f"{held['returned']} returned, {held['unreviewed']} unreviewed")
|
|
526
|
+
return lines
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
# ---- self-test -----------------------------------------------------------------------------------
|
|
530
|
+
|
|
531
|
+
def self_test():
|
|
532
|
+
"""The suite under the release scope `all`: the contract as designed, which release 1 holds closed
|
|
533
|
+
(`placement.scoped`), so the path the redesign reopens stays held by its controls. Release 1's own controls
|
|
534
|
+
run inside it under `release_1`."""
|
|
535
|
+
with placement.scoped("all"):
|
|
536
|
+
return _self_test_all()
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
def _self_test_all():
|
|
540
|
+
"""Positive control first, then one planted violation per rule, each named.
|
|
541
|
+
|
|
542
|
+
Golden: no model call is made here or by this module. What is judged is the packet S7b would be
|
|
543
|
+
sent and the review it would return.
|
|
544
|
+
The body is wrapped so a control that DIES still speaks: a traceback is not a control firing,
|
|
545
|
+
and a revert trial that reads any output counts one as if it were (the WP-12 review). The
|
|
546
|
+
wrapper prints a [FAIL] line naming the control that was in flight, so the evidence says which
|
|
547
|
+
rule stopped being enforced.
|
|
548
|
+
"""
|
|
549
|
+
failures, ran = [], []
|
|
550
|
+
try:
|
|
551
|
+
return _self_test_body(failures, ran)
|
|
552
|
+
except BaseException as exc: # noqa: BLE001 - the suite must speak before it dies
|
|
553
|
+
held = ran[-1] if ran else "<no control ran>"
|
|
554
|
+
print(f"stage_review_proposals --self-test [FAIL] the suite died after {held!r}: "
|
|
555
|
+
f"{type(exc).__name__}: {exc}", file=sys.stderr)
|
|
556
|
+
for name, detail in failures:
|
|
557
|
+
print(f"stage_review_proposals --self-test [FAIL] {name}: {detail}", file=sys.stderr)
|
|
558
|
+
print(f"stage_review_proposals --self-test: INCOMPLETE ({len(ran)} controls ran, {len(failures)} failed "
|
|
559
|
+
f"before the suite died)", file=sys.stderr)
|
|
560
|
+
raise
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
def _self_test_body(failures, ran):
|
|
564
|
+
reporting = []
|
|
565
|
+
|
|
566
|
+
def control(name, got, want):
|
|
567
|
+
if reporting:
|
|
568
|
+
raise RuntimeError(f"CONTROL_AFTER_SUMMARY {name}")
|
|
569
|
+
if not isinstance(got, str):
|
|
570
|
+
raise TypeError(f"CONTROL_GOT_NOT_STR {name}: {type(got).__name__}")
|
|
571
|
+
ran.append(name)
|
|
572
|
+
if want not in got:
|
|
573
|
+
failures.append((name, f"expected {want!r} in {got!r}"))
|
|
574
|
+
|
|
575
|
+
def clean(name, problems):
|
|
576
|
+
if reporting:
|
|
577
|
+
raise RuntimeError(f"CONTROL_AFTER_SUMMARY {name}")
|
|
578
|
+
if not isinstance(problems, list):
|
|
579
|
+
raise TypeError(f"CLEAN_PROBLEMS_NOT_LIST {name}: {type(problems).__name__}")
|
|
580
|
+
ran.append(name)
|
|
581
|
+
if problems:
|
|
582
|
+
failures.append((name, f"expected nothing, got {problems}"))
|
|
583
|
+
|
|
584
|
+
def review(**over):
|
|
585
|
+
# Every property the strict provider dialect requires is present, which is now every
|
|
586
|
+
# property: `merge_findings: None` is "this candidate has no merge to review" (what absence
|
|
587
|
+
# used to mean) and each judgment carries its `evidence` list, empty where the review rests
|
|
588
|
+
# on nothing.
|
|
589
|
+
held = {"verdict": "agree",
|
|
590
|
+
"disposition_review": {"holds": True, "reason": "증거가 그 처분을 지지한다",
|
|
591
|
+
"evidence": ["c1"]},
|
|
592
|
+
"destination_review": {"holds": True, "reason": "가장 싼 자리다",
|
|
593
|
+
"evidence": []},
|
|
594
|
+
"merge_findings": None,
|
|
595
|
+
"faithful_merge": "n/a", "alternative": None,
|
|
596
|
+
"bars": [{"bar": bar, "holds": True, "reason": "충족"}
|
|
597
|
+
for bar in placement.contract_bars()],
|
|
598
|
+
"notes": "동의한다"}
|
|
599
|
+
held.update(over)
|
|
600
|
+
# An override that names a judgment without its `evidence` gets the empty list, because the
|
|
601
|
+
# overrides here are about the judgment's VERDICT and every one of them would otherwise have
|
|
602
|
+
# to restate a field it does not care about. The rule itself is not softened: a review that
|
|
603
|
+
# really omits `evidence` is refused by name, which the control below plants.
|
|
604
|
+
for name in ("disposition_review", "destination_review"):
|
|
605
|
+
if isinstance(held.get(name), dict):
|
|
606
|
+
held[name] = {"evidence": [], **held[name]}
|
|
607
|
+
# The same for an alternative an override names: `destination: None` is "this alternative
|
|
608
|
+
# names no destination", which is what its absence meant, and an override about the
|
|
609
|
+
# DISPOSITION should not have to say so.
|
|
610
|
+
if isinstance(held.get("alternative"), dict):
|
|
611
|
+
held["alternative"] = {"destination": None, **held["alternative"]}
|
|
612
|
+
return held
|
|
613
|
+
|
|
614
|
+
def row(**over):
|
|
615
|
+
held = {"candidate_id": "k1", "kind": "gap", "diagnosis": "gap", "status": "proposed",
|
|
616
|
+
"legacy_incubating": False,
|
|
617
|
+
"proposal": {"disposition": "place",
|
|
618
|
+
"operations": [{"type": "create", "target": "claude/guides/g.md"}]}}
|
|
619
|
+
held.update(over)
|
|
620
|
+
return held
|
|
621
|
+
|
|
622
|
+
def merging(**over):
|
|
623
|
+
held = row(kind="misfire", diagnosis="redundant")
|
|
624
|
+
held["proposal"] = {"disposition": "reduce",
|
|
625
|
+
"operations": [{"type": "merge", "target": "claude/guides/g.md#one",
|
|
626
|
+
"units": ["u1", "u2"]}]}
|
|
627
|
+
held.update(over)
|
|
628
|
+
return held
|
|
629
|
+
|
|
630
|
+
def said(rev, held=None):
|
|
631
|
+
return "; ".join(review_problems(rev, held or row()))
|
|
632
|
+
|
|
633
|
+
clean("an agreeing review of a proposal with no merge passes", review_problems(review(), row()))
|
|
634
|
+
control("and its row carries the plan's own fields", json.dumps(sorted(row_of(review(), row()))),
|
|
635
|
+
'"faithful_merge"')
|
|
636
|
+
|
|
637
|
+
# The merge question, which only code can hold to the operations.
|
|
638
|
+
merge_ok = review(faithful_merge="yes",
|
|
639
|
+
merge_findings=[{"operation_target": "claude/guides/g.md#one",
|
|
640
|
+
"meaning_preserved": True, "unrelated_obligation": False,
|
|
641
|
+
"reason": "두 단위의 뜻이 그대로다"}])
|
|
642
|
+
clean("a merge judged for meaning and for an unrelated obligation passes",
|
|
643
|
+
review_problems(merge_ok, merging()))
|
|
644
|
+
control("a proposal holding a merge whose review answers n/a is returned, naming the operation",
|
|
645
|
+
said(review(), merging()), "MERGE_UNJUDGED")
|
|
646
|
+
only_unjudged = review(merge_findings=[{"operation_target": "claude/guides/g.md#one",
|
|
647
|
+
"meaning_preserved": True, "unrelated_obligation": False,
|
|
648
|
+
"reason": "뜻이 그대로다"}])
|
|
649
|
+
control("and the refusal names the merge target, so the reviewer knows what was not judged",
|
|
650
|
+
said(only_unjudged, merging()), "claude/guides/g.md#one")
|
|
651
|
+
clean("read from the n/a rule alone: the review carries the finding, so no other rule names that "
|
|
652
|
+
"target here",
|
|
653
|
+
[p for p in review_problems(only_unjudged, merging()) if "MERGE_UNJUDGED" not in p])
|
|
654
|
+
control("a review that answers the merge question where there is no merge is returned too",
|
|
655
|
+
said(review(faithful_merge="yes"), row()), "MERGE_JUDGED_WITHOUT_ONE")
|
|
656
|
+
control("a merge with no finding of its own is named",
|
|
657
|
+
said(review(faithful_merge="yes"), merging()), "MERGE_FINDING_ABSENT")
|
|
658
|
+
control("a finding for a merge the proposal does not hold is named",
|
|
659
|
+
said(review(faithful_merge="yes",
|
|
660
|
+
merge_findings=[{"operation_target": "claude/guides/other.md#x",
|
|
661
|
+
"meaning_preserved": True, "unrelated_obligation": False,
|
|
662
|
+
"reason": "r"}]), merging()),
|
|
663
|
+
"MERGE_FINDING_ORPHAN")
|
|
664
|
+
control("a summary of yes over a finding that meaning was lost is refused: the summary may not "
|
|
665
|
+
"be kinder than the detail",
|
|
666
|
+
said(review(faithful_merge="yes",
|
|
667
|
+
merge_findings=[{"operation_target": "claude/guides/g.md#one",
|
|
668
|
+
"meaning_preserved": False, "unrelated_obligation": False,
|
|
669
|
+
"reason": "한 단위의 조건이 사라졌다"}]), merging()),
|
|
670
|
+
"MERGE_SUMMARY_CONTRADICTED")
|
|
671
|
+
control("and over a finding that an obligation was introduced, which is that field's failing "
|
|
672
|
+
"direction",
|
|
673
|
+
said(review(faithful_merge="yes",
|
|
674
|
+
merge_findings=[{"operation_target": "claude/guides/g.md#one",
|
|
675
|
+
"meaning_preserved": True, "unrelated_obligation": True,
|
|
676
|
+
"reason": "둘 다 없던 의무가 생겼다"}]), merging()),
|
|
677
|
+
"MERGE_SUMMARY_CONTRADICTED")
|
|
678
|
+
clean("while a no that its findings support is a complete review",
|
|
679
|
+
review_problems(review(faithful_merge="no", verdict="disagree",
|
|
680
|
+
alternative={"disposition": "none", "reason": "아무 것도 하지 않는다"},
|
|
681
|
+
merge_findings=[{"operation_target": "claude/guides/g.md#one",
|
|
682
|
+
"meaning_preserved": False,
|
|
683
|
+
"unrelated_obligation": False, "reason": "뜻이 바뀐다"}]),
|
|
684
|
+
merging()))
|
|
685
|
+
|
|
686
|
+
# The bars, against the contract text's own list.
|
|
687
|
+
control("a bar left out of the review is returned, not read as a pass",
|
|
688
|
+
said(review(bars=[{"bar": bar, "holds": True, "reason": "충족"}
|
|
689
|
+
for bar in placement.contract_bars()[1:]])),
|
|
690
|
+
"BAR_UNJUDGED")
|
|
691
|
+
control("and the refusal names the bar",
|
|
692
|
+
said(review(bars=[{"bar": bar, "holds": True, "reason": "충족"}
|
|
693
|
+
for bar in placement.contract_bars()[1:]])),
|
|
694
|
+
repr(placement.contract_bars()[0]))
|
|
695
|
+
control("a bar the contract text does not state is named",
|
|
696
|
+
said(review(bars=[*({"bar": b, "holds": True, "reason": "r"} for b in placement.contract_bars()),
|
|
697
|
+
{"bar": "The brevity bar", "holds": True, "reason": "r"}])),
|
|
698
|
+
"BAR_UNKNOWN")
|
|
699
|
+
# the names the sentence asks for, read back out of the sentence: its backticked list after the colon
|
|
700
|
+
asked_bars = re.findall(r"`([^`]+)`", returns_text().split("no other:", 1)[-1])
|
|
701
|
+
control("the packet names exactly the bars a review is held to, each once and in the contract's order, so a "
|
|
702
|
+
"reviewer need not guess which paragraphs of the text are bars",
|
|
703
|
+
f"[{len(asked_bars)}] <{' | '.join(asked_bars)}>",
|
|
704
|
+
f"[{len(placement.contract_bars())}] <{' | '.join(placement.contract_bars())}>")
|
|
705
|
+
control("and that list is not empty", str(len(asked_bars) >= 4), "True")
|
|
706
|
+
held_payload = payload_for({"candidate_id": "k"}, {"judgments": {}})
|
|
707
|
+
control("and the payload a call is handed asks for each of them by name",
|
|
708
|
+
str([f"`{bar}`" in held_payload for bar in placement.contract_bars()]),
|
|
709
|
+
str([True] * len(placement.contract_bars())))
|
|
710
|
+
control("two entries for one bar are refused by name",
|
|
711
|
+
said(review(bars=[*({"bar": b, "holds": True, "reason": "r"} for b in placement.contract_bars()),
|
|
712
|
+
{"bar": placement.contract_bars()[0], "holds": False, "reason": "r"}])),
|
|
713
|
+
"BAR_REPEATED")
|
|
714
|
+
none_row = {"candidate_id": "k", "judgments": {}, "proposal": {"disposition": "none", "destination": {"layer": "ledger", "carrier": None}}}
|
|
715
|
+
control("the reviewer is shown no destination for a `none`, whatever layer its answer wrote, and the answer's "
|
|
716
|
+
"for any other disposition",
|
|
717
|
+
json.dumps([shown_proposal(none_row)["proposal"]["destination"],
|
|
718
|
+
shown_proposal({**none_row, "proposal": {"disposition": "keep", "destination": {"layer": "incubator", "carrier": None}}})["proposal"]["destination"],
|
|
719
|
+
"judgments" in shown_proposal(none_row)]),
|
|
720
|
+
json.dumps([None, {"layer": "incubator", "carrier": None}, False]))
|
|
721
|
+
control("the bars come from the text, so the review's set is the text's set",
|
|
722
|
+
", ".join(placement.contract_bars()), "Leftward reformulation")
|
|
723
|
+
clean("a failing bar is a complete review, and the row carries which ones failed",
|
|
724
|
+
[] if row_of(review(verdict="disagree",
|
|
725
|
+
alternative={"disposition": "none", "reason": "r"},
|
|
726
|
+
bars=[{"bar": bar, "holds": bar != "The gate bar", "reason": "r"}
|
|
727
|
+
for bar in placement.contract_bars()]),
|
|
728
|
+
row())["bars_failing"] == ["The gate bar"] else ["the failing bar is not carried"])
|
|
729
|
+
|
|
730
|
+
# The alternative, held to the same table as the proposal.
|
|
731
|
+
clean("a disagreement with an allowed alternative passes",
|
|
732
|
+
review_problems(review(verdict="disagree",
|
|
733
|
+
alternative={"disposition": "incubate", "reason": "아직 이르다"}),
|
|
734
|
+
row()))
|
|
735
|
+
control("an alternative §7.2 does not allow for this pair is not an alternative",
|
|
736
|
+
said(review(verdict="disagree",
|
|
737
|
+
alternative={"disposition": "correct", "reason": "r"}), row()),
|
|
738
|
+
"ALTERNATIVE_DISALLOWED")
|
|
739
|
+
control("and the refusal says what the pair does allow",
|
|
740
|
+
said(review(verdict="disagree",
|
|
741
|
+
alternative={"disposition": "correct", "reason": "r"}), row()),
|
|
742
|
+
"§7.2 allows")
|
|
743
|
+
control("an agreeing review that nonetheless names an alternative is returned",
|
|
744
|
+
said(review(alternative={"disposition": "none", "reason": "r"})),
|
|
745
|
+
"ALTERNATIVE_WITH_AGREEMENT")
|
|
746
|
+
clean("a disagreement with NO alternative is allowed: holding that nothing should be done is a "
|
|
747
|
+
"position, written as the disposition none",
|
|
748
|
+
review_problems(review(verdict="disagree", alternative=None), row()))
|
|
749
|
+
clean("the legacy row's own allowances are used for a legacy item's alternative",
|
|
750
|
+
review_problems(review(verdict="disagree",
|
|
751
|
+
alternative={"disposition": "drop", "reason": "은퇴시킨다"}),
|
|
752
|
+
row(kind="unclassified", diagnosis="unknown", legacy_incubating=True)))
|
|
753
|
+
control("while the same alternative on a non-legacy unclassified candidate is refused, so the "
|
|
754
|
+
"legacy row is not quietly applied to everything",
|
|
755
|
+
said(review(verdict="disagree", alternative={"disposition": "drop", "reason": "r"}),
|
|
756
|
+
row(kind="unclassified", diagnosis="unknown")),
|
|
757
|
+
"ALTERNATIVE_DISALLOWED")
|
|
758
|
+
|
|
759
|
+
# A review may not decide.
|
|
760
|
+
for field in ("approved", "decision", "applied", "confirmed"):
|
|
761
|
+
control(f"a review carrying {field!r} is returned: the owner resolves a disagreement",
|
|
762
|
+
said({**review(), field: True}), "REVIEW_DECIDES")
|
|
763
|
+
control("and the schema refuses such a field on its own too, so neither check rests on the other",
|
|
764
|
+
"; ".join(_shape_problems({**review(), "approved": True})), "REVIEW_INVALID")
|
|
765
|
+
control("the verdict vocabulary has two values, so an uncertainty cannot reach the owner as a "
|
|
766
|
+
"shrug", said(review(verdict="unsure")), "REVIEW_INVALID")
|
|
767
|
+
control("a review with no notes is returned: the owner reads them beside the proposal's reasons",
|
|
768
|
+
said({k: v for k, v in review().items() if k != "notes"}), "notes")
|
|
769
|
+
|
|
770
|
+
# The packet.
|
|
771
|
+
built = packet_for(row(), row()).decode("utf-8")
|
|
772
|
+
control("the packet carries the contract text S7b judges against", built, "## The bars")
|
|
773
|
+
control("with the same digest the proposal was judged by", built,
|
|
774
|
+
f"sha256:{placement.contract_digest()}")
|
|
775
|
+
control("and the schema the review is held to", built,
|
|
776
|
+
f"SCHEMA: sha256:{packet.sha256_bytes(schema_bytes())}")
|
|
777
|
+
under_review = built.split("<proposal>", 1)[-1].split("</proposal>", 1)[0]
|
|
778
|
+
control("the packet carries the proposal under review", under_review, '"disposition": "place"')
|
|
779
|
+
clean("and that span is the proposal block, not the candidate block that also holds it",
|
|
780
|
+
[] if "<units>" not in under_review else ["the span reaches past the proposal block"])
|
|
781
|
+
control("and says plainly what code has already refused, so the review is asked only about "
|
|
782
|
+
"judgment", built, "they never reached you")
|
|
783
|
+
|
|
784
|
+
# The document: a proposal with no review is not carried as agreed.
|
|
785
|
+
proposals = {"proposals": [row(candidate_id="k1"), row(candidate_id="k2"), row(candidate_id="k3")]}
|
|
786
|
+
doc = document(proposals, {"k1": review(), "k2": review(verdict="unsure")})
|
|
787
|
+
control("a proposal with no review is named as unreviewed rather than passed",
|
|
788
|
+
json.dumps(doc["unreviewed"]), "k3")
|
|
789
|
+
control("and the reason says the review is missing, not that it agreed",
|
|
790
|
+
json.dumps(doc["unreviewed"]), "returned no review")
|
|
791
|
+
control("a review that does not hold is returned by name", json.dumps(doc["returned"]), "k2")
|
|
792
|
+
control("and the counts reconcile with the proposals given",
|
|
793
|
+
f"{doc['counts']['proposals']}={doc['counts']['reviewed']}+{doc['counts']['returned']}"
|
|
794
|
+
f"+{doc['counts']['unreviewed']}", "3=1+1+1")
|
|
795
|
+
control("the document binds the contract and lists the bars it judged by",
|
|
796
|
+
json.dumps(doc["contract"]["bars"]), "Leftward reformulation")
|
|
797
|
+
control("disagreements are counted, because that number is what the owner must work through",
|
|
798
|
+
str(document(proposals, {"k1": review(verdict="disagree", alternative=None)})
|
|
799
|
+
["counts"]["disagreements"]), "1")
|
|
800
|
+
clean("and no row carries a decision of the owner's",
|
|
801
|
+
[k for r in doc["reviews"] for k in r if k in ("approved", "decision", "applied")])
|
|
802
|
+
|
|
803
|
+
# `run` writes inside the run and registers the file. The end-to-end control lives in
|
|
804
|
+
# stage_propose's suite, where the golden run through S6 is built; these two assert the same
|
|
805
|
+
# properties on THIS file's source, so a regression here fails in the file that caused it.
|
|
806
|
+
import ast
|
|
807
|
+
own = ast.parse(pathlib.Path(__file__).read_text(encoding="utf-8"))
|
|
808
|
+
run_fn = next(node for node in own.body if isinstance(node, ast.FunctionDef) and node.name == "run")
|
|
809
|
+
writes = [ast.unparse(node) for node in ast.walk(run_fn) if isinstance(node, ast.Call)
|
|
810
|
+
and ast.unparse(node.func) == "records.write_json"]
|
|
811
|
+
control("every write of this stage passes a path beneath the run, never a bare name: a bare name "
|
|
812
|
+
"is confined and refused as RUN_PATH_ESCAPE",
|
|
813
|
+
"; ".join(writes), "run_dir / OUTPUT")
|
|
814
|
+
registers = [ast.unparse(node) for node in ast.walk(run_fn) if isinstance(node, ast.Call)
|
|
815
|
+
and ast.unparse(node.func) == "stage.output"]
|
|
816
|
+
control("and the file is registered with the stage, or its staleness is unreadable by the next "
|
|
817
|
+
"stage", "; ".join(registers) or "<nothing registered>", "stage.output(OUTPUT)")
|
|
818
|
+
clean("one write and one registration, so neither can be left behind by the other",
|
|
819
|
+
[] if len(writes) == len(registers) == 1 else [f"{len(writes)} writes, {len(registers)} registrations"])
|
|
820
|
+
def refused_text(call):
|
|
821
|
+
"""The refusal as text, or any other exception as text — the same rule as `refused` below.
|
|
822
|
+
|
|
823
|
+
Defined here because the controls above use it: catching `Refused` alone made a control die
|
|
824
|
+
rather than speak when the refusal under test was reverted.
|
|
825
|
+
"""
|
|
826
|
+
try:
|
|
827
|
+
call()
|
|
828
|
+
except Exception as exc: # noqa: BLE001 - the exception IS the answer here
|
|
829
|
+
return f"{type(exc).__name__}: {exc}"
|
|
830
|
+
return ""
|
|
831
|
+
|
|
832
|
+
# S7b takes the same subset S7 does, and asks S7's question about it rather than its own.
|
|
833
|
+
two = {"proposals": [row(candidate_id="k1"), row(candidate_id="k2")]}
|
|
834
|
+
reviews_two = {cid: review() for cid in ("k1", "k2")}
|
|
835
|
+
one = document(two, reviews_two, only=["k2"])
|
|
836
|
+
control("a subset review answers that subset and says which",
|
|
837
|
+
f'{one["counts"]["proposals"]}:{json.dumps(one["subset"])}', '1:["k2"]')
|
|
838
|
+
control("and a full review says it is not a subset",
|
|
839
|
+
json.dumps(document(two, reviews_two)["subset"]), "null")
|
|
840
|
+
|
|
841
|
+
# ---- the upstream population is inherited, not dropped ---------------------------------------
|
|
842
|
+
#
|
|
843
|
+
# S7's document may itself be a subset. Handed one with no `only` of its own, this stage reviewed
|
|
844
|
+
# only the rows it held and reported `subset: null` — a review of one row that read as a review
|
|
845
|
+
# of the population (the WP-12 review). The CLI has no `only` option, so that was the ONLY path
|
|
846
|
+
# a reader would take.
|
|
847
|
+
upstream_doc = {"proposals": [row(candidate_id="k2")], "subset": ["k2"]}
|
|
848
|
+
held_inherited = document(upstream_doc, reviews_two)
|
|
849
|
+
control("an S7 document that is itself a subset is reviewed as that subset, by name",
|
|
850
|
+
json.dumps(held_inherited["subset"]), '["k2"]')
|
|
851
|
+
control("and the document says the marker was inherited rather than asked for, so the "
|
|
852
|
+
"provenance survives",
|
|
853
|
+
json.dumps({"inherited": held_inherited["subset_inherited"],
|
|
854
|
+
"upstream": held_inherited["upstream_subset"]}),
|
|
855
|
+
'{"inherited": true, "upstream": ["k2"]}')
|
|
856
|
+
control("a review of the whole population still says so, and names no upstream subset",
|
|
857
|
+
json.dumps({"subset": document(two, reviews_two)["subset"],
|
|
858
|
+
"inherited": document(two, reviews_two)["subset_inherited"],
|
|
859
|
+
"upstream": document(two, reviews_two)["upstream_subset"]}),
|
|
860
|
+
'{"subset": null, "inherited": false, "upstream": null}')
|
|
861
|
+
control("and a narrower request of its own is NOT recorded as inherited",
|
|
862
|
+
json.dumps({"subset": one["subset"], "inherited": one["subset_inherited"]}),
|
|
863
|
+
'{"subset": ["k2"], "inherited": false}')
|
|
864
|
+
control("asking for a row the upstream subset does not carry is refused by name, since "
|
|
865
|
+
"narrowing past it is how a review of one row could claim thirty",
|
|
866
|
+
refused_text(lambda: document({"proposals": [row(candidate_id="k1"),
|
|
867
|
+
row(candidate_id="k2")],
|
|
868
|
+
"subset": ["k2"]},
|
|
869
|
+
reviews_two, only=["k1"])),
|
|
870
|
+
"SUBSET_OUTSIDE_UPSTREAM k1")
|
|
871
|
+
clean("while a request inside it is answered",
|
|
872
|
+
[] if document({"proposals": [row(candidate_id="k1"), row(candidate_id="k2")],
|
|
873
|
+
"subset": ["k1", "k2"]},
|
|
874
|
+
reviews_two, only=["k2"])["subset"] == ["k2"]
|
|
875
|
+
else ["a request inside the upstream subset was not answered"])
|
|
876
|
+
|
|
877
|
+
# ---- a verdict that contradicts its own findings ---------------------------------------------
|
|
878
|
+
#
|
|
879
|
+
# `verdict=agree` with `disposition_review.holds=false` and no alternative passed, and the
|
|
880
|
+
# document then counted it as agreement with `owner_resolves=false`: a negative finding reached
|
|
881
|
+
# the owner marked as agreement with nothing to resolve (the WP-12 review).
|
|
882
|
+
clean("the derived block set is NOT empty, since an empty one would pass every verdict while "
|
|
883
|
+
"the control above stayed green",
|
|
884
|
+
[] if _schema_review_blocks() else ["the schema named no review block"])
|
|
885
|
+
control("the blocks the rule judges come from the schema, not from a list written here",
|
|
886
|
+
json.dumps(sorted(_schema_review_blocks())),
|
|
887
|
+
json.dumps(["destination_review", "disposition_review"]))
|
|
888
|
+
for field in sorted(_schema_review_blocks()):
|
|
889
|
+
held_review = review(verdict="agree", **{field: {"holds": False, "reason": "r"}})
|
|
890
|
+
control(f"a verdict of agree with a {field} that does not hold is refused by name",
|
|
891
|
+
"; ".join(review_problems(held_review, row())),
|
|
892
|
+
f"REVIEW_VERDICT_CONTRADICTS {field}")
|
|
893
|
+
control("and an agree verdict over an unfaithful merge too",
|
|
894
|
+
"; ".join(review_problems(review(verdict="agree", faithful_merge="no"), row())),
|
|
895
|
+
"REVIEW_VERDICT_CONTRADICTS faithful_merge")
|
|
896
|
+
clean("a verdict of agree whose findings all hold is clean, so the rule judges the "
|
|
897
|
+
"contradiction and not the verdict",
|
|
898
|
+
review_problems(review(verdict="agree"), row()))
|
|
899
|
+
failing_bar = review(verdict="agree")
|
|
900
|
+
failing_bar["bars"] = [{**failing_bar["bars"][0], "holds": False}] + failing_bar["bars"][1:]
|
|
901
|
+
control("a verdict of agree with a semantic bar that does not hold is refused by name (Codex WP-12 r2 F1)",
|
|
902
|
+
"; ".join(review_problems(failing_bar, row())),
|
|
903
|
+
f"REVIEW_VERDICT_CONTRADICTS bars {failing_bar['bars'][0]['bar']}")
|
|
904
|
+
through = document({"proposals": [row(candidate_id="k1")]}, {"k1": failing_bar})
|
|
905
|
+
held_where = ([r.get("item_id") for r in through.get("returned") or []],
|
|
906
|
+
[r.get("item_id") for r in through.get("reviews") or []])
|
|
907
|
+
clean("and the document returns it rather than counting it as agreement",
|
|
908
|
+
[] if held_where == (["k1"], []) else [f"returned and reviewed are {held_where}"])
|
|
909
|
+
clean("and a DISAGREE verdict carrying the same negative finding is clean, which is the shape "
|
|
910
|
+
"the contradiction was hiding behind",
|
|
911
|
+
[problem for problem in review_problems(
|
|
912
|
+
review(verdict="disagree", disposition_review={"holds": False, "reason": "r"},
|
|
913
|
+
alternative={"disposition": "drop", "reason": "r"}), row())
|
|
914
|
+
if "VERDICT_CONTRADICTS" in problem])
|
|
915
|
+
|
|
916
|
+
# ---- the provider's strict dialect: every property required, absence given a name ------------
|
|
917
|
+
#
|
|
918
|
+
# The first live Codex S7b call was refused by the provider with `invalid_json_schema`. The
|
|
919
|
+
# strict subset a provider-hosted structured answer must fit requires EVERY property to be in
|
|
920
|
+
# `required`, so a field whose absence carried a meaning cannot exist: five of this contract's
|
|
921
|
+
# properties were optional, and lane E's projection refused the call before sending rather than
|
|
922
|
+
# letting a nullable stand-in admit a null this schema would then reject.
|
|
923
|
+
#
|
|
924
|
+
# Each of the five was decided on what its absence MEANT, so no reader gains a third case:
|
|
925
|
+
# `merge_findings` is nullable (null = no merge to review, [] = a merge reviewed with nothing
|
|
926
|
+
# found — two different answers), `alternative.destination` is nullable (null = the alternative
|
|
927
|
+
# names no destination), its `carrier` was already nullable and is now required, and both
|
|
928
|
+
# judgments' `evidence` is required outright because [] was already what absence said and is
|
|
929
|
+
# the finding the field exists to make visible.
|
|
930
|
+
held_schema = json.loads(packet.schema_bytes(json.loads(schema_bytes())))
|
|
931
|
+
held_projected, held_strict = packet.provider_schema(held_schema, "codex")
|
|
932
|
+
clean("the contract projects into the provider's strict subset with nothing left over, which "
|
|
933
|
+
"is what lets a Codex seat be sent this call at all", held_strict)
|
|
934
|
+
control("and the projection is produced rather than refused",
|
|
935
|
+
"produced" if held_projected is not None else "refused", "produced")
|
|
936
|
+
control("every property is required, which is the subset's rule and now this contract's shape",
|
|
937
|
+
json.dumps(sorted(set(held_schema["properties"]) - set(held_schema["required"]))), "[]")
|
|
938
|
+
control("a null `merge_findings` reads exactly as its absence did: no merge to review",
|
|
939
|
+
json.dumps(review_problems(review(merge_findings=None), row())), "[]")
|
|
940
|
+
control("while [] is a merge reviewed with nothing found, which is a different answer and is "
|
|
941
|
+
"held to the proposal's own operations",
|
|
942
|
+
"; ".join(review_problems(
|
|
943
|
+
review(faithful_merge="yes", merge_findings=[]),
|
|
944
|
+
row(proposal={"disposition": "reduce",
|
|
945
|
+
"operations": [{"type": "merge",
|
|
946
|
+
"target": "claude/guides/g.md#one"}]}))),
|
|
947
|
+
"MERGE_FINDING_ABSENT claude/guides/g.md#one")
|
|
948
|
+
control("a review that really omits `evidence` is still refused by name, so requiring it is a "
|
|
949
|
+
"rule and not a default the fixture hands out",
|
|
950
|
+
"; ".join(review_problems({**review(),
|
|
951
|
+
"disposition_review": {"holds": True, "reason": "r"}},
|
|
952
|
+
row())),
|
|
953
|
+
"REVIEW_INVALID disposition_review")
|
|
954
|
+
control("and one that omits the whole `merge_findings` property is refused too, since absence "
|
|
955
|
+
"is no longer a value this contract has",
|
|
956
|
+
"; ".join(review_problems({k: v for k, v in review().items()
|
|
957
|
+
if k != "merge_findings"}, row())),
|
|
958
|
+
"REVIEW_INVALID <root>: 'merge_findings' is a required property")
|
|
959
|
+
clean("a null alternative destination is the alternative naming none, for a kind whose row allows `none` "
|
|
960
|
+
"(Codex WP-12 r2 F12: the control expected the empty substring, which every result contains)",
|
|
961
|
+
review_problems(
|
|
962
|
+
review(verdict="disagree",
|
|
963
|
+
disposition_review={"holds": False, "reason": "r"},
|
|
964
|
+
alternative={"disposition": "none", "reason": "r", "destination": None}),
|
|
965
|
+
row(), kind="unclassified", diagnosis="unknown"))
|
|
966
|
+
none_alt = lambda dest: "; ".join(review_problems( # noqa: E731
|
|
967
|
+
review(verdict="disagree", disposition_review={"holds": False, "reason": "r"},
|
|
968
|
+
alternative={"disposition": "none", "reason": "r", "destination": dest}), row()))
|
|
969
|
+
control("a `none` alternative carries no destination, so a layer written beside it is not judged, while the same "
|
|
970
|
+
"layer on any other alternative is",
|
|
971
|
+
json.dumps(["LAYER_UNKNOWN" in none_alt({"layer": "no-such-layer", "carrier": None}),
|
|
972
|
+
"LAYER_UNKNOWN" in "; ".join(review_problems(
|
|
973
|
+
review(verdict="disagree", disposition_review={"holds": False, "reason": "r"},
|
|
974
|
+
alternative={"disposition": "incubate", "reason": "r",
|
|
975
|
+
"destination": {"layer": "no-such-layer", "carrier": None}}), row()))]),
|
|
976
|
+
json.dumps([False, True]))
|
|
977
|
+
control("and an omitted one is refused, so the host must say which it means",
|
|
978
|
+
# Built past the fixture helper on purpose: the helper fills `destination: None` for
|
|
979
|
+
# every override, which is right for a fixture about a disposition and would hide the
|
|
980
|
+
# omission this control is about.
|
|
981
|
+
"; ".join(review_problems(
|
|
982
|
+
{**review(verdict="disagree",
|
|
983
|
+
disposition_review={"holds": False, "reason": "r"}),
|
|
984
|
+
"alternative": {"disposition": "drop", "reason": "r"}},
|
|
985
|
+
row())),
|
|
986
|
+
"REVIEW_INVALID alternative: 'destination' is a required property")
|
|
987
|
+
control("the duplicate `alternative` definition is gone: `alternative_or_null` is what the "
|
|
988
|
+
"contract refers to, and two copies of one contract is the defect this unit keeps "
|
|
989
|
+
"finding", json.dumps(sorted(json.loads(schema_bytes())["$defs"])),
|
|
990
|
+
'["alternative_or_null", "bar_judgment", "judgment", "merge_finding", "text"]')
|
|
991
|
+
|
|
992
|
+
# ---- a scalar review is a named row, not a traceback -----------------------------------------
|
|
993
|
+
def guarded(call):
|
|
994
|
+
"""The call's answer, or the exception as the answer.
|
|
995
|
+
|
|
996
|
+
A control that DIES is not a control: with the root-type guard reverted the membership test
|
|
997
|
+
raises TypeError, the suite ended on a traceback, and the revert trial counted it as silent
|
|
998
|
+
rather than as the guard firing. The exception is what the control reads now.
|
|
999
|
+
"""
|
|
1000
|
+
try:
|
|
1001
|
+
return "; ".join(call())
|
|
1002
|
+
except BaseException as exc: # noqa: BLE001 - the exception IS the answer here
|
|
1003
|
+
return f"the control died: {type(exc).__name__}: {exc}"
|
|
1004
|
+
|
|
1005
|
+
for held_scalar in (7, "a string", [1, 2], None):
|
|
1006
|
+
control(f"a {type(held_scalar).__name__} review is refused by name rather than raising",
|
|
1007
|
+
guarded(lambda: review_problems(held_scalar, row()))[:40], "REVIEW_INVALID")
|
|
1008
|
+
control("and REVIEW_DECIDES keeps its precedence over the shape for an OBJECT, which is why it "
|
|
1009
|
+
"comes first",
|
|
1010
|
+
"; ".join(review_problems({"approved": True}, row())), "REVIEW_DECIDES approved")
|
|
1011
|
+
def refused(call):
|
|
1012
|
+
"""The refusal as text, or any other exception as text.
|
|
1013
|
+
|
|
1014
|
+
Catching `Refused` alone made a control die rather than speak: with the refusal reverted the
|
|
1015
|
+
call reached `run_stage` over a path that does not exist and raised an OSError straight
|
|
1016
|
+
through the suite.
|
|
1017
|
+
"""
|
|
1018
|
+
try:
|
|
1019
|
+
call()
|
|
1020
|
+
except Exception as exc: # noqa: BLE001 - the exception IS the answer here
|
|
1021
|
+
return f"{type(exc).__name__}: {exc}"
|
|
1022
|
+
return ""
|
|
1023
|
+
|
|
1024
|
+
control("a proposal this run does not hold is refused by name rather than dropped",
|
|
1025
|
+
refused(lambda: document(two, reviews_two, only=["k9"])), "SUBSET_UNKNOWN k9")
|
|
1026
|
+
control("and an empty subset is refused", refused(lambda: document(two, reviews_two, only=[])),
|
|
1027
|
+
"SUBSET_EMPTY")
|
|
1028
|
+
# The alternative is a proposal - what the owner may take instead - so its destination goes
|
|
1029
|
+
# through the same function S7's own does. An automated review of lane E's render found this: the
|
|
1030
|
+
# alternative's layer and carrier are model output reaching the owner's page, and the render
|
|
1031
|
+
# escaping them is not the producer refusing them.
|
|
1032
|
+
def alt(**over):
|
|
1033
|
+
held = {"disposition": "correct", "reason": "더 싼 자리다",
|
|
1034
|
+
"destination": {"layer": "guides", "carrier": "claude/guides/g.md"}}
|
|
1035
|
+
held.update(over)
|
|
1036
|
+
return held
|
|
1037
|
+
|
|
1038
|
+
disagreeing = review(verdict="disagree", alternative=alt(),
|
|
1039
|
+
disposition_review={"holds": False, "reason": "그 처분이 아니다"})
|
|
1040
|
+
misfire = row(kind="misfire", diagnosis="wrong or insufficient")
|
|
1041
|
+
clean("an alternative with a §7.4 layer and a relative carrier passes",
|
|
1042
|
+
review_problems(disagreeing, misfire))
|
|
1043
|
+
# release 1 changes no library file (D-20261116-7853bc): the owner may adopt an alternative with `수정`
|
|
1044
|
+
with placement.scoped("release_1"):
|
|
1045
|
+
control("in release 1 an alternative that changes a library file is refused by name",
|
|
1046
|
+
said(disagreeing, misfire), "RELEASE_1_NO_LIBRARY_CHANGE k1 alternative: correct:")
|
|
1047
|
+
clean("and one that changes nothing passes", review_problems(
|
|
1048
|
+
review(verdict="disagree", alternative={"disposition": "incubate", "reason": "관찰을 더 모은다",
|
|
1049
|
+
"destination": {"layer": "incubator", "carrier": None}},
|
|
1050
|
+
disposition_review={"holds": False, "reason": "그 처분이 아니다"}), misfire))
|
|
1051
|
+
release_review_text = payload_for({"candidate_id": "k"}, {"judgments": {}})
|
|
1052
|
+
release_review_section = placement.release_packet_text("review")
|
|
1053
|
+
control("S7b's packet in release 1 holds the alternative to the same refusal, and under the design's scope not",
|
|
1054
|
+
json.dumps([bool(release_review_section) and release_review_section in release_review_text,
|
|
1055
|
+
"## This release changes no library file" in held_payload]), "[true, false]")
|
|
1056
|
+
control("an alternative whose layer is outside §7.4's order is refused by name",
|
|
1057
|
+
said(review(verdict="disagree", alternative=alt(destination={"layer": "everywhere",
|
|
1058
|
+
"carrier": "x"}),
|
|
1059
|
+
disposition_review={"holds": False, "reason": "r"}), misfire),
|
|
1060
|
+
"LAYER_UNKNOWN k1: alternative.destination.layer")
|
|
1061
|
+
# Two gates, and which one speaks is worth being exact about. The SCHEMA refuses a multi-line
|
|
1062
|
+
# carrier first, because the shape check runs before the contract checks - so through
|
|
1063
|
+
# `review_problems` that is the message. The CODE rule is what holds where no schema runs: a
|
|
1064
|
+
# proposal row read from a `proposals.json` this version did not write, which `review_problems`
|
|
1065
|
+
# judges without re-validating. Both are asserted, each where it is the one that answers.
|
|
1066
|
+
control("an alternative carrier carrying a newline is refused by the schema first, which is what "
|
|
1067
|
+
"a forged owner line would need",
|
|
1068
|
+
said(review(verdict="disagree",
|
|
1069
|
+
alternative=alt(destination={"layer": "guides",
|
|
1070
|
+
"carrier": "g.md\nowner approved: yes"}),
|
|
1071
|
+
disposition_review={"holds": False, "reason": "r"}), misfire),
|
|
1072
|
+
"REVIEW_INVALID alternative/destination/carrier")
|
|
1073
|
+
control("and the code rule refuses the same carrier where no schema runs, naming the field",
|
|
1074
|
+
"; ".join(placement.destination_problems(
|
|
1075
|
+
{"layer": "guides", "carrier": "g.md\nowner approved: yes"},
|
|
1076
|
+
where="alternative.destination", item="k1: ")),
|
|
1077
|
+
"DESTINATION_CARRIER_CONTROL k1: alternative.destination.carrier")
|
|
1078
|
+
control("an alternative carrier climbing out of the tree is refused",
|
|
1079
|
+
said(review(verdict="disagree",
|
|
1080
|
+
alternative=alt(destination={"layer": "guides", "carrier": "../../etc/x"}),
|
|
1081
|
+
disposition_review={"holds": False, "reason": "r"}), misfire),
|
|
1082
|
+
"DESTINATION_CARRIER_TRAVERSAL k1: alternative.destination")
|
|
1083
|
+
control("and an absolute one too",
|
|
1084
|
+
said(review(verdict="disagree",
|
|
1085
|
+
alternative=alt(destination={"layer": "guides", "carrier": "/etc/passwd"}),
|
|
1086
|
+
disposition_review={"holds": False, "reason": "r"}), misfire),
|
|
1087
|
+
"DESTINATION_CARRIER_ABSOLUTE k1: alternative.destination")
|
|
1088
|
+
|
|
1089
|
+
control("the rules are S7's own function, not a second copy here",
|
|
1090
|
+
next(line.strip() for line in pathlib.Path(__file__).read_text(encoding="utf-8").splitlines()
|
|
1091
|
+
if "destination_problems" in line and "problems.extend" in line),
|
|
1092
|
+
"placement.destination_problems")
|
|
1093
|
+
clean("an alternative with no destination at all is not a destination problem: whether one is "
|
|
1094
|
+
"required is the pair's question",
|
|
1095
|
+
[p for p in review_problems(
|
|
1096
|
+
review(verdict="disagree", alternative={"disposition": "correct", "reason": "r"},
|
|
1097
|
+
disposition_review={"holds": False, "reason": "r"}), misfire)
|
|
1098
|
+
if "DESTINATION" in p or "LAYER_UNKNOWN" in p])
|
|
1099
|
+
|
|
1100
|
+
# The absent run lives UNDER a temporary directory this control owns, and is removed whichever
|
|
1101
|
+
# way the call goes. `/nonexistent-run` was the path: with the subset guard reverted,
|
|
1102
|
+
# `records.run_stage` reaches `stagelock.hold`, which creates the locks directory before reading
|
|
1103
|
+
# the declaration — so a revert trial of this very control tried to write `/nonexistent-run/locks`
|
|
1104
|
+
# at the filesystem root. The WP-21 review found it, and this repo has paid for a control writing
|
|
1105
|
+
# outside its fixture before.
|
|
1106
|
+
with tempfile.TemporaryDirectory(prefix="s7b-absent-") as absent_root:
|
|
1107
|
+
absent_run = str(pathlib.Path(absent_root) / "no-such-run")
|
|
1108
|
+
control("`run` refuses a subset by name: the stage's output is one file, so a subset run "
|
|
1109
|
+
"would replace the whole review with those rows",
|
|
1110
|
+
refused(lambda: run(absent_run, reviews_two, only=["k2"])), "SUBSET_IN_RUN S7b")
|
|
1111
|
+
clean("and nothing was created for it, not even a lock directory",
|
|
1112
|
+
[] if not pathlib.Path(absent_run).exists()
|
|
1113
|
+
else [f"{absent_run} exists after a refused call"])
|
|
1114
|
+
control("and the refusal is S7's sentence, so one rule has one wording",
|
|
1115
|
+
next(line.strip() for line in
|
|
1116
|
+
pathlib.Path(__file__).read_text(encoding="utf-8").splitlines()
|
|
1117
|
+
if "SUBSET_IN_RUN" in line and "raise" in line),
|
|
1118
|
+
"stage_propose.SUBSET_IN_RUN")
|
|
1119
|
+
control("the refusal comes before the run directory is touched, so a bad call cannot "
|
|
1120
|
+
"half-open a stage",
|
|
1121
|
+
refused(lambda: run(absent_run, reviews_two, only=["k2"])), "SUBSET_IN_RUN")
|
|
1122
|
+
|
|
1123
|
+
control("the question is S7's, asked once: this file calls S7's own check",
|
|
1124
|
+
next(line.strip() for line in pathlib.Path(__file__).read_text(encoding="utf-8").splitlines()
|
|
1125
|
+
if "subset_problems" in line and "problems = " in line),
|
|
1126
|
+
"problems = stage_propose.subset_problems(only, by_id)")
|
|
1127
|
+
|
|
1128
|
+
control("and S7b's input is S7's output under the name S7 owns, not a second spelling",
|
|
1129
|
+
# The SOURCE line, not the value: a literal that happens to equal S7's output today
|
|
1130
|
+
# satisfies a value check and drifts the day S7 renames its file.
|
|
1131
|
+
next(line for line in pathlib.Path(__file__).read_text(encoding="utf-8").splitlines()
|
|
1132
|
+
if line.startswith("INPUTS = ")), "stage_propose.OUTPUT")
|
|
1133
|
+
clean("and that name resolves to the file S7 really writes",
|
|
1134
|
+
[] if INPUTS[0]["artifact"] == stage_propose.OUTPUT else
|
|
1135
|
+
[f'{INPUTS[0]["artifact"]!r} is not {stage_propose.OUTPUT!r}'])
|
|
1136
|
+
|
|
1137
|
+
# The wrapper that makes a dying control speak. Asserted from the source, because a suite that
|
|
1138
|
+
# ends in a traceback prints no control name at all and a revert trial then reads the traceback
|
|
1139
|
+
# as the control firing (the WP-12 review).
|
|
1140
|
+
# The WRAPPER's own source, not the file's. A scan of the whole file is satisfied by this
|
|
1141
|
+
# control's own text — the phrase it looks for appears in the line that looks for it — which is
|
|
1142
|
+
# how a planted mutation passed here before. The wrapper lives in `self_test` and this control
|
|
1143
|
+
# lives in `_self_test_body`, so asking `self_test` for its source excludes the control.
|
|
1144
|
+
import inspect
|
|
1145
|
+
wrapper_text = inspect.getsource(_self_test_all)
|
|
1146
|
+
scope_text = inspect.getsource(self_test)
|
|
1147
|
+
control("a control that dies names itself, since a traceback is not a control firing",
|
|
1148
|
+
next((line.strip() for line in wrapper_text.splitlines()
|
|
1149
|
+
if "died after" in line and "print(" in line), "<no such line>"),
|
|
1150
|
+
"self-test [FAIL] the suite died after")
|
|
1151
|
+
control("and the wrapper is what the entry point runs, so the body cannot be called around it",
|
|
1152
|
+
next((line.strip() for line in wrapper_text.splitlines()
|
|
1153
|
+
if "_self_test_body(" in line), "<no such line>"),
|
|
1154
|
+
"return _self_test_body(failures, ran)")
|
|
1155
|
+
control("and the entry point runs that wrapper under the release scope `all`, the contract as designed",
|
|
1156
|
+
" | ".join(line.strip() for line in scope_text.splitlines()
|
|
1157
|
+
if "scoped(" in line or "_self_test_all()" in line),
|
|
1158
|
+
'with placement.scoped("all"): | return _self_test_all()')
|
|
1159
|
+
|
|
1160
|
+
# ---- the supervised call (release 1) ---------------------------------------------------------
|
|
1161
|
+
held_asked, held_unasked = asked_of({"proposals": [
|
|
1162
|
+
{"candidate_id": "k-model", "answered_by": "model"},
|
|
1163
|
+
{"candidate_id": "legacy:defaulted", "answered_by": "default"},
|
|
1164
|
+
{"candidate_id": "k-older", "disposition": "place"}]})
|
|
1165
|
+
control("a review is asked for a proposal a model wrote, and for one that does not say who wrote it",
|
|
1166
|
+
json.dumps(held_asked), json.dumps(["k-model", "k-older"]))
|
|
1167
|
+
control("and a legacy entry the owner's default answered is not asked, by name",
|
|
1168
|
+
json.dumps(held_unasked), json.dumps({"legacy:defaulted": UNASKED_DEFAULT}))
|
|
1169
|
+
import shutil
|
|
1170
|
+
live_root = pathlib.Path(tempfile.mkdtemp(prefix="s7b-live-", dir="/tmp"))
|
|
1171
|
+
try:
|
|
1172
|
+
from runlib import declare
|
|
1173
|
+
live_run = None
|
|
1174
|
+
try:
|
|
1175
|
+
live_run = stage_propose.fx_through_s6(live_root)
|
|
1176
|
+
# each candidate's judges' marks made different from every other's (Codex WP-12 r3 F8), before S7 reads
|
|
1177
|
+
# them, with S6's record sealed over the new bytes: a packet given another candidate's marks then fails
|
|
1178
|
+
deriv_path = live_run / "judgments" / "derivations.json"
|
|
1179
|
+
deriv = records.read_json(deriv_path)
|
|
1180
|
+
marks = ("met", "unmet", "uncertain")
|
|
1181
|
+
for n, cid in enumerate(sorted(deriv.get("verdicts") or {})):
|
|
1182
|
+
names = sorted(deriv["verdicts"][cid]["requirements"]["A"])[:3]
|
|
1183
|
+
for k, name in enumerate(names):
|
|
1184
|
+
deriv["verdicts"][cid]["requirements"]["A"][name] = marks[(n // 3 ** k) % 3]
|
|
1185
|
+
deriv_path.write_text(json.dumps(deriv), encoding="utf-8")
|
|
1186
|
+
s6_record = records.record_path(live_run, "S6")
|
|
1187
|
+
held_record = json.loads(s6_record.read_text(encoding="utf-8"))
|
|
1188
|
+
|
|
1189
|
+
def resealed(node):
|
|
1190
|
+
if isinstance(node, dict):
|
|
1191
|
+
if node.get("artifact") == "judgments/derivations.json" and "sha256" in node:
|
|
1192
|
+
node["sha256"] = records.sha256_file(deriv_path)
|
|
1193
|
+
for value in node.values():
|
|
1194
|
+
resealed(value)
|
|
1195
|
+
elif isinstance(node, list):
|
|
1196
|
+
for value in node:
|
|
1197
|
+
resealed(value)
|
|
1198
|
+
resealed(held_record)
|
|
1199
|
+
s6_record.write_text(json.dumps(held_record), encoding="utf-8")
|
|
1200
|
+
live_cands = records.read_json(live_run / "checked-candidates.json")["candidates"]
|
|
1201
|
+
stage_propose.run(live_run, {r["candidate_id"]: stage_propose._answered(
|
|
1202
|
+
disposition="none", operations=[], destination={"layer": "incubator", "carrier": None})
|
|
1203
|
+
for r in live_cands})
|
|
1204
|
+
except Exception as exc: # the fixture's own failure is reported, never swallowed
|
|
1205
|
+
live_run = None
|
|
1206
|
+
failures.append(("the golden run through S7 could not be made", repr(exc)))
|
|
1207
|
+
ran.append("the golden run through S7 could not be made")
|
|
1208
|
+
if live_run is not None:
|
|
1209
|
+
proposed = sorted(p["candidate_id"] for p in
|
|
1210
|
+
records.read_json(live_run / stage_propose.OUTPUT)["proposals"])
|
|
1211
|
+
clean("the golden run holds more than one proposal to review",
|
|
1212
|
+
[] if len(proposed) > 1 else [f"{proposed}"])
|
|
1213
|
+
control("a live run with no supervisor is refused by name",
|
|
1214
|
+
refused_text(lambda: live(live_run)), "REVIEW_UNSUPERVISED S7b")
|
|
1215
|
+
declare.amend(live_run, [("budget.per_stage.S7b", 5_000_000)], "S7b's golden budget")
|
|
1216
|
+
dry_summary, _none = live(live_run, dry=True)
|
|
1217
|
+
control("dry: every proposal is measured, no document is written, and the stage is partial",
|
|
1218
|
+
json.dumps([sorted(m["candidate_id"] for m in dry_summary["packets"]),
|
|
1219
|
+
(live_run / OUTPUT).exists(),
|
|
1220
|
+
records.read_json(records.record_path(live_run, STAGE)).get("status")]),
|
|
1221
|
+
json.dumps([proposed, False, "partial"]))
|
|
1222
|
+
# One review decides, which the contract refuses; the others agree.
|
|
1223
|
+
deciding = proposed[0]
|
|
1224
|
+
plan_path = live_root / "plan.json"
|
|
1225
|
+
plan_path.write_text(json.dumps(
|
|
1226
|
+
[{"match": [json.dumps(cid)],
|
|
1227
|
+
"answer": {**review(), "decision": "approve"} if cid == deciding else review()}
|
|
1228
|
+
for cid in proposed], ensure_ascii=False), encoding="utf-8")
|
|
1229
|
+
live_summary, live_doc = live(live_run, supervisor(live_run, live_root / "cells", plan_path))
|
|
1230
|
+
control("each proposal is one supervised call, accepted where the review holds and failed "
|
|
1231
|
+
"where it is refused twice",
|
|
1232
|
+
json.dumps({c["candidate_id"]: c["outcome"] for c in live_summary["calls"]}, sort_keys=True),
|
|
1233
|
+
json.dumps({cid: ("failed" if cid == deciding else "accepted") for cid in proposed},
|
|
1234
|
+
sort_keys=True))
|
|
1235
|
+
control("the document reviews the accepted ones and names the failed one unreviewed BY ITS CALL",
|
|
1236
|
+
json.dumps([sorted(r["item_id"] for r in live_doc["reviews"]),
|
|
1237
|
+
[(u["item_id"], u["why"].split(" (")[0]) for u in live_doc["unreviewed"]]]),
|
|
1238
|
+
json.dumps([proposed[1:], [[deciding, "S7b's call ended failed"]]]))
|
|
1239
|
+
control("the stage is partial while a call is not accepted, and both files are its outputs",
|
|
1240
|
+
json.dumps([records.read_json(records.record_path(live_run, STAGE)).get("status"),
|
|
1241
|
+
(live_run / CALLS).is_file(), (live_run / OUTPUT).is_file()]),
|
|
1242
|
+
json.dumps(["partial", True, True]))
|
|
1243
|
+
# Codex WP-12 r2 F2: each packet carries S6's marks on its candidate's requirements, read from the
|
|
1244
|
+
# derivation S6 wrote, not the empty slot S7's proposal row never fills
|
|
1245
|
+
# Codex WP-12 r3 F8: each candidate's OWN packet, by its call's item, holds exactly its own marks in the
|
|
1246
|
+
# judgments slot, read from the derivation S6 wrote; a search of every packet passed a swap
|
|
1247
|
+
held_verdicts = records.read_json(live_run / "judgments" / "derivations.json").get("verdicts") or {}
|
|
1248
|
+
|
|
1249
|
+
def slot_of(text):
|
|
1250
|
+
inside = text.split("<judgments>\n", 1)[1].split("\n</judgments>", 1)[0] if "<judgments>\n" in text else None
|
|
1251
|
+
return inside
|
|
1252
|
+
|
|
1253
|
+
own_packets = {cid: [slot_of(pk.read_text(encoding="utf-8"))
|
|
1254
|
+
for pk in sorted((live_run / "calls").glob(f"*-{STAGE}-{item_of(cid)}-a*/packet.md"))]
|
|
1255
|
+
for cid in proposed}
|
|
1256
|
+
expected_slots = {cid: json.dumps((held_verdicts.get(cid) or {}).get("requirements") or {},
|
|
1257
|
+
ensure_ascii=False, indent=1) for cid in proposed}
|
|
1258
|
+
clean("every candidate's own packets carry exactly its two judges' marks from S6's derivation",
|
|
1259
|
+
[f"{cid}: {len(held)} packets, slots {[x == expected_slots[cid] for x in held]}"
|
|
1260
|
+
for cid, held in own_packets.items()
|
|
1261
|
+
if not held or any(x != expected_slots[cid] for x in held)])
|
|
1262
|
+
# the fixture's candidates are given marks that differ, so a swap between two packets is visible here
|
|
1263
|
+
clean("and the fixture's candidates carry marks that differ, so a swap between packets would fail above",
|
|
1264
|
+
[] if len(set(expected_slots.values())) == len(expected_slots) > 1
|
|
1265
|
+
else [f"{len(set(expected_slots.values()))} distinct of {len(expected_slots)}"])
|
|
1266
|
+
again_summary, _doc = live(live_run, supervisor(live_run, live_root / "cells", plan_path))
|
|
1267
|
+
control("a re-run reuses every accepted attempt",
|
|
1268
|
+
json.dumps(again_summary["counts"]["reused"]), json.dumps(len(proposed) - 1))
|
|
1269
|
+
clean("the report prints counts and codes and no review's text",
|
|
1270
|
+
[line for line in live_report_lines(live_summary) if "동의한다" in line])
|
|
1271
|
+
finally:
|
|
1272
|
+
shutil.rmtree(live_root, ignore_errors=True)
|
|
1273
|
+
|
|
1274
|
+
reporting.append(True)
|
|
1275
|
+
if failures:
|
|
1276
|
+
for name, detail in failures:
|
|
1277
|
+
print(f"stage_review_proposals --self-test [FAIL] {name}: {detail}", file=sys.stderr)
|
|
1278
|
+
print(f"stage_review_proposals --self-test: FAILED ({len(failures)} of {len(ran)} controls)",
|
|
1279
|
+
file=sys.stderr)
|
|
1280
|
+
return 1
|
|
1281
|
+
print(f"stage_review_proposals --self-test: OK ({len(ran)} controls: the merge question held to the "
|
|
1282
|
+
f"proposal's own operations and to the review's own findings, the bars against the contract "
|
|
1283
|
+
f"text's list both ways, the alternative held to §7.2's table including the legacy row, a "
|
|
1284
|
+
f"review refused for carrying a decision, and a proposal with no review named rather than "
|
|
1285
|
+
f"passed)")
|
|
1286
|
+
return 0
|
|
1287
|
+
|
|
1288
|
+
|
|
1289
|
+
if __name__ == "__main__":
|
|
1290
|
+
if sys.argv[1:2] == ["--self-test"]:
|
|
1291
|
+
sys.exit(self_test())
|
|
1292
|
+
sys.exit("usage: stage_review_proposals.py --self-test")
|