diff --git a/AGENTS.md b/AGENTS.md index d8cbfc98..30a71991 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -44,7 +44,7 @@ Decisions live in `docs/decisions.md`: - routing: loop-claude measures review rounds and unfinished verdicts per rung every 20 cycles, and calls for a routing change when, of two rungs with 5 or more chunks each, the lower took more of either than the one above, or when 5 or more subagents of one type had reports longer than the tool results they read - routing: a worker delegates a task only where it needs just the task's conclusion, and each subagent runs on the rung its task's L picks from the project's rung, never below the project's rung when it files or scores todo.md items - routing: a worker hands a task one rung up on each escalation trigger, up to two rungs above the rung its item picks unless the human agrees, and opens the subagent's prompt with the trigger so the routing figures count it -- routing: a worker whose run ends asking for a higher rung, citing an escalation trigger the judge finds in the transcript, resumes one rung up next cycle, up to two rungs above the rung its item picks +- routing: a worker whose run ends asking for a higher rung, citing an escalation trigger the judge finds in the transcript, steps one rung up as the judge interrupts or next cycle, up to two rungs above the rung its item picks - routing: on a model judge-replay covered, the judge runs on the rung a review would get from the highest E + I among its chunk's items, never below the project's rung - routing: the stability reviewer runs no lower than the project's rung while the worker runs below it, until `stability-replay` shows a lower rung finding every 🔴 and 🟡 the project's rung finds diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c6513b6..1b63650c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- `loop-claude` steps the worker one rung up as the judge interrupts, when the run that asked the human also asked `loop-claude` for a higher rung and the judge quotes the escalation trigger it cites. Before, the step was lost, and the worker carried on from the human's answer on its old rung. The step has the same limits as the step on an unfinished verdict, and no later ruling of that cycle carries a second escalation. The archive's interrupt outcome now names the worker's rung. - A scoring run due because a release's items ran out costs four more seats: it is done twice on one head. `larv-review agreement` compares how often Mid A and the inherited architect vote alike in paired rulings with how often their overall scores move the same way between the two runs. After 10 such pairs it gives a verdict, and on `Assumption fails:` larv-review asks you whether to keep the paired ruling. - `workflow-bench/bench.py` gives each run a fixed list of allowed tools. Before, it skipped every permission check. A run may launch agents, run `/security-review`, edit its clone (not the clone's `.git/` or `.claude/`) and its report, and read its clone and the copy of `~/.claude` it benches. For git it gets one command, `workflow-bench/review_git.py`, and no bare `git`. The wrapper runs `log`, `diff`, `show`, `status`, `ls-files`, `add` and `commit -m` on the run's clone, whatever the working directory. It allows only the options it lists for each, and refuses an argument that names a path outside the clone. git runs with no global or system config, hook, pager or editor. A run loads no settings or MCP servers from `~/.claude` or from the case's clone, so their hooks and extra directories do not apply to it. Every other call is denied. Expect a benched review that needs another git command, or to run a project's code or tests, to say in its report that it could not. - Every goal in `README.md` → Goals is marked `**Maintain:**`, a state to hold, or `**Achieve:**`, a direction to pursue. Each achieve goal has a signal, a counter-signal and a one-line reason under it. A change that breaks a maintain goal is redesigned or dropped, whatever it scores: `rules/todo-items.md` says so, and larv-review's goal alignment step no longer merges such a PR. `rules/goals-and-audience.md` states the form for every project's README. Expect larv-review to stop a PR on a maintain goal where it asked you before. diff --git a/bin/loop_claude/cycle/judge.py b/bin/loop_claude/cycle/judge.py index f322028d..bd55375c 100644 --- a/bin/loop_claude/cycle/judge.py +++ b/bin/loop_claude/cycle/judge.py @@ -59,8 +59,8 @@ class Reply: bundled: int = dataclasses.field(metadata={"description": "The highest L the agent states for a todo.md item it took into this chunk; 0 when it states none."}) # Routes the next cycle's judge and reviewers, as bundled routes the worker. bundled_escape_and_impact: int = dataclasses.field(metadata={"description": "The highest E + I the agent states for a todo.md item it took into this chunk; 0 when it states none."}) - # Routes the next cycle's worker one rung up: docs/decisions.md → `routing: a worker whose run ends asking for a higher rung`. - escalation: str = dataclasses.field(metadata={"description": "Empty unless the chunk is unfinished and the agent's run ends asking loop-claude for a higher rung, citing an escalation trigger. Then: a verbatim quote, without elisions, of an earlier transcript passage showing the trigger fired after any earlier such request, such as a review round's commit title or the agent's report of the finding or failing test. Never the request itself."}) + # Routes the worker one rung up, as the judge interrupts or on the next cycle: docs/decisions.md → `routing: a worker whose run ends asking for a higher rung`. + escalation: str = dataclasses.field(metadata={"description": "Empty unless the chunk is unfinished or interrupt is true, and the agent's run ends asking loop-claude for a higher rung, citing an escalation trigger. Then: a verbatim quote, without elisions, of an earlier transcript passage showing the trigger fired after any earlier such request, such as a review round's commit title or the agent's report of the finding or failing test. Never the request itself."}) evidence: str = dataclasses.field(metadata={"description": "A verbatim quote of the one transcript passage the verdict rests on, without elisions: what triggers the interrupt; for a quoted answer, the agent's question; else what shows the chunk finished or the work remaining."}) finished: bool = dataclasses.field(metadata={"description": "Whether the chunk is finished."}) interrupt: bool = dataclasses.field(metadata={"description": "Whether the human must now be interrupted."}) @@ -87,6 +87,10 @@ class Rejected(Failure): class Interrupt: evidence: str question: str + # The judge's quote showing that the worker's cited escalation trigger fired; empty for none. + escalation: str = "" + # The bundled L the judge saw, 0 for none, as on Unfinished: an escalation steps up from the rung that item picks. + bundled: int = 0 @dataclasses.dataclass(frozen=True) @@ -123,18 +127,18 @@ def verdict_from(output: object) -> Verdict | Failure: # type(), not isinstance(): JSON true is no integer. if type(output.get(name)) is not kind: return Failure(f"the judge's reply has no {name} of type {JSON_TYPES[kind]}") + # A bundled level off its scale counts as none: holding the rung is safe, and three failures would stop an unattended loop. + bundled = output["bundled"] if 0 <= output["bundled"] <= HIGHEST_L else 0 if output["interrupt"]: if not output["question"].strip(): return Failure("the judge interrupted without a question") - return Interrupt(output["evidence"], output["question"]) + return Interrupt(output["evidence"], output["question"], output["escalation"], bundled) if output["answer"].strip(): if not output["question"].strip(): return Failure("the judge quoted an answer without a question") return QuotedAnswer(output["evidence"], output["question"], output["answer"]) if output["finished"]: return Finished(output["evidence"]) - # A bundled level off its scale counts as none: holding the rung is safe, and three failures would stop an unattended loop. - bundled = output["bundled"] if 0 <= output["bundled"] <= HIGHEST_L else 0 bundled_escape_and_impact = output["bundled_escape_and_impact"] if on_its_scale(output["bundled_escape_and_impact"]) else 0 return Unfinished(output["evidence"], bundled, output["escalation"], bundled_escape_and_impact) @@ -160,12 +164,7 @@ def judge_args(rung: Rung) -> list[str]: def run_judge(root: str, args: list[str], prompt: str, shown: str, quotable: str, effects: Effects) -> Verdict | Failure | Limited: - """One judge run, its three quotes each checked against what they quote: - - evidence, against shown, its fragments in order: a misquote is a Failure, which judge retries; - - a quoted answer, against quotable, word for word: a misquote puts the question to the human; - - an escalation, against shown, word for word: a misquote drops it, so the worker's rung holds. - A misquoted answer or escalation is no Failure, which would otherwise exit an unattended loop. Neither may be elided, since stitched fragments can say what the records or the transcript do not. - """ + """One judge run. Its evidence is checked against shown, its fragments in order: a misquote is a Failure, which judge retries.""" reply = claude_reply(effects.claude, args, root, prompt, "the judge") if isinstance(reply, Failure | Limited): return reply @@ -175,10 +174,20 @@ def run_judge(root: str, args: list[str], prompt: str, shown: str, quotable: str return Rejected(verdict.reason, replied) if not grounded(verdict.evidence, shown): return Rejected(f"the judge quoted {verdict.evidence!r}, which is not in the transcript" + (f", for the question: {verdict.question}" if isinstance(verdict, Interrupt | QuotedAnswer) else ""), replied) - if isinstance(verdict, QuotedAnswer) and not verbatim(verdict.answer, quotable): - return Interrupt(verdict.evidence, verdict.question) - if isinstance(verdict, Unfinished) and verdict.escalation and not verbatim(verdict.escalation, shown): - return dataclasses.replace(verdict, escalation="") + return quotes_checked(verdict, shown, quotable) + + +def quotes_checked(verdict: Verdict, shown: str, quotable: str) -> Verdict: + """The verdict with its quotes checked word for word, since stitched fragments can say what the records or the transcript do not: + - a quoted answer, against quotable: a misquote puts the question to the human; + - an escalation, on an interrupt or an unfinished verdict, against shown: a misquote drops it, so the worker's rung holds. + A misquote is no Failure, which would otherwise exit an unattended loop. + """ + match verdict: + case QuotedAnswer() if not verbatim(verdict.answer, quotable): + return Interrupt(verdict.evidence, verdict.question) + case Interrupt() | Unfinished() if verdict.escalation and not verbatim(verdict.escalation, shown): + return dataclasses.replace(verdict, escalation="") return verdict diff --git a/bin/loop_claude/cycle/run.py b/bin/loop_claude/cycle/run.py index fb5ed116..2a1998c8 100644 --- a/bin/loop_claude/cycle/run.py +++ b/bin/loop_claude/cycle/run.py @@ -7,9 +7,9 @@ from transcript_archive.write import archive from claude_code.session import delete_session, Session, session_open, transcript_file from loop_claude.effects import Effects from failure import Failure -from loop_claude.cycle.judge import Finished, Interrupt, judge, QuotedAnswer, Rejected, Unfinished +from loop_claude.cycle.judge import Finished, Interrupt, judge, QuotedAnswer, Rejected, Unfinished, Verdict from loop_claude.cycle.interrupt import interrupt -from loop_claude.routing import judge_rung +from loop_claude.routing import judge_rung, stepped_by_interrupt from transcript_archive import outcomes from loop_claude.paths import Paths from loop_claude.cycle import prompts @@ -40,19 +40,41 @@ class Cycle: anchor: Rung | None # Empty when the previous cycle's verdict was not Unfinished. unfinished_evidence: str + # Only an interrupt's escalation changes the route within a cycle. No transition reads the route or the fields below, so they stay out of the states. + # The route that interrupt left, for ask to archive; None unless the latest event stepped the route up. + stepped_from: Route | None = None + # Whether an interrupt of this cycle took an escalation, after which no ruling of the cycle carries one. + escalation_spent: bool = False -def run_cycle(cycle: Cycle) -> Stop | Finished | Unfinished: +@dataclasses.dataclass(frozen=True) +class Concluded: + """How a cycle ended: its verdict, and the route it ended on, which an interrupt's escalation may have stepped up from the route it began on.""" + verdict: Finished | Unfinished + route: Route + + +def run_cycle(cycle: Cycle) -> Stop | Concluded: state: State = Working() try: while not isinstance(state, Ended): event = step(cycle, state) if isinstance(event, Stop): return stopped(cycle, event, event.reason) + cycle = escalated(cycle, event) state = transition(state, event) except KeyboardInterrupt: return stopped(cycle, Stop(130, ""), "Ctrl-C") - return state.verdict + return Concluded(state.verdict, cycle.route) + + +def escalated(cycle: Cycle, event: Event) -> Cycle: + """The cycle after event. Where the judge interrupted with an escalation, its route steps up before the human is asked, so the work after the answer runs on it.""" + cycle = dataclasses.replace(cycle, stepped_from=None) + if not (isinstance(event, Ruled) and isinstance(event.verdict, Interrupt) and event.verdict.escalation): + return cycle + route = stepped_by_interrupt(cycle.anchor, cycle.route, event.verdict.bundled) if cycle.anchor else cycle.route + return dataclasses.replace(cycle, route=route, stepped_from=cycle.route if route != cycle.route else None, escalation_spent=True) def stopped(cycle: Cycle, stop: Stop, why: str) -> Stop: @@ -118,7 +140,14 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop: if isinstance(entries, Failure): return Stop(1, entries.reason) verdict = judge(cycle.root, cycle.task, cycle.premises, cycle.records, render(entries), judge_of(cycle), cycle.effects, lambda rejected: keep_rejection(cycle, transcript_path, rejected)) - return verdict if isinstance(verdict, Stop) else Ruled(verdict) + return verdict if isinstance(verdict, Stop) else Ruled(unspent(verdict, cycle.escalation_spent)) + + +def unspent(verdict: Verdict, spent: bool) -> Verdict: + """The verdict without its escalation once an interrupt of the cycle took one. The judge may quote a different passage for the trigger that already stepped the route, and no comparison of quotes tells the two apart, so one trigger buys one step. It lives here, not in judge.quotes_checked, since it reads the cycle, and judge-replay replays the judge alone.""" + if spent and isinstance(verdict, Interrupt | Unfinished) and verdict.escalation: + return dataclasses.replace(verdict, escalation="") + return verdict def keep_rejection(cycle: Cycle, transcript_path: str, rejected: Rejected) -> Stop | None: @@ -131,8 +160,11 @@ def keep_rejection(cycle: Cycle, transcript_path: str, rejected: Rejected) -> St def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) -> HumanAnswered | Stop: question = question_for(ruling) # Archived now, so the transcript the question was asked on is kept with it; the human's answer then grows the transcript. - if failure := archive(cycle.project_archive, transcript_path, cycle.task, outcomes.interrupted(question, ruling.evidence, str(judge_of(cycle))), cycle.effects.now()): - return Stop(1, failure.reason) + # The interrupt names the rung the worker ran on before it; a step-up archived after it names the stepped rung, so the figures charge each stretch to its own rung. + interrupted = outcomes.interrupted(question, ruling.evidence, str(judge_of(cycle)), ruling.escalation if isinstance(ruling, Interrupt) else "", str(cycle.stepped_from or cycle.route)) + for outcome in (interrupted, outcomes.stepped_up(str(cycle.route))) if cycle.stepped_from else (interrupted,): + if failure := archive(cycle.project_archive, transcript_path, cycle.task, outcome, cycle.effects.now()): + return Stop(1, failure.reason) return interrupt(cycle.root, cycle.session.id, cycle.route.rung, transcript_path, question, cycle.paths, worker_environment(cycle), cycle.effects) or HumanAnswered() diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index a9860928..5a162fca 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -81,9 +81,11 @@ E + I, or the routed item's (Route.reviewed_on in bin/model_routing/route.py). A scale counts as none. Every second unfinished verdict on a chunk steps it up one rung (routing.stepped). So does an unfinished verdict on a worker that ended its run asking for a higher rung, once the judge quotes the transcript showing that the escalation trigger it named -fired (~/.claude/CLAUDE.md → "Working with the codebase" lists them). That step stops two rungs +fired (~/.claude/CLAUDE.md → "Working with the codebase" lists them). An interrupt with such a quote +steps the rung as it comes in, before the human is asked (routing.stepped_by_interrupt), and no later +ruling of that cycle carries a second escalation. Either step stops two rungs above the rung the chunk's item picks, and the worker's prompts offer it only while the worker is -below that limit. Each finished or unfinished verdict, stop and step-up in the archive names the +below that limit. Each finished or unfinished verdict, interrupt, stop and step-up in the archive names the worker's rung, with the item, L and E + I that routed the chunk, and any taken-in E + I that picks a higher review rung, which is archived as a step-up too. A rerun resumes an open chunk on the latest route named there, and counts its unfinished verdicts afresh. A rung no longer on the ladder, or @@ -221,10 +223,12 @@ def run_loop(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launc loop_run = routed(loop_run, anchor, lambda: archived_route(archive_folder, session), lambda: plan_item(fetched_plan(root))) 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)) - if isinstance(verdict, Stop): - return verdict - before, loop_run = loop_run.route, after_verdict(loop_run, anchor, verdict) + concluded = 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)) + if isinstance(concluded, Stop): + return concluded + # The route the cycle ended on, which a step-up at an interrupt may have raised and archived, is the one the verdict steps from. + ended = dataclasses.replace(loop_run, route=concluded.route if anchor else None) + before, loop_run = ended.route, after_verdict(ended, anchor, concluded.verdict) if stop := archive_step(archive_folder, session, loop_run, before, effects): return stop if stop := check_routing(archive_root(paths.home, env), anchor or Rung(models.worker), paths, effects): diff --git a/bin/loop_claude/routing.py b/bin/loop_claude/routing.py index 09e5ec49..2eb463c3 100644 --- a/bin/loop_claude/routing.py +++ b/bin/loop_claude/routing.py @@ -60,20 +60,33 @@ def escalation_cap(anchor: Rung, route: Route) -> Rung: def stepped(anchor: Rung, route: Route, bundled: int, escalated: bool) -> Route: - """The route after one more unfinished verdict. Its rules, in order: the rung never falls below kept_rung; a bundled item lifts it to the rung that item's L picks; every second unfinished verdict steps it up one rung; so does an escalation the judge found, up to escalation_cap, two rungs above item_rung; and both steps on one verdict make one step. + """The route after one more unfinished verdict. Its rung never falls below taken_in's. It steps up one rung on every second unfinished verdict, or on an escalation the judge found while the rung is below escalation_cap; where both fall on one verdict, it steps once. bundled and escalated are the verdict's fields, not the verdict, since loop_claude.cycle.judge imports this module through prompts. """ rung = taken_in(anchor, route, bundled) unfinished = route.unfinished + 1 - counted_out = unfinished >= UNFINISHED_PER_STEP - # The judge found the escalation trigger the worker cited in asking for a higher rung. - escalates = escalated and position(rung) < position(escalation_cap(anchor, route)) - if counted_out or escalates: - return dataclasses.replace(route, rung=stepped_up(rung), unfinished=0) + if unfinished >= UNFINISHED_PER_STEP or (escalated and below_cap(anchor, route, rung)): + return stepped_from(route, rung) return dataclasses.replace(route, rung=rung, unfinished=unfinished) +def stepped_by_interrupt(anchor: Rung, route: Route, bundled: int) -> Route: + """The route after the judge's interrupt carried an escalation: taken_in's rung, one rung up while that is below escalation_cap. An interrupt is no unfinished verdict, so the count of those restarts only with a step.""" + rung = taken_in(anchor, route, bundled) + return stepped_from(route, rung) if below_cap(anchor, route, rung) else dataclasses.replace(route, rung=rung) + + +def stepped_from(route: Route, rung: Rung) -> Route: + """The route one rung above rung, with the count of unfinished verdicts restarted.""" + return dataclasses.replace(route, rung=stepped_up(rung), unfinished=0) + + +def below_cap(anchor: Rung, route: Route, rung: Rung) -> bool: + """Whether an escalation trigger may take the worker one rung up from rung without the human's yes: rung is below escalation_cap, two rungs above item_rung.""" + return position(rung) < position(escalation_cap(anchor, route)) + + def taken_in(anchor: Rung, route: Route, bundled: int) -> Rung: """kept_rung, raised to the rung bundled picks from anchor; bundled is the highest L the judge saw the worker take into the chunk, 0 for none.""" return highest(kept_rung(anchor, route), worker_rung(anchor, bundled)) if bundled else kept_rung(anchor, route) diff --git a/bin/loop_claude/test_black_box.py b/bin/loop_claude/test_black_box.py index 42031b5d..d5702a90 100644 --- a/bin/loop_claude/test_black_box.py +++ b/bin/loop_claude/test_black_box.py @@ -458,6 +458,24 @@ class Cycles(unittest.TestCase): self.assertIn(" Verdict: unfinished\n\nEvidence:\n> I ask for a higher rung.\n\nEscalation:\n> Stability round 2: a 🔴.\n\nJudge: judge-model\nWorker: claude-opus-5-5 at high effort, routed by item 4's L of 4 and E + I of 5\n\n Stepped up\n\nWorker: claude-opus-5-5 at xhigh effort, routed by item 4's L of 4 and E + I of 5\n", outcomes) self.assertIn(" Verdict: unfinished\n\nEvidence:\n> I ask for a higher rung.\n\nJudge: judge-model\nWorker: claude-opus-5-5 at xhigh effort, routed by item 4's L of 4 and E + I of 5\n", outcomes) + def test_steps_the_worker_up_once_as_the_judge_interrupts_when_the_run_also_cites_an_escalation_trigger(self): + checkout = Checkout(self) + checkout.env["LOOP_CLAUDE_WORKER_MODEL"] = "claude-opus-5-5" + checkout.commit_plan(TODO) + cited = "Stability round 2: a 🔴." + run = checkout.run([ + worker(say=f"{cited} Trigger 3 fired; I ask for a higher rung. Shall I use A or B?"), judge(interrupt=True, evidence="Shall I use A or B?", question="A or B?", escalation=cited), + interrupt(type="B"), judge(evidence="B", escalation="Trigger 3 fired; I ask for a higher rung."), + worker(say="carrying on"), + ], terminal_input="") + self.assertEqual(run.code, 130) + self.assertEqual(run.roles(), ["worker", "judge", "interrupt", "judge", "worker", "judge"]) + self.assertEqual([(argument(call, "--model"), argument(call, "--effort")) for call in run.calls if call["role"] != "judge"], [("claude-opus-5-5", "high"), ("claude-opus-5-5", "xhigh"), ("claude-opus-5-5", "xhigh")]) + outcomes = sorted(verdict.removeprefix(f"Task: {TASK}\n\n") for verdict in checkout.archived().values()) + self.assertIn(" Stepped up\n\nWorker: claude-opus-5-5 at xhigh effort, routed by item 4's L of 4 and E + I of 5\n", "".join(outcomes)) + self.assertNotIn("at max effort", "".join(outcomes)) + self.assertIn("Verdict: interrupt\n\nA or B?\n\nEvidence:\n> Shall I use A or B?\n\nEscalation:\n> Stability round 2: a 🔴.\n\nJudge: judge-model\nWorker: claude-opus-5-5 at high effort, routed by item 4's L of 4 and E + I of 5\n\n Stepped up\n\nWorker: claude-opus-5-5 at xhigh effort, routed by item 4's L of 4 and E + I of 5\n", "".join(outcomes)) + def test_runs_a_cheap_items_worker_below_the_projects_rung_with_its_reviewers_and_judge_on_it(self): checkout = Checkout(self) checkout.env["LOOP_CLAUDE_WORKER_MODEL"] = checkout.env["LOOP_CLAUDE_JUDGE_MODEL"] = "claude-opus-5-5" @@ -624,7 +642,7 @@ class Interrupt(unittest.TestCase): self.assertEqual(run.stderr.strip().splitlines()[-2:], ["A or B?", "the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal"]) [(copy, verdict)] = checkout.archived().items() self.assertEqual(copy, (checkout.transcripts()[0]).read_text()) - self.assertEqual(verdict, f"Task: {TASK}\n\n Verdict: interrupt\n\nA or B?\n\nEvidence:\n> Shall I use A or B?\n\nJudge: judge-model\n\n Stopped: the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal\n\nWorker: worker-model\n") + self.assertEqual(verdict, f"Task: {TASK}\n\n Verdict: interrupt\n\nA or B?\n\nEvidence:\n> Shall I use A or B?\n\nJudge: judge-model\nWorker: worker-model\n\n Stopped: the human is needed to answer the question above, but stdin or stdout is not a terminal; rerun loop-claude on a terminal\n\nWorker: worker-model\n") self.assertEqual(stat.S_IMODE((checkout.temp / "deep").stat().st_mode), 0o700) self.assertIn(f"transcript: {checkout.archive() / 'proj'}/", run.stderr) session = argument(run.calls[0], "--session-id") diff --git a/bin/loop_claude/test_loop_claude.py b/bin/loop_claude/test_loop_claude.py index 6a4e0cf0..5784e4cc 100644 --- a/bin/loop_claude/test_loop_claude.py +++ b/bin/loop_claude/test_loop_claude.py @@ -194,15 +194,15 @@ class Cycles(unittest.TestCase): def test_a_finished_chunk_is_archived_and_its_session_deleted(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("finished")]) - self.assertEqual(run.run_cycle(self.cycle(fake)), Finished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Finished("working")) self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: finished\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: worker-model\n"]) self.assertIsNone(session.transcript_file(self.session)) def test_a_fresh_worker_reads_the_preflights_facts_and_a_resumed_one_does_not(self): worker = Worker(self.paths.claude_code_transcripts.parent) fake = FakeEffects(streams=[worker, worker], claude=[judged("unfinished"), judged("finished")]) - self.assertEqual(run.run_cycle(self.cycle(fake)), Unfinished("working")) - self.assertEqual(run.run_cycle(self.cycle(fake, unfinished_evidence="working")), Finished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Unfinished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake, unfinished_evidence="working")).verdict, Finished("working")) fresh, resumed = (args[args.index("-p") + 1] for args in fake.made("stream_claude")) self.assertIn("- A preflight fact.", fresh) self.assertNotIn("- A preflight fact.", resumed) @@ -210,7 +210,7 @@ class Cycles(unittest.TestCase): def test_a_worker_is_handed_the_projects_rung_its_own_and_its_reviewers_in_its_environment(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("finished")]) cycle = dataclasses.replace(self.cycle(fake), anchor=Rung("claude-opus-5-5", "medium"), route=Route(Rung("claude-haiku-5-5", "max"), 163, 1, 5)) - self.assertEqual(run.run_cycle(cycle), Finished("working")) + self.assertEqual(run.run_cycle(cycle).verdict, Finished("working")) self.assertEqual(fake.worker_environments, [{"LOOP_CLAUDE_PROJECT_RUNG": "claude-opus-5-5 at medium effort", "LOOP_CLAUDE_WORKER_RUNG": "claude-haiku-5-5 at max effort", "LOOP_CLAUDE_REVIEWER_RUNG": "claude-opus-5-5 at high effort"}]) def test_the_claude_an_interrupt_resumes_is_handed_the_same_rungs_as_the_worker(self): @@ -220,15 +220,15 @@ class Cycles(unittest.TestCase): return 0 fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt"), judged("finished")], on_terminal_claude=[answer], git=[ran()]) cycle = dataclasses.replace(self.cycle(fake), anchor=Rung("claude-opus-5-5", "medium"), route=Route(Rung("claude-haiku-5-5", "max"), 163, 1, 5)) - self.assertEqual(run.run_cycle(cycle), Finished("working")) + self.assertEqual(run.run_cycle(cycle).verdict, Finished("working")) self.assertEqual(fake.terminal_environments, fake.worker_environments) self.assertEqual(fake.terminal_environments[0]["LOOP_CLAUDE_WORKER_RUNG"], "claude-haiku-5-5 at max effort") def test_an_unfinished_chunks_transcript_is_archived_and_the_next_cycle_resumes_its_session_with_the_judges_evidence(self): fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[judged("unfinished")] * 2) - self.assertEqual(run.run_cycle(self.cycle(fake)), Unfinished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Unfinished("working")) self.assertTrue(session.transcript_file(self.session)) - self.assertEqual(run.run_cycle(self.cycle(fake, unfinished_evidence="working")), Unfinished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake, unfinished_evidence="working")).verdict, Unfinished("working")) workers = fake.made("stream_claude") self.assertIn("--session-id", workers[0]) self.assertIn("--resume", workers[1]) @@ -246,7 +246,7 @@ class Cycles(unittest.TestCase): unfilled = ran(json.dumps({"structured_output": {"interrupt": False}})) misquoted = judged("finished", evidence="never said") fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[unfilled, misquoted, judged("finished")]) - self.assertEqual(run.run_cycle(self.cycle(fake)), Finished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Finished("working")) stamp = "2026-09-21T14:13:20Z" self.assertEqual(self.archived_outcomes(), [ "Task: Do it.\n\n" @@ -279,7 +279,7 @@ class Cycles(unittest.TestCase): (folder / "custom-title.json").write_text("first") (folder.parent / f"{self.session.id}.orphaned-1.jsonl").write_text("o\n") fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 3, claude=[judged("unfinished"), judged("finished"), judged("unfinished")]) - self.assertEqual(run.run_cycle(self.cycle(fake)), Unfinished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Unfinished("working")) [chunk] = self.archive.iterdir() kept = chunk / "session" / str(self.session.id) self.assertEqual((chunk / "session" / f"{self.session.id}.orphaned-1.jsonl").read_text(), "o\n") @@ -287,7 +287,7 @@ class Cycles(unittest.TestCase): with open(folder / "subagents" / "agent-a.jsonl", "a") as handle: handle.write("more\n") (folder / "custom-title.json").write_text("second") - self.assertEqual(run.run_cycle(self.cycle(fake)), Finished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Finished("working")) self.assertFalse(folder.exists()) self.assertEqual((kept / "subagents" / "agent-a.jsonl").read_text(), "a\nmore\n") self.assertEqual((kept / "subagents" / "workflows" / "journal.jsonl").stat().st_mtime, 0) @@ -295,7 +295,7 @@ class Cycles(unittest.TestCase): self.assertEqual(stat.S_IMODE((kept / "subagents" / "agent-a.jsonl").stat().st_mode), 0o600) folder.mkdir() (folder / "custom-title.json").write_text("third") - self.assertEqual(run.run_cycle(self.cycle(fake)), Unfinished("working")) + self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Unfinished("working")) [next_chunk] = set(self.archive.iterdir()) - {chunk} self.assertEqual(sorted(path.read_text() for path in (next_chunk / "session" / str(self.session.id)).glob("custom-title.json*")), ["third"]) @@ -314,8 +314,8 @@ class Cycles(unittest.TestCase): handle.write(json.dumps(human("the second")) + "\n") return 0 fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)], claude=[judged("interrupt"), judged("unfinished")], on_terminal_claude=[answer], git=[ran()]) - self.assertEqual(run.run_cycle(self.cycle(fake)), Unfinished("working")) - self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: interrupt\n\nWhich one?\n\nEvidence:\n> working\n\nJudge: judge-model\n", "Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: unfinished\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: worker-model\n"]) + self.assertEqual(run.run_cycle(self.cycle(fake)).verdict, Unfinished("working")) + self.assertEqual(self.archived_outcomes(), ["Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: interrupt\n\nWhich one?\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: worker-model\n", "Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: unfinished\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: worker-model\n"]) self.assertIn(str(self.session.id), fake.made("claude_on_terminal")[0]) judge_prompts = [stdin for args, stdin in fake.made("claude")] self.assertEqual(len(judge_prompts), 2) @@ -335,7 +335,7 @@ class Cycles(unittest.TestCase): self.assertEqual(printed.getvalue().count("=== README.md's Goals and Audience, AGENTS.md, docs/decisions.md, ~/.claude/CLAUDE.md, ~/.claude/rules/ or ~/.claude/skills/larv-review/standards/ answered: Which one? ===\nUse *A*."), 3) self.assertIn("Which one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md, ~/.claude/CLAUDE.md, ~/.claude/rules/ or ~/.claude/skills/larv-review/standards/ says:\nUse *A*.\n\nThose files have answered 3 questions this cycle", said.getvalue()) quoted = "2026-09-21T14:13:20Z Verdict: quoted answer\n\nWhich one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md, ~/.claude/CLAUDE.md, ~/.claude/rules/ or ~/.claude/skills/larv-review/standards/ says:\n> Use *A*.\n\nEvidence:\n> working\n\nJudge: judge-model\n" - self.assertEqual(self.archived_outcomes(), [f"Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: interrupt\n\nWhich one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md, ~/.claude/CLAUDE.md, ~/.claude/rules/ or ~/.claude/skills/larv-review/standards/ says:\nUse *A*.\n\nThose files have answered 3 questions this cycle, the most allowed, so this one comes to you.\n\nEvidence:\n> working\n\nJudge: judge-model\n\n2026-09-21T14:13:20Z Stopped: the human is needed to answer the question above, but the interrupt ended with nothing typed\n\nWorker: worker-model\n", *[f"Task: Do it.\n\n{quoted}"] * 3]) + self.assertEqual(self.archived_outcomes(), [f"Task: Do it.\n\n2026-09-21T14:13:20Z Verdict: interrupt\n\nWhich one?\n\nREADME.md's Goals and Audience, AGENTS.md, docs/decisions.md, ~/.claude/CLAUDE.md, ~/.claude/rules/ or ~/.claude/skills/larv-review/standards/ says:\nUse *A*.\n\nThose files have answered 3 questions this cycle, the most allowed, so this one comes to you.\n\nEvidence:\n> working\n\nJudge: judge-model\nWorker: worker-model\n\n2026-09-21T14:13:20Z Stopped: the human is needed to answer the question above, but the interrupt ended with nothing typed\n\nWorker: worker-model\n", *[f"Task: Do it.\n\n{quoted}"] * 3]) def test_stops_when_a_quoted_answer_cannot_be_archived(self): self.archive.parent.mkdir(parents=True) @@ -645,6 +645,17 @@ class Routing(unittest.TestCase): self.assertEqual(routing.stepped(self.OPUS, Route(self.XHIGH), 0, True), Route(self.XHIGH, unfinished=1)) self.assertEqual(routing.stepped(self.OPUS, Route(self.SONNET, 3, 2, 4), 4, True), Route(self.HIGH, 3, 2, 4, unfinished=1)) + def test_steps_up_a_rung_as_the_judge_interrupts_up_to_two_above_the_items_rung_without_counting_an_unfinished_verdict(self): + self.assertEqual(routing.stepped_by_interrupt(self.OPUS, Route(self.HIGH, 3, 4, 5, unfinished=1), 0), Route(self.XHIGH, 3, 4, 5)) + self.assertEqual(routing.stepped_by_interrupt(self.OPUS, Route(self.XHIGH, 3, 4, 5), 0), Route(self.MAX, 3, 4, 5)) + self.assertEqual(routing.stepped_by_interrupt(self.OPUS, Route(self.MAX, 3, 4, 5, unfinished=1), 0), Route(self.MAX, 3, 4, 5, unfinished=1)) + self.assertEqual(routing.stepped_by_interrupt(self.OPUS, Route(self.SONNET, 3, 2, 4), 0), Route(self.OPUS, 3, 2, 4)) + + def test_steps_up_from_the_rung_a_taken_in_item_picks_as_the_judge_interrupts(self): + self.assertEqual(routing.stepped_by_interrupt(self.OPUS, Route(self.OPUS, 3, 3, 4), 4), Route(self.XHIGH, 3, 3, 4)) + self.assertEqual(routing.stepped_by_interrupt(self.OPUS, Route(self.XHIGH, 3, 4, 5), 4), Route(self.MAX, 3, 4, 5)) + self.assertEqual(routing.stepped_by_interrupt(self.OPUS, Route(self.MAX, 3, 4, 5, unfinished=1), 4), Route(self.MAX, 3, 4, 5, unfinished=1)) + def test_keeps_an_e_plus_i_taken_in_only_where_it_picks_a_higher_review_rung(self): taken = Route(self.OPUS, 3, 3, 4).taking_in(6) self.assertEqual(taken, Route(self.OPUS, 3, 3, 4, escape_and_impact_taken_in=6)) @@ -1074,6 +1085,27 @@ class Verdict(unittest.TestCase): self.assertEqual(verdict_from({**reply, "finished": True}), Finished("e")) self.assertEqual(verdict_from({**reply, "escalation": None}), Failure("the judge's reply has no escalation of type string")) + def test_takes_an_escalation_quote_on_an_interrupt(self): + reply = {"answer": "", "bundled": 0, "bundled_escape_and_impact": 0, "escalation": "round 2: 🔴", "interrupt": True, "evidence": "e", "finished": False, "question": "Which one?"} + self.assertEqual(verdict_from(reply), Interrupt("e", "Which one?", "round 2: 🔴")) + self.assertEqual(verdict_from({**reply, "bundled": 4}), Interrupt("e", "Which one?", "round 2: 🔴", 4)) + self.assertEqual(verdict_from({**reply, "bundled": 5}), Interrupt("e", "Which one?", "round 2: 🔴")) + + def test_drops_an_escalation_quote_the_transcript_does_not_hold_word_for_word_from_an_interrupt_or_an_unfinished_verdict(self): + shown = "The agent: round 2: 🔴. Which one?" + self.assertEqual(judge.quotes_checked(Interrupt("e", "q", "round 2: 🔴"), shown, ""), Interrupt("e", "q", "round 2: 🔴")) + self.assertEqual(judge.quotes_checked(Interrupt("e", "q", "round 2: … 🔴"), shown, ""), Interrupt("e", "q")) + self.assertEqual(judge.quotes_checked(Unfinished("e", 0, "round 3: 🔴"), shown, ""), Unfinished("e")) + + def test_puts_a_quoted_answer_the_records_do_not_hold_word_for_word_to_the_human(self): + self.assertEqual(judge.quotes_checked(QuotedAnswer("e", "q", "not there"), "shown", "the records"), Interrupt("e", "q")) + self.assertEqual(judge.quotes_checked(QuotedAnswer("e", "q", "the records"), "shown", "From the records: the records"), QuotedAnswer("e", "q", "the records")) + + def test_drops_an_escalation_from_every_ruling_of_a_cycle_once_an_interrupt_took_one(self): + self.assertEqual(run.unspent(Unfinished("e", 0, "round 2: 🔴"), True), Unfinished("e")) + self.assertEqual(run.unspent(Interrupt("e", "q", "another passage"), True), Interrupt("e", "q")) + self.assertEqual(run.unspent(Unfinished("e", 0, "round 2: 🔴"), False), Unfinished("e", 0, "round 2: 🔴")) + class LoopRuns(unittest.TestCase): def test_stops_naming_the_reload_when_it_hands_over_anything_but_the_state_with_a_task(self): diff --git a/bin/routing_figures/test_routing_figures.py b/bin/routing_figures/test_routing_figures.py index f6bd0bba..d7ef8e85 100644 --- a/bin/routing_figures/test_routing_figures.py +++ b/bin/routing_figures/test_routing_figures.py @@ -191,7 +191,7 @@ class Archive(unittest.TestCase): def test_counts_the_verdicts_across_every_projects_chunks(self): self.chunk("home/x", "c1", stamped("2026-10-14T10:00:00Z", outcomes.unfinished("w", "e", "j", "")) + stamped("2026-10-14T10:01:00Z", outcomes.stopped("w", "Ctrl-C")) + stamped("2026-10-14T10:02:00Z", outcomes.finished("w", "e", "j")), []) - self.chunk("log", "c2", stamped("2026-10-14T10:00:00Z", outcomes.interrupted("q", "e", "j")), []) + self.chunk("log", "c2", stamped("2026-10-14T10:00:00Z", outcomes.interrupted("q", "e", "j", "", "w")), []) self.assertEqual(archive.cycles(self.root), 2) self.assertEqual(archive.cycles(self.root / "missing"), 0) diff --git a/bin/transcript_archive/outcomes.py b/bin/transcript_archive/outcomes.py index d987f9da..fa5811ef 100644 --- a/bin/transcript_archive/outcomes.py +++ b/bin/transcript_archive/outcomes.py @@ -16,9 +16,9 @@ FINISHED_AT = re.compile(rf"^({STAMPED}) {re.escape(FINISHED)}$", re.MULTILINE) UNFINISHED_AT = re.compile(rf"^{STAMPED} {re.escape(UNFINISHED)}$", re.MULTILINE) # A verdict closes each cycle the judge ruled on; an interrupt or a stop closes none. VERDICT_AT = re.compile(rf"^{STAMPED} (?:{re.escape(FINISHED)}|{re.escape(UNFINISHED)})$", re.MULTILINE) -# An outcome opens with its UTC stamp; a verdict that closes a cycle, a stop, or a step up ends with the worker line. +# An outcome opens with its UTC stamp; a verdict that closes a cycle, an interrupt, a stop, or a step up ends with the worker line. OUTCOME_AT = re.compile(rf"^({STAMPED}) ", re.MULTILINE) -NAMES_A_WORKER = ("Verdict: finished\n", "Verdict: unfinished\n", "Stopped: ", "Stepped up\n") +NAMES_A_WORKER = ("Verdict: finished\n", "Verdict: unfinished\n", "Verdict: interrupt\n", "Stopped: ", "Stepped up\n") WORKER = "Worker: " # The rung that judged a verdict. JUDGE = "Judge: " @@ -34,8 +34,10 @@ def unfinished(worker: str, evidence: str, judge: str, escalation: str) -> str: return f"{UNFINISHED}\n\nEvidence:\n{quoted(evidence)}\n\n{escalated}{JUDGE}{judge}\n{WORKER}{worker}" -def interrupted(question: str, evidence: str, judge: str) -> str: - return f"{INTERRUPTED}\n\n{question}\n\nEvidence:\n{quoted(evidence)}\n\n{JUDGE}{judge}" +def interrupted(question: str, evidence: str, judge: str, escalation: str, worker: str) -> str: + """escalation is the judge's quote showing that the worker's cited escalation trigger fired; empty for none. worker is the rung the worker ran on until the interrupt.""" + escalated = f"Escalation:\n{quoted(escalation)}\n\n" if escalation else "" + return f"{INTERRUPTED}\n\n{question}\n\nEvidence:\n{quoted(evidence)}\n\n{escalated}{JUDGE}{judge}\n{WORKER}{worker}" def answered(question: str, sources: str, answer: str, evidence: str, judge: str) -> str: diff --git a/bin/transcript_archive/test_transcript_archive.py b/bin/transcript_archive/test_transcript_archive.py index cbc776e4..2f09f32c 100644 --- a/bin/transcript_archive/test_transcript_archive.py +++ b/bin/transcript_archive/test_transcript_archive.py @@ -47,19 +47,23 @@ class Outcomes(unittest.TestCase): def test_the_archive_stamps_what_it_reads_back(self): self.assertRegex(f"{utc(NOW)} {outcomes.finished('m', 'merged', 'j')}", outcomes.FINISHED_AT) - def test_reads_back_the_worker_of_each_outcome_that_closes_a_cycle(self): + def test_reads_back_the_worker_of_each_outcome_that_names_one(self): kept = "Task: Do it.\n\n" + "\n".join(f"{utc(NOW + offset)} {outcome}\n" for offset, outcome in enumerate([ outcomes.unfinished("w1", "Worker: not this", "j", ""), - outcomes.interrupted("Which one?\nWorker: nor this", "e", "j"), + outcomes.interrupted("Which one?\nWorker: nor this", "e", "j", "", "w1b"), outcomes.stopped("w2", "the judge failed\nthree times"), outcomes.finished("w3", "merged", "j"), ])) - self.assertEqual(outcomes.workers(kept), [(utc(NOW), "w1"), (utc(NOW + 2), "w2"), (utc(NOW + 3), "w3")]) + self.assertEqual(outcomes.workers(kept), [(utc(NOW), "w1"), (utc(NOW + 1), "w1b"), (utc(NOW + 2), "w2"), (utc(NOW + 3), "w3")]) def test_archives_the_escalation_an_unfinished_verdict_quotes_beside_its_evidence(self): self.assertEqual(outcomes.unfinished("w", "e", "j", "round 2: 🔴"), "Verdict: unfinished\n\nEvidence:\n> e\n\nEscalation:\n> round 2: 🔴\n\nJudge: j\nWorker: w") self.assertEqual(outcomes.unfinished("w", "e", "j", ""), "Verdict: unfinished\n\nEvidence:\n> e\n\nJudge: j\nWorker: w") + def test_archives_the_escalation_an_interrupt_quotes_beside_its_evidence(self): + self.assertEqual(outcomes.interrupted("q?", "e", "j", "round 2: 🔴", "w"), "Verdict: interrupt\n\nq?\n\nEvidence:\n> e\n\nEscalation:\n> round 2: 🔴\n\nJudge: j\nWorker: w") + self.assertEqual(outcomes.interrupted("q?", "e", "j", "", "w"), "Verdict: interrupt\n\nq?\n\nEvidence:\n> e\n\nJudge: j\nWorker: w") + def test_reads_no_worker_from_an_outcome_written_before_the_worker_line(self): kept = f"Task: Do it.\n\n{utc(NOW)} Stopped: Ctrl-C\n\n{utc(NOW)} Verdict: unfinished\n\nEvidence:\n> Worker: no\n" self.assertEqual(outcomes.workers(kept), []) diff --git a/docs/decisions.md b/docs/decisions.md index a8cd4802..fb1e291b 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -284,15 +284,17 @@ loop-claude's prompt names the rungs a trigger opens, so the worker computes no Valid while the ladder orders its rungs by competence. -## routing: a worker whose run ends asking for a higher rung, citing an escalation trigger the judge finds in the transcript, resumes one rung up next cycle, up to two rungs above the rung its item picks +## routing: a worker whose run ends asking for a higher rung, citing an escalation trigger the judge finds in the transcript, steps one rung up as the judge interrupts or next cycle, up to two rungs above the rung its item picks 2026-10-15, lilleman asked for it. Serves goals 1.1 and 1.4: when the hard part is the rest of the chunk, handing it to subagents piece by piece leaves the worker, which reads and checks each of their diffs, on a rung that proved too low. The worker climbs only once its run records a trigger. loop-claude's prompt offers the step beside the escalated subagent of `routing: a worker hands a task one rung up`, as long as the limit leaves a rung that subagent may take without the human's yes. The worker then ends its run asking loop-claude for a higher rung and naming the trigger. The judge quotes an earlier passage that shows the trigger fired, such as a review round's commit title or the worker's report of the failing test, never the request itself. The trigger must have fired since any earlier such request, so one trigger buys one step. The judge sees the worker's text and tool calls but no tool results, so the quote shows that the run recorded the trigger, not that a tool's output bears it out. loop-claude checks the quote word for word, as it checks a quoted answer, since stitched fragments can make up a trigger. Without such a quote, the rung holds. A misquote is no failure, since holding the rung is safe and three failures stop an unattended loop. The next prompt names the worker's rung, so the worker learns whether the step went through. +A run that asks for a higher rung may also ask the human something only they can answer. The judge then interrupts, and the interrupt carries the quote too, checked the same way. loop-claude steps the rung as the interrupt comes in, before the human is asked, since the human's answer is followed by work the stepped rung should do: in the session the interrupt opens, and in whatever run resumes with the answer. An interrupt is no unfinished verdict, so it adds to no count. The judge may quote a different passage for the trigger that already stepped the rung, and loop-claude cannot tell that from a new trigger. So once an interrupt has taken an escalation, no later ruling of that cycle carries one. A trigger that fires after the human's answer waits for the next cycle. + The step is one rung up from the rung the worker would otherwise hold: its own, or the rung an item the judge saw it take in picks, whichever is higher. It resets the count of unfinished verdicts, so the step every second one takes counts afresh; when both steps fall on one verdict, the worker steps once. It stops at the limit escalated subagents stop at, two rungs above the rung the chunk started on. Past that limit the rung holds: loop-claude takes no yes from the human between cycles, so a worker there asks the human for an escalated subagent instead. The judge keeps its rung, as `routing: on a model judge-replay covered` says. -The archive quotes the judge's passage under `Escalation:` in the unfinished verdict, beside any step-up it causes. `bin/routing_figures/` counts that verdict as unfinished, not as an escalation by trigger, which it counts only from subagent prompts. +The archive quotes the judge's passage under `Escalation:` in the unfinished verdict or the interrupt. The step an unfinished verdict causes is archived after it. The step an interrupt causes is archived with it, at once: the interrupt names the rung the worker ran on until then, and a step-up archived beside it names the rung it runs on from then. So the routing figures charge each stretch to its own rung, and a loop that dies while the human answers resumes on the stepped rung. `bin/routing_figures/` counts neither as an escalation by trigger, which it counts only from subagent prompts. Valid while the worker reports in its transcript the triggers that fired. diff --git a/docs/reading-cost.md b/docs/reading-cost.md index 7a1a172e..f31e1933 100644 --- a/docs/reading-cost.md +++ b/docs/reading-cost.md @@ -620,3 +620,7 @@ Read most (opens and searches): - `bin/loop_claude/routing.py` 2 - `bin/markdown_text.py` 2 - `bin/todo_table.py` 2 + +## Reading cost, chunk 819681d5ebae, finished 2026-10-17T19:47:42Z + +98148 new input tokens before the first commit. diff --git a/todo.md b/todo.md index 6bc84cf4..baaee3a0 100644 --- a/todo.md +++ b/todo.md @@ -6,13 +6,13 @@ `Bar = 0.1` -`Next ID = 179` +`Next ID = 180` ## Items | ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score | |---|---|---|---|---|---|---|---|---|---|---|---| -| 178 | 0.2.0 | | defect | **Step the worker one rung up as the judge interrupts, when the interrupted run also asked loop-claude for a higher rung and the judge finds the escalation trigger that run cites.** | 2 | 2 | 2 | 4 | 4 | 1.3 by 3, 1.1 by 3 | 8.2 | +| 179 | 0.2.0 | | defect | **Step the worker one rung up when the judge quotes an answer from the README or the records and the run also cites an escalation trigger, as it does on an interrupt.** | 2 | 2 | 3 | 5 | 4 | 1.3 by 3, 1.1 by 2 | 7.3 | | 168 | 0.2.0 | | | **Have the human answer an interrupt on loop-claude's terminal and resume the worker headless with the answer, opening the interactive session only when they ask for it.** | 4 | 2 | 3 | 7 | 5 | 1.5 by 8 | 1.8 | | 73 | 0.2.0 | | | **Have each reviewer write its full report to a file and return the worker only its findings' one-line summaries.** | 3 | 2 | 3 | 6 | 5 | 1.4 by 4 | 1.1 | | 159 | 0.2.0 | | decision | **Run each review pass on the lowest rung that a replay of its archived rounds shows finding every 🔴 and 🟡 the project's rung finds, even below the worker's rung.** | 4 | 2 | 3 | 7 | 6 | 1.4 by 7 | 1.1 | @@ -84,13 +84,9 @@ ## Details -### 178. Step the worker one rung up as the judge interrupts, when the interrupted run also asked loop-claude for a higher rung and the judge finds the escalation trigger that run cites. +### 179. Step the worker one rung up when the judge quotes an answer from the README or the records and the run also cites an escalation trigger, as it does on an interrupt. -A defect against goal 1.3, the same rules in every session: the escalation rule (`docs/decisions.md` → `routing: a worker whose run ends asking for a higher rung…`) does not hold when the run that asks for a higher rung also asks the human something only they can answer. Only an `Unfinished` verdict carries an escalation, the judge's quote of the trigger the worker cites (`bin/loop_claude/cycle/judge.py`), and only `after_verdict` (`bin/loop_claude/loop/main.py`) calls `stepped`, on an unfinished verdict. An interrupt carries none, so `bin/loop_claude/cycle/run.py` opens the interrupt on the worker's current rung, and the step-up is lost. The worker cannot ask again: a step-up needs a trigger that fired since its last request. - -Have the judge's interrupt carry an escalation, checked word for word as on `Unfinished`. Step the worker's rung up as the judge's interrupt comes in, before the human is asked. The worker then carries on from the answer on the stepped rung. Today that is in the interactive session the interrupt opens. Once item 168 lands, it is the headless run that resumes with the answer, or the session `/talk` opens. The step obeys the decision's limits: one rung, at most two above the item's rung, and one step per trigger, so the verdict the judge gives after the interrupt does not step again on the same quote. An interrupt does not count as an unfinished verdict. The change touches two places the comprehension seats found hard, `routing.py`'s `stepped` and `judge.py`'s `run_judge`. Leave each easier to read. - -It happened in item 84's chunk on 2026-10-17. The worker, on Sonnet 5.5 at high, ended its run asking loop-claude for a higher rung. It cited trigger 4: the architect's BLOCK, which stood after the architect's rerun one rung up. In the same run it asked the human about a cost, and the judge ruled interrupt. After the human's answer, the worker did the redesign the BLOCK asked for in the interactive session on Sonnet 5.5 at high, one rung below the Opus 5.5 at medium the step would have given. +A defect against goal 1.3, the same rules in every session, and a sibling of the interrupt case the previous chunk fixed (`docs/decisions.md` → `routing: a worker whose run ends asking for a higher rung…`). `verdict_from` in `bin/loop_claude/cycle/judge.py` builds a `QuotedAnswer` without the reply's `escalation`, so a run that asks a question the README or the records answer, and also asks loop-claude for a higher rung, loses the step: the worker resumes with the quoted answer in the same cycle on its old rung, and cannot ask again because a step-up needs a trigger that fired since its last request. Have `QuotedAnswer` carry the escalation and the bundled L, check it word for word as on an interrupt, and step the route as the answer is quoted, before the worker resumes (`bin/loop_claude/cycle/run.py` `escalated`). The same limits hold: one rung, at most two above the item's rung, one step per trigger per cycle, and the step is archived with the quoted-answer outcome as an interrupt's is. Found by the stability review of PR #305. ### 168. Have the human answer an interrupt on loop-claude's terminal and resume the worker headless with the answer, opening the interactive session only when they ask for it.