Answer principles round 1: 0 🔴, 2 🟡; block item 218 on item 170, name record_fields and RECORD_FIELDS, say an unreadable Worker line on stderr

This commit is contained in:
2026-10-22 22:12:29 +02:00
parent c5fdaf43f6
commit f6594bc048
9 changed files with 63 additions and 42 deletions
+3 -3
View File
@@ -119,15 +119,15 @@ def verdict_from(output: object) -> Verdict | Failure:
if output["interrupt"]:
if not output["question"].strip():
return Failure("the judge interrupted without a question")
return Interrupt(output["evidence"], output["question"], output["escalation"], likelihood, output["release_ready"])
return Interrupt(output["evidence"], output["question"], escalation=output["escalation"], highest_likelihood_taken_in=likelihood, release_ready=output["release_ready"])
if output["answer"].strip():
if not output["question"].strip():
return Failure("the judge quoted an answer without a question")
return QuotedAnswer(output["evidence"], output["question"], output["answer"], output["escalation"], likelihood)
return QuotedAnswer(output["evidence"], output["question"], output["answer"], escalation=output["escalation"], highest_likelihood_taken_in=likelihood)
if output["finished"]:
return Finished(output["evidence"])
escape_and_impact = output["highest_escape_and_impact_taken_in"] if on_its_scale(output["highest_escape_and_impact_taken_in"]) else 0
return Unfinished(output["evidence"], likelihood, output["escalation"], escape_and_impact)
return Unfinished(output["evidence"], escalation=output["escalation"], highest_likelihood_taken_in=likelihood, highest_escape_and_impact_taken_in=escape_and_impact)
def judge(root: str, task: str, premises: str, records: str, entries: list[dict], escalated_at: int, rung: Rung, effects: Effects, keep: typing.Callable[[Rejected], Stop | None]) -> Verdict | Stop:
+13 -7
View File
@@ -108,8 +108,9 @@ Routing: the archive and reruns
Each finished or unfinished verdict, interrupt, quoted answer, stop and step-up in the archive ends
with a Worker: line, the route's JSON record (Route.record in bin/model_routing/route.py). A rerun
resumes an open chunk on the latest route named there, and counts its unfinished verdicts afresh; it
also reads the prose lines written before the record. A rung no longer on the ladder, or below the
resumes an open chunk on the latest route named there, and counts its unfinished verdicts afresh.
It also reads a Worker: line an older loop-claude wrote as a sentence, such as "claude-opus-5-5 at
high effort, routed by item 3's L of 4 and E + I of 5". A rung no longer on the ladder, or below the
one its item's L picks, is dropped, and the chunk is routed afresh from todo.md. So is a chunk whose
archived line names an R + C, as loop-claude wrote before it routed on L. A todo.md or an archive
that cannot be read or parsed is said on stderr, and the chunk is routed without it.
@@ -260,8 +261,10 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
def routed(route: Route | None, anchor: Rung | None, model: str, archived: typing.Callable[[], Route | None], item: typing.Callable[[], Item | None]) -> Route:
"""The route the cycle runs on. Off the ladder, where anchor, the project's rung, is None, the worker runs on model, the project's.
On it, a chunk keeps route, or on a rerun the one its archive last names, while that is at or above the rung its item's L picks from anchor; else the plan item routes it afresh."""
"""The route the cycle runs on. anchor is the project's rung, and model the project's model.
Where anchor is None, the model is off the ladder, and the worker runs on it. Otherwise the chunk keeps route, or on a rerun the route its archive last names, while that route's rung is at or above the one its item's L picks from anchor. Else the plan item routes the chunk afresh.
"""
if anchor is None:
return Route(Rung(model))
route = route or archived()
@@ -269,7 +272,7 @@ def routed(route: Route | None, anchor: Rung | None, model: str, archived: typin
def after_verdict(loop_run: LoopRun, anchor: Rung | None, concluded: Concluded) -> LoopRun:
"""The loop run the next cycle starts from. A finished chunk drops its route. An unfinished one steps from the route its cycle ended on, which an interrupt's or a quoted answer's escalation may have raised; off the ladder, it keeps that route."""
"""The loop run the next cycle starts from. A finished chunk drops its route. An unfinished one takes the route after_unfinished makes of the route its cycle ended on, which an interrupt's or a quoted answer's escalation may have raised; off the ladder, it keeps that route."""
verdict = concluded.verdict
if isinstance(verdict, Finished):
return dataclasses.replace(loop_run, route=None, unfinished_evidence="")
@@ -278,7 +281,7 @@ def after_verdict(loop_run: LoopRun, anchor: Rung | None, concluded: Concluded)
def archive_step(archive_folder: pathlib.Path, session: Session, task: str, before: Route, after: Route | None, effects: Effects) -> Stop | None:
"""Archives after, the route an unfinished verdict moved the chunk to from before, where its record differs: a rung up, or a higher E + I taken in. The verdict itself names before, the route its cycle ran on."""
"""Archives the route after an unfinished verdict as a step-up, where its record differs from the route before it: a higher rung, or a higher E + I taken in. The verdict itself names the route before, which its cycle ran on."""
if after is None or after.record() == before.record():
return None
path = transcript_file(session)
@@ -293,7 +296,10 @@ def archived_route(archive_folder: pathlib.Path, session: Session) -> Route | No
if isinstance(worker, Failure):
print(f"routing the chunk afresh: {worker.reason}", file=sys.stderr)
return None
return route_from(worker) if worker else None
route = route_from(worker) if worker else None
if worker and route is None:
print(f"routing the chunk afresh: the archive's latest Worker: line names no route loop-claude can read: {worker}", file=sys.stderr)
return route
def chunk_start(session: Session, preflight: pathlib.Path, root: str, effects: Effects) -> tuple[str, typing.Callable[[], Item | None]]:
+1 -1
View File
@@ -22,7 +22,7 @@ class LoopRun:
root: str
task: str
unfinished_evidence: str
# None until the chunk is routed, and once it finishes.
# Set by each unfinished verdict; None before the chunk's first one, and once it finishes.
route: Route | None = None
+2 -2
View File
@@ -67,7 +67,7 @@ def escalation_cap(anchor: Rung, route: Route) -> Rung:
def after_unfinished(anchor: Rung, route: Route, verdict: Unfinished) -> Route:
"""The route the next cycle runs on after an unfinished verdict.
Its rung rises to the one the highest L the worker took in picks, and never falls. From there it steps one rung up on every second unfinished verdict, or on an escalation while below escalation_cap; where both fall on one verdict, it steps once. A step on an escalation moves the route's mark, Route.escalated_at, to where the judge stopped reading, so the trigger it quoted buys no second step; a step on the count of unfinished verdicts alone keeps the mark. The highest E + I taken in moves to the route where Route.taking_in keeps it.
Its rung never falls. It first rises to the rung that the verdict's highest L taken in picks, where that is higher. From there it steps one rung up on every second unfinished verdict, or on an escalation while below escalation_cap; where both fall on one verdict, it steps once. A step on an escalation moves the route's mark, Route.escalated_at, to where the judge stopped reading, so the trigger it quoted buys no second step; a step on the count of unfinished verdicts alone keeps the mark. Last, the route takes in the verdict's highest E + I, as Route.taking_in does.
"""
rung = raised(anchor, route, verdict.highest_likelihood_taken_in)
mark = escalation_mark(verdict)
@@ -98,7 +98,7 @@ def below_cap(anchor: Rung, route: Route, rung: Rung) -> bool:
def raised(anchor: Rung, route: Route, likelihood_taken_in: int) -> Rung:
"""kept_rung, raised to the rung likelihood_taken_in, the highest L the worker took into the chunk, picks from anchor; 0 for none."""
"""kept_rung, raised to the rung that likelihood_taken_in picks from anchor. likelihood_taken_in is the highest L the worker took into the chunk, or 0 for none."""
return highest(kept_rung(anchor, route), worker_rung(anchor, likelihood_taken_in)) if likelihood_taken_in else kept_rung(anchor, route)
+22 -8
View File
@@ -32,13 +32,17 @@ from loop_claude.loop import main, reload, routing_check
from transcript_archive import outcomes, write
from loop_claude import paths, routing
from transcript_archive.location import project_archive
from model_routing.route import Route, route_from
from model_routing.route import Record, Route, route_from
from loop_claude.stop import Stop
from utc_stamp import utc
from loop_claude.cycle.judge import verdict_from
# How the archive records a worker that runs off the ladder.
OFF_LADDER = '{"model": "worker-model"}'
# How it records routes by item 179's L of 2 and E + I of 5, on Routing's rungs.
SONNET_179 = '{"model": "claude-sonnet-5-5", "effort": "high", "item": 179, "likelihood": 2, "escape_and_impact": 5}'
OPUS_179_AT_3 = '{"model": "claude-opus-5-5", "effort": "medium", "item": 179, "likelihood": 2, "escape_and_impact": 5, "escalated_at": 3}'
OPUS_179_AT_6 = '{"model": "claude-opus-5-5", "effort": "medium", "item": 179, "likelihood": 2, "escape_and_impact": 5, "escalated_at": 6}'
CWD = pathlib.Path("/c")
NOW = 1790000000
@@ -368,8 +372,8 @@ class Cycles(unittest.TestCase):
self.assertEqual([args[args.index("--effort") + 1] for args in (first, resumed)], ["high", "medium"])
self.assertTrue(resumed[resumed.index("-p") + 1].endswith(f"Continue the task. Your request for a higher rung went through: loop-claude runs you on {Routing.OPUS}. The escalation triggers that fired before this step are spent.{prompts.rungs_held(concluded.route, Routing.OPUS)}"))
self.assertNotIn("went through", first[first.index("-p") + 1])
answered = f"Verdict: quoted answer\n\nWhich one?\n\n{prompts.QUOTE_SOURCES} says:\n> Use A.\n\nEvidence:\n> working\n\nEscalation:\n> working\n\nJudge: judge-model\nWorker: {Route(Routing.SONNET, 179, 2, 5).record()}\n"
stepped = f"Stepped up\n\nWorker: {Route(Routing.OPUS, 179, 2, 5, escalated_at=3).record()}\n"
answered = f"Verdict: quoted answer\n\nWhich one?\n\n{prompts.QUOTE_SOURCES} says:\n> Use A.\n\nEvidence:\n> working\n\nEscalation:\n> working\n\nJudge: judge-model\nWorker: {SONNET_179}\n"
stepped = f"Stepped up\n\nWorker: {OPUS_179_AT_3}\n"
kept = "".join(self.archived_outcomes())
self.assertIn(f"Z {answered}\n20", kept)
self.assertIn(f"Z {stepped}", kept)
@@ -381,8 +385,8 @@ class Cycles(unittest.TestCase):
with contextlib.redirect_stdout(io.StringIO()), contextlib.redirect_stderr(io.StringIO()):
self.assertEqual(run.run_cycle(cycle), Stop(2, "the human is needed to answer the question above, but nothing was typed"))
kept = "".join(self.archived_outcomes())
self.assertIn(f"Evidence:\n> working\n\nEscalation:\n> working\n\nJudge: judge-model\nWorker: {Route(Routing.SONNET, 179, 2, 5).record()}\n", kept)
self.assertIn(f"Stepped up\n\nWorker: {Route(Routing.OPUS, 179, 2, 5, escalated_at=6).record()}\n", kept)
self.assertIn(f"Evidence:\n> working\n\nEscalation:\n> working\n\nJudge: judge-model\nWorker: {SONNET_179}\n", kept)
self.assertIn(f"Stepped up\n\nWorker: {OPUS_179_AT_6}\n", kept)
def test_a_ruling_steps_the_route_only_on_an_escalation_from_the_rung_its_taken_in_l_picks(self):
cycle = dataclasses.replace(self.cycle(FakeEffects()), anchor=Routing.OPUS, route=Route(Routing.OPUS, 3, 3, 4))
@@ -742,12 +746,12 @@ TODO = """# todo
def unfinished(likelihood=0, escalated_at=None):
"""An unfinished verdict: the worker took in an item of that L, 0 for none, and the judge found an escalation after reading escalated_at transcript entries, None for none."""
return Unfinished("e", likelihood, "round 2: 🔴" if escalated_at is not None else "", entries_read=escalated_at)
return Unfinished("e", escalation="round 2: 🔴" if escalated_at is not None else "", highest_likelihood_taken_in=likelihood, entries_read=escalated_at)
def interrupted(likelihood=0, escalated_at=None):
"""An interrupt, its arguments as unfinished's."""
return Interrupt("e", "q", "round 2: 🔴" if escalated_at is not None else "", likelihood, entries_read=escalated_at)
return Interrupt("e", "q", escalation="round 2: 🔴" if escalated_at is not None else "", highest_likelihood_taken_in=likelihood, entries_read=escalated_at)
class Routing(unittest.TestCase):
@@ -893,7 +897,7 @@ class Routing(unittest.TestCase):
self.assertEqual(route_from(Route(self.HIGH, 3, 4, 5, unfinished=1).record()), Route(self.HIGH, 3, 4, 5))
def test_reads_no_route_from_a_record_of_unknown_or_mistyped_fields_or_levels_off_their_scales(self):
for record in ('{"effort": "high"}', '{"model": "claude-opus-5-5", "effort": "high", "unfinished": 1}', '{"model": "claude-opus-5-5", "item": "3"}', '{"model": "claude-opus-5-5", "effort": "high", "escalated_at": -3}', '{"model": "claude-opus-5-5", "item": true, "likelihood": 4, "escape_and_impact": 5}', '{"model": "claude-opus-5-5", "effort": "high", "item": 3, "likelihood": 5, "escape_and_impact": 5}', '{"model": "claude-opus-5-5", "effort": "high", "escape_and_impact_taken_in": 9}', '["claude-opus-5-5"]', '{"model": '):
for record in ('{"effort": "high"}', '{"model": "claude-opus-5-5", "effort": "high", "unfinished": 1}', '{"model": "claude-opus-5-5", "item": "3"}', '{"model": "claude-opus-5-5", "effort": 3}', '{"model": 5}', '{"model": "claude-opus-5-5", "effort": "high", "escalated_at": -3}', '{"model": "claude-opus-5-5", "item": true, "likelihood": 4, "escape_and_impact": 5}', '{"model": "claude-opus-5-5", "effort": "high", "item": 3, "likelihood": 5, "escape_and_impact": 5}', '{"model": "claude-opus-5-5", "effort": "high", "escape_and_impact_taken_in": 9}', '["claude-opus-5-5"]', '{"model": '):
with self.subTest(record=record):
self.assertIsNone(route_from(record))
@@ -946,6 +950,11 @@ class RouteSources(unittest.TestCase):
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.unfinished(route.record(), "working", "j", ""), NOW))
self.assertEqual(main.archived_route(archive, opened), route)
with contextlib.redirect_stderr(io.StringIO()):
self.assertIsNone(write.archive(archive, str(transcript), "Do it.", outcomes.stepped_up(Record('{"model": "claude-opus-5-5", "rung": 3}')), NOW + 1))
with contextlib.redirect_stderr(io.StringIO()) as stderr:
self.assertIsNone(main.archived_route(archive, opened))
self.assertEqual(stderr.getvalue(), 'routing the chunk afresh: the archive\'s latest Worker: line names no route loop-claude can read: {"model": "claude-opus-5-5", "rung": 3}\n')
(chunk,) = archive.iterdir()
chunk.chmod(0)
try:
@@ -964,6 +973,11 @@ class Steps(unittest.TestCase):
self.assertEqual(main.after_verdict(run_with, self.OPUS, run.Concluded(Finished("x"), run_with.route)), dataclasses.replace(run_with, route=None, unfinished_evidence=""))
self.assertEqual(main.after_verdict(run_with, self.OPUS, run.Concluded(Unfinished("new", 4), run_with.route)), dataclasses.replace(run_with, route=Route(Rung("claude-opus-5-5", "high"), unfinished=1), unfinished_evidence="new"))
def test_steps_from_the_route_its_cycle_ended_on_which_a_ruling_may_have_raised(self):
run_with = main.LoopRun(cycle_number=1, root="/r", task="do it", unfinished_evidence="", route=Route(self.OPUS, 3, 3, 4))
raised = Route(Rung("claude-opus-5-5", "high"), 3, 3, 4, escalated_at=5)
self.assertEqual(main.after_verdict(run_with, self.OPUS, run.Concluded(Unfinished("new"), raised)).route, dataclasses.replace(raised, unfinished=1))
def test_keeps_the_route_its_cycle_ended_on_off_the_ladder(self):
off_ladder = Route(Rung("worker-model"))
run_with = main.LoopRun(cycle_number=1, root="/r", task="do it", unfinished_evidence="")
+4 -4
View File
@@ -1,4 +1,4 @@
"""What the judge rules on a cycle: the verdicts cycle.judge.verdict_from builds from its reply, which the cycle, the loop and routing read."""
"""The verdicts cycle.judge.verdict_from builds from the judge's reply. They sit outside cycle/, since routing reads them and cycle imports routing."""
import dataclasses
@@ -11,7 +11,7 @@ class Interrupt:
# The highest L the judge saw the worker take into the chunk, 0 for none: an escalation steps up from the rung that L picks.
highest_likelihood_taken_in: int = 0
release_ready: bool = False
# How many transcript entries the judge read, which judge_once stamps. An escalation the verdict carries moves the route's mark there; one on a verdict never stamped, None, steps nothing.
# How many transcript entries the judge read, which judge_once stamps. An escalation the verdict carries moves the route's mark there. None means judge_once never stamped it, and then its escalation doesn't step the worker.
entries_read: int | None = None
@@ -35,9 +35,9 @@ class Finished:
@dataclasses.dataclass(frozen=True)
class Unfinished:
evidence: str
# As on Interrupt; it raises the worker to the rung it picks.
# As on Interrupt; the worker also rises to the rung that L picks.
highest_likelihood_taken_in: int = 0
# The judge's quote showing that the worker's cited escalation trigger fired; empty for none.
# As on Interrupt.
escalation: str = ""
# The highest E + I the judge saw the worker take into the chunk, 0 for none.
highest_escape_and_impact_taken_in: int = 0