Elaboration: a session ended by its last refusal is a valid NoPatch row

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 22:27:05 +01:00
commit 2c17cf8fa3
2 changed files with 47 additions and 24 deletions

View file

@ -13943,18 +13943,11 @@ mod tests {
);
assert_eq!(session.lens, lens);
assert_eq!(session.instructions, lens.instructions());
// The world structure prints this world's ids, which differ
// between the eight worlds; everything else must not.
prompts.insert(
agent_prompt
.split('[')
.enumerate()
.map(|(index, part)| match (index, part.split_once(']')) {
(0, _) | (_, None) => part.to_owned(),
(_, Some((_, rest))) => rest.to_owned(),
})
.collect::<String>(),
);
// The world structure prints this world's ids and their order,
// which differ between the eight worlds; the rest must not.
let before = agent_prompt.split("Standing structure").next().unwrap();
let after = agent_prompt.rsplit("Tools:").next().unwrap();
prompts.insert(format!("{before}{after}"));
texts.insert(session.instructions.clone());
}
let second = elaboration_runner(&mailbox, script.clone(), store.clone());
@ -15426,9 +15419,8 @@ mod tests {
// Past `MAX_REFUSALS` the session ends and its deficit id, which
// moves with the ancestry, starts a new one; rows may grow then,
// but only one session is ever in flight.
assert_eq!(
store.elaboration_in_flight().await.unwrap().len(),
1,
assert!(
store.elaboration_in_flight().await.unwrap().len() <= 1,
"tick {tick}: an orphan session is in flight"
);
if tick < crate::elaboration::MAX_REFUSALS {

View file

@ -220,17 +220,45 @@ impl ElaborationCheckpoint {
refusals,
completed,
..
} => derive_elaboration_capture(
agent_prompt,
refusals,
completed,
ELABORATION_ROUND_BUDGET,
)
.is_ok_and(|capture| !capture.submitted),
} => {
derive_elaboration_capture(
agent_prompt,
refusals,
completed,
ELABORATION_ROUND_BUDGET,
)
.is_ok_and(|capture| !capture.submitted)
|| ended_by_refusal(
agent_prompt,
refusals,
completed,
ELABORATION_ROUND_BUDGET,
)
}
}
}
}
/// Whether the conversation ends in the refusal past `MAX_REFUSALS`: the last
/// refusal follows the last round, and the repair it would have opened was
/// never authored. A `NoPatch` row is either this or a conversation that
/// ended without a submit.
fn ended_by_refusal(
agent_prompt: &str,
refusals: &[Refusal],
completed: &[InferenceOutput],
budget: usize,
) -> bool {
refusals.len() > MAX_REFUSALS
&& refusals
.last()
.is_some_and(|refusal| refusal.after_round == completed.len())
&& matches!(
evaluate_elaboration_loop(agent_prompt, refusals, completed, budget),
Ok(ElaborationLoopEvaluation::Continue { .. })
)
}
/// A session may gather more evidence and may end, but it may never rewrite the
/// answer it bound to, the ancestry it was built against, the lens it drew, or
/// the text it was built with. This compares a row to the row that follows it,
@ -1790,8 +1818,11 @@ impl SeedCheckpoint {
refusals,
completed,
..
} => derive_elaboration_capture(agent_prompt, refusals, completed, SEED_ROUND_BUDGET)
.is_ok_and(|capture| !capture.submitted),
} => {
derive_elaboration_capture(agent_prompt, refusals, completed, SEED_ROUND_BUDGET)
.is_ok_and(|capture| !capture.submitted)
|| ended_by_refusal(agent_prompt, refusals, completed, SEED_ROUND_BUDGET)
}
}
}
}