Make \`TrajectoryJudge\` evaluations durable operations inside Temporal, DBOS, and Prefect runs
Makes TrajectoryJudge durable instead of refusing to run inside a Temporal, DBOS, or Prefect workflow or flow, following the ToolCallJudge pattern from #9041.
[!WARNING]
Compatibility impact: A TrajectoryJudge without an explicit id on an agent that also has a durability capability (TemporalDurability, DBOSDurability, PrefectDurability) now raises UserError when the agent is built, even if the agent is only run outside its workflow. Before, only a run inside the workflow raised, at run start.
Why this can ship in a minor release: Pydantic AI Harness is on 0.x releases, and this only affects agents that already combine the judge with durable execution. Core's bind-time error names the fix.
Migration: Give each judge a distinct id: TrajectoryJudge(model=..., id='drift').
- Closes #8988
What changed
- The judge's model call moved into
_judge_call, decorated with@durable_operation('evaluate'). It takes the rendered prompt and returnsSteer | None(AllGoodhas no data, so it crosses the boundary asNoneand the serialized result stays unambiguous). The claim on the shared usage, the steeringenqueue, andon_verdictstay on the caller's side, since a durable worker cannotenqueue. - The
before_runrejection is gone. - The design question from the issue: inside a durable context the evaluation is awaited on the cadence tick. Outside durable execution it still runs in the background, exactly as before, so plain users see no change.
Why awaited (in durable runs only)
Keeping it concurrent is not replay-safe on every engine. On replay, DBOS and Prefect return a recorded step at once, so a background evaluation would enqueue its steering at a different point than the original run did. The replayed message history would then diverge, and so would every step id after it. Temporal happens to order activity completions in its history, but the harness should not depend on one engine. Awaiting on the tick pins the steering to the same next request on both runs.
The cost is latency on every every-th request, and only in durable runs. That seems like the right trade compared with refusing to run at all. A failed evaluation is raised at the tick instead of at the next tick or at run end.
Tests
- With
RecordingDurability, the journal ismodel.request, capability__drift.evaluate, model.request, .... The steering reaches the very next request, the claims are released, and aSteerverdict and anAllGoodverdict both cross the boundary. - A failing durable operation is raised at the tick.
- A judge without an
idcan't bind to a durable agent. - A real DBOS workflow is run twice under the same workflow id. It records the
evaluatestep, delivers the steering, and asks the judge model only once. - The existing background-path tests are unchanged.
Checklist
- No breaking changes in accordance with the version policy. (Harness 0.x; see the compatibility note above.)
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.