From 2c17cf8fa3f7ec8ac5c390a892194a55c7057eb3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 2 Dec 2026 22:27:05 +0100 Subject: [PATCH] Elaboration: a session ended by its last refusal is a valid NoPatch row Co-Authored-By: Claude Sonnet 5.5 --- crates/ghostlight/src/controllers.rs | 22 ++++--------- crates/ghostlight/src/elaboration.rs | 49 +++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/crates/ghostlight/src/controllers.rs b/crates/ghostlight/src/controllers.rs index 3badf70..26bfae8 100644 --- a/crates/ghostlight/src/controllers.rs +++ b/crates/ghostlight/src/controllers.rs @@ -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::(), - ); + // 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 { diff --git a/crates/ghostlight/src/elaboration.rs b/crates/ghostlight/src/elaboration.rs index ea247e9..58633b1 100644 --- a/crates/ghostlight/src/elaboration.rs +++ b/crates/ghostlight/src/elaboration.rs @@ -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) + } } } }