Answer the fourth round: a repeated question goes to the human, three records answers a cycle as the backstop, the quote in the interrupt, the cycle redefined

This commit is contained in:
2026-10-03 01:32:22 +02:00
parent 387c22087c
commit 1839c8a19e
9 changed files with 46 additions and 35 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ JUDGE_RULES = (
"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 project's records; a question it answered "
"is no longer open.\n"
"is no longer open, unless the agent asks it again: then it is the human's, with answer empty.\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"
"Where README.md or the project's records answer that question, quote the passage that answers it "
+1 -1
View File
@@ -52,7 +52,7 @@ def stopped(cycle: Cycle, stop: Stop, why: str) -> Stop:
def step(cycle: Cycle, state: Active) -> Event | Stop:
match state:
case Working(answer):
case Working(answer, _):
return work(cycle, answer)
case Judging(transcript_path, _):
return rule(cycle, transcript_path)
+17 -14
View File
@@ -2,25 +2,29 @@ import dataclasses
from loop_claude.cycle.verdicts import AnsweredFromRecords, Finished, Interrupt, Unfinished, Verdict
# A backstop, so a worker the records' answers do not satisfy cannot loop unattended; the judge sends a repeated question to the human.
RECORDS_ANSWERS_PER_CYCLE = 3
@dataclasses.dataclass(frozen=True)
class Working:
"""The worker runs, resumed with the records' answer when there is one."""
answer: str | None = None
records_answers: int = 0
@dataclasses.dataclass(frozen=True)
class Judging:
"""The judge rules; answered_from_records holds once the records answered a question this cycle."""
"""The judge rules; records_answers counts the questions the records answered this cycle."""
transcript_path: str
answered_from_records: bool = False
records_answers: int = 0
@dataclasses.dataclass(frozen=True)
class Interrupting:
transcript_path: str
question: str
answered_from_records: bool = False
records_answers: int = 0
@dataclasses.dataclass(frozen=True)
@@ -63,20 +67,19 @@ Event = WorkerRan | Ruled | HumanAnswered | Archived
def transition(state: State, event: Event) -> State:
match state, event:
case Working(answer), WorkerRan(transcript_path):
return Judging(transcript_path, answer is not None)
case Judging(_, False), Ruled(AnsweredFromRecords(answer=answer)):
return Working(answer)
# One records answer per cycle, so a worker the answer did not satisfy cannot loop unattended.
case Judging(transcript_path, True), Ruled(AnsweredFromRecords(question=question)):
return Interrupting(transcript_path, question, True)
case Judging(transcript_path, answered_from_records), Ruled(Interrupt(question=question)):
return Interrupting(transcript_path, question, answered_from_records)
case Working(_, records_answers), WorkerRan(transcript_path):
return Judging(transcript_path, records_answers)
case Judging(_, records_answers), Ruled(AnsweredFromRecords(answer=answer)) if records_answers < RECORDS_ANSWERS_PER_CYCLE:
return Working(answer, records_answers + 1)
case Judging(transcript_path, records_answers), Ruled(AnsweredFromRecords(question=question, answer=answer)):
return Interrupting(transcript_path, f"{question}\n\nREADME.md or the project's records say:\n{answer}", records_answers)
case Judging(transcript_path, records_answers), Ruled(Interrupt(question=question)):
return Interrupting(transcript_path, question, records_answers)
case Judging(transcript_path, _), Ruled(Finished() | Unfinished() as verdict):
return Closing(transcript_path, verdict)
# The human works in the interrupt's claude session, so the judge rules again on the transcript it leaves.
case Interrupting(transcript_path, _, answered_from_records), HumanAnswered():
return Judging(transcript_path, answered_from_records)
case Interrupting(transcript_path, _, records_answers), HumanAnswered():
return Judging(transcript_path, records_answers)
case Closing(), Archived():
return Ended()
raise ValueError(f"no transition from {state} on {event}")
+2 -2
View File
@@ -7,8 +7,8 @@ premises; the task runs at the checkout root. Each cycle a worker runs the task;
the transcript's last 400,000 characters against the premises and the project's records, AGENTS.md
and docs/decisions.md where they exist, and rules whether the chunk, the work of one PR, is finished.
A choice the worker made that the premises or the records settle is not asked about. When the worker
asks a question they answer, the judge quotes the answer and the worker resumes with it; the
worker's next question in the cycle goes to the human.
asks a question they answer, the judge quotes the answer and the worker resumes with it, up to three
times a cycle; a question asked again after its answer, or a fourth, goes to the human.
A question only the human can answer, or a release ready to cut, is an interrupt: `claude --resume`
on the terminal, every worktree first marked trusted in ~/.claude.json. An unfinished chunk resumes
its session next cycle; the next chunk starts a fresh session.
+16 -13
View File
@@ -127,26 +127,28 @@ class Streamed:
class Transitions(unittest.TestCase):
def test_each_state_moves_on_its_events_and_only_on_them(self):
answered = states.Ruled(AnsweredFromRecords("e", "Which one?", "A."))
legal = (
(states.Working(), states.WorkerRan("/t"), states.Judging("/t")),
(states.Working("A."), states.WorkerRan("/t"), states.Judging("/t", True)),
(states.Working("A.", 3), states.WorkerRan("/t"), states.Judging("/t", 3)),
(states.Judging("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?")),
(states.Judging("/t", True), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", True)),
(states.Judging("/t"), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Working("A.")),
(states.Judging("/t", True), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Interrupting("/t", "Which one?", True)),
(states.Judging("/t", True), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
(states.Judging("/t", True), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
(states.Judging("/t", 3), states.Ruled(Interrupt("e", "Which one?")), states.Interrupting("/t", "Which one?", 3)),
(states.Judging("/t"), answered, states.Working("A.", 1)),
(states.Judging("/t", 2), answered, states.Working("A.", 3)),
(states.Judging("/t", 3), answered, states.Interrupting("/t", "Which one?\n\nREADME.md or the project's records say:\nA.", 3)),
(states.Judging("/t"), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
(states.Judging("/t", 3), states.Ruled(Finished("e")), states.Closing("/t", Finished("e"))),
(states.Judging("/t"), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
(states.Judging("/t", 3), states.Ruled(Unfinished("e")), states.Closing("/t", Unfinished("e"))),
(states.Interrupting("/t", "q"), states.HumanAnswered(), states.Judging("/t")),
(states.Interrupting("/t", "q", True), states.HumanAnswered(), states.Judging("/t", True)),
(states.Interrupting("/t", "q", 3), states.HumanAnswered(), states.Judging("/t", 3)),
(states.Closing("/t", Finished("e")), states.Archived(), states.Ended()),
)
for state, event, after in legal:
with self.subTest(state=state, event=event):
self.assertEqual(states.transition(state, event), after)
every_state = (states.Working(), states.Working("A."), states.Judging("/t"), states.Judging("/t", True), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", True), states.Closing("/t", Finished("e")), states.Ended())
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), states.Ruled(AnsweredFromRecords("e", "Which one?", "A.")), states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived())
every_state = (states.Working(), states.Working("A.", 3), states.Judging("/t"), states.Judging("/t", 3), states.Interrupting("/t", "q"), states.Interrupting("/t", "q", 3), states.Closing("/t", Finished("e")), states.Ended())
every_event = (states.WorkerRan("/t"), states.Ruled(Interrupt("e", "Which one?")), answered, states.Ruled(Finished("e")), states.Ruled(Unfinished("e")), states.HumanAnswered(), states.Archived())
for state in every_state:
for event in every_event:
if (state, event) not in [(state, event) for state, event, _ in legal]:
@@ -242,14 +244,15 @@ class Cycles(unittest.TestCase):
self.assertNotIn("the second", prompts[0])
self.assertIn("[human] the second", prompts[1])
def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_once_per_cycle(self):
def test_a_question_the_records_answer_resumes_the_worker_with_the_answer_three_times_a_cycle(self):
answered = judged("interrupt", answer="Use *A*.")
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 2, claude=[answered, answered, judged("unfinished")], on_terminal_claude=[0], git=[ran()])
with contextlib.redirect_stderr(io.StringIO()):
fake = FakeEffects(streams=[Worker(self.paths.claude_code_transcripts.parent)] * 4, claude=[answered] * 4, on_terminal_claude=[0], git=[ran()])
with contextlib.redirect_stderr(io.StringIO()) as said:
self.assertEqual(run.run_cycle(self.cycle(fake, records="From AGENTS.md:\nUse A.")), Stop(2, "the human is needed to answer the question above, but the interrupt ended with nothing typed"))
resumed = fake.made("stream_claude")[1]
self.assertEqual(resumed[resumed.index("-p") + 1], "README.md or the project's records answer your question:\n\nUse *A*.\n\nContinue the task.")
self.assertEqual(len(fake.made("claude_on_terminal")), 1)
self.assertEqual(len(fake.made("stream_claude")), 4)
self.assertIn("Which one?\n\nREADME.md or the project's records say:\nUse *A*.", said.getvalue())
def test_the_judge_fails_on_an_answer_the_records_do_not_hold(self):
invented = judged("interrupt", answer="Use B.")