Answer stability round 1: 0 🔴, 2 🟡 (0 misread); tie the help's transcript floor to TRANSCRIPT_FLOOR, split the floor test, and name the shortfall in the judge's failure, with the prose round's wording
This commit is contained in:
@@ -20,7 +20,7 @@ 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.
|
||||
# The judge reads the transcript's last 50,000 characters at least, about 15,000 tokens, or all of a shorter one. Where the rest of its prompt leaves less room, the judge doesn't run, 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 """
|
||||
@@ -298,7 +298,7 @@ def answer_checked(verdict: Verdict, quotable: str) -> Verdict:
|
||||
|
||||
|
||||
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."""
|
||||
"""The prompt, and what the judge's quotes are checked against; a Failure where the premises, the records, the task and the rules leave room for less than the transcript's last TRANSCRIPT_FLOOR characters, or all of a shorter transcript."""
|
||||
head = (
|
||||
f"From the goals file, {brief.premises}\n\n"
|
||||
f"The records: {brief.records_named}:\n{brief.records or 'none'}\n\n"
|
||||
@@ -306,10 +306,11 @@ def judge_prompt(brief: Brief) -> tuple[str, Grounds] | Failure:
|
||||
f"{transcript_heading(brief.driver)}"
|
||||
)
|
||||
rules = judge_rules(brief.answer_destinations, brief.driver)
|
||||
room = max(0, JUDGE_PROMPT_CHARS - len(head) - len(rules) - 2)
|
||||
room = 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.")
|
||||
needed = min(len(transcript), TRANSCRIPT_FLOOR)
|
||||
if room < needed:
|
||||
return Failure(f"the premises, the records, the task and the judge's rules leave {max(0, room):,} of the judge's {JUDGE_PROMPT_CHARS:,} characters for the transcript, less than the last {needed:,} characters of it that the judge must read. Cut the records, which take {len(brief.records):,}, by at least {needed - room:,}.")
|
||||
# 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(
|
||||
|
||||
@@ -149,22 +149,39 @@ 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)))
|
||||
# A transcript longer than the floor: an old message, then the last one.
|
||||
LONG = [assistant({"type": "text", "text": "old " + "x" * judge.TRANSCRIPT_FLOOR}), assistant({"type": "text", "text": "Merged."})]
|
||||
|
||||
def overhead(self):
|
||||
"""The characters of the judge's prompt that are neither the records nor the transcript."""
|
||||
prompt, grounds = judge.judge_prompt(self.brief(self.LONG, 0, records="r"))
|
||||
return len(prompt) - len(grounds.shown) - 1
|
||||
|
||||
def test_fails_naming_the_shortfall_where_the_records_leave_less_than_the_transcripts_floor(self):
|
||||
failed = judge.judge_prompt(self.brief(self.LONG, 0, records="r" * (judge.JUDGE_PROMPT_CHARS + 1)))
|
||||
self.assertIsInstance(failed, Failure)
|
||||
for fact in ("400,000", "400,001", f"{judge.TRANSCRIPT_FLOOR:,}", f"by at least {judge.TRANSCRIPT_FLOOR + self.overhead() + 1:,}"):
|
||||
self.assertIn(fact, failed.reason)
|
||||
|
||||
def test_judge_once_returns_that_failure_without_starting_claude(self):
|
||||
failed = judge.judge_once("/r", self.brief(self.LONG, 0, records="r" * judge.JUDGE_PROMPT_CHARS), Rung("judge-model"), FakeEffects(claude=[]).effects())
|
||||
self.assertIsInstance(failed, Failure)
|
||||
self.assertIn(f"{judge.TRANSCRIPT_FLOOR:,}", failed.reason)
|
||||
|
||||
def test_shows_more_than_the_floor_of_the_transcripts_tail_where_the_records_leave_room(self):
|
||||
prompt, grounds = judge.judge_prompt(self.brief(self.LONG, 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)
|
||||
room = judge.JUDGE_PROMPT_CHARS - (len(prompt) - len(grounds.shown))
|
||||
at_floor = judge.JUDGE_PROMPT_CHARS - 10000 + room - 2 * judge.TRANSCRIPT_FLOOR
|
||||
self.assertEqual(len(judge.judge_prompt(self.brief(entries, 0, records="r" * at_floor))[1].shown), judge.TRANSCRIPT_FLOOR, "a head that leaves exactly the floor still shows it")
|
||||
self.assertIsInstance(judge.judge_prompt(self.brief(entries, 0, records="r" * (at_floor + 1))), Failure)
|
||||
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_shows_the_floor_where_the_records_leave_exactly_that(self):
|
||||
at_floor = judge.JUDGE_PROMPT_CHARS - self.overhead() - judge.TRANSCRIPT_FLOOR
|
||||
self.assertEqual(len(judge.judge_prompt(self.brief(self.LONG, 0, records="r" * at_floor))[1].shown), judge.TRANSCRIPT_FLOOR)
|
||||
self.assertIsInstance(judge.judge_prompt(self.brief(self.LONG, 0, records="r" * (at_floor + 1))), Failure)
|
||||
|
||||
def test_shows_a_transcript_shorter_than_the_floor_whole(self):
|
||||
_, grounds = judge.judge_prompt(self.brief([assistant({"type": "text", "text": "Merged."})], 0, records="r" * (judge.JUDGE_PROMPT_CHARS - 10000)))
|
||||
self.assertEqual(grounds.shown, "Merged.")
|
||||
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user