Stop the judge rather than show it under 50,000 characters of the transcript, read a twice-named record once, test the forge timeout and decide the merge stop from the pull requests found
This commit is contained in:
@@ -20,6 +20,8 @@ from claude_code.tokens import tokens_of
|
||||
|
||||
# At 3 to 4 characters a token, 100,000 to 133,000 tokens, which leaves a 200,000-token context room for the reply; the largest session rendered here was 364,000 characters on 2026-10-03.
|
||||
JUDGE_PROMPT_CHARS = 400000
|
||||
# The least of the transcript's tail the judge reads, about 15,000 tokens. Where the head leaves less, the judge stops, since a cut record could hide the rule that makes it interrupt.
|
||||
TRANSCRIPT_FLOOR = 50000
|
||||
INTERRUPT_RULES = (
|
||||
"""Decide whether the human must now be interrupted. ~/.claude/CLAUDE.md → "Working loop", "Ask, don't guess" says """
|
||||
"which choices are reserved for the human. interrupt=true when any of these appear:\n"
|
||||
@@ -186,7 +188,10 @@ def judge(root: str, brief: Brief, rung: Rung, effects: Effects, keep: typing.Ca
|
||||
|
||||
def judge_once(root: str, brief: Brief, rung: Rung, effects: Effects) -> Verdict | Failure | Limited:
|
||||
"""One judge run on the brief, as judge retries it; judge-replay replays it."""
|
||||
prompt, grounds = judge_prompt(brief)
|
||||
built = judge_prompt(brief)
|
||||
if isinstance(built, Failure):
|
||||
return built
|
||||
prompt, grounds = built
|
||||
verdict = run_judge(root, judge_args(rung, brief.driver), prompt, grounds, effects)
|
||||
return verdict if isinstance(verdict, Failure | Limited) else escalation_mark.stamped(verdict, len(brief.entries))
|
||||
|
||||
@@ -292,8 +297,8 @@ def answer_checked(verdict: Verdict, quotable: str) -> Verdict:
|
||||
return verdict
|
||||
|
||||
|
||||
def judge_prompt(brief: Brief) -> tuple[str, Grounds]:
|
||||
"""The prompt, and what the judge's quotes are checked against."""
|
||||
def judge_prompt(brief: Brief) -> tuple[str, Grounds] | Failure:
|
||||
"""The prompt, and what the judge's quotes are checked against; a Failure where the rest leaves less of the transcript's tail than TRANSCRIPT_FLOOR."""
|
||||
head = (
|
||||
f"From the goals file, {brief.premises}\n\n"
|
||||
f"The records: {brief.records_named}:\n{brief.records or 'none'}\n\n"
|
||||
@@ -303,6 +308,8 @@ def judge_prompt(brief: Brief) -> tuple[str, Grounds]:
|
||||
rules = judge_rules(brief.answer_destinations, brief.driver)
|
||||
room = max(0, JUDGE_PROMPT_CHARS - len(head) - len(rules) - 2)
|
||||
transcript = escalation_mark.transcript(brief.entries, brief.escalated_at, typed_answer, brief.driver)
|
||||
if room < min(len(transcript), TRANSCRIPT_FLOOR):
|
||||
return Failure(f"the premises, the records and the task leave the transcript {room:,} characters of the judge's {JUDGE_PROMPT_CHARS:,}, under the {TRANSCRIPT_FLOOR:,} of its tail it must read; the records take {len(brief.records):,}. Shorten them.")
|
||||
# The tail, where an interrupt or a finish lands; the session's transcript grows cycle over cycle.
|
||||
shown = transcript[max(0, len(transcript) - room):]
|
||||
grounds = Grounds(
|
||||
|
||||
@@ -135,9 +135,9 @@ class Verdict(unittest.TestCase):
|
||||
|
||||
|
||||
class JudgePrompt(unittest.TestCase):
|
||||
def brief(self, entries, escalated_at, answer_destinations="the plan or a comment"):
|
||||
def brief(self, entries, escalated_at, answer_destinations="the plan or a comment", records=""):
|
||||
"""What the judge of a-driver reads of a transcript holding entries."""
|
||||
return judge.Brief("Do it.", "## Goals", "", "the project's decisions", answer_destinations, kinds(*entries), escalated_at, "a-driver")
|
||||
return judge.Brief("Do it.", "## Goals", records, "the project's decisions", answer_destinations, kinds(*entries), escalated_at, "a-driver")
|
||||
|
||||
def test_shows_the_transcripts_tail_and_returns_what_it_showed(self):
|
||||
entries = [assistant({"type": "text", "text": "old " + "x" * judge.JUDGE_PROMPT_CHARS}), assistant({"type": "text", "text": "new"})]
|
||||
@@ -149,6 +149,19 @@ class JudgePrompt(unittest.TestCase):
|
||||
self.assertEqual(grounds.after_mark, "old " + "x" * judge.JUDGE_PROMPT_CHARS + "\n\nnew")
|
||||
self.assertEqual(grounds.quotable, "## Goals\n\n")
|
||||
|
||||
def test_stops_rather_than_show_less_of_the_transcripts_tail_than_its_floor_whatever_the_size_of_the_records(self):
|
||||
entries = [assistant({"type": "text", "text": "old " + "x" * judge.TRANSCRIPT_FLOOR}), assistant({"type": "text", "text": "Merged."})]
|
||||
too_long = self.brief(entries, 0, records="r" * judge.JUDGE_PROMPT_CHARS)
|
||||
self.assertEqual(judge.judge_prompt(too_long), Failure(f"the premises, the records and the task leave the transcript 0 characters of the judge's 400,000, under the {judge.TRANSCRIPT_FLOOR:,} of its tail it must read; the records take 400,000. Shorten them."))
|
||||
self.assertEqual(judge.judge_once("/r", too_long, Rung("judge-model"), FakeEffects(claude=[]).effects()), judge.judge_prompt(too_long))
|
||||
prompt, grounds = judge.judge_prompt(self.brief(entries, 0, records="r" * (judge.JUDGE_PROMPT_CHARS - judge.TRANSCRIPT_FLOOR - 10000)))
|
||||
self.assertTrue(grounds.shown.endswith("\n\nMerged."))
|
||||
self.assertGreaterEqual(len(grounds.shown), judge.TRANSCRIPT_FLOOR)
|
||||
self.assertLessEqual(len(prompt), judge.JUDGE_PROMPT_CHARS)
|
||||
short = [assistant({"type": "text", "text": "Merged."})]
|
||||
_, grounds = judge.judge_prompt(self.brief(short, 0, records="r" * (judge.JUDGE_PROMPT_CHARS - 10000)))
|
||||
self.assertEqual(grounds.shown, "Merged.", "a transcript shorter than the floor needs only its own length")
|
||||
|
||||
def test_the_judge_prompt_and_schema_call_the_worker_the_worker(self):
|
||||
prompt, _ = judge.judge_prompt(self.brief([assistant({"type": "text", "text": "done"})], 1))
|
||||
self.assertNotRegex(prompt + json.dumps(judge.judge_schema("a-driver")), r"\b[Aa]gent")
|
||||
|
||||
Reference in New Issue
Block a user