Step the worker up as the judge quotes an answer when the run also cites an escalation trigger

This commit is contained in:
2026-10-17 22:24:37 +02:00
parent 89bbc9de18
commit fc24e9bae2
10 changed files with 90 additions and 40 deletions
+23 -12
View File
@@ -40,10 +40,10 @@ class Cycle:
anchor: Rung | None
# Empty when the previous cycle's verdict was not Unfinished.
unfinished_evidence: str
# Only an interrupt's escalation changes the route within a cycle. No transition reads the route or the fields below, so they stay out of the states.
# The route that interrupt left, for ask to archive; None unless the latest event stepped the route up.
# Only an interrupt's or a quoted answer's escalation changes the route within a cycle. No transition reads the route or the fields below, so they stay out of the states.
# The route that ruling left, for ask and keep_answer to archive; None unless the latest event stepped the route up.
stepped_from: Route | None = None
# Whether an interrupt of this cycle took an escalation, after which no ruling of the cycle carries one.
# Whether an interrupt or a quoted answer of this cycle took an escalation, after which no ruling of the cycle carries one.
escalation_spent: bool = False
@@ -69,9 +69,9 @@ def run_cycle(cycle: Cycle) -> Stop | Concluded:
def escalated(cycle: Cycle, event: Event) -> Cycle:
"""The cycle after event. Where the judge interrupted with an escalation, its route steps up before the human is asked, so the work after the answer runs on it."""
"""The cycle after event. Where the judge interrupted or quoted an answer with an escalation, its route steps up before the human is asked or the worker resumes, so the work after the answer runs on it."""
cycle = dataclasses.replace(cycle, stepped_from=None)
if not (isinstance(event, Ruled) and isinstance(event.verdict, Interrupt) and event.verdict.escalation):
if not (isinstance(event, Ruled) and isinstance(event.verdict, Interrupt | QuotedAnswer) and event.verdict.escalation):
return cycle
route = stepped_by_interrupt(cycle.anchor, cycle.route, event.verdict.bundled) if cycle.anchor else cycle.route
return dataclasses.replace(cycle, route=route, stepped_from=cycle.route if route != cycle.route else None, escalation_spent=True)
@@ -130,7 +130,11 @@ def worker_start(cycle: Cycle, answered: QuotedAnswer | None) -> list[str]:
def keep_answer(cycle: Cycle, answered: QuotedAnswer) -> Stop | None:
path = transcript_file(cycle.session)
if path and (failure := archive(cycle.project_archive, path, cycle.task, outcomes.answered(answered.question, prompts.QUOTE_SOURCES, answered.answer, answered.evidence, str(judge_of(cycle))), cycle.effects.now())):
if not path:
return None
# As in ask: the answer names the rung the worker ran on until then, and a step-up archived after it names the rung it runs on from then.
quoted = outcomes.answered(answered.question, prompts.QUOTE_SOURCES, answered.answer, answered.evidence, answered.escalation, str(judge_of(cycle)), str(cycle.stepped_from or cycle.route))
if failure := archive_stepped(cycle, path, quoted):
return Stop(1, failure.reason)
return None
@@ -144,8 +148,8 @@ def rule(cycle: Cycle, transcript_path: str) -> Ruled | Stop:
def unspent(verdict: Verdict, spent: bool) -> Verdict:
"""The verdict without its escalation once an interrupt of the cycle took one. The judge may quote a different passage for the trigger that already stepped the route, and no comparison of quotes tells the two apart, so one trigger buys one step. It lives here, not in judge.quotes_checked, since it reads the cycle, and judge-replay replays the judge alone."""
if spent and isinstance(verdict, Interrupt | Unfinished) and verdict.escalation:
"""The verdict without its escalation once an interrupt or a quoted answer of the cycle took one. The judge may quote a different passage for the trigger that already stepped the route, and no comparison of quotes tells the two apart, so one trigger buys one step. It lives here, not in judge.quotes_checked, since it reads the cycle, and judge-replay replays the judge alone."""
if spent and isinstance(verdict, Interrupt | QuotedAnswer | Unfinished) and verdict.escalation:
return dataclasses.replace(verdict, escalation="")
return verdict
@@ -161,13 +165,20 @@ def ask(cycle: Cycle, transcript_path: str, ruling: Interrupt | QuotedAnswer) ->
question = question_for(ruling)
# Archived now, so the transcript the question was asked on is kept with it; the human's answer then grows the transcript.
# The interrupt names the rung the worker ran on before it; a step-up archived after it names the stepped rung, so the figures charge each stretch to its own rung.
interrupted = outcomes.interrupted(question, ruling.evidence, str(judge_of(cycle)), ruling.escalation if isinstance(ruling, Interrupt) else "", str(cycle.stepped_from or cycle.route))
for outcome in (interrupted, outcomes.stepped_up(str(cycle.route))) if cycle.stepped_from else (interrupted,):
if failure := archive(cycle.project_archive, transcript_path, cycle.task, outcome, cycle.effects.now()):
return Stop(1, failure.reason)
interrupted = outcomes.interrupted(question, ruling.evidence, str(judge_of(cycle)), ruling.escalation, str(cycle.stepped_from or cycle.route))
if failure := archive_stepped(cycle, transcript_path, interrupted):
return Stop(1, failure.reason)
return interrupt(cycle.root, cycle.session.id, cycle.route.rung, transcript_path, question, cycle.paths, worker_environment(cycle), cycle.effects) or HumanAnswered()
def archive_stepped(cycle: Cycle, transcript_path: str, outcome: str) -> Failure | None:
"""Archives the outcome of a ruling, then the step-up it caused when it stepped the route. The first failure is returned."""
for kept in (outcome, outcomes.stepped_up(str(cycle.route))) if cycle.stepped_from else (outcome,):
if failure := archive(cycle.project_archive, transcript_path, cycle.task, kept, cycle.effects.now()):
return failure
return None
def question_for(ruling: Interrupt | QuotedAnswer) -> str:
if isinstance(ruling, Interrupt):
return ruling.question