Answer principles round 2: 0 🔴, 3 🟡; cite item 171 in the figures decision, check a handed route's levels as a value, carry the item and levels in ArchivedWorker

This commit is contained in:
2026-10-16 12:56:20 +02:00
parent 50fdd9e66d
commit 24549589ec
7 changed files with 31 additions and 20 deletions
+3 -6
View File
@@ -58,13 +58,10 @@ def decoded_as(value: object, kind: typing.Any) -> typing.Any:
if not isinstance(value, dict) or not required <= value.keys() <= shape.keys():
return REJECTED
fields = {name: decoded_as(field, shape[name]) for name, field in value.items()}
if any(field in (REJECTED, RETIRED) for field in fields.values()):
return REJECTED
try:
return kind(**fields)
except ValueError:
# A dataclass that checks its fields, as Route does, refuses a handed state that breaks them.
# A dataclass that checks its fields, as Route does, names the check fits.
if any(field in (REJECTED, RETIRED) for field in fields.values()) or not getattr(kind, "fits", lambda _: True)(fields):
return REJECTED
return kind(**fields)
return value if type(value) is kind else REJECTED
+3
View File
@@ -908,6 +908,9 @@ class LoopRuns(unittest.TestCase):
self.assertIsNone(reload.decode_handed(json.dumps(handed), main.LoopRun))
del handed["route"]["rung"]
self.assertIsNone(reload.decode_handed(json.dumps(handed), main.LoopRun))
off_scale = dataclasses.asdict(state)
off_scale["route"]["likelihood"] = 9
self.assertIsNone(reload.decode_handed(json.dumps(off_scale), main.LoopRun))
def test_drops_a_route_an_older_loop_claude_handed_under_r_plus_c_so_the_chunk_routes_afresh(self):
older = {"cycle_number": 3, "root": "/r", "task": "do it", "unfinished_evidence": "", "route": {"rung": {"model": "claude-opus-5-5", "effort": "high"}, "item": 3, "risk_and_complexity": 11, "unfinished": 1}}
+21 -10
View File
@@ -14,9 +14,10 @@ LEVELS_ROUTED = re.compile(r"L of (?P<likelihood>[0-9]+) and E \+ I of (?P<escap
class ArchivedWorker(typing.NamedTuple):
"""What an archived worker line names, whatever its route says: the worker's rung, and whether an item routed it."""
"""What an archived worker line names: the worker's rung, the item that routed it, 0 for none, and the text naming that item's levels, which an older loop-claude wrote as an R + C."""
rung: Rung
routed: bool
item: int
levels: str
def on_their_scales(likelihood: int, escape_and_impact: int) -> bool:
@@ -24,9 +25,14 @@ def on_their_scales(likelihood: int, escape_and_impact: int) -> bool:
return 1 <= likelihood <= LEVELS["L"] and 2 <= escape_and_impact <= LEVELS["E"] + LEVELS["I"]
def levels_fit(item: int, likelihood: int, escape_and_impact: int) -> bool:
"""Whether a route may hold these: an item with levels on their scales, or no item and no levels."""
return on_their_scales(likelihood, escape_and_impact) if item else not (likelihood or escape_and_impact)
@dataclasses.dataclass(frozen=True)
class Route:
"""A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'. A route with an item holds levels on their scales, and one without holds none, so no rung is picked from a level off its scale.
"""A chunk's worker rung, and the plan item that picked it, 0 for none, with its L, which picked the worker's rung, and its E + I, which picks its reviewers'. A route holds only levels that levels_fit, so no rung is picked from a level off its scale.
unfinished counts the unfinished verdicts towards the next one-rung step; a reload hands it over with the rung.
"""
@@ -39,9 +45,15 @@ class Route:
unfinished: int = 0
def __post_init__(self) -> None:
if (self.item and not on_their_scales(self.likelihood, self.escape_and_impact)) or (not self.item and (self.likelihood or self.escape_and_impact)):
# A guard against a programming error, which nothing catches: route_from and the reload decoder check fits before they build a route.
if not levels_fit(self.item, self.likelihood, self.escape_and_impact):
raise ValueError(f"a route by item {self.item} cannot hold an L of {self.likelihood} and an E + I of {self.escape_and_impact}")
@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."""
return levels_fit(fields.get("item", 0), fields.get("likelihood", 0), fields.get("escape_and_impact", 0))
def __str__(self) -> str:
"""What the archive records as each verdict's worker; ROUTED reads it back."""
return f"{self.rung}, routed by item {self.item}'s L of {self.likelihood} and E + I of {self.escape_and_impact}" if self.item else str(self.rung)
@@ -51,16 +63,15 @@ def archived_worker(worker: str) -> ArchivedWorker | None:
"""What an archived worker line names; None for a model run off the ladder."""
found = ROUTED.fullmatch(worker)
rung = Rung.parse(found["rung"]) if found else None
return ArchivedWorker(rung, bool(found["item"])) if found and rung else None
return ArchivedWorker(rung, int(found["item"] or 0), found["levels"] or "") if found and rung else None
def route_from(worker: str) -> Route | None:
"""The route an archived worker line names; None for a model run off the ladder, or a route by anything but levels on their scales."""
archived = archived_worker(worker)
if archived is None or not archived.routed:
if archived is None or not archived.item:
return Route(archived.rung) if archived else None
found = typing.cast(re.Match[str], ROUTED.fullmatch(worker))
levels = LEVELS_ROUTED.fullmatch(found["levels"])
if not levels or not on_their_scales(int(levels["likelihood"]), int(levels["escape_and_impact"])):
levels = LEVELS_ROUTED.fullmatch(archived.levels)
if not levels or not levels_fit(archived.item, int(levels["likelihood"]), int(levels["escape_and_impact"])):
return None
return Route(archived.rung, int(found["item"]), int(levels["likelihood"]), int(levels["escape_and_impact"]))
return Route(archived.rung, archived.item, int(levels["likelihood"]), int(levels["escape_and_impact"]))
+1 -1
View File
@@ -94,7 +94,7 @@ def measured(chunk: Chunk, home: str) -> ChunkFigures:
start = archived_worker(cycles[0][1]) if cycles else None
return ChunkFigures(
tokens=tokens,
start=start.rung if start and start.routed else None,
start=start.rung if start and start.item else None,
rounds_past_first=rounds_past_first(chunk.worker, home),
unfinished=sum(len(UNFINISHED_AT.findall(kept)) for kept in chunk.outcomes),
delegated=delegated,