Resume a worker one rung up next cycle when it ends its run asking for a higher rung and the judge finds the escalation trigger it cites

This commit is contained in:
2026-10-15 21:55:11 +02:00
parent ddb86cb7ec
commit 501fc8c606
16 changed files with 154 additions and 75 deletions
+16 -5
View File
@@ -32,20 +32,24 @@ JUDGE_RULES = (
"interrupt=false otherwise. Bookkeeping the agent settled silently - what to document, wording, "
"where a note goes - is not on its own a reason to interrupt. The human may have replied inside the transcript, on a [human] line: judge only what "
"is still open, never a question they already answered there. A [loop] line is what loop-claude told "
"the agent, such as an answer quoted from README.md or the records.\n"
"the agent, such as an answer quoted from README.md or the records.\n\n"
"Where the agent asked or flagged something itself, the question is that one, in the agent's own "
"wording; never construct another from facts it stated.\n"
"wording; never construct another from facts it stated.\n\n"
"Where README.md or the records answer the agent's own question and no [loop] line has "
"quoted that answer yet, set interrupt=false and quote the passage that answers it; the agent is "
"then given that passage in place of the human's reply. An interrupt outranks a quoted answer, and either "
"outranks finished.\n"
"outranks finished.\n\n"
"The chunk is the piece of work the agent is on, shipped as one pull request. "
"finished=true when the chunk is complete: merged, or nothing remains that the agent could do on "
f"its own. Even then, it is finished only once {ANSWERS_RECORDED}. An answer counts as recorded "
f"where README.md or the records above hold it, {', '.join(HUMAN_RULE_NAMES)} included. It also counts where "
f"the transcript shows the agent writing it into {ANSWER_DESTINATIONS}; writing it into "
f"{either(HUMAN_RULE_NAMES)} does not count. finished=false when work remains that a further run can "
"continue: an open PR, a review not yet run, CI not yet reported, an answer not yet recorded."
"continue: an open PR, a review not yet run, CI not yet reported, an answer not yet recorded.\n\n"
"The agent may end its run asking for a higher rung, citing an escalation trigger that ~/.claude/CLAUDE.md lists. "
"That request is for loop-claude, not a question for the human. Where the chunk is unfinished, quote in "
"escalation the passage that shows the trigger fired, such as the finding or the failing test. Leave "
"escalation empty where the agent asks for no higher rung, or where only its own claim shows the trigger."
)
@@ -54,6 +58,8 @@ class Reply:
answer: str = dataclasses.field(metadata={"description": "With interrupt false, the passage of README.md or the records that answers the agent's question, quoted verbatim, without elisions. Empty otherwise."})
# Routes the next cycle's worker. Counting the item the chunk was routed on is harmless: loop-claude never steps the worker down.
bundled: int = dataclasses.field(metadata={"description": "The highest R + C 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 that ends its run asking for a higher rung`.
escalation: str = dataclasses.field(metadata={"description": "Where the chunk is unfinished and the agent's run ends asking for a higher rung, citing an escalation trigger: a verbatim quote, without elisions, of the transcript passage that shows that trigger fired, other than the agent's own claim. Empty otherwise."})
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."})
@@ -94,6 +100,8 @@ class Unfinished:
evidence: str
# The bundled R + C the judge saw, 0 for none.
bundled: int = 0
# The passage that shows the escalation trigger the worker cited fired, empty for none.
escalation: str = ""
Verdict = Interrupt | QuotedAnswer | Finished | Unfinished
@@ -118,7 +126,7 @@ def verdict_from(output: object) -> Verdict | Failure:
return Finished(output["evidence"])
if not 0 <= output["bundled"] <= HIGHEST_R_PLUS_C:
return Failure(f"the judge's bundled R + C {output['bundled']} is not from 0 to {HIGHEST_R_PLUS_C}")
return Unfinished(output["evidence"], output["bundled"])
return Unfinished(output["evidence"], output["bundled"], output["escalation"])
def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects) -> Verdict | Stop:
@@ -153,6 +161,9 @@ def run_judge(root: str, args: list[str], prompt: str, shown: str, quotable: str
# Not a Failure: a misquote would otherwise exit an unattended loop. Never elided: stitched fragments can say what the records do not.
if isinstance(verdict, QuotedAnswer) and not verbatim(verdict.answer, quotable):
return Interrupt(verdict.evidence, verdict.question)
# Not a Failure either: the worker's rung then holds, which is safe.
if isinstance(verdict, Unfinished) and verdict.escalation and not grounded(verdict.escalation, shown):
return dataclasses.replace(verdict, escalation="")
return verdict