Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6e9b596
fix(scenario-eval): render a request's thinking deltas as one judge-v…
yyhhyyyyyy Nov 24, 2026
43b5d38
test(scenario-eval): require one line per job in the opening scenarios
yyhhyyyyyy Nov 24, 2026
7cfafa1
test(scenario-eval): give the compact scenario a user steer to open a…
yyhhyyyyyy Nov 24, 2026
b2f1bcc
docs(timeline-branches): pre-register the opening-rate gate
yyhhyyyyyy Nov 24, 2026
bd214e3
fix(scenario-eval): score the note a switch follow-up's request carries
yyhhyyyyyy Nov 24, 2026
890e3f0
fix(scenario-eval): exempt only the request a run's turn cap stopped
yyhhyyyyyy Nov 24, 2026
e284fef
fix(scenario-eval): exempt only the request the turn cap found in flight
yyhhyyyyyy Nov 24, 2026
3df5d31
perf(scenario-eval): append a request's thinking deltas to one buffer
yyhhyyyyyy Nov 24, 2026
200f5c4
feat(scenario-eval): judge the opening gate over a fixed three-probe …
yyhhyyyyyy Nov 24, 2026
c19ebcb
refactor(scenario-eval): keep gate 2 in the design text
yyhhyyyyyy Nov 24, 2026
12e36fd
fix(scenario-eval): place a request by the turn it ran in
yyhhyyyyyy Nov 24, 2026
8c7520c
test(scenario-eval): write the cap's interrupt with the scope it has
yyhhyyyyyy Nov 24, 2026
b827fb1
test(scenario-eval): settle the compact scenario's lines after the fi…
yyhhyyyyyy Nov 24, 2026
8107ca0
test(capabilities): pin a line's identity across a manual compaction
yyhhyyyyyy Nov 24, 2026
0b2808c
fix(scenario-eval): start the compact scenario's line where the sessi…
yyhhyyyyyy Nov 24, 2026
e7e9d98
test(capabilities): keep the parent read test's session as main has it
yyhhyyyyyy Nov 24, 2026
0390f0d
fix(scenario-eval): read a saved setup failure back by its stop
yyhhyyyyyy Nov 24, 2026
0d115c2
fix(scenario-eval): score a probe only after its fixture request ran
yyhhyyyyyy Nov 24, 2026
e364b21
fix(scenario-eval): keep an incomplete fixture to the turn cap
yyhhyyyyyy Nov 24, 2026
c3d480a
fix(scenario-eval): read a switch note check as a reason or none
yyhhyyyyyy Nov 24, 2026
98f53ea
fix(scenario-eval): compare only the runs with an outcome and read ea…
yyhhyyyyyy Nov 25, 2026
e8bcde4
test(scenario-eval): pin a steer receipt and an unseen switch input
yyhhyyyyyy Nov 25, 2026
74874fa
test(scenario-eval): pin the cap-cut precedence over a confirmed failure
yyhhyyyyyy Nov 25, 2026
12477bb
fix(scenario-eval): report a confirmed switch-note failure before the…
yyhhyyyyyy Nov 25, 2026
646b3e5
test(scenario-eval): pin an unconsumed receipt before a missing note
yyhhyyyyyy Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions crates/dim-agent-capabilities/tests/branch_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8367,6 +8367,182 @@ async fn a_roster_and_an_identity_replay_separately_after_a_compaction() {
soon(agent.close()).await.unwrap();
}

/// [`Compact`] with a 29,000-token window, so a manual step has a cut that
/// keeps the last turn inside the retention bound.
#[derive(Clone, Copy)]
struct Roomy;
impl ResolveContextModel for Roomy {
fn resolve(
&self,
_: Arc<ModelRequest>,
_: CancellationToken,
) -> HostFuture<'_, Arc<dyn ContextModel>> {
Box::pin(async { Ok(Arc::new(Roomy) as Arc<dyn ContextModel>) })
}
}
impl ContextModel for Roomy {
fn context_window(&self) -> f64 {
29_000.
}
fn output_tokens(&self) -> f64 {
64.
}
fn threshold_tokens(&self) -> f64 {
20_000.
}
fn count_tokens(&self, request: &ModelRequest) -> f64 {
Compact.count_tokens(request)
}
}
impl CompactionStrategy for Roomy {
fn name(&self) -> &str {
Compact.name()
}
fn replacement_size(&self, model: &dyn ContextModel) -> f64 {
Compact.replacement_size(model)
}
fn compact(
&self,
input: CompactionInput,
cancel: CancellationToken,
) -> HostFuture<'_, StrategyOutcome> {
Compact.compact(input, cancel)
}
}

