Bind a project's rung to its ladder in ProjectRung, and step an L 3 worker one rung up and an L 4 worker two up
CI / tests (pull_request) Failing after 3m48s
CI / tests (pull_request) Failing after 3m48s
This commit is contained in:
+33
-31
@@ -9,7 +9,7 @@ The worker, and the session /talk opens, run on a Route (model_routing/route.py)
|
||||
|
||||
A step-up weighs five rungs:
|
||||
|
||||
- the project's rung: the cheapest rung of the project's model, which each L's rung is counted from, up or down;
|
||||
- the project's rung, a ProjectRung (model_routing/ladder.py) that also holds the ladder: the cheapest rung of the project's model, which each L's rung is counted from, up or down;
|
||||
- item_rung: the rung the chunk started on, which the routed item's L picked;
|
||||
- the route's rung: where the worker runs now, at or above item_rung;
|
||||
- floor_rung: the lowest rung the worker may run on next, which is the route's rung, raised where an item the worker took in has an L that picks a higher one;
|
||||
@@ -34,7 +34,7 @@ from loop_claude import escalation_mark
|
||||
from failure import Failure
|
||||
from loop_claude.verdicts import Interrupt, QuotedAnswer, Unfinished
|
||||
from plan.todo_table import Item, NoItemsTable
|
||||
from model_routing.ladder import Ladder, Rung
|
||||
from model_routing.ladder import Ladder, ProjectRung, Rung
|
||||
from plan_store.plans import Plan
|
||||
from model_routing.route import Route
|
||||
|
||||
@@ -59,42 +59,43 @@ def routed_item(plan: Plan | Failure, cut: LastCut, item_id: int | None = None)
|
||||
return takes if takes and takes.likelihood and takes.escape_and_impact else None
|
||||
|
||||
|
||||
def first_route(ladder: Ladder, project: Rung, item: Item | None) -> Route:
|
||||
"""The route a chunk starts on: the rung its item's L picks on ladder from the project's rung, or the project's rung without an item."""
|
||||
def first_route(project: ProjectRung, item: Item | None) -> Route:
|
||||
"""The route a chunk starts on: the rung its item's L picks from the project's rung, or the project's rung without an item."""
|
||||
if item is None:
|
||||
return Route(project)
|
||||
return Route(ladder.worker_rung(project, item.likelihood), item.id, item.likelihood, item.escape_and_impact)
|
||||
return Route(project.rung)
|
||||
return Route(project.worker_rung(item.likelihood), item.id, item.likelihood, item.escape_and_impact)
|
||||
|
||||
|
||||
def kept(route: Route, ladder: Ladder, project: Rung) -> bool:
|
||||
def kept(route: Route, project: ProjectRung) -> bool:
|
||||
"""Whether a chunk keeps route: its rung is on the ladder and at or above item_rung."""
|
||||
return floor_rung(ladder, project, route) == route.rung
|
||||
return floor_rung(project, route) == route.rung
|
||||
|
||||
|
||||
def item_rung(ladder: Ladder, project: Rung, route: Route) -> Rung:
|
||||
def item_rung(project: ProjectRung, route: Route) -> Rung:
|
||||
"""The rung the route's item's L picks from the project's rung, or the project's rung itself when no item routed it. The worker may run on a rung below the project's."""
|
||||
return ladder.worker_rung(project, route.likelihood) if route.item else project
|
||||
return project.worker_rung(route.likelihood) if route.item else project.rung
|
||||
|
||||
|
||||
def floor_rung(ladder: Ladder, project: Rung, route: Route, likelihood_taken_in: int = 0) -> Rung:
|
||||
def floor_rung(project: ProjectRung, route: Route, likelihood_taken_in: int = 0) -> Rung:
|
||||
"""The lowest rung the worker may run on: the route's own, raised to item_rung where it is lower or off the ladder, and to the rung likelihood_taken_in picks from project. likelihood_taken_in is the highest L the worker took into the chunk, 0 for none."""
|
||||
floor = ladder.highest(route.rung, item_rung(ladder, project, route))
|
||||
return ladder.highest(floor, ladder.worker_rung(project, likelihood_taken_in)) if likelihood_taken_in else floor
|
||||
floor = project.ladder.highest(route.rung, item_rung(project, route))
|
||||
return project.ladder.highest(floor, project.worker_rung(likelihood_taken_in)) if likelihood_taken_in else floor
|
||||
|
||||
|
||||
def escalation_rungs(ladder: Ladder, project: Rung, route: Route) -> tuple[Rung, ...]:
|
||||
def escalation_rungs(project: ProjectRung, route: Route) -> tuple[Rung, ...]:
|
||||
"""The rungs an escalation trigger opens to the worker, least competent first: from one above its own up to escalation_cap; none off the ladder."""
|
||||
ladder = project.ladder
|
||||
if route.rung not in ladder.rungs:
|
||||
return ()
|
||||
return ladder.rungs[ladder.position(route.rung) + 1:ladder.position(escalation_cap(ladder, project, route)) + 1]
|
||||
return ladder.rungs[ladder.position(route.rung) + 1:ladder.position(escalation_cap(project, route)) + 1]
|
||||
|
||||
|
||||
def escalation_cap(ladder: Ladder, project: Rung, route: Route) -> Rung:
|
||||
def escalation_cap(project: ProjectRung, route: Route) -> Rung:
|
||||
"""The highest rung an escalation trigger takes the worker or a task to without the human's yes: docs/decisions.md → `routing: a worker hands a task one rung up`.
|
||||
|
||||
It counts from item_rung, the rung the chunk started on, so a step-up between cycles narrows what the worker may climb without a yes, and never widens it.
|
||||
"""
|
||||
return ladder.climbed(item_rung(ladder, project, route), ESCALATION_CAP)
|
||||
return project.ladder.climbed(item_rung(project, route), ESCALATION_CAP)
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -104,31 +105,32 @@ class StepUp:
|
||||
after: Route
|
||||
|
||||
|
||||
def next_route(ladder: Ladder, project: Rung | None, route: Route, verdict: Unfinished | Interrupt | QuotedAnswer) -> Route:
|
||||
def next_route(project: ProjectRung | None, route: Route, verdict: Unfinished | Interrupt | QuotedAnswer) -> Route:
|
||||
"""The route the worker runs on after the judge's verdict. Off the ladder, project is None, and the route holds. The rung never falls."""
|
||||
if project is None:
|
||||
return route
|
||||
if isinstance(verdict, Unfinished):
|
||||
return unfinished_route(ladder, project, route, verdict)
|
||||
return escalated_route(ladder, project, route, verdict)
|
||||
return unfinished_route(project, route, verdict)
|
||||
return escalated_route(project, route, verdict)
|
||||
|
||||
|
||||
def unfinished_route(ladder: Ladder, project: Rung, route: Route, verdict: Unfinished) -> Route:
|
||||
"""The route after an unfinished verdict. The rung rises to floor_rung, which the verdict's highest L taken in may raise.
|
||||
def unfinished_route(project: ProjectRung, route: Route, verdict: Unfinished) -> Route:
|
||||
"""The route after an unfinished verdict, as the module docstring's table says.
|
||||
|
||||
The verdict counts towards UNFINISHED_PER_STEP. Where steps says so, the rung steps once from the floor, and the mark moves only where the verdict escalates. Last, the route takes in the verdict's highest E + I, as Route.taking_in does.
|
||||
The rung rises to floor_rung, which the verdict's highest L taken in may raise. The verdict counts towards UNFINISHED_PER_STEP. Where steps says so, the rung steps once from the floor; the mark moves only where the verdict carries an escalation. Last, the route takes in the verdict's highest E + I, as Route.taking_in does.
|
||||
"""
|
||||
floor = floor_rung(project, route, verdict.taken_in.highest_likelihood)
|
||||
mark = escalation_mark.moved_to(verdict)
|
||||
floor = floor_rung(ladder, project, route, verdict.taken_in.highest_likelihood)
|
||||
escalates = mark is not None and below_cap(project, route, floor)
|
||||
counted = route.unfinished + 1
|
||||
if steps(counted, mark is not None and below_cap(ladder, project, route, floor)):
|
||||
after = one_rung_up(ladder, route, floor, route.escalated_at if mark is None else mark)
|
||||
if steps(counted, escalates):
|
||||
after = one_rung_up(project.ladder, route, floor, route.escalated_at if mark is None else mark)
|
||||
else:
|
||||
after = dataclasses.replace(route, rung=floor, unfinished=counted)
|
||||
return after.taking_in(verdict.taken_in.highest_escape_and_impact)
|
||||
|
||||
|
||||
def escalated_route(ladder: Ladder, project: Rung, route: Route, verdict: Interrupt | QuotedAnswer) -> Route:
|
||||
def escalated_route(project: ProjectRung, route: Route, verdict: Interrupt | QuotedAnswer) -> Route:
|
||||
"""The route after an interrupt or a quoted answer. Without an escalation it holds, since neither is an unfinished verdict.
|
||||
|
||||
With one, the rung rises to floor_rung, which the verdict's highest L taken in may raise. Where floor_rung lies below escalation_cap, the rung steps one up from it and the mark moves, as loop_claude/escalation_mark.py says; at the cap the rung stays on floor_rung and the mark holds.
|
||||
@@ -136,8 +138,8 @@ def escalated_route(ladder: Ladder, project: Rung, route: Route, verdict: Interr
|
||||
mark = escalation_mark.moved_to(verdict)
|
||||
if mark is None:
|
||||
return route
|
||||
floor = floor_rung(ladder, project, route, verdict.taken_in.highest_likelihood)
|
||||
return one_rung_up(ladder, route, floor, mark) if below_cap(ladder, project, route, floor) else dataclasses.replace(route, rung=floor)
|
||||
floor = floor_rung(project, route, verdict.taken_in.highest_likelihood)
|
||||
return one_rung_up(project.ladder, route, floor, mark) if below_cap(project, route, floor) else dataclasses.replace(route, rung=floor)
|
||||
|
||||
|
||||
def steps(counted: int, escalates: bool) -> bool:
|
||||
@@ -145,9 +147,9 @@ def steps(counted: int, escalates: bool) -> bool:
|
||||
return counted >= UNFINISHED_PER_STEP or escalates
|
||||
|
||||
|
||||
def below_cap(ladder: Ladder, project: Rung, route: Route, floor: Rung) -> bool:
|
||||
def below_cap(project: ProjectRung, route: Route, floor: Rung) -> bool:
|
||||
"""Whether an escalation from floor may step the rung: floor lies below escalation_cap."""
|
||||
return ladder.position(floor) < ladder.position(escalation_cap(ladder, project, route))
|
||||
return project.ladder.position(floor) < project.ladder.position(escalation_cap(project, route))
|
||||
|
||||
|
||||
def step_up(before: Route, after: Route) -> StepUp | None:
|
||||
|
||||
Reference in New Issue
Block a user