diff --git a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/prefill_during_tool.rs b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/prefill_during_tool.rs index 9cac08cd1f..54b7accdd9 100644 --- a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/prefill_during_tool.rs +++ b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/prefill_during_tool.rs @@ -96,23 +96,23 @@ fn missed(reason: &'static str, persona: &str) { } impl LlmDeliberationFaculty { - /// Her act dispatched its tool: warm the prompt she just sent (`template` with `messages`) into + /// Her act dispatched its tool: warm the prompt she just sent (`template` with `view`'s messages) into /// her page's slot while the tool runs. Never blocks the act; a newer pass supersedes an older - /// one nobody took. + /// one nobody took. It names the same view end as her act (`view_messages`): a warm pass that + /// named none made the engine forget where her next prompt diverges, so her saved page dropped + /// that checkpoint and her next act re-prefilled from the head (the M5, 2026-11-16: 83 of 95 + /// view-end-less pages followed a warm pass; ~100k-token re-prefills). pub(super) fn prefill_during_tool( &self, adapter: &Arc, room: Uuid, template: Option<&TextGenerationRequest>, - messages: &[ChatMessage], + view: &DeliberationPromptView, ) { let (Some(page), Some(template), PromptCache::PinnedSlot) = (self.page(room), template, adapter.prompt_cache()) else { return; }; - let mut request = TextGenerationRequest::clone(template); - request.messages = messages.to_vec(); - request.max_tokens = Some(1); - request.request_id = Some(Uuid::new_v4().to_string()); + let request = warm_request(template, &view.messages, view.resumes_at()); let pass = WarmPrefix { adapter: Arc::clone(adapter), request }; let warm = spawn_when_ready(pass, ()); if self.prefix_warm.0.lock().replace(Warming { page, warm }).is_some() { @@ -164,3 +164,30 @@ impl LlmDeliberationFaculty { } } } + +/// The warm pass's request: her act's template and prompt, her act's view end, one token. +fn warm_request(template: &TextGenerationRequest, messages: &[ChatMessage], view_messages: Option) -> TextGenerationRequest { + let mut request = TextGenerationRequest::clone(template); + request.messages = messages.to_vec(); + request.view_messages = view_messages; + request.max_tokens = Some(1); + request.request_id = Some(Uuid::new_v4().to_string()); + request +} + +#[cfg(test)] +mod tests { + use super::*; + + // what this catches: the warm pass sending her prompt with no view end, which made the engine + // forget where her next prompt diverges (regression, the M5 2026-11-16: ~100k-token re-prefills) + #[test] + fn the_warm_pass_names_her_acts_view_end() { + let template = TextGenerationRequest { view_messages: None, max_tokens: Some(900), ..Default::default() }; + let messages = vec![ChatMessage::text("system", "s"), ChatMessage::text("user", "board"), ChatMessage::text("user", "pick")]; + let warm = warm_request(&template, &messages, Some(2)); + assert_eq!(warm.view_messages, Some(2), "the warm pass carries her act's view end"); + assert_eq!(warm.max_tokens, Some(1), "it decodes one token"); + assert_eq!(warm.messages.len(), 3, "it sends the prompt she just sent"); + } +} diff --git a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/verdict/contribute.rs b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/verdict/contribute.rs index b80efb9b33..1afa4751ff 100644 --- a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/verdict/contribute.rs +++ b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/verdict/contribute.rs @@ -842,7 +842,7 @@ impl LlmDeliberationFaculty { return Some(v); } if !calls.is_empty() { - self.prefill_during_tool(&binding.adapter, ws.room_id, request_template.as_ref(), &view.messages); + self.prefill_during_tool(&binding.adapter, ws.room_id, request_template.as_ref(), &view); return Some(self.act_verdict(calls, &resp, ws.activity_room_id)); } }