/// A manual compaction, the one `session.context.compact` asks the loop for,
/// replays a line's identity the way an automatic one does: the request after
/// it still carries which line it is (Timeline branches §12.3). The identity
/// probe of the compact scenario now reads a manual compaction, so this is the
/// property that probe depends on.
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn a_manual_compaction_replays_a_lines_identity() {
let mut builder = AgentBuilder::new(AgentConfig::default());
builder
.timeline_store(dim_agent_runtime::TimelineStoreBinding::new(Arc::new(
MemoryTimelineStore::default(),
)))
.session_value(Arc::new(HistoryRenderer::default()))
.process_value(Arc::new(ModelHost(Arc::new(FlowModel))))
.session_value(Arc::new(ToolHost(Arc::new(MockTools))))
.session_value(Arc::new(PrepareContextHost(Arc::new(IdentityContext))))
.session_value(Arc::new(ContextModelHost(Some(Arc::new(Roomy)))))
.session_value(Arc::new(CompactionStrategyHost(Some(Arc::new(Roomy)))))
.require_feature(
Feature::new("PrepareModelHost").session("PrepareModelHost", |names| {
Ok(Box::new(DefaultPrepareModelPlugin::new(names)?))
}),
);
defaults::install(&mut builder);
let agent = MinimalHost::start(&builder).await.unwrap();
// The Session's own model: a manual compaction at idle has no request to
// adopt one from.
let session = soon(agent.create_session(SessionConfig {
model: ModelSelection {
provider_id: "test".into(),
model_id: "flow".into(),
capability_snapshot: None,
config: None,
metadata: None,
},
..SessionConfig::default()
}))
.await
.unwrap();
let line = open_line(&session, "compact my line").await;
for text in ["x".repeat(1500), "y".repeat(1500)] {
session.submit(text, InputMode::Queue, &line).await.unwrap();
patient(session.idle(&line)).await.unwrap();
}
// The manual step reads the configuration the branch adopted; a flow test
// adopts none until it configures one.
session
.configure(
ConfigureUpdate {
model: Some(ModelSelection {
provider_id: "test".into(),
model_id: "flow".into(),
capability_snapshot: None,
config: None,
metadata: None,
}),
..Default::default()
},
&line,
)
.await
.unwrap();
let command = session
.service::<dim_agent_capabilities::agent_loop::AgentLoop>(&line)
.expect("the line's loop")
.compact()
.unwrap();
// A compaction is not a turn: `session.idle` returns before its step has
// written its result.
patient(async {
loop {
let events = chain_events(&session, &line, ..).await.unwrap();
if events.iter().any(|event| {
matches!(&event.kind, EventKind::ContextCompaction(data)
if data.command == Some(command))
}) {
return;
}
tokio::time::sleep(Duration::from_millis(20)).await;
}
})
.await;
session
.submit("after the compaction".into(), InputMode::Queue, &line)
.await
.unwrap();
patient(session.idle(&line)).await.unwrap();
let events = chain_events(&session, &line, ..).await.unwrap();
let (at, outcome) = events
.iter()
.find_map(|event| match &event.kind {
EventKind::ContextCompaction(data) if data.command == Some(command) => {
Some((event.sequence, &data.outcome))
}
_ => None,
})
.expect("the manual compaction wrote its result");
assert!(
matches!(outcome, ContextCompactionResult::Completed { .. }),
"the manual compaction completed on the line: {outcome:?}"
);
let message = baseline_message(&events, "branch:line")
.expect("the manual compaction replayed the line's identity");
let MessageContent::Text(text) = &message.content else {
panic!("the identity is text: {message:?}");
};
assert!(
text.starts_with(&format!(
"<dim-branch-line branch=\"{line}\" parent=\"main\""
)),
"{text}"
);
// The request after the compaction carries that baseline: the opening input
// that carried the identity is behind the cut.
let request = events
.iter()
.filter(|event| event.sequence > at)
.find_map(|event| match &event.kind {
EventKind::ModelCall(data) => Some(&data.request),
_ => None,
})
.expect("the request after the compaction");
// One identity message and no second copy from the history: the opening
// input that carried it is behind the cut.
let identities = request
.messages
.iter()
.filter(|message| said(message).starts_with("<dim-branch-line"))
.count();
assert_eq!(identities, 1, "the baseline's identity is the only one");
soon(agent.close()).await.unwrap();
}

