Answer architecture round 1: 0 🔴, 4 🟡; move verdicts out of cycle, derive RECORDED, type the archived worker as Record, drop stale help names

This commit is contained in:
2026-10-22 22:00:09 +02:00
parent c3ae228639
commit cb48719493
14 changed files with 53 additions and 48 deletions
+2 -1
View File
@@ -34,13 +34,14 @@ from project_key import checkout_of
from loop_claude.effects import Effects
from failure import Failure
from rung_replay.search import first_reply, replayed
from loop_claude.cycle.judge import judge_once, Verdict
from loop_claude.cycle.judge import judge_once
from claude_code.reply import Limited
from model_routing.ladder import lowest_worker_rung, project_rung, Rung
from loop_claude.project.premises import read_premises
from loop_claude.project.records import read_records
from claude_code.transcript import read_transcript
from loop_claude.stop import Stop
from loop_claude.verdicts import Verdict
TOOL = "judge-replay"
USAGE = f"{TOOL} <model>, a model on the routing ladder"
+1 -1
View File
@@ -6,7 +6,7 @@ import typing
from transcript_archive.outcomes import ANSWERED, FINISHED, first_verdict, INTERRUPTED, task_of, UNFINISHED
from failure import Failure
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from rung_replay.search import Replay
from model_routing.ladder import Rung
+1 -1
View File
@@ -13,7 +13,7 @@ from transcript_archive.outcomes import ANSWERED, FINISHED, INTERRUPTED, UNFINIS
from judge_replay.replay import Case, case_from, report, reproduced, sample, verdict_kind
from loop_claude.effects import Effects
from failure import Failure
from loop_claude.cycle.judge import Finished, Interrupt, QuotedAnswer, Unfinished
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
from judge_replay import main
from rung_replay.search import Miss, Replay, Tried
from model_routing.ladder import Rung
+1 -1
View File
@@ -7,7 +7,7 @@ from loop_claude.cycle.prompts import ANSWER_DESTINATIONS, ANSWERS_RECORDED, typ
from claude_code.reply import claude_reply, Limited
from loop_claude.effects import Effects
from failure import Failure
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from claude_code.entries import human_text, loop_text
from todo_table import LEVELS
from model_routing.route import on_its_scale
+1 -1
View File
@@ -8,7 +8,7 @@ from transcript_archive.write import archive
from claude_code.session import delete_session, Session, session_open, transcript_file
from loop_claude.effects import Effects
from failure import Failure
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
from loop_claude.cycle.judge import judge, Rejected
from transcript_archive import outcomes
from loop_claude.paths import Paths
+1 -1
View File
@@ -1,6 +1,6 @@
import dataclasses
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished, Verdict
# A backstop for what the judge misses, such as a reworded repeat, so the worker cannot loop unattended on answers quoted from README.md or the records.
QUOTED_ANSWERS_PER_CYCLE = 3
+16 -17
View File
@@ -94,26 +94,25 @@ The judge reports the highest L and the highest E + I the worker states for an i
next cycle steps the worker up to the rung that L picks, never down, and the reviewers to the rung
picked by the higher of two: that E + I, or the routed item's (Route.reviewed_on in
bin/model_routing/route.py). A level off its scale counts as none. Every second unfinished verdict
on a chunk steps it up one rung (routing.stepped). So does an unfinished verdict on a worker that
ended its run asking for a higher rung, once the judge quotes the transcript showing that the
escalation trigger it named fired (~/.claude/CLAUDE.md → "Working with the codebase" lists them). An
interrupt or a quoted answer with such a quote steps the rung as it comes in, before the human is
asked or the worker resumes (routing.stepped_by_ruling). Each such step marks how many transcript
entries the session held, and from then on the judge must quote the worker's own lines after that
mark, where it reads a [step] line. Each step on an escalation stops two rungs above the rung the
chunk's item picks, and the worker's prompts offer it only while the worker is below that limit.
on a chunk steps it up one rung (routing.after_unfinished). So does an unfinished verdict on a
worker that ended its run asking for a higher rung, once the judge quotes the transcript showing
that the escalation trigger it named fired (~/.claude/CLAUDE.md → "Working with the codebase" lists
them). An interrupt or a quoted answer with such a quote steps the rung as it comes in, before the
human is asked or the worker resumes (routing.after_ruling). Each such step marks how many
transcript entries the session held, and from then on the judge must quote the worker's own lines
after that mark, where it reads a [step] line. Each step on an escalation stops two rungs above the
rung the chunk's item picks, and the worker's prompts offer it only while the worker is below that
limit.
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, a JSON record of the route: the worker's rung as model and effort, the item, L
and E + I that routed the chunk, any taken-in E + I that picks a higher review rung (archived as a
step-up too), and the mark. 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 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.
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
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.
Routing: the judge's rung
@@ -194,7 +193,7 @@ from chunk_pick import default_plan, DefaultPlan
from git_repo import default_ref
from loop_claude.effects import Effects
from failure import Failure
from loop_claude.cycle.verdicts import Finished
from loop_claude.verdicts import Finished
from loop_claude.project.model_choice import get_or_ask_models
from todo_table import Item
from transcript_archive.read import latest_worker
+1 -1
View File
@@ -3,7 +3,7 @@ import dataclasses
from chunk_pick import chunk_item, LastCut, Next
from model_routing.ladder import climbed, highest, LADDER, position, project_rung, review_floor, Rung, stepped_up, worker_rung
from loop_claude.cycle.verdicts import escalation_mark, Interrupt, QuotedAnswer, Unfinished
from loop_claude.verdicts import escalation_mark, Interrupt, QuotedAnswer, Unfinished
from failure import Failure
from todo_table import Item, items, NoItemsTable
from model_routing.route import Route
+7 -7
View File
@@ -23,7 +23,7 @@ from chunk_pick import DefaultPlan, LastCut
from loop_claude.effects import Effects, PYTHON_TIMEOUT, run_python
from claude_code import entries, reply, session
from failure import Failure
from loop_claude.cycle.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
from loop_claude.verdicts import Finished, Interrupt, QuotedAnswer, Unfinished
from loop_claude.cycle import interrupt, judge, prompts, retry, run, states, worker
from model_routing import ladder
from model_routing.ladder import LADDER, Rung
@@ -1329,7 +1329,7 @@ class Verdict(unittest.TestCase):
self.assertEqual(verdict_from({"highest_likelihood_taken_in": 0, "highest_escape_and_impact_taken_in": 0, "escalation": "", "answer": "", "interrupt": True, "evidence": "x", "finished": False, "question": " ", "release_ready": False}), Failure("the judge interrupted without a question"))
self.assertEqual(verdict_from(None), Failure("the judge returned no reply"))
def test_takes_a_bundled_l_on_its_scale_and_counts_any_other_as_none(self):
def test_takes_the_highest_l_taken_in_on_its_scale_and_counts_any_other_as_none(self):
reply = {"answer": "", "highest_escape_and_impact_taken_in": 0, "escalation": "", "interrupt": False, "evidence": "e", "finished": False, "question": "", "release_ready": False}
self.assertEqual(verdict_from({**reply, "highest_likelihood_taken_in": 4}), Unfinished("e", 4))
self.assertEqual(verdict_from({**reply, "highest_likelihood_taken_in": True}), Failure("the judge's reply has no highest_likelihood_taken_in of type integer"))
@@ -1338,14 +1338,14 @@ class Verdict(unittest.TestCase):
self.assertEqual(verdict_from({**reply, "highest_likelihood_taken_in": highest_likelihood_taken_in}), Unfinished("e", 0))
def test_takes_a_bundled_e_plus_i_on_its_scale_and_counts_any_other_as_none(self):
def test_takes_the_highest_e_plus_i_taken_in_on_its_scale_and_counts_any_other_as_none(self):
reply = {"answer": "", "highest_likelihood_taken_in": 0, "escalation": "", "interrupt": False, "evidence": "e", "finished": False, "question": "", "release_ready": False}
self.assertEqual(verdict_from({**reply, "highest_escape_and_impact_taken_in": 6}), Unfinished("e", 0, highest_escape_and_impact_taken_in=6))
self.assertEqual(verdict_from({**reply, "highest_escape_and_impact_taken_in": 2}), Unfinished("e", 0, highest_escape_and_impact_taken_in=2))
self.assertEqual(verdict_from({**reply, "highest_escape_and_impact_taken_in": False}), Failure("the judge's reply has no highest_escape_and_impact_taken_in of type integer"))
for highest_likelihood_taken_in in (1, 9, -1):
with self.subTest(highest_likelihood_taken_in=highest_likelihood_taken_in):
self.assertEqual(verdict_from({**reply, "highest_escape_and_impact_taken_in": highest_likelihood_taken_in}), Unfinished("e", 0))
for escape_and_impact in (1, 9, -1):
with self.subTest(escape_and_impact=escape_and_impact):
self.assertEqual(verdict_from({**reply, "highest_escape_and_impact_taken_in": escape_and_impact}), Unfinished("e", 0))
def test_takes_an_escalation_quote_on_an_unfinished_verdict(self):
reply = {"answer": "", "highest_likelihood_taken_in": 0, "highest_escape_and_impact_taken_in": 0, "escalation": "round 2: 🔴", "interrupt": False, "evidence": "e", "finished": False, "question": "", "release_ready": False}
@@ -1365,7 +1365,7 @@ class Verdict(unittest.TestCase):
self.assertEqual(judge.quotes_checked(Interrupt("e", "q", "round 2: … 🔴"), judge.Grounds(shown, shown, "")), Interrupt("e", "q"))
self.assertEqual(judge.quotes_checked(Unfinished("e", 0, "round 3: 🔴"), judge.Grounds(shown, shown, "")), Unfinished("e"))
def test_takes_an_escalation_quote_and_a_bundled_l_on_a_quoted_answer(self):
def test_takes_an_escalation_quote_and_the_highest_l_taken_in_on_a_quoted_answer(self):
reply = {"answer": "A.", "highest_likelihood_taken_in": 4, "highest_escape_and_impact_taken_in": 0, "escalation": "round 2: 🔴", "interrupt": False, "evidence": "e", "finished": False, "question": "Which one?", "release_ready": False}
self.assertEqual(verdict_from(reply), QuotedAnswer("e", "Which one?", "A.", "round 2: 🔴", 4))
self.assertEqual(verdict_from({**reply, "highest_likelihood_taken_in": 5}), QuotedAnswer("e", "Which one?", "A.", "round 2: 🔴"))
@@ -1,4 +1,4 @@
"""What the judge rules on a cycle: the verdicts judge.verdict_from builds from its reply."""
"""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."""
import dataclasses
+10 -6
View File
@@ -9,8 +9,8 @@ from model_routing.ladder import REVIEW_STEPS, Rung
# How a worker opens the prompt of a subagent it escalates a task to, `Escalation trigger 2: …`: docs/decisions.md → `routing: a worker hands a task one rung up`.
ESCALATION_MARKER = "Escalation trigger"
# The Route fields the archive records beside the rung's model and effort. unfinished stays out, so a rerun restarts that count.
RECORDED = ("item", "likelihood", "escape_and_impact", "escape_and_impact_taken_in", "escalated_at")
# What Route.record writes. The outcome writers in transcript_archive/outcomes.py take only this as the worker, so mypy refuses a str(route) there.
Record = typing.NewType("Record", str)
# A worker line loop-claude wrote before it archived the route as a record. Nothing writes this format any more, so its wording never changes. route_from reads it for the chunks the routing figures still count, and for a chunk a rerun resumes across the change.
LEGACY_WORKER = re.compile(r"(?P<rung>.+?)(?:, routed by item (?P<item>[0-9]+)'s L of (?P<likelihood>[0-9]+) and E \+ I of (?P<escape_and_impact>[0-9]+))?(?:, taking in an E \+ I of (?P<escape_and_impact_taken_in>[0-9]+))?(?:, escalated at transcript entry (?P<escalated_at>[0-9]+))?")
@@ -59,7 +59,7 @@ class Route:
@staticmethod
def fits(fields: typing.Mapping[str, typing.Any]) -> bool:
"""Whether a route may be built from these fields, as the reload decoder asks of a handed one."""
"""Whether a route may be built from these fields; route_from and the reload decoder ask before they build one."""
return levels_fit(fields.get("item", 0), fields.get("likelihood", 0), fields.get("escape_and_impact", 0), fields.get("escape_and_impact_taken_in", 0))
def taking_in(self, escape_and_impact: int) -> "Route":
@@ -70,10 +70,14 @@ class Route:
"""The E + I that picks the reviewers' and the judge's rung: the routed item's or the highest taken in, whichever is higher; 0 for neither."""
return max(self.escape_and_impact, self.escape_and_impact_taken_in)
def record(self) -> str:
def record(self) -> Record:
"""What the archive records as each verdict's worker: a JSON object of the rung's model and effort and the RECORDED fields, leaving out each that is 0 or empty; route_from reads it back."""
fields = {"model": self.rung.model, "effort": self.rung.effort, **{name: getattr(self, name) for name in RECORDED}}
return json.dumps({name: value for name, value in fields.items() if value})
return Record(json.dumps({name: value for name, value in fields.items() if value}))
# The Route fields a record holds beside the rung's model and effort. A human reads the record in the archive, so unlike the JSON a reload hands over (loop_claude/loop/reload.py), it is flat, splits the rung into model and effort, and leaves out zeros. It leaves out unfinished, so a rerun restarts that count, and recorded rejects a negative number, which record never writes.
RECORDED = tuple(field.name for field in dataclasses.fields(Route) if field.name not in ("rung", "unfinished"))
def route_from(worker: str) -> Route | None:
@@ -102,4 +106,4 @@ def legacy_fields(line: str) -> dict[str, typing.Any] | None:
rung = Rung.parse(found["rung"]) if found else None
if not (found and rung):
return None
return {"model": rung.model, "effort": rung.effort, **{name: int(found[name] or 0) for name in RECORDED}}
return {"model": rung.model, "effort": rung.effort, **{name: int(value or 0) for name, value in found.groupdict().items() if name != "rung"}}
+1 -1
View File
@@ -130,7 +130,7 @@ def add(tokens: dict[str, collections.Counter[str]], project: str, kind: str, ru
def rung_at(cycles: list[tuple[str, str]], timestamp: str) -> Rung | str:
"""The rung of the cycle running at timestamp: the worker named by the first outcome stamped at or after it, or else by the last outcome. A worker off the ladder is returned as its text."""
"""The rung of the cycle running at timestamp: the worker named by the first outcome stamped at or after it, or else by the last outcome. A worker line route_from cannot read is returned as its text, and "unrouted" where no outcome names a worker."""
second = timestamp[:19] + "Z"
found = next((rung for stamp, rung in cycles if stamp >= second), cycles[-1][1] if cycles else "unrouted")
route = route_from(found)
+8 -7
View File
@@ -1,6 +1,7 @@
import re
from markdown_text import quoted
from model_routing.route import Record
from utc_stamp import STAMPED
TASK = "Task: "
@@ -28,23 +29,23 @@ def escalation_block(escalation: str) -> str:
return f"Escalation:\n{quoted(escalation)}\n\n" if escalation else ""
def finished(worker: str, evidence: str, judge: str) -> str:
def finished(worker: Record, evidence: str, judge: str) -> str:
return f"{FINISHED}\n\nEvidence:\n{quoted(evidence)}\n\n{JUDGE}{judge}\n{WORKER}{worker}"
def unfinished(worker: str, evidence: str, judge: str, escalation: str) -> str:
def unfinished(worker: Record, evidence: str, judge: str, escalation: str) -> str:
"""escalation is the judge's quote showing that the worker's cited escalation trigger fired; empty for none."""
escalated = escalation_block(escalation)
return f"{UNFINISHED}\n\nEvidence:\n{quoted(evidence)}\n\n{escalated}{JUDGE}{judge}\n{WORKER}{worker}"
def interrupted(question: str, evidence: str, judge: str, escalation: str, worker: str) -> str:
"""escalation is the judge's quote showing that the worker's cited escalation trigger fired; empty for none. worker is the rung the worker ran on until the interrupt."""
def interrupted(question: str, evidence: str, judge: str, escalation: str, worker: Record) -> str:
"""escalation is the judge's quote showing that the worker's cited escalation trigger fired; empty for none. worker is the record of the route the worker ran on until the interrupt."""
escalated = escalation_block(escalation)
return f"{INTERRUPTED}\n\n{question}\n\nEvidence:\n{quoted(evidence)}\n\n{escalated}{JUDGE}{judge}\n{WORKER}{worker}"
def answered(question: str, sources: str, answer: str, evidence: str, escalation: str, judge: str, worker: str) -> str:
def answered(question: str, sources: str, answer: str, evidence: str, escalation: str, judge: str, worker: Record) -> str:
"""escalation and worker are as on interrupted."""
escalated = escalation_block(escalation)
return f"{ANSWERED}\n\n{question}\n\n{sources} says:\n{quoted(answer)}\n\nEvidence:\n{quoted(evidence)}\n\n{escalated}{JUDGE}{judge}\n{WORKER}{worker}"
@@ -55,12 +56,12 @@ def rejected(why: str, reply: str, judge: str) -> str:
return f"{REJECTED}: {why}\n\nReply:\n{quoted(reply)}\n\n{JUDGE}{judge}"
def stepped_up(worker: str) -> str:
def stepped_up(worker: Record) -> str:
"""The rung the next cycle steps up to, archived as it steps, so a rerun after any exit resumes on it."""
return f"Stepped up\n\n{WORKER}{worker}"
def stopped(worker: str, why: str) -> str:
def stopped(worker: Record, why: str) -> str:
return f"Stopped: {why}\n\n{WORKER}{worker}"
+2 -2
View File
@@ -94,7 +94,7 @@ The architecture pass of PR #296 found one rung under two names: `bin/model_rout
### 210. Hold the escalation mark in one module that states that one trigger buys one step, so a reader changes it without opening four files.
Release 0.3.0's scoring runs found the mark spread out (first run: PR #324 at c713910; rerun: PR #324 rerun at c713910). `bin/model_routing/route.py:66` `Route.escalated_at`: "the escalation mark lives in six units across four files" (Junior A, first run), "one concept spread over five files" (Mid A, rerun). `bin/loop_claude/cycle/judge.py:153` `escalation_mark`: "no single place states that one trigger buys one step" (Maintainability senior, rerun). `bin/loop_claude/cycle/run.py:45` `Cycle.stepped_from` and `:69` `escalated`: "state outside the state machine, cleared on every event but HumanTyped" (Mid A, rerun). `bin/loop_claude/cycle/judge.py:216` `quotes_checked` checks the escalation against `Grounds.since_step` beside the quoted answer: "three quote checks follow different rules" (Junior A, rerun). This lowers Locality: changing the mark means opening `route.py`, `judge.py`, `run.py` and `routing.py` together. Move the mark's stamping, `STEP_LINE`, the since-step grounds and their check, and the step's state into one module, and make `stepped_from` part of the cycle's state machine. Make `Route.escalated_at`, `escalation_mark`, `Cycle.stepped_from`, `escalated` and `quotes_checked` easier to read. The archive's `Worker:` record holds the mark as `escalated_at`, so a rerun keeps it; the move keeps that field. `escalation_mark` now lives in `bin/loop_claude/cycle/verdicts.py`.
Release 0.3.0's scoring runs found the mark spread out (first run: PR #324 at c713910; rerun: PR #324 rerun at c713910). `bin/model_routing/route.py:66` `Route.escalated_at`: "the escalation mark lives in six units across four files" (Junior A, first run), "one concept spread over five files" (Mid A, rerun). `bin/loop_claude/cycle/judge.py:153` `escalation_mark`: "no single place states that one trigger buys one step" (Maintainability senior, rerun). `bin/loop_claude/cycle/run.py:45` `Cycle.stepped_from` and `:69` `escalated`: "state outside the state machine, cleared on every event but HumanTyped" (Mid A, rerun). `bin/loop_claude/cycle/judge.py:216` `quotes_checked` checks the escalation against `Grounds.since_step` beside the quoted answer: "three quote checks follow different rules" (Junior A, rerun). This lowers Locality: changing the mark means opening `route.py`, `judge.py`, `run.py` and `routing.py` together. Move the mark's stamping, `STEP_LINE`, the since-step grounds and their check, and the step's state into one module, and make `stepped_from` part of the cycle's state machine. Make `Route.escalated_at`, `escalation_mark`, `Cycle.stepped_from`, `escalated` and `quotes_checked` easier to read. The archive's `Worker:` record holds the mark as `escalated_at`, so a rerun keeps it; the move keeps that field. `escalation_mark` now lives in `bin/loop_claude/verdicts.py`.
### 190. Rewrite the `docs/decisions.md` entries `todo.md: one table …`, `loop-claude: a judge decides …` and `loop-claude: before it opens claude …` as the current state, so a reader no longer replays superseded paragraphs to learn what holds.
@@ -142,7 +142,7 @@ The README line covers the bench's transcripts in `workflow-bench/logs/` too (go
### 218. Drop `LEGACY_WORKER` from `bin/model_routing/route.py`, so `route_from` reads only the JSON record, once `routing-calls-raised.md` holds a `Reset` stamped after PR #357's merge.
PR #357 archived the route as a JSON record, and kept `LEGACY_WORKER` to read the prose worker lines loop-claude wrote before it. The routing figures still count the chunks that hold them: 51 when PR #357 shipped, every chunk finished after the reset of 2026-10-21T22:16:41Z. Once a later `Reset` puts those chunks out of the figures, only a chunk left open across PR #357's merge still needs the old reader, and it routes afresh without it. Delete `LEGACY_WORKER`, `legacy_fields` and their test, and the sentence in "loop-claude --help" on reading the prose lines.
PR #357 archived the route as a JSON record, and kept `LEGACY_WORKER` to read the prose worker lines loop-claude wrote before it. The routing figures still count the chunks that hold them: 51 when PR #357 shipped, every chunk finished after the reset of 2026-10-21T22:16:41Z. Once a later `Reset` puts those chunks out of the figures, only a chunk left open across PR #357's merge still needs the old reader, and it routes afresh without it. Delete `LEGACY_WORKER`, `legacy_fields` and their test, and the sentence in "loop-claude --help" on reading the prose lines. Reword the comment at `Rung.__str__` in `bin/model_routing/ladder.py`: it gives the archive lines written before `Route.record` as a reason `parse` must keep reading that spelling.
### 123. Have `bin/comprehension_history.py` parse each history entry once into seats, votes and places, so `latest_places`, `worse_places` and `worse_votes` neither depend on table order nor split a label to find a seat.