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,1002 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""S9b review of a review version's Korean (plan WP-20 K4; design §9; done-when 2).
|
|
3
|
+
|
|
4
|
+
Each row S7 proposed for carries the six Korean reason fields the owner reads (`stage_propose.REASON_FIELDS`; the flat
|
|
5
|
+
proposal's singular `reason` is a copy of `reasons.reason`). S9b judges each against the row's English payload
|
|
6
|
+
(`stage_render.english_of`, hashed as the row's `payload_sha256`) for faithfulness and plain wording, with the packet
|
|
7
|
+
carrying both texts and the hash. A row that fails is regenerated ONCE by S7's seat (`stage_propose.regeneration_packet`;
|
|
8
|
+
the answer enters only through `stage_propose.regenerate_reasons`, which lets nothing but those six fields move) and
|
|
9
|
+
reviewed again; a row still failing, or one whose regeneration was refused or never came, carries the visible mark
|
|
10
|
+
"번역 검토 실패" in the next render. A row is never withheld and never vetoed: S9b marks, the owner decides.
|
|
11
|
+
|
|
12
|
+
The calls are not wired here, as S7's and S7b's are not (WP-12): the stage runs over the reviews, regenerations and
|
|
13
|
+
second reviews the caller supplies, and `packets_of` gives the first review's packets. A review S9b did not return is
|
|
14
|
+
listed unreviewed; one that does not hold is returned with its codes; neither is guessed.
|
|
15
|
+
|
|
16
|
+
Outputs, each written once per review version: `review-s9b.v<n>.json` (per row: verdict, failing fields, whether it
|
|
17
|
+
was regenerated, the second review, the mark) and `regenerated-reasons.v<n>.json` (each regenerated proposal, whole).
|
|
18
|
+
|
|
19
|
+
stage_review_korean.py --self-test
|
|
20
|
+
"""
|
|
21
|
+
import collections
|
|
22
|
+
import json
|
|
23
|
+
import pathlib
|
|
24
|
+
import re
|
|
25
|
+
import sys
|
|
26
|
+
|
|
27
|
+
if __package__ in (None, ""): # run as a script: put session-distill/ on the import path
|
|
28
|
+
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
|
29
|
+
from runlib import packet, placement, records, stage_adjudicate, stage_propose, stage_render, validate # noqa: E402
|
|
30
|
+
from runlib.records import Refused # noqa: E402
|
|
31
|
+
|
|
32
|
+
HERE = pathlib.Path(__file__).resolve().parents[1]
|
|
33
|
+
STAGE = "S9b"
|
|
34
|
+
SCHEMA_PATH = HERE / "schemas" / "s9b.schema.json"
|
|
35
|
+
TEMPLATE = "s9b"
|
|
36
|
+
SEAT = "review-korean"
|
|
37
|
+
MARK = "번역 검토 실패"
|
|
38
|
+
FIELDS = stage_propose.REASON_FIELDS
|
|
39
|
+
_VALIDATOR = []
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def outputs_of(version):
|
|
43
|
+
return f"review-s9b.v{version}.json", f"regenerated-reasons.v{version}.json"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def inputs_of(version):
|
|
47
|
+
return ({"artifact": f"review.v{version}.json", "producer_stage": "S9"},
|
|
48
|
+
{"artifact": stage_propose.OUTPUT, "producer_stage": "S7"},
|
|
49
|
+
{"artifact": "checked-candidates.json", "producer_stage": "S5"},
|
|
50
|
+
{"artifact": "judgments/derivations.json", "producer_stage": "S6"})
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def schema_bytes():
|
|
54
|
+
if not SCHEMA_PATH.is_file():
|
|
55
|
+
raise Refused(f"S9B_SCHEMA_ABSENT {SCHEMA_PATH}: a review would be judged by nothing")
|
|
56
|
+
return SCHEMA_PATH.read_bytes()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def validator():
|
|
60
|
+
if not _VALIDATOR:
|
|
61
|
+
_VALIDATOR.append(validate.compile_schema(json.loads(schema_bytes())))
|
|
62
|
+
return _VALIDATOR[0]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def reviewable(rows_doc):
|
|
66
|
+
"""The rows whose O6 text is S7's Korean: every row carrying a proposal with its reasons."""
|
|
67
|
+
return [r for r in rows_doc["rows"] if isinstance((r.get("proposal") or {}).get("reasons"), dict)]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def korean_of(answer):
|
|
71
|
+
return {name: (answer.get("reasons") or {}).get(name) for name in FIELDS}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def korean_sha256_of(answer):
|
|
75
|
+
"""The sha256 of the six Korean fields of `answer`, the text S9b judges, by S9's rule (`stage_render
|
|
76
|
+
.korean_sha256_of`), which holds a verdict to it before showing one (Codex WP-20 r1 F3, r2 F1)."""
|
|
77
|
+
return stage_render.korean_sha256_of(answer)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def carried_ids(by_id, before):
|
|
81
|
+
"""The rows an earlier S9b run judged whose English payload AND Korean are what it judged: only those carry its
|
|
82
|
+
verdict. A row whose Korean moved is judged again (its regeneration, once used, is not given again)."""
|
|
83
|
+
return {i for i, row in by_id.items()
|
|
84
|
+
if (before.get(i) or {}).get("payload_sha256") == row["payload_sha256"]
|
|
85
|
+
and (before.get(i) or {}).get("korean_sha256") == korean_sha256_of(row.get("proposal"))}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def regeneration_used(previous):
|
|
89
|
+
"""The rows whose one regeneration an earlier version already used: a row is regenerated once, across versions.
|
|
90
|
+
Each version's review carries the whole history (`regeneration_used`), so a row an intervening version left
|
|
91
|
+
unreviewed or returned keeps it (Codex WP-20 r2 F2)."""
|
|
92
|
+
previous = previous or {}
|
|
93
|
+
return (set(previous.get("regeneration_used") or [])
|
|
94
|
+
| {e["item_id"] for e in previous.get("rows") or [] if e.get("regenerated") or e.get("regeneration_used")})
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def payload_sha256_of(row, answer):
|
|
98
|
+
"""The English payload's sha256 of `row` carrying `answer`: equal to the row's own when only Korean moved."""
|
|
99
|
+
return stage_render.keyed({**row, "proposal": answer})["payload_sha256"]
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def packet_for(row, answer=None, call_id="c1"):
|
|
103
|
+
"""One review's packet: the row's ids and hashes, its English payload and the Korean fields of `answer` (the row's
|
|
104
|
+
own proposal unless a regenerated one is given). The English payload is the row's, whichever Korean is judged."""
|
|
105
|
+
return packet.build(call_id, STAGE, SEAT, payload_for(row, answer), schema=schema_bytes(), repo=HERE.parent)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def payload_for(row, answer=None):
|
|
109
|
+
"""The review packet's payload alone: what a supervised call is handed."""
|
|
110
|
+
answer = answer or row["proposal"]
|
|
111
|
+
return packet.render(TEMPLATE, {
|
|
112
|
+
"row": json.dumps({"item_id": row["item_id"], "item_sha": row["item_sha"],
|
|
113
|
+
"payload_sha256": row["payload_sha256"]}, ensure_ascii=False, indent=1),
|
|
114
|
+
"english_payload": json.dumps(stage_render.english_of(row), ensure_ascii=False, indent=1, sort_keys=True),
|
|
115
|
+
"korean_fields": json.dumps(korean_of(answer), ensure_ascii=False, indent=1),
|
|
116
|
+
"returns": "Return one JSON object in the schema of this call.",
|
|
117
|
+
}, template_dir=HERE / "packets")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def packets_of(rows_doc):
|
|
121
|
+
"""`{item_id: packet bytes}` of the first review, one per reviewable row."""
|
|
122
|
+
return {r["item_id"]: packet_for(r, call_id=f"s9b-{r['item_id']}") for r in reviewable(rows_doc)}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def verdict_problems(verdict):
|
|
126
|
+
"""Every problem of one S9b answer, by name: its shape, its field set, and its verdict against its fields."""
|
|
127
|
+
problems = [f"S9B_SCHEMA_INVALID {v}" for v in validate.validate_instance(validator(), verdict)]
|
|
128
|
+
if problems:
|
|
129
|
+
return problems
|
|
130
|
+
seen = collections.Counter(f["field"] for f in verdict["fields"])
|
|
131
|
+
problems += [f"S9B_FIELD_TWICE {name}: the answer judges it {n} times" for name, n in sorted(seen.items()) if n > 1]
|
|
132
|
+
problems += [f"S9B_FIELD_MISSING {name}: the answer does not judge it" for name in FIELDS if name not in seen]
|
|
133
|
+
holds = all(f["faithful"] and f["plain"] for f in verdict["fields"])
|
|
134
|
+
if (verdict["verdict"] == "pass") != holds:
|
|
135
|
+
problems.append(f"S9B_VERDICT_INCONSISTENT {verdict['verdict']}: the fields say "
|
|
136
|
+
f"{'every one holds' if holds else 'some do not hold'}")
|
|
137
|
+
return problems
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def code_of(problem):
|
|
141
|
+
"""A problem's code: its leading name, without the punctuation some messages follow it with."""
|
|
142
|
+
return re.match(r"[A-Z0-9_]+", problem).group(0) if re.match(r"[A-Z0-9_]+", problem) else problem
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def failing_of(verdict):
|
|
146
|
+
return sorted(f["field"] for f in verdict["fields"] if not (f["faithful"] and f["plain"]))
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def document(rows_doc, proposals, candidates, derivations, reviews, regenerations=None, second=None, previous=None,
|
|
150
|
+
previous_regenerated=None):
|
|
151
|
+
"""`(review_s9b, regenerated, problems)` for one review version. A row an earlier S9b run judged, whose English
|
|
152
|
+
payload has not moved since, is carried from it unreviewed, its regenerated proposal with it: a row is regenerated
|
|
153
|
+
once, across versions too. `problems` names an answer for a row S9b was not asked about, or one it judged before;
|
|
154
|
+
with any, nothing is written."""
|
|
155
|
+
regenerations, second = dict(regenerations or {}), dict(second or {})
|
|
156
|
+
by_id = {r["item_id"]: r for r in reviewable(rows_doc)}
|
|
157
|
+
before = {e["item_id"]: e for e in (previous or {}).get("rows") or []}
|
|
158
|
+
carried, used = carried_ids(by_id, before), regeneration_used(previous)
|
|
159
|
+
held_regenerated = ((previous_regenerated or {}).get("proposals")) or {}
|
|
160
|
+
answers = {p["candidate_id"]: p for p in (proposals or {}).get("proposals") or []}
|
|
161
|
+
cands = {c["candidate_id"]: c for c in (candidates or {}).get("candidates") or []}
|
|
162
|
+
verdicts = (derivations or {}).get("verdicts") or {}
|
|
163
|
+
problems = [f"S9B_UNACCOUNTED {i}: a review for a row S9b was not asked about" for i in sorted(set(reviews) - set(by_id))]
|
|
164
|
+
problems += [f"REVIEW_CARRIED {i}: S9b judged it at v{previous['version']} and neither its English payload nor "
|
|
165
|
+
"its Korean has moved" for i in sorted(set(reviews) & carried)]
|
|
166
|
+
rows, unreviewed, returned, regenerated, asked = [], [], [], {}, set()
|
|
167
|
+
for ident, row in by_id.items():
|
|
168
|
+
if ident in carried:
|
|
169
|
+
entry = before[ident]
|
|
170
|
+
rows.append({**entry, "carried_from": entry.get("carried_from") or previous["version"]})
|
|
171
|
+
if entry.get("regenerated"):
|
|
172
|
+
held = ((previous_regenerated or {}).get("proposals") or {}).get(ident)
|
|
173
|
+
if held is None:
|
|
174
|
+
problems.append(f"CARRY_INCOMPLETE {ident}: v{previous['version']} says it was regenerated and "
|
|
175
|
+
"its regenerated proposals do not hold it")
|
|
176
|
+
else:
|
|
177
|
+
regenerated[ident] = held
|
|
178
|
+
continue
|
|
179
|
+
review = reviews.get(ident)
|
|
180
|
+
if review is None:
|
|
181
|
+
unreviewed.append({"item_id": ident, "why": "S9b returned no review for this row"})
|
|
182
|
+
continue
|
|
183
|
+
found = verdict_problems(review)
|
|
184
|
+
if found:
|
|
185
|
+
returned.append({"item_id": ident, "pass": "first", "codes": [code_of(x) for x in found]})
|
|
186
|
+
continue
|
|
187
|
+
# A row whose shown Korean is an earlier version's regeneration keeps it: the next render lays only this
|
|
188
|
+
# version's regenerated proposals over S7's, so one left out here would be shown as S7's original beside a
|
|
189
|
+
# verdict on the regenerated text (Codex WP-20 r2 F1). Held to S7's own rule, as S9 holds the overlay.
|
|
190
|
+
shown = held_regenerated.get(ident)
|
|
191
|
+
if (shown is not None and korean_sha256_of(shown) == korean_sha256_of(row.get("proposal"))
|
|
192
|
+
and not stage_propose.regenerated_problems((answers.get(ident) or {}).get("proposal") or row["proposal"],
|
|
193
|
+
shown)):
|
|
194
|
+
regenerated[ident] = shown
|
|
195
|
+
held = {"item_id": ident, "payload_sha256": row["payload_sha256"],
|
|
196
|
+
"korean_sha256": korean_sha256_of(row.get("proposal")), "verdict": review["verdict"],
|
|
197
|
+
"failing": failing_of(review), "regenerated": False, "regeneration_used": ident in used,
|
|
198
|
+
"regeneration": None, "second": None, "mark": False, "notes": review["notes"]}
|
|
199
|
+
if review["verdict"] == "fail" and ident in used:
|
|
200
|
+
# its one regeneration was used at an earlier version: the row is marked, never regenerated again
|
|
201
|
+
held.update({"regeneration": {"state": "used_before"}, "mark": True})
|
|
202
|
+
elif review["verdict"] == "fail":
|
|
203
|
+
asked.add(ident)
|
|
204
|
+
held.update(failure_after_retry(row, answers.get(ident), cands.get(ident), derivations,
|
|
205
|
+
verdicts.get(ident), regenerations.get(ident), second.get(ident),
|
|
206
|
+
regenerated))
|
|
207
|
+
if held["regenerated"]:
|
|
208
|
+
# the Korean the next render shows is the regenerated text, so that is what a carried verdict binds
|
|
209
|
+
held.update({"regeneration_used": True, "korean_sha256": korean_sha256_of(regenerated[ident])})
|
|
210
|
+
rows.append(held)
|
|
211
|
+
problems += [f"REGENERATION_UNASKED {i}: a regeneration for a row S9b did not fail"
|
|
212
|
+
for i in sorted(set(regenerations) - asked)]
|
|
213
|
+
problems += [f"SECOND_REVIEW_UNASKED {i}: a second review for a row that was not regenerated"
|
|
214
|
+
for i in sorted(set(second) - set(regenerated))]
|
|
215
|
+
tally = collections.Counter
|
|
216
|
+
review_doc = {"stage": STAGE, "version": rows_doc["version"], "render_sha256": rows_doc["render_sha256"],
|
|
217
|
+
"previous": ({"version": previous["version"]} if previous else None),
|
|
218
|
+
"rows": rows, "unreviewed": unreviewed, "returned": returned,
|
|
219
|
+
# every row whose one regeneration has been used, in this version or any earlier one
|
|
220
|
+
"regeneration_used": sorted(used | {r["item_id"] for r in rows
|
|
221
|
+
if r.get("regenerated") or r.get("regeneration_used")}),
|
|
222
|
+
"counts": {"reviewable": len(by_id), "reviewed": len(rows), "unreviewed": len(unreviewed),
|
|
223
|
+
"returned": len(returned), "verdict": dict(tally(r["verdict"] for r in rows)),
|
|
224
|
+
"regenerated": sum(1 for r in rows if r["regenerated"]),
|
|
225
|
+
"marked": sum(1 for r in rows if r["mark"]),
|
|
226
|
+
"carried": sum(1 for r in rows if r.get("carried_from"))}}
|
|
227
|
+
return review_doc, {"stage": STAGE, "version": rows_doc["version"], "proposals": regenerated}, problems
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def failure_after_retry(row, proposal_row, candidate, derivations, derivation_row, regeneration, second, regenerated):
|
|
231
|
+
"""What a failing row becomes: regenerated once and reviewed again, or marked. The regeneration enters only through
|
|
232
|
+
`regenerate_reasons`; a refused one, an absent one, or a second review that fails, is absent or does not hold,
|
|
233
|
+
leaves the row marked."""
|
|
234
|
+
if regeneration is None:
|
|
235
|
+
return {"regeneration": {"state": "absent"}, "mark": True}
|
|
236
|
+
answer = (proposal_row or {}).get("proposal") or row["proposal"]
|
|
237
|
+
try:
|
|
238
|
+
new = stage_propose.regenerate_reasons(answer, regeneration, candidate or {}, derivations, derivation_row,
|
|
239
|
+
legacy_incubating=bool(row.get("legacy_incubating")))
|
|
240
|
+
except records.RunStopped:
|
|
241
|
+
raise
|
|
242
|
+
except Refused as exc:
|
|
243
|
+
return {"regeneration": {"state": "refused", "codes": [code_of(x) for x in str(exc).split("; ")]},
|
|
244
|
+
"mark": True}
|
|
245
|
+
if payload_sha256_of(row, new) != row["payload_sha256"]:
|
|
246
|
+
return {"regeneration": {"state": "refused", "codes": ["PAYLOAD_MOVED"]}, "mark": True}
|
|
247
|
+
regenerated[row["item_id"]] = new
|
|
248
|
+
held = {"regenerated": True, "regeneration": {"state": "accepted"}}
|
|
249
|
+
if second is None:
|
|
250
|
+
return {**held, "second": {"state": "unreviewed"}, "mark": True}
|
|
251
|
+
found = verdict_problems(second)
|
|
252
|
+
if found:
|
|
253
|
+
return {**held, "second": {"state": "returned", "codes": [code_of(x) for x in found]}, "mark": True}
|
|
254
|
+
return {**held, "second": {"state": "reviewed", "verdict": second["verdict"], "failing": failing_of(second),
|
|
255
|
+
"notes": second["notes"]},
|
|
256
|
+
"mark": second["verdict"] == "fail"}
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
def previous_of(run_dir, version):
|
|
260
|
+
"""`(review, regenerated)` of the highest earlier version S9b reviewed, the two held to each other by the sha256 the
|
|
261
|
+
review recorded of the regenerated file (S9B_CHANGED); `(None, None)` when S9b has reviewed no earlier version."""
|
|
262
|
+
run_dir = pathlib.Path(run_dir)
|
|
263
|
+
done = sorted(int(m.group(1)) for p in run_dir.glob("review-s9b.v*.json")
|
|
264
|
+
for m in [re.fullmatch(r"review-s9b\.v(\d+)\.json", p.name)] if m and int(m.group(1)) < version)
|
|
265
|
+
if not done:
|
|
266
|
+
return None, None
|
|
267
|
+
review_rel, regen_rel = outputs_of(done[-1])
|
|
268
|
+
review = records.read_json(run_dir / review_rel)
|
|
269
|
+
if not (run_dir / regen_rel).is_file() or records.sha256_file(run_dir / regen_rel) != review.get("regenerated_sha256"):
|
|
270
|
+
raise Refused(f"S9B_CHANGED {regen_rel}: its bytes are not the ones {review_rel} recorded; S9b's outputs are "
|
|
271
|
+
"written once")
|
|
272
|
+
return review, records.read_json(run_dir / regen_rel)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def latest_version(run_dir):
|
|
276
|
+
rec = records.stage_records(pathlib.Path(run_dir)).get("S9") or {}
|
|
277
|
+
held = [int(m.group(1)) for o in rec.get("outputs") or []
|
|
278
|
+
for m in [re.fullmatch(r"review\.v(\d+)\.json", o.get("artifact", ""))] if m]
|
|
279
|
+
if not held:
|
|
280
|
+
raise Refused("RENDER_ABSENT S9b: S9's record names no review version to review")
|
|
281
|
+
return max(held)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
# ---- the supervised calls (release 1) ---------------------------------------------------------------------------
|
|
285
|
+
# Three kinds, in the order design §9 gives them: the first review of each row S9b has not judged before (its seat),
|
|
286
|
+
# one regeneration of a row that failed (S7's seat, declared for this stage as `seats["S9b.regenerate"]`, since the
|
|
287
|
+
# dispatcher admits a seat only for the stage that declares it), and the second review of a regenerated row. Each is
|
|
288
|
+
# an item of its own through the dispatcher; what they return is handed to `document` exactly as the golden path
|
|
289
|
+
# hands it answers, so the rules a row is held to have one owner.
|
|
290
|
+
SEAT_KEY = "S9b"
|
|
291
|
+
REGENERATE_SEAT_KEY = "S9b.regenerate"
|
|
292
|
+
REVIEW_CASE, REGENERATE_CASE = "review", "regenerate"
|
|
293
|
+
OUTPUT_CAP = 20_000
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def calls_rel(version):
|
|
297
|
+
return f"review-korean/calls.v{version}.json"
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def item_of(item_id):
|
|
301
|
+
"""A row's item name in its calls: opaque, since a call directory's name must not be the id."""
|
|
302
|
+
import hashlib
|
|
303
|
+
return "r" + hashlib.sha256(item_id.encode("utf-8")).hexdigest()[:12]
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def supervisor(run_dir, cells, plan=None, seats_path=None):
|
|
307
|
+
"""The supervisor S9b's calls go through, their cells under `cells` (made mode 700). With `plan`, S6's golden
|
|
308
|
+
host answers from it and starts no model (a Codex seat is answered from a plan by that host alone)."""
|
|
309
|
+
from runlib import dispatch, stage_judge
|
|
310
|
+
if plan is not None:
|
|
311
|
+
return stage_judge.supervisor(run_dir, cells, plan, seats_path)
|
|
312
|
+
cells = pathlib.Path(cells)
|
|
313
|
+
cells.mkdir(mode=0o700, parents=True, exist_ok=True)
|
|
314
|
+
return dispatch.Supervisor(run_dir, cell_root=cells, realization="live", seats_path=seats_path)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def collect(run_dir, declaration, supervisor, rows_doc, proposals, candidates, derivations, previous, tranche):
|
|
318
|
+
"""`(reviews, regenerations, second, calls)`: what the supervised calls returned for the rows S9b judges now.
|
|
319
|
+
|
|
320
|
+
A row carried from an earlier version is not asked about (`document` carries it). A first review that fails names
|
|
321
|
+
its failing fields; the regeneration is asked with them and its answer is held, as the stage's check of that call,
|
|
322
|
+
to `stage_propose.regenerate_reasons` and to the row's English payload not moving — the two rules `document`
|
|
323
|
+
applies — so its one retry is told why. A call that ends other than accepted leaves its answer out, and
|
|
324
|
+
`document` then says what the row becomes: unreviewed, or marked."""
|
|
325
|
+
from runlib import gate, stage_judge, stage_read
|
|
326
|
+
seats = (declaration or {}).get("seats") or {}
|
|
327
|
+
seat, regen_seat = seats.get(SEAT_KEY), seats.get(REGENERATE_SEAT_KEY)
|
|
328
|
+
if not seat:
|
|
329
|
+
raise Refused(f"SEAT_UNDECLARED {SEAT_KEY}: S9b's seat is named by run.json's seats")
|
|
330
|
+
by_id = {r["item_id"]: r for r in reviewable(rows_doc)}
|
|
331
|
+
before = {e["item_id"]: e for e in (previous or {}).get("rows") or []}
|
|
332
|
+
carried, used = carried_ids(by_id, before), regeneration_used(previous)
|
|
333
|
+
asked = [i for i in by_id if i not in carried]
|
|
334
|
+
answers = {p["candidate_id"]: p for p in (proposals or {}).get("proposals") or []}
|
|
335
|
+
cands = {c["candidate_id"]: c for c in (candidates or {}).get("candidates") or []}
|
|
336
|
+
verdicts = (derivations or {}).get("verdicts") or {}
|
|
337
|
+
episode = declaration["budget"]["per_episode"]
|
|
338
|
+
caps = {"tokens": episode["tokens"], "compactions": episode["compactions"]}
|
|
339
|
+
review_schema = json.loads(schema_bytes().decode("utf-8"))
|
|
340
|
+
limits = stage_judge.limits_of(seat, run_dir, declaration, supervisor.seats_path, case=REVIEW_CASE,
|
|
341
|
+
output_cap=OUTPUT_CAP, stage=STAGE)
|
|
342
|
+
|
|
343
|
+
def capacity_held(call_dir, capacity):
|
|
344
|
+
held = ((records.read_json(pathlib.Path(call_dir) / "call.json").get("bound")) or {}).get("context_capacity")
|
|
345
|
+
if held != capacity:
|
|
346
|
+
raise Refused(f"CAPACITY_UNRECORDED {pathlib.Path(call_dir).name}: its call record carries the capacity "
|
|
347
|
+
f"{held!r}, and S9b was admitted against {capacity!r}")
|
|
348
|
+
|
|
349
|
+
def review_check(call_dir):
|
|
350
|
+
capacity_held(call_dir, limits["capacity"])
|
|
351
|
+
return verdict_problems(stage_read.answer_of(call_dir))
|
|
352
|
+
|
|
353
|
+
def one(item, held_seat, text, schema, case, held_limits, check, held_schema_bytes):
|
|
354
|
+
out = supervisor.item(STAGE, item, held_seat, text, schema, case_type=case, caps=caps, view_window=False,
|
|
355
|
+
tranche=tranche, max_output_tokens=OUTPUT_CAP, resume=True,
|
|
356
|
+
context_capacity=held_limits["capacity"], stage_check=check,
|
|
357
|
+
packet_check=lambda built: stage_judge.attempt_problems(
|
|
358
|
+
built, held_limits, held_schema_bytes, SEAT_KEY, code="S9B_OVER_CAPACITY"))
|
|
359
|
+
answer = gate.accepted(pathlib.Path(out["accepted"]), judged=True) if out["outcome"] == "accepted" else None
|
|
360
|
+
return answer, {"item": item, "case": case, **stage_judge.call_row(out)}
|
|
361
|
+
|
|
362
|
+
reviews, regenerations, second, calls = {}, {}, {}, []
|
|
363
|
+
for ident in asked:
|
|
364
|
+
row, item = by_id[ident], item_of(ident)
|
|
365
|
+
first, held = one(f"{item}-1", seat, payload_for(row), review_schema, REVIEW_CASE, limits, review_check,
|
|
366
|
+
schema_bytes())
|
|
367
|
+
calls.append({"item_id": ident, **held})
|
|
368
|
+
if first is None:
|
|
369
|
+
continue
|
|
370
|
+
reviews[ident] = first
|
|
371
|
+
if first["verdict"] != "fail" or ident in used:
|
|
372
|
+
continue # a pass, or a fail whose one regeneration an earlier version used (`document` marks it)
|
|
373
|
+
if not regen_seat:
|
|
374
|
+
raise Refused(f"SEAT_UNDECLARED {REGENERATE_SEAT_KEY}: a failing row is regenerated by S7's seat, which "
|
|
375
|
+
f"run.json declares for this stage under that key")
|
|
376
|
+
original = (answers.get(ident) or {}).get("proposal") or row["proposal"]
|
|
377
|
+
legacy = bool(row.get("legacy_incubating"))
|
|
378
|
+
regen_limits = stage_judge.limits_of(regen_seat, run_dir, declaration, supervisor.seats_path,
|
|
379
|
+
case=REGENERATE_CASE, output_cap=OUTPUT_CAP, stage=STAGE)
|
|
380
|
+
|
|
381
|
+
def regeneration_check(call_dir, row=row, original=original, ident=ident, legacy=legacy,
|
|
382
|
+
capacity=regen_limits["capacity"]):
|
|
383
|
+
capacity_held(call_dir, capacity)
|
|
384
|
+
try:
|
|
385
|
+
new = stage_propose.regenerate_reasons(original, stage_read.answer_of(call_dir), cands.get(ident) or {},
|
|
386
|
+
derivations, verdicts.get(ident), legacy_incubating=legacy)
|
|
387
|
+
except records.RunStopped:
|
|
388
|
+
raise
|
|
389
|
+
except Refused as exc:
|
|
390
|
+
return str(exc).split("; ")
|
|
391
|
+
return [] if payload_sha256_of(row, new) == row["payload_sha256"] else \
|
|
392
|
+
["PAYLOAD_MOVED: the regeneration changed the row's English payload"]
|
|
393
|
+
|
|
394
|
+
text = stage_propose.regeneration_payload(original, cands.get(ident) or {"candidate_id": ident}, derivations,
|
|
395
|
+
verdicts.get(ident), failing_of(first))
|
|
396
|
+
again, held = one(f"{item}-g", regen_seat, text, json.loads(stage_propose.schema_bytes().decode("utf-8")),
|
|
397
|
+
REGENERATE_CASE, regen_limits, regeneration_check, stage_propose.schema_bytes())
|
|
398
|
+
calls.append({"item_id": ident, **held})
|
|
399
|
+
if again is None:
|
|
400
|
+
continue
|
|
401
|
+
regenerations[ident] = again
|
|
402
|
+
new = stage_propose.regenerate_reasons(original, again, cands.get(ident) or {}, derivations,
|
|
403
|
+
verdicts.get(ident), legacy_incubating=legacy)
|
|
404
|
+
two, held = one(f"{item}-2", seat, payload_for(row, new), review_schema, REVIEW_CASE, limits, review_check,
|
|
405
|
+
schema_bytes())
|
|
406
|
+
calls.append({"item_id": ident, **held})
|
|
407
|
+
if two is not None:
|
|
408
|
+
second[ident] = two
|
|
409
|
+
return reviews, regenerations, second, {"seat": seat, "regenerate_seat": regen_seat, "asked": len(asked),
|
|
410
|
+
"carried": len(by_id) - len(asked), "calls": calls}
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def run(run_dir, reviews=None, regenerations=None, second=None, *, supervisor=None, tranche="calibration"):
|
|
414
|
+
"""S9b over the current review version, through the shared mechanism: nothing is written on refusal, and a
|
|
415
|
+
version's review is written once (S9B_VERSION_REVIEWED). With `supervisor`, the reviews, regenerations and second
|
|
416
|
+
reviews are what its calls return (`collect`) and `review-korean/calls.v<n>.json` says what each call did; without
|
|
417
|
+
one they are the caller's."""
|
|
418
|
+
if supervisor is not None and any(x is not None for x in (reviews, regenerations, second)):
|
|
419
|
+
raise Refused("INPUT_INVALID S9b: answers in hand and a supervisor are two sources for one review")
|
|
420
|
+
if supervisor is None and reviews is None:
|
|
421
|
+
raise Refused("REVIEW_UNSUPERVISED S9b: a review call goes through a supervisor; without one, give the "
|
|
422
|
+
"reviews in hand")
|
|
423
|
+
run_dir = pathlib.Path(run_dir)
|
|
424
|
+
version = latest_version(run_dir)
|
|
425
|
+
review_rel, regen_rel = outputs_of(version)
|
|
426
|
+
adjudicated_specs = stage_adjudicate.adjudicated_inputs(run_dir)
|
|
427
|
+
state = {"finish": False}
|
|
428
|
+
|
|
429
|
+
def reviewed_once():
|
|
430
|
+
# Under the stage's lock and before its record is replaced (`records.run_stage`'s `admit`). Inside the
|
|
431
|
+
# stage, the refusal replaced the complete record of the review that is there with a failed one, and S9
|
|
432
|
+
# then refused the unsettled S9b while S9b refused the reviewed version; before the lock, two
|
|
433
|
+
# invocations could each pass it in turn and the second overwrote the first's review.
|
|
434
|
+
# The review file is the version's commit and is written last: the regenerated proposals and the calls
|
|
435
|
+
# before it may be there from a run cut short between its writes, and that run is finished by running again
|
|
436
|
+
# (its accepted calls are reused, `resume=True`), not refused (Codex WP-20 r1 F4). A review written whose
|
|
437
|
+
# record did not end complete (cut short after the commit, while the outputs were being registered) is
|
|
438
|
+
# finished by registering what it committed, never by reviewing again (Codex WP-20 r2 F3).
|
|
439
|
+
if (run_dir / review_rel).exists():
|
|
440
|
+
rec = records.stage_records(run_dir).get(STAGE) or {}
|
|
441
|
+
if rec.get("status") == "complete" and review_rel in {o.get("artifact") for o in rec.get("outputs") or []}:
|
|
442
|
+
raise Refused(f"S9B_VERSION_REVIEWED {review_rel}: a version's Korean is reviewed once; render the "
|
|
443
|
+
f"next version (S9) and review that")
|
|
444
|
+
state["finish"] = True
|
|
445
|
+
with records.run_stage(run_dir, STAGE, inputs_of(version) + adjudicated_specs, admit=reviewed_once) as stage:
|
|
446
|
+
read = lambda rel: records.read_json(run_dir / rel) # noqa: E731
|
|
447
|
+
if state["finish"]:
|
|
448
|
+
committed = read(review_rel)
|
|
449
|
+
if not (run_dir / regen_rel).is_file() or \
|
|
450
|
+
records.sha256_file(run_dir / regen_rel) != committed.get("regenerated_sha256"):
|
|
451
|
+
raise Refused(f"S9B_CHANGED {regen_rel}: its bytes are not the ones {review_rel} recorded, so the "
|
|
452
|
+
"committed review cannot be finished")
|
|
453
|
+
for rel in (regen_rel, calls_rel(version), review_rel):
|
|
454
|
+
if (run_dir / rel).is_file():
|
|
455
|
+
stage.output(rel)
|
|
456
|
+
return {"version": version, "finished": True, **committed["counts"]}
|
|
457
|
+
previous, previous_regenerated = previous_of(run_dir, version)
|
|
458
|
+
# S10's adjudication laid over S6's derivations and S7's proposals (K5), so a row admitted by adjudication
|
|
459
|
+
# is regenerated against its recomputed derivation and its second-pass proposal
|
|
460
|
+
derivations, proposals, _s7b, laid = stage_adjudicate.overlay(
|
|
461
|
+
read("judgments/derivations.json"), read(stage_propose.OUTPUT), {},
|
|
462
|
+
stage_adjudicate.read_inputs(run_dir, adjudicated_specs))
|
|
463
|
+
if laid:
|
|
464
|
+
raise Refused("\n".join(laid))
|
|
465
|
+
held_calls = None
|
|
466
|
+
if supervisor is not None:
|
|
467
|
+
supervisor.interrupted(STAGE)
|
|
468
|
+
reviews, regenerations, second, held_calls = collect(
|
|
469
|
+
run_dir, stage.declaration, supervisor, read(f"review.v{version}.json"), proposals,
|
|
470
|
+
read("checked-candidates.json"), derivations, previous, tranche)
|
|
471
|
+
review_doc, regen_doc, problems = document(read(f"review.v{version}.json"), proposals,
|
|
472
|
+
read("checked-candidates.json"), derivations,
|
|
473
|
+
reviews, regenerations, second, previous, previous_regenerated)
|
|
474
|
+
if problems:
|
|
475
|
+
raise Refused("\n".join(problems))
|
|
476
|
+
# the regenerated proposals first, so the review can bind them by sha256 and a later run can hold them to it;
|
|
477
|
+
# the calls next; the review last, since its presence is what says the version was reviewed
|
|
478
|
+
records.write_json(run_dir, run_dir / regen_rel, regen_doc)
|
|
479
|
+
stage.output(regen_rel)
|
|
480
|
+
if held_calls is not None:
|
|
481
|
+
outcomes = [c["outcome"] for c in held_calls["calls"]]
|
|
482
|
+
held_calls["counts"] = {o: outcomes.count(o) for o in sorted(set(outcomes))}
|
|
483
|
+
records.write_json(run_dir, run_dir / calls_rel(version), {"stage": STAGE, "version": version, **held_calls})
|
|
484
|
+
stage.output(calls_rel(version))
|
|
485
|
+
review_doc["regenerated_sha256"] = records.sha256_file(run_dir / regen_rel)
|
|
486
|
+
records.write_json(run_dir, run_dir / review_rel, review_doc)
|
|
487
|
+
stage.output(review_rel)
|
|
488
|
+
return {"version": version, **review_doc["counts"],
|
|
489
|
+
**({"calls": held_calls["counts"], "asked": held_calls["asked"]} if held_calls is not None else {})}
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
# ---- self-test ----------------------------------------------------------------------------------------------------
|
|
493
|
+
|
|
494
|
+
def self_test():
|
|
495
|
+
"""The suite under the release scope `all`: the contract as designed, which release 1 holds closed
|
|
496
|
+
(`placement.scoped`), so the path the redesign reopens stays held by its controls. Release 1's own controls
|
|
497
|
+
run inside it under `release_1`."""
|
|
498
|
+
with placement.scoped("all"):
|
|
499
|
+
return _self_test_all()
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
def _self_test_all():
|
|
503
|
+
"""Positive controls first; then each path a row can take; then one planted violation per rule, each named."""
|
|
504
|
+
import copy
|
|
505
|
+
failures, ran, reporting = [], [], []
|
|
506
|
+
|
|
507
|
+
def mark_ran(name):
|
|
508
|
+
if reporting:
|
|
509
|
+
raise RuntimeError(f"CONTROL_AFTER_SUMMARY {name}")
|
|
510
|
+
ran.append(name)
|
|
511
|
+
|
|
512
|
+
def control(name, got, want):
|
|
513
|
+
mark_ran(name)
|
|
514
|
+
if not isinstance(got, str):
|
|
515
|
+
raise TypeError(f"CONTROL_GOT_NOT_STR {name}: {type(got).__name__}")
|
|
516
|
+
if want not in got:
|
|
517
|
+
failures.append((name, f"expected {want!r} in {got[:500]!r}"))
|
|
518
|
+
|
|
519
|
+
def equal(name, got, want):
|
|
520
|
+
mark_ran(name)
|
|
521
|
+
if got != want:
|
|
522
|
+
failures.append((name, f"expected {want!r}, got {got!r}"))
|
|
523
|
+
|
|
524
|
+
def clean(name, problems):
|
|
525
|
+
mark_ran(name)
|
|
526
|
+
if not isinstance(problems, list):
|
|
527
|
+
raise TypeError(f"CLEAN_PROBLEMS_NOT_LIST {name}: {type(problems).__name__}")
|
|
528
|
+
if problems:
|
|
529
|
+
failures.append((name, f"expected nothing, got {problems}"))
|
|
530
|
+
|
|
531
|
+
docs = stage_render.fixture_docs()
|
|
532
|
+
built = stage_render.document(docs)
|
|
533
|
+
rows_doc = {"version": 1, "render_sha256": "r" * 64, "rows": built["rows"]}
|
|
534
|
+
ids = [r["item_id"] for r in reviewable(rows_doc)]
|
|
535
|
+
|
|
536
|
+
def verdict(failing=(), notes="모두 그대로 옮겼다", **over):
|
|
537
|
+
held = {"verdict": "fail" if failing else "pass",
|
|
538
|
+
"fields": [{"field": name, "faithful": name not in failing, "plain": True,
|
|
539
|
+
"finding": "예외를 빠뜨렸다" if name in failing else "그대로다"} for name in FIELDS],
|
|
540
|
+
"notes": notes}
|
|
541
|
+
held.update(over)
|
|
542
|
+
return held
|
|
543
|
+
|
|
544
|
+
def regenerated(ident, **reasons):
|
|
545
|
+
answer = next(p["proposal"] for p in docs["proposals"]["proposals"] if p["candidate_id"] == ident)
|
|
546
|
+
return {**copy.deepcopy(answer), "reasons": {**answer["reasons"], **reasons}}
|
|
547
|
+
|
|
548
|
+
def doc(reviews, regenerations=None, second=None):
|
|
549
|
+
return document(rows_doc, docs["proposals"], docs["candidates"], docs["derivations"], reviews, regenerations,
|
|
550
|
+
second)
|
|
551
|
+
|
|
552
|
+
def row_in(review_doc, ident):
|
|
553
|
+
return next((r for r in review_doc["rows"] if r["item_id"] == ident), {})
|
|
554
|
+
|
|
555
|
+
# ---- positive controls -------------------------------------------------------------------------------------
|
|
556
|
+
equal("every row S7 proposed for is reviewed, and no other", sorted(ids), ["due_decision:P-1@r1", "k-a", "k-g"])
|
|
557
|
+
equal("the schema judges exactly the six reason fields S7 owns",
|
|
558
|
+
json.loads(schema_bytes())["$defs"]["field"]["properties"]["field"]["enum"], list(FIELDS))
|
|
559
|
+
clean("a passing review holds", verdict_problems(verdict()))
|
|
560
|
+
good, regen, problems = doc({i: verdict() for i in ids})
|
|
561
|
+
clean("every row passing makes a review with nothing refused", problems)
|
|
562
|
+
equal("and no row is regenerated or marked", (good["counts"]["regenerated"], good["counts"]["marked"],
|
|
563
|
+
regen["proposals"]), (0, 0, {}))
|
|
564
|
+
|
|
565
|
+
# ---- the packet carries both texts and the hash (done-when 2's golden counterpart) ----------------------------
|
|
566
|
+
k_g = next(r for r in rows_doc["rows"] if r["item_id"] == "k-g")
|
|
567
|
+
text = packet_for(k_g).decode("utf-8")
|
|
568
|
+
control("the packet carries the row's payload_sha256", text, k_g["payload_sha256"])
|
|
569
|
+
control("the packet carries the English payload", text, '"target": "router/other.md"')
|
|
570
|
+
control("the packet carries the Korean fields", text, json.dumps(k_g["proposal"]["reasons"]["what_happened"],
|
|
571
|
+
ensure_ascii=False))
|
|
572
|
+
equal("the packet's English payload holds no Korean field", k_g["proposal"]["reasons"]["what_happened"] in
|
|
573
|
+
text.split("<english_payload>", 1)[-1].split("</english_payload>", 1)[0], False)
|
|
574
|
+
control("the packet is S9b's, under the seat's role", text, "STAGE: S9b\nSEAT: review-korean")
|
|
575
|
+
|
|
576
|
+
# ---- each path a failing row can take -----------------------------------------------------------------------
|
|
577
|
+
better = regenerated("k-g", what_happened="다시 쓴 무엇이 있었나: 예외까지 적었다")
|
|
578
|
+
once, regen, problems = doc({**{i: verdict() for i in ids}, "k-g": verdict(failing=["what_happened"])},
|
|
579
|
+
{"k-g": better}, {"k-g": verdict()})
|
|
580
|
+
clean("a failing row regenerated once and passing on review makes a review with nothing refused", problems)
|
|
581
|
+
equal("it is regenerated, reviewed again, and not marked",
|
|
582
|
+
{k: row_in(once, "k-g").get(k) for k in ("verdict", "failing", "regenerated", "mark")}
|
|
583
|
+
| {"second": (row_in(once, "k-g").get("second") or {}).get("verdict")},
|
|
584
|
+
{"verdict": "fail", "failing": ["what_happened"], "regenerated": True, "mark": False, "second": "pass"})
|
|
585
|
+
equal("its regenerated proposal is carried whole, with only the Korean moved",
|
|
586
|
+
(regen["proposals"].get("k-g", {}).get("reasons", {}).get("what_happened"),
|
|
587
|
+
{k: v for k, v in regen["proposals"].get("k-g", {}).items() if k != "reasons"}
|
|
588
|
+
== {k: v for k, v in k_g["proposal"].items() if k != "reasons"}),
|
|
589
|
+
("다시 쓴 무엇이 있었나: 예외까지 적었다", True))
|
|
590
|
+
equal("the second review's packet judges the regenerated Korean against the same English payload",
|
|
591
|
+
(better["reasons"]["what_happened"] in packet_for(k_g, better).decode("utf-8"),
|
|
592
|
+
payload_sha256_of(k_g, better) == k_g["payload_sha256"]), (True, True))
|
|
593
|
+
twice, _r, _p = doc({**{i: verdict() for i in ids}, "k-g": verdict(failing=["what_happened"])},
|
|
594
|
+
{"k-g": better}, {"k-g": verdict(failing=["cost"])})
|
|
595
|
+
equal("a row failing twice is marked", (row_in(twice, "k-g").get("mark"),
|
|
596
|
+
(row_in(twice, "k-g").get("second") or {}).get("failing")),
|
|
597
|
+
(True, ["cost"]))
|
|
598
|
+
moved = {**better, "disposition": "drop"}
|
|
599
|
+
refused, regen, problems = doc({**{i: verdict() for i in ids}, "k-g": verdict(failing=["what_happened"])},
|
|
600
|
+
{"k-g": moved})
|
|
601
|
+
equal("a regeneration that moves anything but the Korean is refused by S7's own rule, and the row is marked",
|
|
602
|
+
(row_in(refused, "k-g").get("mark"), (row_in(refused, "k-g").get("regeneration") or {}).get("codes"),
|
|
603
|
+
regen["proposals"]), (True, ["REGENERATION_CHANGED"], {}))
|
|
604
|
+
same, _r, _p = doc({**{i: verdict() for i in ids}, "k-g": verdict(failing=["what_happened"])},
|
|
605
|
+
{"k-g": regenerated("k-g")})
|
|
606
|
+
equal("a regeneration that rewrites nothing is refused as REGENERATION_UNCHANGED",
|
|
607
|
+
(row_in(same, "k-g").get("regeneration") or {}).get("codes"), ["REGENERATION_UNCHANGED"])
|
|
608
|
+
absent, _r, _p = doc({**{i: verdict() for i in ids}, "k-g": verdict(failing=["what_happened"])})
|
|
609
|
+
equal("a failing row with no regeneration is marked", (row_in(absent, "k-g").get("mark"),
|
|
610
|
+
row_in(absent, "k-g").get("regeneration")),
|
|
611
|
+
(True, {"state": "absent"}))
|
|
612
|
+
unseen, _r, _p = doc({**{i: verdict() for i in ids}, "k-g": verdict(failing=["what_happened"])}, {"k-g": better})
|
|
613
|
+
equal("a regenerated row with no second review is marked", (row_in(unseen, "k-g").get("mark"),
|
|
614
|
+
row_in(unseen, "k-g").get("second")),
|
|
615
|
+
(True, {"state": "unreviewed"}))
|
|
616
|
+
|
|
617
|
+
broken, _r, _p = doc({**{i: verdict() for i in ids}, "k-g": verdict(failing=["what_happened"])},
|
|
618
|
+
{"k-g": better}, {"k-g": {**verdict(), "verdict": "maybe"}})
|
|
619
|
+
equal("a second review that does not hold leaves the row marked, with its codes",
|
|
620
|
+
(row_in(broken, "k-g").get("mark"), row_in(broken, "k-g").get("second")),
|
|
621
|
+
(True, {"state": "returned", "codes": ["S9B_SCHEMA_INVALID"]}))
|
|
622
|
+
|
|
623
|
+
# ---- a later version: what S9b judged is carried, so a row is regenerated once across versions ---------------
|
|
624
|
+
_o, regen_once, _p = doc({**{i: verdict() for i in ids}, "k-g": verdict(failing=["what_happened"])},
|
|
625
|
+
{"k-g": better}, {"k-g": verdict()})
|
|
626
|
+
later_rows = copy.deepcopy({**rows_doc, "version": 2})
|
|
627
|
+
# S9 lays a regenerated proposal over S7's in the next render (decision (a), K4b), so the later version's k-g
|
|
628
|
+
# carries the regenerated Korean, the text its second review judged
|
|
629
|
+
for r in later_rows["rows"]:
|
|
630
|
+
if r["item_id"] in regen_once["proposals"]:
|
|
631
|
+
r["proposal"] = copy.deepcopy(regen_once["proposals"][r["item_id"]])
|
|
632
|
+
|
|
633
|
+
def later(reviews, previous=once, previous_regenerated=None, rows=None):
|
|
634
|
+
return document(rows or later_rows, docs["proposals"], docs["candidates"], docs["derivations"], reviews,
|
|
635
|
+
None, None, previous, regen_once if previous_regenerated is None else previous_regenerated)
|
|
636
|
+
carried_doc, carried_regen, problems = later({})
|
|
637
|
+
clean("a later version whose rows S9b judged before needs no review", problems)
|
|
638
|
+
equal("each is carried from the version that judged it, its regenerated proposal with it",
|
|
639
|
+
(sorted((r["item_id"], r.get("carried_from")) for r in carried_doc["rows"]),
|
|
640
|
+
sorted(carried_regen["proposals"]), carried_doc["counts"]["carried"]),
|
|
641
|
+
(sorted((i, 1) for i in ids), ["k-g"], 3))
|
|
642
|
+
control("a review given for a carried row is refused: it was judged, and regenerated, already",
|
|
643
|
+
"\n".join(later({"k-g": verdict()})[2]), "REVIEW_CARRIED k-g")
|
|
644
|
+
moved_rows = copy.deepcopy(later_rows)
|
|
645
|
+
next(r for r in moved_rows["rows"] if r["item_id"] == "k-a")["payload_sha256"] = "f" * 64
|
|
646
|
+
fresh, _r, _p = later({}, rows=moved_rows)
|
|
647
|
+
equal("a row whose English payload moved since is asked again", [u["item_id"] for u in fresh["unreviewed"]],
|
|
648
|
+
["k-a"])
|
|
649
|
+
# Codex WP-20 r1 F3: the English payload's hash leaves the Korean out, so a verdict is bound to the Korean too
|
|
650
|
+
korean_moved = copy.deepcopy(later_rows)
|
|
651
|
+
k_a = next(r for r in korean_moved["rows"] if r["item_id"] == "k-a")
|
|
652
|
+
k_a["proposal"]["reasons"] = {**k_a["proposal"]["reasons"],
|
|
653
|
+
FIELDS[0]: (k_a["proposal"]["reasons"].get(FIELDS[0]) or "") + " 바뀐 문장"}
|
|
654
|
+
fresh_ko, _r, _p = later({}, rows=korean_moved)
|
|
655
|
+
equal("a row whose Korean moved since, its English payload unchanged, is asked again and not carried",
|
|
656
|
+
([u["item_id"] for u in fresh_ko["unreviewed"]], "k-a" in {r["item_id"] for r in fresh_ko["rows"]}),
|
|
657
|
+
(["k-a"], False))
|
|
658
|
+
regen_moved = copy.deepcopy(later_rows)
|
|
659
|
+
k_g = next(r for r in regen_moved["rows"] if r["item_id"] == "k-g")
|
|
660
|
+
k_g["proposal"]["reasons"] = {**k_g["proposal"]["reasons"],
|
|
661
|
+
FIELDS[0]: (k_g["proposal"]["reasons"].get(FIELDS[0]) or "") + " 바뀐 문장"}
|
|
662
|
+
used_doc, used_regen, used_problems = document(regen_moved, docs["proposals"], docs["candidates"],
|
|
663
|
+
docs["derivations"], {"k-g": verdict(failing=["what_happened"])},
|
|
664
|
+
None, None, once, regen_once)
|
|
665
|
+
equal("a row regenerated at an earlier version whose Korean moved is judged again, and failing it is marked "
|
|
666
|
+
"without a second regeneration", (row_in(used_doc, "k-g").get("regeneration"),
|
|
667
|
+
row_in(used_doc, "k-g").get("mark"), sorted(used_regen["proposals"]),
|
|
668
|
+
used_problems), ({"state": "used_before"}, True, [], []))
|
|
669
|
+
# Codex WP-20 r2 F1: the row shows v1's regenerated Korean and its English moved, so it is judged afresh; the
|
|
670
|
+
# regenerated text it shows stays in this version's regenerated proposals, which the next render lays over S7's
|
|
671
|
+
english_moved = copy.deepcopy(later_rows)
|
|
672
|
+
next(r for r in english_moved["rows"] if r["item_id"] == "k-g")["payload_sha256"] = "e" * 64
|
|
673
|
+
fresh_doc, fresh_regen, fresh_problems = document(english_moved, docs["proposals"], docs["candidates"],
|
|
674
|
+
docs["derivations"], {"k-g": verdict()}, None, None, once,
|
|
675
|
+
regen_once)
|
|
676
|
+
equal("a fresh pass on an earlier regeneration keeps that regeneration as what the row shows, bound to it",
|
|
677
|
+
(fresh_problems, sorted(fresh_regen["proposals"]), row_in(fresh_doc, "k-g").get("korean_sha256")),
|
|
678
|
+
([], ["k-g"], korean_sha256_of(regen_once["proposals"]["k-g"])))
|
|
679
|
+
# Codex WP-20 r2 F2: a version that left the row unreviewed keeps its used regeneration in the history
|
|
680
|
+
gap_doc, _gr, _gp = document(english_moved, docs["proposals"], docs["candidates"], docs["derivations"], {},
|
|
681
|
+
None, None, once, regen_once)
|
|
682
|
+
equal("a version that left a regenerated row unreviewed still names its used regeneration",
|
|
683
|
+
("k-g" in {u["item_id"] for u in gap_doc["unreviewed"]}, gap_doc.get("regeneration_used")), (True, ["k-g"]))
|
|
684
|
+
third = copy.deepcopy(english_moved)
|
|
685
|
+
third["version"] = 3
|
|
686
|
+
next(r for r in third["rows"] if r["item_id"] == "k-g")["payload_sha256"] = "d" * 64
|
|
687
|
+
after_gap, _ar, after_problems = document(third, docs["proposals"], docs["candidates"], docs["derivations"],
|
|
688
|
+
{"k-g": verdict(failing=["what_happened"])}, {"k-g": better}, None,
|
|
689
|
+
{**gap_doc, "version": 2}, {"proposals": {}})
|
|
690
|
+
control("so a later version does not regenerate it again, whatever the version between did",
|
|
691
|
+
"; ".join(after_problems), "REGENERATION_UNASKED k-g")
|
|
692
|
+
control("and a regeneration given for it is refused, since its one regeneration was used",
|
|
693
|
+
"\n".join(document(regen_moved, docs["proposals"], docs["candidates"], docs["derivations"],
|
|
694
|
+
{"k-g": verdict(failing=["what_happened"])}, {"k-g": better}, None, once,
|
|
695
|
+
regen_once)[2]), "REGENERATION_UNASKED k-g")
|
|
696
|
+
control("a carried regeneration its file does not hold is named",
|
|
697
|
+
"\n".join(later({}, previous_regenerated={"proposals": {}})[2]), "CARRY_INCOMPLETE k-g")
|
|
698
|
+
import tempfile as _tempfile
|
|
699
|
+
import shutil as _shutil
|
|
700
|
+
held_dir = pathlib.Path(_tempfile.mkdtemp(prefix="s9b-prev-"))
|
|
701
|
+
try:
|
|
702
|
+
review_rel, regen_rel = outputs_of(1)
|
|
703
|
+
records.write_json(held_dir, held_dir / regen_rel, regen_once)
|
|
704
|
+
records.write_json(held_dir, held_dir / review_rel,
|
|
705
|
+
{**once, "regenerated_sha256": records.sha256_file(held_dir / regen_rel)})
|
|
706
|
+
got_prev, got_regen = previous_of(held_dir, 2)
|
|
707
|
+
equal("the previous review is found and held to its regenerated proposals",
|
|
708
|
+
((got_prev or {}).get("version"), sorted((got_regen or {}).get("proposals") or {})), (1, ["k-g"]))
|
|
709
|
+
records.write_json(held_dir, held_dir / regen_rel, {"proposals": {}})
|
|
710
|
+
try:
|
|
711
|
+
changed = f"returned {previous_of(held_dir, 2)[0] is not None}"
|
|
712
|
+
except Refused as exc:
|
|
713
|
+
changed = str(exc)
|
|
714
|
+
control("regenerated proposals changed since their review are refused by name", changed,
|
|
715
|
+
"S9B_CHANGED regenerated-reasons.v1.json")
|
|
716
|
+
finally:
|
|
717
|
+
_shutil.rmtree(held_dir, ignore_errors=True)
|
|
718
|
+
|
|
719
|
+
# ---- rows S9b did not judge, and answers it was not asked for ------------------------------------------------
|
|
720
|
+
partial, _r, problems = doc({"k-a": verdict()})
|
|
721
|
+
# in the review's rank order: k-g, which S7b left to the owner, ranks ahead of due_decision (5851e09's S7b key)
|
|
722
|
+
equal("a row S9b returned no review for is listed unreviewed, never withheld",
|
|
723
|
+
([u["item_id"] for u in partial["unreviewed"]], [r["item_id"] for r in partial["rows"]]),
|
|
724
|
+
(["k-g", "due_decision:P-1@r1"], ["k-a"]))
|
|
725
|
+
inconsistent, _r, _p = doc({**{i: verdict() for i in ids}, "k-a": verdict(verdict="fail")})
|
|
726
|
+
equal("a verdict that disagrees with its fields is returned with its code",
|
|
727
|
+
inconsistent["returned"], [{"item_id": "k-a", "pass": "first", "codes": ["S9B_VERDICT_INCONSISTENT"]}])
|
|
728
|
+
short = verdict()
|
|
729
|
+
short["fields"] = short["fields"][:5] + [dict(short["fields"][0])]
|
|
730
|
+
control("an answer judging one field twice and another not at all is named",
|
|
731
|
+
"\n".join(verdict_problems(short)), "S9B_FIELD_TWICE what_happened")
|
|
732
|
+
control("and the missing field by name", "\n".join(verdict_problems(short)), "S9B_FIELD_MISSING falsifier")
|
|
733
|
+
control("an answer outside the schema is returned", "\n".join(verdict_problems({**verdict(), "verdict": "maybe"})),
|
|
734
|
+
"S9B_SCHEMA_INVALID")
|
|
735
|
+
control("a review for a row S9b was not asked about is named",
|
|
736
|
+
"\n".join(doc({**{i: verdict() for i in ids}, "k-zz": verdict()})[2]), "S9B_UNACCOUNTED k-zz")
|
|
737
|
+
control("a regeneration for a row that did not fail is named",
|
|
738
|
+
"\n".join(doc({i: verdict() for i in ids}, {"k-a": regenerated("k-a", cost="다른 비용")})[2]),
|
|
739
|
+
"REGENERATION_UNASKED k-a")
|
|
740
|
+
control("a second review for a row that was not regenerated is named",
|
|
741
|
+
"\n".join(doc({i: verdict() for i in ids}, None, {"k-a": verdict()})[2]), "SECOND_REVIEW_UNASKED k-a")
|
|
742
|
+
|
|
743
|
+
# ---- the stage, end to end on the golden run ------------------------------------------------------------------
|
|
744
|
+
import shutil
|
|
745
|
+
import subprocess
|
|
746
|
+
import tempfile
|
|
747
|
+
root = pathlib.Path(tempfile.mkdtemp(prefix="s9b-"))
|
|
748
|
+
|
|
749
|
+
class SectionStopped(Exception):
|
|
750
|
+
pass
|
|
751
|
+
try:
|
|
752
|
+
try:
|
|
753
|
+
run_dir = stage_render.golden_run(root)
|
|
754
|
+
stage_render.run(run_dir)
|
|
755
|
+
except Exception as exc: # an upstream stage that breaks fails this section's first control by name
|
|
756
|
+
equal("S9b reviews the golden run's review version 1", f"GOLDEN_RUN_FAILED {type(exc).__name__}: {exc}"[:300],
|
|
757
|
+
(1, None))
|
|
758
|
+
raise SectionStopped from exc
|
|
759
|
+
cli_out = root / "cli"
|
|
760
|
+
shutil.copytree(run_dir.parent, cli_out)
|
|
761
|
+
cut_dir = shutil.copytree(run_dir.parent, root / "cut") / run_dir.name
|
|
762
|
+
try:
|
|
763
|
+
out, said = run(run_dir, {}), None
|
|
764
|
+
except Refused as exc:
|
|
765
|
+
out, said = {}, str(exc)
|
|
766
|
+
equal("S9b reviews the golden run's review version 1", (out.get("version"), said), (1, None))
|
|
767
|
+
rec = records.stage_records(run_dir).get(STAGE) or {}
|
|
768
|
+
equal("its record names the review and the regenerated proposals",
|
|
769
|
+
sorted(o["artifact"] for o in rec.get("outputs") or []),
|
|
770
|
+
["regenerated-reasons.v1.json", "review-s9b.v1.json"])
|
|
771
|
+
try:
|
|
772
|
+
again = f"written {run(run_dir, {})}"
|
|
773
|
+
except Refused as exc:
|
|
774
|
+
again = str(exc)
|
|
775
|
+
control("a version's Korean is reviewed once", again, "S9B_VERSION_REVIEWED")
|
|
776
|
+
after = records.stage_records(run_dir).get(STAGE) or {}
|
|
777
|
+
equal("and that refusal leaves the review's own record as it was: complete, naming the same outputs",
|
|
778
|
+
(after.get("status"), sorted(o["artifact"] for o in after.get("outputs") or [])),
|
|
779
|
+
("complete", ["regenerated-reasons.v1.json", "review-s9b.v1.json"]))
|
|
780
|
+
# two invocations in turn: the other one finishes its review after this one was started and before this one
|
|
781
|
+
# holds the stage's lock. Stood in for by taking the review away, and putting it back as the stage opens.
|
|
782
|
+
# (both outputs: the check refuses on the review, and the regenerated proposals go with it)
|
|
783
|
+
both = ("review-s9b.v1.json", "regenerated-reasons.v1.json")
|
|
784
|
+
record_rel = f"stages/{STAGE}/record.json"
|
|
785
|
+
held_record = (run_dir / record_rel).read_bytes()
|
|
786
|
+
held_outputs = {rel: (run_dir / rel).read_bytes() for rel in both}
|
|
787
|
+
held_review = held_outputs["review-s9b.v1.json"]
|
|
788
|
+
real_stage = records.run_stage
|
|
789
|
+
|
|
790
|
+
def other_finishes_first(*args, **kwargs):
|
|
791
|
+
for rel, data in held_outputs.items():
|
|
792
|
+
(run_dir / rel).write_bytes(data)
|
|
793
|
+
return real_stage(*args, **kwargs)
|
|
794
|
+
late, untouched = "not run", False
|
|
795
|
+
try:
|
|
796
|
+
for rel in both:
|
|
797
|
+
(run_dir / rel).unlink()
|
|
798
|
+
records.run_stage = other_finishes_first
|
|
799
|
+
late = f"written {run(run_dir, {})}"
|
|
800
|
+
except Refused as exc:
|
|
801
|
+
late = str(exc).split(" ", 1)[0]
|
|
802
|
+
except Exception as exc: # noqa: BLE001 - a second review that got past the lock fails here by name
|
|
803
|
+
late = f"{type(exc).__name__} past the lock"
|
|
804
|
+
finally:
|
|
805
|
+
records.run_stage = real_stage
|
|
806
|
+
# read before anything is put back, the record's bytes among them: a record replaced and finished
|
|
807
|
+
# again still says complete
|
|
808
|
+
untouched = all((run_dir / rel).is_file() and (run_dir / rel).read_bytes() == data
|
|
809
|
+
for rel, data in {**held_outputs, record_rel: held_record}.items())
|
|
810
|
+
for rel, data in {**held_outputs, record_rel: held_record}.items():
|
|
811
|
+
(run_dir / rel).write_bytes(data)
|
|
812
|
+
after = records.stage_records(run_dir).get(STAGE) or {}
|
|
813
|
+
equal("an invocation that reaches the stage's lock after another one reviewed the version is refused there, "
|
|
814
|
+
"with both outputs and the record's own bytes untouched",
|
|
815
|
+
(late, untouched and bool(held_review), after.get("status")),
|
|
816
|
+
("S9B_VERSION_REVIEWED", True, "complete"))
|
|
817
|
+
# Codex WP-20 r1 F4: a run cut short after the regenerated proposals are written and before the review is.
|
|
818
|
+
# The review is the version's commit, so running again finishes it instead of refusing the version.
|
|
819
|
+
real_write, cut = records.write_json, []
|
|
820
|
+
|
|
821
|
+
def dies_at_review(run_dir_, path, doc, *args, **kwargs):
|
|
822
|
+
if pathlib.Path(path).name == outputs_of(1)[0] and not cut:
|
|
823
|
+
cut.append(True)
|
|
824
|
+
raise RuntimeError("cut short before the review is written")
|
|
825
|
+
return real_write(run_dir_, path, doc, *args, **kwargs)
|
|
826
|
+
records.write_json = dies_at_review
|
|
827
|
+
try:
|
|
828
|
+
first_try = f"written {run(cut_dir, {})}"
|
|
829
|
+
except RuntimeError as exc:
|
|
830
|
+
first_try = str(exc)
|
|
831
|
+
finally:
|
|
832
|
+
records.write_json = real_write
|
|
833
|
+
left = sorted(p.name for p in cut_dir.glob("re*-*.v1.json"))
|
|
834
|
+
try:
|
|
835
|
+
second_try = run(cut_dir, {})
|
|
836
|
+
except Refused as exc:
|
|
837
|
+
second_try = str(exc).split(" ", 1)[0]
|
|
838
|
+
cut_rec = records.stage_records(cut_dir).get(STAGE) or {}
|
|
839
|
+
equal("a review cut short before its review file leaves only the regenerated proposals, and running again "
|
|
840
|
+
"finishes the version", (first_try, left, getattr(second_try, "get", lambda k: second_try)("version"),
|
|
841
|
+
cut_rec.get("status"), sorted(o["artifact"] for o in cut_rec.get("outputs") or [])),
|
|
842
|
+
("cut short before the review is written", ["regenerated-reasons.v1.json"], 1, "complete",
|
|
843
|
+
["regenerated-reasons.v1.json", "review-s9b.v1.json"]))
|
|
844
|
+
# Codex WP-20 r2 F3: cut short after the review is written, while its outputs are being registered. The
|
|
845
|
+
# committed review is finished by registering it, not reviewed again, and not refused as reviewed.
|
|
846
|
+
late_dir = shutil.copytree(cli_out, root / "late") / run_dir.name
|
|
847
|
+
real_write_after, written = records.write_json, []
|
|
848
|
+
|
|
849
|
+
def dies_after_review(run_dir_, path, doc, *args, **kwargs):
|
|
850
|
+
out = real_write_after(run_dir_, path, doc, *args, **kwargs)
|
|
851
|
+
if pathlib.Path(path).name == outputs_of(1)[0] and not written:
|
|
852
|
+
written.append(True)
|
|
853
|
+
raise RuntimeError("cut short after the review is written")
|
|
854
|
+
return out
|
|
855
|
+
records.write_json = dies_after_review
|
|
856
|
+
try:
|
|
857
|
+
late_first = f"written {run(late_dir, {})}"
|
|
858
|
+
except RuntimeError as exc:
|
|
859
|
+
late_first = str(exc)
|
|
860
|
+
finally:
|
|
861
|
+
records.write_json = real_write_after
|
|
862
|
+
try:
|
|
863
|
+
late_second = run(late_dir, {})
|
|
864
|
+
except Refused as exc:
|
|
865
|
+
late_second = str(exc).split(" ", 1)[0]
|
|
866
|
+
late_rec = records.stage_records(late_dir).get(STAGE) or {}
|
|
867
|
+
equal("a review cut short after its review file is finished by registering it, not reviewed again",
|
|
868
|
+
(late_first, getattr(late_second, "get", lambda k: late_second)("finished"), late_rec.get("status"),
|
|
869
|
+
sorted(o["artifact"] for o in late_rec.get("outputs") or [])),
|
|
870
|
+
("cut short after the review is written", True, "complete",
|
|
871
|
+
["regenerated-reasons.v1.json", "review-s9b.v1.json"]))
|
|
872
|
+
try:
|
|
873
|
+
late_third = f"written {run(late_dir, {})}"
|
|
874
|
+
except Refused as exc:
|
|
875
|
+
late_third = str(exc)
|
|
876
|
+
control("and once finished it is reviewed once, as any version is", late_third, "S9B_VERSION_REVIEWED")
|
|
877
|
+
(cli_out / "reviews.json").write_text("{}", encoding="utf-8")
|
|
878
|
+
done = subprocess.run([sys.executable, "-I", str(HERE / "distill.py"), "review-korean", "--run-id",
|
|
879
|
+
run_dir.name, "--out", str(cli_out), "--reviews", str(cli_out / "reviews.json")],
|
|
880
|
+
capture_output=True, text=True, timeout=600)
|
|
881
|
+
control("the driver's `review-korean` runs S9b as a process over the reviews it is given",
|
|
882
|
+
f"rc={done.returncode} {done.stdout}{done.stderr[-400:]}", "rc=0 S9b review-korean: version 1")
|
|
883
|
+
bare = subprocess.run([sys.executable, "-I", str(HERE / "distill.py"), "review-korean", "--run-id",
|
|
884
|
+
run_dir.name, "--out", str(cli_out)], capture_output=True, text=True, timeout=600)
|
|
885
|
+
control("and with neither reviews nor a cell root is refused by name", f"rc={bare.returncode} {bare.stderr[-400:]}",
|
|
886
|
+
"rc=1 INPUT_INVALID review-korean --cells")
|
|
887
|
+
except SectionStopped:
|
|
888
|
+
pass
|
|
889
|
+
except Exception as exc: # a later break fails this section by name, never the whole suite
|
|
890
|
+
failures.append(("the golden run's section ran to its end", f"{type(exc).__name__}: {exc}"[:600]))
|
|
891
|
+
finally:
|
|
892
|
+
shutil.rmtree(root, ignore_errors=True)
|
|
893
|
+
|
|
894
|
+
# ---- the supervised calls (release 1): a golden run whose S7 PROPOSED, so there are rows to review ----
|
|
895
|
+
live_root = pathlib.Path(tempfile.mkdtemp(prefix="s9b-live-"))
|
|
896
|
+
try:
|
|
897
|
+
from runlib import declare, stage_judge, stage_retrieve, stage_review_proposals
|
|
898
|
+
live_run = stage_retrieve.fx_gold(live_root / "base", stage_retrieve.fx_current(stage_judge.fx_library()))
|
|
899
|
+
declare.amend(live_run, [("budget.per_stage.S6", 20_000_000)], "S9b self-test: the golden run through S9")
|
|
900
|
+
stage_retrieve.run(live_run, "aa" * 8)
|
|
901
|
+
planner = live_root / "planner"
|
|
902
|
+
shutil.copytree(live_run.parent, planner)
|
|
903
|
+
judge_plan, _p = stage_judge.fx_judge_plan(planner / live_run.name, live_root / "judge-plan.json")
|
|
904
|
+
stage_judge.run(live_run, stage_judge.supervisor(live_run, live_root / "judge-cells", judge_plan))
|
|
905
|
+
live_deriv = records.read_json(live_run / "judgments" / "derivations.json")
|
|
906
|
+
ledger_only = stage_propose._answered(disposition="none", operations=[],
|
|
907
|
+
destination={"layer": "incubator", "carrier": None},
|
|
908
|
+
unknowns=stage_propose._carry(live_deriv))
|
|
909
|
+
stage_propose.run(live_run, {c["candidate_id"]: ledger_only for c in
|
|
910
|
+
records.read_json(live_run / "checked-candidates.json")["candidates"]})
|
|
911
|
+
stage_review_proposals.run(live_run, {})
|
|
912
|
+
stage_render.run(live_run)
|
|
913
|
+
live_rows = reviewable(records.read_json(live_run / "review.v1.json"))
|
|
914
|
+
equal("the golden run through S9 holds rows to review, more than two", len(live_rows) > 2, True)
|
|
915
|
+
try:
|
|
916
|
+
run(live_run)
|
|
917
|
+
bare_said = "ran"
|
|
918
|
+
except Refused as exc:
|
|
919
|
+
bare_said = str(exc)
|
|
920
|
+
control("S9b with neither answers nor a supervisor is refused by name", bare_said, "REVIEW_UNSUPERVISED S9b")
|
|
921
|
+
try:
|
|
922
|
+
run(live_run, supervisor=supervisor(live_run, live_root / "cells-0", live_root / "judge-plan.json"))
|
|
923
|
+
unseated = "ran"
|
|
924
|
+
except Refused as exc:
|
|
925
|
+
unseated = str(exc)
|
|
926
|
+
control("a run that seats no S9b is refused before any call", unseated, "SEAT_UNDECLARED S9b")
|
|
927
|
+
failing_id, marked_id, unanswered_id = (r["item_id"] for r in live_rows[:3])
|
|
928
|
+
rewritten = copy.deepcopy(live_rows[0]["proposal"])
|
|
929
|
+
rewritten["reasons"]["proposal"] = "다시 쓴 제안"
|
|
930
|
+
moved = copy.deepcopy(live_rows[1]["proposal"])
|
|
931
|
+
moved["disposition"] = "keep" # a regeneration that moves more than the Korean
|
|
932
|
+
named = lambda ident: '"item_id": ' + json.dumps(ident) # noqa: E731 - the review packet's own row line
|
|
933
|
+
plan_rows = [
|
|
934
|
+
{"match": [named(failing_id), "다시 쓴 제안"], "answer": verdict()},
|
|
935
|
+
{"match": ["faithfulness check (proposal)"], "answer": rewritten},
|
|
936
|
+
{"match": [named(failing_id)], "answer": verdict(("proposal",))},
|
|
937
|
+
{"match": ["faithfulness check (reason)"], "answer": moved},
|
|
938
|
+
{"match": [named(marked_id)], "answer": verdict(("reason",))},
|
|
939
|
+
{"match": [named(unanswered_id)], "answer": {"verdict": "pass"}}, # not the schema's shape
|
|
940
|
+
] + [{"match": [named(r["item_id"])], "answer": verdict()} for r in live_rows[3:]]
|
|
941
|
+
plan_path = live_root / "s9b-plan.json"
|
|
942
|
+
plan_path.write_text(json.dumps(plan_rows, ensure_ascii=False), encoding="utf-8")
|
|
943
|
+
current_seats = records.declaration_state(live_run, who="S9b self-test")[0]["seats"]
|
|
944
|
+
declare.amend(live_run, [("seats", {**current_seats, SEAT_KEY: "codex:gpt-6-astra/high",
|
|
945
|
+
REGENERATE_SEAT_KEY: "claude:claude-opus-5-5/high"}),
|
|
946
|
+
("budget.per_stage.S9b", 5_000_000)], "S9b's golden seats and budget")
|
|
947
|
+
out = run(live_run, supervisor=supervisor(live_run, live_root / "cells", plan_path))
|
|
948
|
+
held_calls = records.read_json(live_run / calls_rel(1))
|
|
949
|
+
by_item = collections.defaultdict(list)
|
|
950
|
+
for call in held_calls["calls"]:
|
|
951
|
+
by_item[call["item_id"]].append((call["case"], call["outcome"]))
|
|
952
|
+
equal("a row that fails is three calls - its review, S7's regeneration, its second review - and one that "
|
|
953
|
+
"passes is one",
|
|
954
|
+
[by_item[failing_id], sorted(set(len(v) for k, v in by_item.items()
|
|
955
|
+
if k not in (failing_id, marked_id, unanswered_id)))],
|
|
956
|
+
[[("review", "accepted"), ("regenerate", "accepted"), ("review", "accepted")], [1]])
|
|
957
|
+
equal("a regeneration that moves more than the Korean fails its call by the rule's own name, and no second "
|
|
958
|
+
"review is asked",
|
|
959
|
+
[by_item[marked_id], "REGENERATION_CHANGED" in json.dumps(next(
|
|
960
|
+
c["attempts"] for c in held_calls["calls"]
|
|
961
|
+
if c["item_id"] == marked_id and c["case"] == "regenerate"))],
|
|
962
|
+
[[("review", "accepted"), ("regenerate", "failed")], True])
|
|
963
|
+
review_doc = records.read_json(live_run / "review-s9b.v1.json")
|
|
964
|
+
row_of = {r["item_id"]: r for r in review_doc["rows"]}
|
|
965
|
+
equal("the regenerated row is unmarked after a passing second review; the one whose regeneration never came "
|
|
966
|
+
"is marked",
|
|
967
|
+
[(row_of[failing_id]["regenerated"], row_of[failing_id]["mark"], row_of[failing_id]["second"]["verdict"]),
|
|
968
|
+
(row_of[marked_id]["regenerated"], row_of[marked_id]["mark"], row_of[marked_id]["regeneration"])],
|
|
969
|
+
[(True, False, "pass"), (False, True, {"state": "absent"})])
|
|
970
|
+
equal("a row whose review call was refused twice is unreviewed, not guessed",
|
|
971
|
+
[[u["item_id"] for u in review_doc["unreviewed"]], unanswered_id in row_of], [[unanswered_id], False])
|
|
972
|
+
equal("the regenerated proposal is the one the stage keeps, and only its Korean moved",
|
|
973
|
+
[records.read_json(live_run / "regenerated-reasons.v1.json")["proposals"][failing_id]["reasons"]["proposal"],
|
|
974
|
+
list(records.read_json(live_run / "regenerated-reasons.v1.json")["proposals"])],
|
|
975
|
+
["다시 쓴 제안", [failing_id]])
|
|
976
|
+
equal("the summary counts the calls and the rows asked", [out["asked"], out["calls"].get("accepted", 0) > 0],
|
|
977
|
+
[len(live_rows), True])
|
|
978
|
+
rec = records.stage_records(live_run).get(STAGE) or {}
|
|
979
|
+
equal("and the calls' record is one of the stage's outputs",
|
|
980
|
+
calls_rel(1) in [o["artifact"] for o in rec.get("outputs") or []], True)
|
|
981
|
+
except Exception as exc: # a break here fails this section by name, never the whole suite
|
|
982
|
+
mark_ran("the supervised calls' section ran to its end")
|
|
983
|
+
failures.append(("the supervised calls' section ran to its end", f"{type(exc).__name__}: {exc}"[:700]))
|
|
984
|
+
finally:
|
|
985
|
+
shutil.rmtree(live_root, ignore_errors=True)
|
|
986
|
+
|
|
987
|
+
reporting.append(True)
|
|
988
|
+
if failures:
|
|
989
|
+
for label, detail in failures:
|
|
990
|
+
print(f"stage_review_korean --self-test [FAIL] {label}: {detail}", file=sys.stderr)
|
|
991
|
+
print(f"stage_review_korean --self-test: FAILED ({len(failures)} of {len(ran)} controls)", file=sys.stderr)
|
|
992
|
+
return 1
|
|
993
|
+
print(f"stage_review_korean --self-test: OK ({len(ran)} controls: the packet carries both texts and the hash; a "
|
|
994
|
+
f"failing row regenerated once through S7's own rule and reviewed again; marked when it fails twice, when "
|
|
995
|
+
f"its regeneration is refused or absent, or when its second review is; never withheld)")
|
|
996
|
+
return 0
|
|
997
|
+
|
|
998
|
+
|
|
999
|
+
if __name__ == "__main__":
|
|
1000
|
+
if sys.argv[1:2] == ["--self-test"]:
|
|
1001
|
+
sys.exit(self_test())
|
|
1002
|
+
sys.exit("usage: stage_review_korean.py --self-test")
|