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
+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"}}