Stop loop-claude and ask the human after six unfinished verdicts running
This commit is contained in:
@@ -107,6 +107,8 @@ Exit 2, when the human is needed and cannot answer:
|
||||
- the input ends while a model is picked
|
||||
- an interrupt's answer is empty, or the input ends before one is typed
|
||||
- the claude opened for /talk, or for a release ready to cut, ends with nothing typed
|
||||
- the judge rules a chunk unfinished 6 cycles running; a finished chunk restarts the run, and a rerun
|
||||
gives the chunk 6 more
|
||||
Rerunning resumes any open session.
|
||||
|
||||
"""
|
||||
@@ -115,7 +117,7 @@ import pathlib
|
||||
import sys
|
||||
import typing
|
||||
|
||||
from loop_claude.routing import after_unfinished, first_route, kept, routed_item
|
||||
from loop_claude.routing import after_unfinished, ESCALATION_CAP, first_route, kept, routed_item, UNFINISHED_PER_STEP
|
||||
from transcript_archive.write import archive
|
||||
from transcript_archive.location import archive_root, project_archive
|
||||
from loop_claude.loop.routing_check import check_routing
|
||||
@@ -139,10 +141,12 @@ from loop_claude.project.premises import read_premises
|
||||
from loop_claude.project.records import read_records
|
||||
from model_routing.route import Route, route_from
|
||||
from claude_code.session import Session, session_named, session_open, transcript_file
|
||||
from loop_claude.stop import Stop
|
||||
from loop_claude.stop import needs_human, Stop
|
||||
|
||||
# Seconds routing waits for origin to name its default branch, asked only where the checkout records none; past them, the chunk runs on the project's rung.
|
||||
ORIGIN_TIMEOUT = 60
|
||||
# How many unfinished verdicts running end the loop to ask the human, so a worker and a judge that disagree about a chunk cannot cycle unattended without end: the worker's two escalation steps, which every second verdict takes, and one step's worth more at the top. No archived chunk has had more than one.
|
||||
UNFINISHED_LIMIT = UNFINISHED_PER_STEP * (ESCALATION_CAP + 1)
|
||||
|
||||
|
||||
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, cwd: pathlib.Path, effects: Effects) -> int:
|
||||
@@ -188,6 +192,8 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
|
||||
loop_run = after_verdict(loop_run, project, concluded)
|
||||
if stop := archive_step(archive_folder, session, loop_run.task, concluded.route, loop_run.route, effects):
|
||||
return stop
|
||||
if stop := past_limit(archive_folder, session, loop_run, effects):
|
||||
return stop
|
||||
if stop := check_routing(archive_root(paths.home, env), project or Rung(models.worker), paths, effects):
|
||||
return stop
|
||||
|
||||
@@ -204,11 +210,11 @@ def routed(route: Route | None, project: Rung | None, model: str, archived: typi
|
||||
|
||||
|
||||
def after_verdict(loop_run: LoopRun, project: Rung | None, concluded: Concluded) -> LoopRun:
|
||||
"""The loop run the next cycle starts from. A finished chunk drops its route. An unfinished one takes the route stepped_route makes, and the evidence the judge gave for the verdict."""
|
||||
"""The loop run the next cycle starts from. A finished chunk drops its route and its run of unfinished verdicts. An unfinished one takes the route stepped_route makes, the evidence the judge gave for the verdict, and counts the verdict."""
|
||||
verdict = concluded.verdict
|
||||
if isinstance(verdict, Finished):
|
||||
return dataclasses.replace(loop_run, route=None, unfinished_evidence="")
|
||||
return dataclasses.replace(loop_run, route=stepped_route(project, concluded.route, verdict), unfinished_evidence=verdict.evidence)
|
||||
return dataclasses.replace(loop_run, route=None, unfinished_evidence="", unfinished_run=0)
|
||||
return dataclasses.replace(loop_run, route=stepped_route(project, concluded.route, verdict), unfinished_evidence=verdict.evidence, unfinished_run=loop_run.unfinished_run + 1)
|
||||
|
||||
|
||||
def stepped_route(project: Rung | None, ended_on: Route, verdict: Unfinished) -> Route:
|
||||
@@ -216,6 +222,16 @@ def stepped_route(project: Rung | None, ended_on: Route, verdict: Unfinished) ->
|
||||
return after_unfinished(project, ended_on, verdict) if project else ended_on
|
||||
|
||||
|
||||
def past_limit(archive_folder: pathlib.Path, session: Session, loop_run: LoopRun, effects: Effects) -> Stop | None:
|
||||
"""The stop that asks the human once the chunk has had UNFINISHED_LIMIT unfinished verdicts running, archived with the route the next cycle would run on, so a rerun resumes on it."""
|
||||
if loop_run.unfinished_run < UNFINISHED_LIMIT or loop_run.route is None:
|
||||
return None
|
||||
stop = needs_human("decide whether the chunk is finished", f"the judge ruled it unfinished {loop_run.unfinished_run} cycles running; rerun loop-claude to give it {UNFINISHED_LIMIT} more")
|
||||
path = transcript_file(session)
|
||||
failure = archive(archive_folder, path, loop_run.task, outcomes.stopped(loop_run.route.worker_line(), stop.reason), effects.now()) if path else None
|
||||
return Stop(1, f"{failure.reason}\n{stop.reason}") if failure else stop
|
||||
|
||||
|
||||
def archive_step(archive_folder: pathlib.Path, session: Session, task: str, before: Route, after: Route | None, effects: Effects) -> Stop | None:
|
||||
"""Archives the route after an unfinished verdict as a step-up, where its worker line differs from the one before it: a higher rung, or a higher E + I taken in. The verdict itself names the route before, which its cycle ran on."""
|
||||
if after is None or after.worker_line() == before.worker_line():
|
||||
|
||||
@@ -24,6 +24,8 @@ class LoopRun:
|
||||
unfinished_evidence: str
|
||||
# Set by each unfinished verdict; None before the chunk's first one, and once it finishes.
|
||||
route: Route | None = None
|
||||
# How many unfinished verdicts the chunk has had running; a finished chunk restarts it, and a rerun starts it at 0.
|
||||
unfinished_run: int = 0
|
||||
|
||||
|
||||
def decode_handed(handed: str, kind: type[T]) -> T | None:
|
||||
|
||||
Reference in New Issue
Block a user