diff --git a/docs/design/model-prompts.md b/docs/design/model-prompts.md index 360ba2c0f..0cc4a0bb4 100644 --- a/docs/design/model-prompts.md +++ b/docs/design/model-prompts.md @@ -165,7 +165,7 @@ A probe's rate counts judged, non-failed runs only, and failed runs are compared The last row is the rule's limit at the floor: catching that loss 80% of the time needs about 44–51 runs per scenario per arm. The report therefore prints both arms' counts, both rates, the loss, the p-value and the Holm threshold for every comparison, so a reader sees a loss the rule did not flag as well as one it did. The measured table resamples whole runs, which keeps each run's probes together. The pooled rows do not: they count each probe of each run as an observation, and the probes of one run share a transcript, so those p-values are optimistic. That errs toward rejecting, which means failing a candidate, and the per-probe rows compare one probe over whole runs. -**Failed and unjudged runs.** A failed run is one that ended on an error or its wall-clock budget, or one whose judging did not happen: there was nothing the judge could be asked, or a judge call failed — a window overflow, a transport or an HTTP error, or a reply cut off at its output cap. An unjudged run is one the judge answered but gave no usable verdicts for after two re-asks, or one whose view does not fit the judge's budget, which is never asked: it enters none of its arm's probe rates, and the report counts it and lists it with its reason; the unjudged-run rate compares it. A failed run is out of the probe rates too, and is compared once, as the failed-run rate. Those two rates count the runs an arm had something to compare in — its judged, failed and unjudged runs — and an incomplete fixture is not one of them: it lowers neither rate, and the report states the arm's attempts and its incomplete fixtures beside the rates. An incomplete run is one the harness's turn cap stopped before a request its probes read existed: the step after the first idle never ran, or an input the runner submitted — the message, a request that step submitted, a switch follow-up or a steer — was not carried by the request of the turn that consumed it. A request carries an input when nothing begins or ends a turn between the consumption and the request's `step/model-start`, and either the request's own model call exists or the call of a request that replaced it in the same turn does. A run its wall clock stopped is a failed run, not an incomplete one, and a run that ended idle is scored for the requests its export holds. An incomplete run is neither a failed nor a judged run: it enters none of its arm's probe rates, does not count toward the floor, and the report lists it with its reason apart from the failed and unjudged runs, so a probe no request could answer is not read as the candidate's loss. A re-asked verdict comes from a longer conversation with the same judge at the same settings, and both arms are re-asked by the same rule. A run is judged through a view of its export: each request is given against the previous request of its line — the messages added since that request, or the whole message list after a history change — and every other field of the request appears in full only when it changed, or as an unchanged marker when it did not, so nothing is dropped. A request's consecutive `step/thinking` deltas are one line carrying their text in order, because a delta line is mostly an event id and field names and the judge reads the run as a whole. The judge reads the view in one call. A view that does not fit the judge's declared window — the window less the reply's `maxTokens` — is not split into parts: a probe that counts, orders or holds over a whole run cannot be answered from one part, so the run is unjudged before any call, and the report gives the estimate and the budget. The estimate is the runner's own and is taken before any call, so a predicted overflow is never asked. A call the provider refuses for a window overflow therefore means the declared window or the estimate was wrong, and it stays a failed run: a refusal is how a run outgrowing its model's real window shows up, and failed runs are compared between the arms. The scenario judge is asked for `present` or `absent`; the verdict parser the scenario and summary evaluations share also accepts `contradicted`, which a `must_not_show` probe treats as not shown. An evaluation whose judge declares no window fails before its first call. +**Failed and unjudged runs.** A failed run is one that ended on an error or its wall-clock budget, or one whose judging did not happen: there was nothing the judge could be asked, or a judge call failed — a window overflow, a transport or an HTTP error, or a reply cut off at its output cap. An unjudged run is one the judge answered but gave no usable verdicts for after two re-asks, or one whose view does not fit the judge's budget, which is never asked: it enters none of its arm's probe rates, and the report counts it and lists it with its reason; the unjudged-run rate compares it. A failed run is out of the probe rates too, and is compared once, as the failed-run rate. Those two rates count the runs an arm had something to compare in — its judged, failed and unjudged runs — and an incomplete fixture is not one of them: it lowers neither rate, and the report states the arm's attempts and its incomplete fixtures beside the rates. An incomplete run is one the harness's turn cap stopped before a request its probes read existed: the step after the first idle never ran, or an input the runner submitted — the message, a request that step submitted, a switch follow-up or a steer — was not carried by the request of the turn that consumed it. A request carries an input when nothing begins or ends a turn between the consumption and the request's `step/model-start`, and either the request's own model call exists or the call of a request that replaced it in the same turn does. A run its wall clock stopped is a failed run, not an incomplete one, and a run that ended idle is scored for the requests its export holds. An incomplete run is neither a failed nor a judged run: it enters none of its arm's probe rates, does not count toward the floor, and the report lists it with its reason apart from the failed and unjudged runs, so a probe no request could answer is not read as the candidate's loss. A re-asked verdict comes from a longer conversation with the same judge at the same settings, and both arms are re-asked by the same rule. A run is judged through a view of its export: each request is given against the previous request of its line — the messages added since that request, or the whole message list after a history change — and every other field of the request appears in full only when it changed, or as an unchanged marker when it did not, so nothing is dropped. A request's consecutive `step/thinking` deltas are one line carrying their text in order, because a delta line is mostly an event id and field names and the judge reads the run as a whole. The judge reads the view in one call. A view that does not fit the judge's declared window — the window less the reply's `maxTokens` — is not split into parts: a probe that counts, orders or holds over a whole run cannot be answered from one part, so the run is unjudged before any call, and the report gives the estimate and the budget. Every run's record states the estimate the fit check took and the judge's budget it compared, so a scenario that sits near the budget is visible before it flips a judgement. A run whose judging ended on a timeout keeps the pair when it reached the check; a run that never reached it, and a record written before the runner recorded the pair, states none. The estimate is the runner's own and is taken before any call, so a predicted overflow is never asked. A call the provider refuses for a window overflow therefore means the declared window or the estimate was wrong, and it stays a failed run: a refusal is how a run outgrowing its model's real window shows up, and failed runs are compared between the arms. The scenario judge is asked for `present` or `absent`; the verdict parser the scenario and summary evaluations share also accepts `contradicted`, which a `must_not_show` probe treats as not shown. An evaluation whose judge declares no window fails before its first call. **The candidate runs through the shipped assembly.** It is put in place at its author's factory configuration, as the summary strategy's optional system prompt member specified in [ContextCompaction §13.4](plugins/ContextCompaction.md#134-evaluation) allows a candidate prompt to replace the fixed one — the product profile never sets it — and never by patching strings in an evaluation-only path, so both arms run the shipped request building, chunking and failure handling. diff --git a/xtask/src/scenario_eval.rs b/xtask/src/scenario_eval.rs index fe50de9eb..43a358479 100644 --- a/xtask/src/scenario_eval.rs +++ b/xtask/src/scenario_eval.rs @@ -1197,6 +1197,8 @@ fn pooled_record(source: &Path, run: SavedRun, scenarios: &[Scenario]) -> Result error: run.error, judge_error: run.judge_error, judge_reasks: run.judge_reasks, + judge_estimate: run.judge_estimate, + judge_budget: run.judge_budget, judge_calls: run.judge_calls, temperature_dropped: run.temperature_dropped, decline_retries: run.decline_retries, @@ -1280,7 +1282,11 @@ async fn rejudge_one( .join(format!("run-{}.judge-view.jsonl", saved.run)); let view = std::fs::read_to_string(&path) .map_err(|error| format!("{}: {error}", path.display()))?; - judge_export(host, resolver, judge, scenario, &view, limits, cancel).await + let mut fit = None; + judge_export( + host, resolver, judge, scenario, &view, limits, cancel, &mut fit, + ) + .await }; let stop = stop_name(&saved.stop)?; Ok(RunRecord { @@ -1300,6 +1306,8 @@ async fn rejudge_one( judge_error: judging.error, judge_reasks: judging.reasks, judge_calls: judging.calls, + judge_estimate: judging.fit.map(|(estimate, _)| estimate), + judge_budget: judging.fit.map(|(_, budget)| budget), temperature_dropped: Some(judging.temperature_dropped), decline_retries: saved.decline_retries, switch_retries: saved.switch_retries, @@ -1341,6 +1349,10 @@ struct SavedRun { #[serde(default)] judge_reasks: u32, #[serde(default)] + judge_estimate: Option, + #[serde(default)] + judge_budget: Option, + #[serde(default)] judge_calls: Vec, /// The texts the arm was given; empty in a record written before the /// runner recorded them. @@ -2856,6 +2868,13 @@ struct RunRecord { /// How many times the judge was asked again for an answer it could not /// use. judge_reasks: u32, + /// The view's estimate against the judge's budget the fit check compared: + /// present when the check ran — judged, unreadable, a failed call, unfit, + /// or a judge phase that timed out after it — and `None` when no view was + /// built, the judge was not resolved, the run is incomplete, or the judge + /// phase timed out before the check ran. + judge_estimate: Option, + judge_budget: Option, /// One entry per judge call the run made, in order: what its stream /// reported. judge_calls: Vec, @@ -3200,6 +3219,12 @@ struct ChildOutcome { /// The judge's declared window and output cap: `(0, 0)` when the child /// never resolved them, as a run the parent killed has not. judge_window: (u64, u64), + /// The view's estimate and the judge's budget the fit check compared; + /// absent in an outcome written before the child recorded them. + #[serde(default)] + judge_estimate: Option, + #[serde(default)] + judge_budget: Option, } /// The child outcome of a run the harness aborted. @@ -3230,6 +3255,8 @@ fn harness_outcome(error: String, preflight: Vec) -> ChildOutcom model_configuration: None, judge_configuration: None, judge_window: (0, 0), + judge_estimate: None, + judge_budget: None, } } @@ -3800,6 +3827,8 @@ async fn child_drive( model_configuration: carried_parts(&instrument_configuration(&model)), judge_configuration: carried_parts(&instrument_configuration(&judge)), judge_window: (limits.window, limits.max_output), + judge_estimate: judging.fit.map(|(estimate, _)| estimate), + judge_budget: judging.fit.map(|(_, budget)| budget), }) } @@ -5383,6 +5412,8 @@ fn supervisor_outcome( model_configuration: None, judge_configuration: None, judge_window: (0, 0), + judge_estimate: None, + judge_budget: None, } } @@ -5740,6 +5771,8 @@ fn child_record( judge_error: outcome.judge_error.clone(), judge_reasks: outcome.judge_reasks, + judge_estimate: outcome.judge_estimate, + judge_budget: outcome.judge_budget, judge_calls: outcome.judge_calls.clone(), temperature_dropped: Some(outcome.temperature_dropped), decline_retries: Some(outcome.decline_retries), @@ -5839,6 +5872,11 @@ struct Judging { calls: Vec, /// Whether the judge had to drop its temperature. temperature_dropped: bool, + /// The view's estimate and the judge's budget the fit check compared, + /// once the check has run — including a run it left unfit, and a judge + /// phase that then timed out (model-prompts §8.1). `None` before the + /// check, or when there was no view to check. + fit: Option<(f64, f64)>, } impl Judging { /// A run the judge was never asked about: it left no export, the profile @@ -5852,11 +5890,13 @@ impl Judging { reasks: 0, calls: Vec::new(), temperature_dropped: false, + fit: None, } } - /// A timed-out run whose judge did not answer within its cleanup grace: - /// the call is recorded as failed, and every probe stays unparsed. - fn unfinished(scenario: &Scenario, error: String) -> Self { + /// A timed-out run whose judge did not answer within its grace: the call + /// is recorded as failed, every probe stays unparsed, and the fit the run + /// took before its first call is kept when it reached the check. + fn unfinished(scenario: &Scenario, error: String, fit: Option<(f64, f64)>) -> Self { Self { outcome: JudgeOutcome::CallFailed, probes: unparsed(scenario), @@ -5864,6 +5904,7 @@ impl Judging { reasks: 0, calls: Vec::new(), temperature_dropped: false, + fit, } } /// A run the harness stopped before a request its probes read existed: @@ -5878,6 +5919,7 @@ impl Judging { reasks: 0, calls: Vec::new(), temperature_dropped: false, + fit: None, } } } @@ -6104,10 +6146,13 @@ async fn drive_once( // answered by the deadline leaves the run's judgment unfinished instead of // holding the child — and the worker that runs it — open. A run that did // not stop on its wall clock judges as before. + let mut fit = None; let judging = if let Some(deadline) = driven.cleanup_deadline { match tokio::time::timeout_at( deadline, - judge_export(&host, &resolver, judge, scenario, &view, limits, cancel), + judge_export( + &host, &resolver, judge, scenario, &view, limits, cancel, &mut fit, + ), ) .await { @@ -6117,6 +6162,7 @@ async fn drive_once( "the judge did not finish within the cleanup grace after the run stopped on \ its wall clock" .to_owned(), + fit, ), } } else { @@ -6128,7 +6174,9 @@ async fn drive_once( let budget = judge_phase_budget(settings.judge_budget_ms); match tokio::time::timeout( budget, - judge_export(&host, &resolver, judge, scenario, &view, limits, cancel), + judge_export( + &host, &resolver, judge, scenario, &view, limits, cancel, &mut fit, + ), ) .await { @@ -6139,6 +6187,7 @@ async fn drive_once( "the judge did not finish within its phase budget of {}s", budget.as_secs_f64() ), + fit, ), } }; @@ -8992,6 +9041,11 @@ async fn judge_window( /// probe without one, is asked again with what was wrong, at most [`REASKS`] /// times; a call that fails during a re-ask ends the asking. An answer that /// stays unusable leaves every probe `unparsed` (model-prompts §8.1). +#[expect( + clippy::too_many_arguments, + reason = "one parameter per part of one run's judging, plus the slot a timeout \ + reads so it can keep the fit the check took" +)] async fn judge_export( host: &Arc, resolver: &Arc, @@ -9000,6 +9054,7 @@ async fn judge_export( view: &str, limits: JudgeWindow, cancel: &CancellationToken, + fit: &mut Option<(f64, f64)>, ) -> Judging { let statements = scenario .probes @@ -9024,6 +9079,8 @@ async fn judge_export( let facts = window_facts(limits.window, allowance, &whole); let estimate = facts.count_tokens(&whole); let budget = facts.context_window() - facts.output_tokens(); + let pair = Some((estimate, budget)); + *fit = pair; if estimate > budget { return Judging { outcome: JudgeOutcome::Unfit, @@ -9034,6 +9091,7 @@ async fn judge_export( reasks: 0, calls: Vec::new(), temperature_dropped: false, + fit: pair, }; } let (outcome, probes, error) = loop { @@ -9117,6 +9175,7 @@ async fn judge_export( reasks, calls, temperature_dropped: dropped, + fit: pair, } } @@ -9848,6 +9907,8 @@ mod tests { error: None, judge_error: None, judge_reasks: 0, + judge_estimate: None, + judge_budget: None, judge_calls: Vec::new(), temperature_dropped: Some(false), decline_retries: Some(0), @@ -14972,6 +15033,7 @@ mod tests { max_output: 1_024, }, &CancellationToken::new(), + &mut None, ) .await; assert_eq!( @@ -15095,6 +15157,7 @@ mod tests { max_output: 384_000, }, &CancellationToken::new(), + &mut None, ) .await; assert_eq!( @@ -15473,6 +15536,18 @@ mod tests { "a re-judged run keeps the count its source recorded: {}", records[1] ); + for record in &records[..2] { + assert!( + record["judgeEstimate"].is_f64() && record["judgeBudget"].is_f64(), + "a re-judged run states the fit its new judge took: {record}" + ); + } + assert_eq!( + records[2]["judgeEstimate"], + Value::Null, + "a run whose judge was never asked records no fit: {}", + records[2] + ); assert_eq!( previously_unjudged["arm"], "current", "{previously_unjudged}" @@ -17197,24 +17272,28 @@ mod tests { assert_eq!(records.len(), 4, "one run per arm and scenario"); for record in &records { assert_eq!(record["failed"], false, "{record}"); + let estimate = record["judgeEstimate"].as_f64().unwrap(); + let budget = record["judgeBudget"].as_f64().unwrap(); + assert_eq!( + budget, 39_800., + "the judge's budget is its declared window less its output cap" + ); if record["scenario"] == "case" { assert_eq!(record["judgeOutcome"], "judged", "{record}"); assert_eq!(record["probes"][0]["verdict"], "present", "{record}"); + assert!( + budget - estimate > 4_000., + "the judged view keeps headroom under the judge's budget: {record}" + ); } else { assert_eq!(record["judgeOutcome"], "unfit", "{record}"); assert_eq!(record["probes"][0]["verdict"], "unparsed", "{record}"); let error = record["judgeError"].as_str().unwrap(); assert!(error.starts_with("the judge view needs about "), "{error}"); assert!(error.contains(" tokens; the judge's budget is "), "{error}"); - let numbers = error - .split(|character: char| !character.is_ascii_digit() && character != '.') - .filter(|part| !part.is_empty()) - .map(|part| part.parse::().unwrap()) - .collect::>(); - assert_eq!(numbers.len(), 2, "{error}"); assert!( - numbers[0] - numbers[1] > 4_000., - "the overgrown view clears the judge's budget with room to spare: {error}" + estimate - budget > 4_000., + "the overgrown view clears the judge's budget with room to spare: {record}" ); } } @@ -17249,6 +17328,44 @@ mod tests { ); } + /// A judge that outlives its phase budget records a failed call, and the + /// record keeps the fit the run took before the judge's first call, so it + /// reads apart from a run that never reached the check + /// (model-prompts §8.1). + #[tokio::test(flavor = "multi_thread", worker_threads = 4)] + async fn a_judge_that_outlives_its_budget_keeps_the_fit_it_took() { + let fixture = Fixture::holding( + "judge-timeout", + judged, + |text| { + text.contains("You check statements") + .then_some(Duration::from_secs(60)) + }, + json!({ + "message": "Say hello.", + "budget": {"turns": 4, "seconds": 120, "window": 24000}, + "probes": [{"id": "ran", "kind": "must_show", "text": "the run has a transcript"}] + }), + &[], + 24_000, + ) + .await; + let mut options = fixture.judge_options(fixture.directory.join("out")); + options.judge_budget_ms = Some(200); + fixture.evaluate(&options).await.unwrap(); + let records = fixture.records(&options.out); + assert_eq!(records.len(), 2, "one run per arm"); + for record in &records { + assert_eq!(record["judgeOutcome"], "call_failed", "{record}"); + let estimate = record["judgeEstimate"].as_f64().unwrap(); + let budget = record["judgeBudget"].as_f64().unwrap(); + assert!( + estimate < budget, + "the view fitted the judge before its first call: {record}" + ); + } + } + /// A run offers the shipped assembly's whole tool catalog — the workspace /// tools and Questions, not only the mock profile's three — carries a /// workspace tool's result into its next request (model-prompts §8.1), and