judgment
judgment
¶
Judgment client — automated FERMATA decider (#203).
A daemon-internal consumer (the SemanticAnalyzer pattern) that
evaluates a sheet paused in FERMATA and may produce the resolution the
composer would otherwise issue via mzt resolve — alongside the
composer, never replacing them.
Design (4-model lab, 2026-06-11 — unanimous on every load-bearing point):
- Off-loop, fail-open. EventBus subscriber on
baton.sheet.escalation_needed; LLM calls run as background tasks, semaphore-bounded, strictly timed out. ANY failure (timeout, crash, parse miss, refusal) leaves the sheet in plain composer-resolvable FERMATA. The baton never awaits, blocks on, or knows about the judge. - Startup reconciliation. The EventBus is edge-triggered: a FERMATA
recovered across a restart fired its event in a dead process. On
start()the client scans live state for pre-existing FERMATA sheets and enqueues them. - Single producer API. Decisions go through
BatonAdapter.resolve_fermata(atomic status validation, the same marker + consumed/ audit trail as the composer path) — never raw marker writes. - Safety gates (config:
JudgmentConfigon the score):accept/skipexcluded fromallowed_decisionsby default; confidence belowmin_confidencedefers; a DURABLE per-sheet cap (SheetState.judgment_count, incremented only on actual resolutions) terminates judge-retry loops; per-JOB config resolution from the job's persisted config snapshot (no cross-job contamination). - Injection posture. The evidence the judge reads is repo/agent-
controlled. Defenses that are load-bearing: validation-results-are-
ground-truth framing, untrusted-block delimiters, and above all the
decision allowlist (a judge that cannot output
acceptcannot be lobbied into it). Prior judge rationale is never replayed as trusted context — only normalized structured facts (decision/confidence/ resolved) reach later judgments.
Classes¶
JudgmentClient
¶
JudgmentClient(*, live_states, resolve_fn, backend_factory, diagnostic_fn=None, max_concurrent=1, persist_fn=None)
EventBus consumer that auto-resolves FERMATA sheets when configured.
Lifecycle mirrors SemanticAnalyzer::
client = JudgmentClient(
live_states=manager._live_states,
resolve_fn=adapter.resolve_fermata,
diagnostic_fn=manager._diagnostic_snapshot,
backend_factory=...,
)
await client.start(event_bus) # subscribes + reconciles
...
await client.stop(event_bus)
Source code in src/marianne/daemon/judgment.py
Methods:¶
start
async
¶
Subscribe to escalation events and reconcile pre-existing fermatas.
The EventBus is edge-triggered — a restart-recovered FERMATA fired its event in a previous process — so startup scans live state and enqueues every currently-FERMATA sheet whose job enables judgment.
Two-mechanism invariant (goal-mode audit, 2026-06-12): this sweep
is the BELT; the adapter's _reconcile_fermata_polling re-emits
escalation_needed for every sheet newly entering fermata
polling — including restart-recovered ones — and is the
SUSPENDERS. _live_states[job_id] is populated (manager resume
path) BEFORE baton registration, which precedes the re-emit, so an
event pre-dating this subscription implies the job is already
visible to this sweep, and a sweep-miss implies the event hasn't
fired yet and will arrive after subscription. On the restart path
this sweep finds nothing by construction (GH #382): orphan recovery
spawns resume tasks and returns, so _live_states is empty when
start() runs, and every restart-recovered fermata reaches the
judge through the adapter's re-emit instead. The sweep earns its
keep only when a client is started against an already-populated
state map (tests, embedding). Double-processing is idempotent: the
durable judgment_count cap + the FERMATA-status check in
resolve_fermata.
Source code in src/marianne/daemon/judgment.py
stop
async
¶
Unsubscribe and cancel in-flight judgments (fail-open: the affected sheets simply remain in FERMATA for the composer).
Source code in src/marianne/daemon/judgment.py
Functions:¶
parse_judgment
¶
Extract (decision, confidence) from a judge response.
Scans bottom-up for the last JUDGMENT: <decision> <confidence>
line. Returns None when no valid line exists (callers treat that as
a defer — fail-open).
Source code in src/marianne/daemon/judgment.py
build_judgment_prompt
¶
build_judgment_prompt(*, job_id, sheet_num, state, task_description, diagnostics, prior_judgments, allowed_decisions)
Assemble the bounded, untrusted-framed judge prompt.
Ordered by signal value (lab consensus): fermata reason → validation details (ground truth) → classifier/error history → attempts → runtime diagnostics → untrusted stderr → prior judgment FACTS (never prior rationale as trusted text).
Source code in src/marianne/daemon/judgment.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |