|
|
|
@@ -102,13 +102,13 @@ Exit 1, saying why, when:
|
|
|
|
|
more than 2 minutes past. The judge's reply gives its reset time only as text, so the judge is
|
|
|
|
|
always retried every 10 minutes. stderr says when the next try is due.
|
|
|
|
|
|
|
|
|
|
Exit 2, when the human is needed and cannot answer:
|
|
|
|
|
Exit 2, when the human is needed to go on and cannot be asked, or the chunk has gone on too long:
|
|
|
|
|
- stdin or stdout is not a terminal, when a model must be picked or an interrupt answered
|
|
|
|
|
- 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
|
|
|
|
|
- the judge rules a chunk unfinished 6 cycles running; finish the chunk yourself, or rerun to give it
|
|
|
|
|
6 more. A finished chunk restarts the run.
|
|
|
|
|
Rerunning resumes any open session.
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
@@ -117,12 +117,12 @@ import pathlib
|
|
|
|
|
import sys
|
|
|
|
|
import typing
|
|
|
|
|
|
|
|
|
|
from loop_claude.routing import after_unfinished, ESCALATION_CAP, first_route, kept, routed_item, UNFINISHED_PER_STEP
|
|
|
|
|
from loop_claude.routing import after_unfinished, first_route, kept, routed_item
|
|
|
|
|
from transcript_archive.write import archive
|
|
|
|
|
from transcript_archive.location import archive_root, project_archive
|
|
|
|
|
from loop_claude.loop.routing_check import check_routing
|
|
|
|
|
from loop_claude.project.checkout import checkout_root
|
|
|
|
|
from loop_claude.cycle.run import Concluded, Cycle, run_cycle
|
|
|
|
|
from loop_claude.cycle.run import archived_stop, Concluded, Cycle, run_cycle
|
|
|
|
|
from loop_claude.loop.reload import decode_handed, exec_if_edited, fingerprint, LoopRun, RELOAD_FLAG
|
|
|
|
|
from chunk_pick import default_plan, DefaultPlan
|
|
|
|
|
from git_repo import default_ref
|
|
|
|
@@ -145,8 +145,8 @@ 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)
|
|
|
|
|
# How many unfinished verdicts running end the loop, so a worker and a judge that disagree about a chunk cannot cycle unattended without end. A policy number, not derived from the routing steps: well above the one unfinished verdict any archived chunk has had, and low enough that a stuck pair spends six worker and judge runs, not more. "loop-claude --help" states it.
|
|
|
|
|
UNFINISHED_LIMIT = 6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: pathlib.Path, cwd: pathlib.Path, effects: Effects) -> int:
|
|
|
|
@@ -189,11 +189,10 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc
|
|
|
|
|
concluded = run_cycle(Cycle(effects=effects, facts=facts, judge_model=models.judge, paths=paths, premises=premises, project=project, project_archive=archive_folder, records=records, root=loop_run.root, route=route, session=session, task=loop_run.task, unfinished_evidence=loop_run.unfinished_evidence))
|
|
|
|
|
if isinstance(concluded, Stop):
|
|
|
|
|
return concluded
|
|
|
|
|
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
|
|
|
|
|
closed = closed_cycle(loop_run, project, concluded, archive_folder, session, effects)
|
|
|
|
|
if isinstance(closed, Stop):
|
|
|
|
|
return closed
|
|
|
|
|
loop_run = closed
|
|
|
|
|
if stop := check_routing(archive_root(paths.home, env), project or Rung(models.worker), paths, effects):
|
|
|
|
|
return stop
|
|
|
|
|
|
|
|
|
@@ -209,12 +208,31 @@ def routed(route: Route | None, project: Rung | None, model: str, archived: typi
|
|
|
|
|
return route if route and kept(route, project) else first_route(project, item())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def closed_cycle(loop_run: LoopRun, project: Rung | None, concluded: Concluded, archive_folder: pathlib.Path, session: Session, effects: Effects) -> LoopRun | Stop:
|
|
|
|
|
"""The loop run after a cycle concluded, with the step-up archived; the stop that asks the human, archived, once the chunk has had UNFINISHED_LIMIT unfinished verdicts running."""
|
|
|
|
|
after = after_verdict(loop_run, project, concluded)
|
|
|
|
|
if stop := archive_step(archive_folder, session, after.task, concluded.route, after.route, effects):
|
|
|
|
|
return stop
|
|
|
|
|
if limit := past_limit(after):
|
|
|
|
|
# An unfinished verdict always leaves a route. It is archived as the next cycle would run on it, so a rerun resumes there.
|
|
|
|
|
return archived_stop(archive_folder, session, after.task, after.route or concluded.route, limit, limit.reason, effects)
|
|
|
|
|
return after
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def past_limit(loop_run: LoopRun) -> Stop | None:
|
|
|
|
|
"""The stop that asks the human once the loop run holds UNFINISHED_LIMIT unfinished verdicts running."""
|
|
|
|
|
if loop_run.unfinished_run < UNFINISHED_LIMIT:
|
|
|
|
|
return None
|
|
|
|
|
return needs_human("decide whether the chunk is finished", f"the judge ruled it unfinished {loop_run.unfinished_run} cycles running and loop-claude does not go on unasked; finish the chunk yourself, or rerun loop-claude to give it {UNFINISHED_LIMIT} more cycles")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 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="", 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)
|
|
|
|
|
route = stepped_route(project, concluded.route, verdict)
|
|
|
|
|
return dataclasses.replace(loop_run, route=route, unfinished_evidence=verdict.evidence, unfinished_run=loop_run.unfinished_run + 1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def stepped_route(project: Rung | None, ended_on: Route, verdict: Unfinished) -> Route:
|
|
|
|
@@ -222,16 +240,6 @@ 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():
|
|
|
|
|