Archive each judge reply the loop rejects, with why and the reply

This commit is contained in:
2026-10-16 23:11:29 +02:00
parent 5747d2792a
commit 23dac2c1d1
9 changed files with 68 additions and 16 deletions
+11 -4
View File
@@ -74,6 +74,12 @@ JUDGE_SCHEMA = {
}
@dataclasses.dataclass(frozen=True)
class Rejected(Failure):
"""The judge replied, and loop-claude refused the reply for the reason; reply is what the judge returned, as json."""
reply: str
@dataclasses.dataclass(frozen=True)
class Interrupt:
evidence: str
@@ -127,8 +133,9 @@ def verdict_from(output: object) -> Verdict | Failure:
return Unfinished(output["evidence"], bundled, output["escalation"])
def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects) -> Verdict | Stop:
return retried("judge", lambda: judge_once(root, task, premises, records, rendered_transcript, rung, effects), effects)
def judge(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects, keep: typing.Callable[[Failure], Stop | None]) -> Verdict | Stop:
"""keep sees each failure of a judge run, such as a Rejected reply, before the retry."""
return retried("judge", lambda: judge_once(root, task, premises, records, rendered_transcript, rung, effects), effects, keep)
def judge_once(root: str, task: str, premises: str, records: str, rendered_transcript: str, rung: Rung, effects: Effects) -> Verdict | Failure | Limited:
@@ -159,9 +166,9 @@ def run_judge(root: str, args: list[str], prompt: str, shown: str, quotable: str
return reply
verdict = verdict_from(structured_output(reply))
if isinstance(verdict, Failure):
return Failure(f"{verdict.reason}; it replied: {json.dumps(reply, ensure_ascii=False)}")
return Rejected(verdict.reason, json.dumps(reply, ensure_ascii=False))
if not grounded(verdict.evidence, shown):
return Failure(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 ""))
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 ""), json.dumps(reply, ensure_ascii=False))
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):