/// The compaction above and the child's replay need a line cut after its
/// opener wrote a roster, so the inherited block is in the child's prefix.
async fn wait_for_roster(session: &Session, line: &str) {
Expand Down
2 changes: 1 addition & 1 deletion docs/design/model-prompts.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,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. 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. 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. 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.

Expand Down
4 changes: 3 additions & 1 deletion docs/design/timeline-branches.md
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ The opening and switching roles add eight scenarios: `long-work-and-a-flaky-test
| Over-splitting | `timeline-branches/over-splitting` | Lines opened for short or sequential steps |
| Never ending | `timeline-branches/never-ending` | A line that is done but does not call `end` |
| Sibling relay | `timeline-branches/sibling-relay` | An opener is used to pass messages between lines that should have been one line |
| Identity after compaction | `timeline-branches-compact/identity-after-compaction` | After compaction on `main` and on a line, each still knows which line it is and which lines are its own |
| Identity after compaction | `timeline-branches-compact/identity-after-compaction` | After compaction on `main` and on a line, each still knows which line it is |
| Continuing on a line after a switch | `—` | A line that became the default branch calls `end` on itself, hands its work to another line, keeps waking its opener with idle notices, or cannot open a line while the root could |
| Opening lines after a switch | `timeline-branches/switch-then-open-lines` | The new default branch does both independent additions itself instead of opening a line for one of them, or the former default branch takes the new work |
| The root opens while a line holds the role | `timeline-branches/root-opens-after-switch` | The user asks the root for a line after another line became the default branch: the root must open it, the new line must start from the root's history, and it must report to the root |
Expand Down Expand Up @@ -571,6 +571,8 @@ A candidate for a policy text is put in place at that text's factory member ([mo

The coordination text and the status notes are judged together, as one family, in the change that first puts a candidate for either in place ([model-facing prompts §8](model-prompts.md#8-judging-a-change)): the tool description at `BranchToolConfig.description`, the status notes at `BranchToolConfig.default_note`, `BranchToolConfig.user_default_note` and `BranchToolConfig.former_default_note`, and the roster's closing at `BranchToolConfig.roster_closing`. A later change to one of them re-runs the family, because a text that reads well alone can still lose a comparison another one wins. The opening text is judged on the should-open scenarios of §12.3 and, for this design, on `root-opens-after-switch`: a guard that let only the default branch open a line would make the root answer the request instead of opening one, and that scenario is where the difference shows.

**Gate 2, the opening rate.** The opening text is also judged against the opening probes: `line-opened-for-one-job` in `long-work-and-a-flaky-test` and in `refactor-and-a-pasted-report`, and `new-default-opens-a-line` in `switch-then-open-lines`. The three probes form one family, fixed before any data at `m = 3`; no probe leaves it whatever its counts. A probe's gain is `c₁/n₁ − c₀/n₀`, where `c₀` of `n₀` counted runs passed in the current arm and `c₁` of `n₁` in the candidate arm; the arms need not count the same runs, and the gain and its p-value use each arm's own counts. A probe enters with `p = 1` and cannot reject when its gain is at most `δ = 0.05`; it still takes its rank, so a probe at its ceiling never shrinks the family or loosens another probe's threshold. Otherwise its p-value is the one-sided mid-p Fisher exact test of "no gain" on `(c₀, n₀)` against `(c₁, n₁)`. Holm's step-down at `α = 0.10` runs over all three rows: the row at rank `i` of the ascending p-values is tested against `α / (4 − i)`, and none rejects after one fails. At least one probe must reject for the opening text to pass gate 2, and every opening probe is also a comparison of gate 1, where a significant fall is a regression. Gate 2 is inconclusive when an arm counted no run on a probe, so the comparison cannot be made ([model-facing prompts §8.1](model-prompts.md#81-the-rule)), or when no probe could gain more than `δ` even with a perfect candidate arm, because then no gain can be measured. A candidate passes the opening text only when gate 1 (no regression, and the floor) and gate 2 both pass.

## 13. Interactions

| Feature | Interaction |
Expand Down
Loading