Answer architecture round 3: 0 🔴, 1 🟡; pick the next chunk's item in one function, todo_table.chunk_item, which routing and the preflight both call, so routing names no item where the release after the last cut has none

This commit is contained in:
2026-10-17 02:19:11 +02:00
parent 45004e1b0b
commit 4cf3c2bd8c
9 changed files with 130 additions and 95 deletions
+14 -8
View File
@@ -50,9 +50,10 @@ for the worker and the interrupt; with both set, nothing is asked.
Where that model is on the routing ladder (bin/model_routing/ladder.py), the worker and the
interrupt run on one of the ladder's rungs: a model at an effort. As a chunk starts, todo.md on the
default branch, as chunk-preflight has just fetched it, routes it: its earliest release's top item
that does not wait, the item the preflight states where that release is the next. An item waits
while it is marked question, or while an item that blocks it is still in the table. The item's L
default branch, as chunk-preflight has just fetched it, routes it on the item the preflight names
(todo_table.chunk_item): the earliest release's top item that does not wait, where that release is
the one after the newest v* tag, or there is no such tag. An item waits while it is marked
question, or while an item that blocks it is still in the table. The item's L
picks the worker's rung, stepping from the model's cheapest rung by WORKER_STEPS in
bin/model_routing/ladder.py, below it for a low L; without such an item, or with its L, E or I
unscored, the chunk runs on the model's cheapest rung. The
@@ -154,7 +155,7 @@ from loop_claude.loop.routing_check import check_routing
from loop_claude.project.checkout import checkout_root
from loop_claude.cycle.run import Cycle, run_cycle
from loop_claude.loop.reload import decode_handed, exec_if_edited, fingerprint, LoopRun, RELOAD_FLAG
from git_repo import default_branch_todo
from git_repo import default_plan, DefaultPlan
from loop_claude.effects import Effects
from failure import Failure
from loop_claude.cycle.judge import Finished, Unfinished
@@ -213,7 +214,7 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
facts = "" if session_open(session) else chunk_facts(launcher.with_name("chunk-preflight"), loop_run.root, effects)
anchor = project_rung(models.worker)
root = loop_run.root
loop_run = routed(loop_run, anchor, lambda: archived_route(archive_folder, session), lambda: plan_item(default_branch_todo(root, ORIGIN_TIMEOUT)))
loop_run = routed(loop_run, anchor, lambda: archived_route(archive_folder, session), lambda: plan_item(default_plan(root, ORIGIN_TIMEOUT)))
route = loop_run.route or Route(Rung(models.worker))
print(f"\n=== cycle {loop_run.cycle_number}, worker on {route.rung} ===", flush=True)
verdict = run_cycle(Cycle(anchor=anchor, effects=effects, facts=facts, judge_model=models.judge, paths=paths, premises=premises, project_archive=archive_folder, records=records, root=loop_run.root, route=route, session=session, task=loop_run.task, unfinished_evidence=loop_run.unfinished_evidence))
@@ -269,9 +270,14 @@ def chunk_facts(preflight: pathlib.Path, root: str, effects: Effects) -> str:
return prompts.preflight_facts(done.stdout.strip())
def plan_item(todo: str | Failure) -> Item | None:
"""The item that routes a chunk, from todo.md as git_repo.default_branch_todo reads it, as chunk-preflight does, so both take todo_table.next_item's pick. None without one, so the chunk runs on the project's rung."""
item = todo if isinstance(todo, Failure) else routed_item(todo)
def plan_item(plan: DefaultPlan | Failure) -> Item | None:
"""The item that routes a chunk, from the default branch as git_repo.default_plan reads it, as chunk-preflight does, so both take todo_table.chunk_item's pick. None without one, so the chunk runs on the project's rung."""
if isinstance(plan, Failure):
item: Item | Failure | None = plan
elif isinstance(plan.todo, Failure):
item = plan.todo
else:
item = routed_item(plan.todo, plan.tag, plan.commits)
if isinstance(item, Failure):
print(f"routing on the project's rung: {item.reason}", file=sys.stderr)
return None
+4 -4
View File
@@ -1,9 +1,9 @@
"""Which ladder rung a chunk's worker and judge run on: docs/decisions.md → `routing:`."""
import dataclasses
from todo_table import chunk_item, Item, items
from model_routing.ladder import climbed, highest, LADDER, position, project_rung, review_floor, Rung, stepped_up, worker_rung
from failure import Failure
from todo_table import Item, items, next_item
from model_routing.route import Route
UNFINISHED_PER_STEP = 2
@@ -13,12 +13,12 @@ ESCALATION_CAP = 2
JUDGE_REPLAYED = ("claude-opus-5-5",)
def routed_item(todo: str) -> Item | Failure | None:
"""The item todo_table.next_item names; None when there is none, or it lacks L, E or I."""
def routed_item(todo: str, tag: str | None | Failure, commits: int | Failure) -> Item | Failure | None:
"""The item todo_table.chunk_item picks from todo.md, given the newest v* tag and the commits since it; None when there is none, or it lacks L, E or I."""
found = items(todo)
if isinstance(found, Failure):
return found
takes = next_item(found or [])
_, takes = chunk_item(found or [], tag, commits)
return takes if takes and takes.likelihood and takes.escape_and_impact else None
+28 -17
View File
@@ -18,6 +18,7 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from routing_figures import archive
from loop_claude.project import checkout, model_choice, records
from git_repo import DefaultPlan
from loop_claude.effects import Effects, PYTHON_TIMEOUT, run_python
from claude_code import entries, reply, session
from failure import Failure
@@ -587,24 +588,32 @@ class Routing(unittest.TestCase):
SONNET = Rung("claude-sonnet-5-5", "high")
def test_routes_on_the_next_releases_top_item_that_waits_on_no_question(self):
self.assertEqual(routing.routed_item(TODO).id, 3)
self.assertIsNone(routing.routed_item(TODO.replace("| | **Do", "| question | **Do")))
self.assertIsNone(routing.routed_item("# todo\n"))
self.assertIsNone(routing.routed_item(TODO[:TODO.index("| 7 |")]))
self.assertEqual(routing.routed_item(TODO, None, 0).id, 3)
self.assertIsNone(routing.routed_item(TODO.replace("| | **Do", "| question | **Do"), None, 0))
self.assertIsNone(routing.routed_item("# todo\n", None, 0))
self.assertIsNone(routing.routed_item(TODO[:TODO.index("| 7 |")], None, 0))
old_shape = "## Items\n\n| ID | Release | Exempt | Item | R | S | C | A | G | Goals | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n| 3 | 0.2.0 | | **Do the next thing.** | 5 | 3 | 6 | 8 | 9 | 1 | 25 |\n"
self.assertIsNone(routing.routed_item(old_shape))
self.assertEqual(routing.routed_item(TODO.replace("| 4 | 2 | 3 |", "| x | 2 | 3 |")), Failure("item 3's L 'x' is not a whole number from 1 to 4"))
self.assertIsNone(routing.routed_item(old_shape, None, 0))
self.assertEqual(routing.routed_item(TODO.replace("| 4 | 2 | 3 |", "| x | 2 | 3 |"), None, 0), Failure("item 3's L 'x' is not a whole number from 1 to 4"))
def test_routes_on_no_item_where_the_release_after_the_last_cut_has_none(self):
self.assertEqual(routing.routed_item(TODO, "v0.1.0", 3).id, 3)
self.assertIsNone(routing.routed_item(TODO, "v0.2.0", 3))
later_only = TODO[:TODO.index("| 7 |")] + TODO[TODO.index("| 1 | 0.3.0 |"):]
self.assertIsNone(routing.routed_item(later_only, "v0.1.0", 3))
self.assertIsNone(routing.routed_item(later_only, "v0.1.0", 0))
self.assertEqual(routing.routed_item(later_only, "v0.2.0", 3).id, 1)
def test_routes_past_an_item_a_waiting_item_blocks(self):
todo = "## Items\n\n| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|---|\n| 7 | 0.2.0 | | question | **Ask first.** | 4 | 3 | 5 | 10 | 1 | 1 by 9 | 30 |\n| 8 | 0.2.0 | 7 | | **Use the answer.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 | 30 |\n| 9 | 0.2.0 | 8 | | **Build on it.** | 1 | 1 | 1 | 1 | 1 | 1 by 9 | 30 |\n| 3 | 0.2.0 | | | **Do the next thing.** | 4 | 2 | 3 | 7 | 3 | 1 by 9 | 25 |\n"
self.assertEqual(routing.routed_item(todo).id, 3)
self.assertEqual(routing.routed_item(todo.replace("| question |", "| |")).id, 7)
self.assertEqual(routing.routed_item(todo, None, 0).id, 3)
self.assertEqual(routing.routed_item(todo.replace("| question |", "| |"), None, 0).id, 7)
first = "| 7 | 0.2.0 | | question | **Ask first.** | 4 | 3 | 5 | 10 | 1 | 1 by 9 | 30 |\n"
self.assertEqual(routing.routed_item(todo.replace(first, "") + first).id, 3)
self.assertEqual(routing.routed_item(todo.replace(first, "") + first, None, 0).id, 3)
def test_starts_a_chunk_on_the_rung_its_items_l_picks_below_the_projects_too(self):
self.assertEqual(routing.first_route(self.OPUS, routing.routed_item(TODO)), Route(self.HIGH, 3, 4, 5))
cheap = routing.routed_item(TODO.replace("| 4 | 2 | 3 |", "| 1 | 2 | 3 |"))
self.assertEqual(routing.first_route(self.OPUS, routing.routed_item(TODO, None, 0)), Route(self.HIGH, 3, 4, 5))
cheap = routing.routed_item(TODO.replace("| 4 | 2 | 3 |", "| 1 | 2 | 3 |"), None, 0)
self.assertEqual(routing.first_route(self.OPUS, cheap), Route(Rung("claude-haiku-5-5", "max"), 3, 1, 5))
self.assertEqual(routing.first_route(self.OPUS, None), Route(self.OPUS))
@@ -679,7 +688,7 @@ class Routing(unittest.TestCase):
def test_routes_nothing_on_an_item_without_e_or_i(self):
without_i = TODO.replace("| E | I | R |", "| E | R |").replace("|---|---|---|---|---|---|---|---|---|---|---|", "|---|---|---|---|---|---|---|---|---|---|").replace("| 4 | 3 | 5 | 10 |", "| 4 | 3 | 10 |").replace("| 4 | 2 | 3 | 7 |", "| 4 | 2 | 7 |").replace("| 1 | 1 | 1 | 1 |", "| 1 | 1 | 1 |")
self.assertIsNone(routing.routed_item(without_i))
self.assertIsNone(routing.routed_item(without_i, None, 0))
def test_archives_the_route_in_a_line_it_reads_back(self):
route = Route(self.HIGH, 3, 4, 5)
@@ -705,7 +714,7 @@ class Routing(unittest.TestCase):
def test_keeps_a_chunks_route_or_its_archived_one_at_or_above_the_rung_its_item_picks_and_else_routes_afresh(self):
def run_with(route=None):
return main.LoopRun(cycle_number=1, root="/r", task="do it", unfinished_evidence="", route=route)
item = routing.routed_item(TODO)
item = routing.routed_item(TODO, None, 0)
archived = Route(self.XHIGH, 3, 4, 5)
def never():
raise AssertionError("not asked")
@@ -721,12 +730,14 @@ class Routing(unittest.TestCase):
class RouteSources(unittest.TestCase):
def test_routes_on_the_plan_item_and_says_why_it_routes_on_the_projects_rung(self):
self.assertIsNone(main.plan_item(""))
self.assertEqual(main.plan_item(TODO).id, 3)
for todo, said in ((TODO.replace("| 4 | 2 | 3 |", "| x | 2 | 3 |"), "routing on the project's rung: item 3's L 'x' is not a whole number from 1 to 4\n"), (Failure("git show origin/main:todo.md printed text that is not UTF-8"), "routing on the project's rung: git show origin/main:todo.md printed text that is not UTF-8\n")):
self.assertIsNone(main.plan_item(DefaultPlan("origin/main", "", None, 0)))
self.assertEqual(main.plan_item(DefaultPlan("origin/main", TODO, "v0.1.0", 3)).id, 3)
self.assertIsNone(main.plan_item(DefaultPlan("origin/main", TODO, "v0.2.0", 3)))
unreadable = Failure("git show origin/main:todo.md printed text that is not UTF-8")
for plan, said in ((DefaultPlan("origin/main", TODO.replace("| 4 | 2 | 3 |", "| x | 2 | 3 |"), None, 0), "routing on the project's rung: item 3's L 'x' is not a whole number from 1 to 4\n"), (DefaultPlan("origin/main", unreadable, None, 0), f"routing on the project's rung: {unreadable.reason}\n"), (Failure("no origin remote"), "routing on the project's rung: no origin remote\n")):
with self.subTest(said=said):
with contextlib.redirect_stderr(io.StringIO()) as stderr:
self.assertIsNone(main.plan_item(todo))
self.assertIsNone(main.plan_item(plan))
self.assertTrue(stderr.getvalue().startswith(said), stderr.getvalue())
def test_resumes_on_the_archived_route_and_says_why_it_routes_afresh(self):