From da8d73a9dc11f66e7830870d3615514bf7a9a064 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 31 Oct 2026 00:56:35 -0500 Subject: [PATCH 1/4] The render receipt: what each served prompt showed her, in order, at the level the view chose, bound to her and the request (HER-TOOLS; #5585 consumes it) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - continuum-context: `Level` moves to `levels` (the crate's levels-of-detail owner) so the epoch can record it; each `Event` carries its occurrence (`ElementId`, now serde) and level; `View::receipt()` projects every block after the head in prompt order (occurrence, level, version, retired, chars); `View::sent()` keeps it until `take_submitted()`, never saved. - continuum-cognition: `render_receipt::{RenderReceipt, RenderReceiptSink}`; the faculty takes the view's receipt on every outcome of the request that carried it and delivers it to its one sink only where that request was served, so a prompt the engine never accepted is never receipted; a measurement fork has no sink. - The memory incarnation joins the binding with #5585's `WorkingMemory::incarnation` (Codex). - clippy: one pre-existing `map_or(true, …)` in view.rs becomes `is_none_or`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/cognition/llm_deliberation_faculty.rs | 9 +++ .../llm_deliberation_faculty/request.rs | 9 +++ core/continuum-cognition/src/cognition/mod.rs | 1 + .../src/cognition/render_receipt.rs | 23 +++++++ core/continuum-context/src/cause.rs | 2 +- core/continuum-context/src/epoch.rs | 42 +++++++---- core/continuum-context/src/levels.rs | 12 ++++ core/continuum-context/src/view.rs | 69 +++++++++++++++++-- core/continuum-context/src/view/allot.rs | 10 +-- core/continuum-context/src/view/tests.rs | 29 ++++++++ 10 files changed, 178 insertions(+), 28 deletions(-) create mode 100644 core/continuum-cognition/src/cognition/render_receipt.rs diff --git a/core/continuum-cognition/src/cognition/llm_deliberation_faculty.rs b/core/continuum-cognition/src/cognition/llm_deliberation_faculty.rs index 9d6a932a44..c9c559661a 100644 --- a/core/continuum-cognition/src/cognition/llm_deliberation_faculty.rs +++ b/core/continuum-cognition/src/cognition/llm_deliberation_faculty.rs @@ -236,6 +236,8 @@ pub struct LlmDeliberationFaculty { pub working_set: Option, /// Her context view across acts (`prompt/epoch.rs`): one epoch that only appends, turned /// over when it outgrows her history's grant. + /// Where her render receipts go (`crate::cognition::render_receipt`); `None` drops them. + receipt_sink: Option>, context_view: parking_lot::Mutex< Option>, >, @@ -272,6 +274,7 @@ impl LlmDeliberationFaculty { genome: empty_genome(), decoding: relaxed_decoding(), working_set: None, + receipt_sink: None, context_view: parking_lot::Mutex::new(None), tools_epoch: parking_lot::Mutex::new(None), forked: false, @@ -353,6 +356,12 @@ impl LlmDeliberationFaculty { /// browses, and the model loads any one tool's schema on demand via /// `commands/help`. An emitted call becomes a [`Decision::Act`] verdict the /// act→observe driver runs (the faculty itself never executes). + /// Install the one sink her render receipts go to (the task ledger, #5585). + pub fn with_receipt_sink(mut self, sink: Arc) -> Self { + self.receipt_sink = Some(sink); + self + } + pub fn with_tools(mut self, tools: Vec) -> Self { self.tools = tools; self.rebuild_tool_surface(); diff --git a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs index 9a3b832064..4b5a76cf96 100644 --- a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs +++ b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs @@ -84,6 +84,8 @@ impl LlmDeliberationFaculty { /// (`slots::PageKey::Fork`). Set only by `fork_eval_cycle`. pub fn forked(mut self) -> Self { self.forked = true; + // A fork's prompts are not hers: they never acknowledge what she was shown. + self.receipt_sink = None; self } @@ -288,6 +290,10 @@ impl LlmDeliberationFaculty { .and_then(|r| r.timing.as_ref()) .map(|t| (t.cached_tokens, t.prefill_tokens)), ); + // The render receipt: taken on every outcome, so a failed request's prompt is never + // receipted, and delivered only where the request was served. + let submitted = self.context_view.lock().as_mut().and_then(continuum_context::view::View::take_submitted); + let receipted_request = request_id.clone(); let receipt = match &gen_result { Ok(response) => crate::ai::provenance::GenerationReceipt::from_response(request_id, response), Err(error) => crate::ai::provenance::GenerationReceipt::faulted(request_id, error.to_string()), @@ -296,6 +302,9 @@ impl LlmDeliberationFaculty { // window reads: in the window it was served in, whether or not her turn settles soon. if matches!(receipt.outcome, crate::ai::provenance::GenerationOutcome::Served { .. }) { crate::cognition::resident_service::note_generation(self.persona_id); + if let (Some(view), Some(sink)) = (submitted, self.receipt_sink.as_ref()) { + sink.record(crate::cognition::render_receipt::RenderReceipt { owner: self.persona_id, request: receipted_request, view }); + } } receipts.push( receipt diff --git a/core/continuum-cognition/src/cognition/mod.rs b/core/continuum-cognition/src/cognition/mod.rs index 00fe7356d6..1b42ce42a1 100644 --- a/core/continuum-cognition/src/cognition/mod.rs +++ b/core/continuum-cognition/src/cognition/mod.rs @@ -91,6 +91,7 @@ pub use continuum_capture::prompt_capture; pub mod rag_source_faculty; pub mod rate_proposals; pub mod recall_faculty; +pub mod render_receipt; pub use continuum_prompt::audience; pub use continuum_engram::recall_ranker; pub mod replay; diff --git a/core/continuum-cognition/src/cognition/render_receipt.rs b/core/continuum-cognition/src/cognition/render_receipt.rs new file mode 100644 index 0000000000..291a0de59d --- /dev/null +++ b/core/continuum-cognition/src/cognition/render_receipt.rs @@ -0,0 +1,23 @@ +//! The render receipt: what one submitted prompt showed her, bound to whose mind it was and +//! which request carried it (HER-TOOLS, "The render receipt"). The view takes its half when the +//! prompt is sent (`View::sent`); the deliberation faculty binds it and hands it to the one sink +//! where the request was served, so a prompt the engine never accepted is never receipted. +//! The task ledger (#5585) is the sink: it acknowledges a task's end from the first receipt that +//! shows that task's item, and writes nothing else. The memory incarnation joins the binding +//! with that ledger's `WorkingMemory::incarnation`. + +use uuid::Uuid; + +/// One submitted, served prompt: whose, which request, and what it showed her in order. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct RenderReceipt { + pub owner: Uuid, + pub request: String, + pub view: continuum_context::view::Receipt, +} + +/// Where render receipts go. One per mind, installed at assembly; none installed, a receipt is +/// dropped (nothing consumes it yet). +pub trait RenderReceiptSink: Send + Sync { + fn record(&self, receipt: RenderReceipt); +} diff --git a/core/continuum-context/src/cause.rs b/core/continuum-context/src/cause.rs index 2e20d44ec6..3f5268a250 100644 --- a/core/continuum-context/src/cause.rs +++ b/core/continuum-context/src/cause.rs @@ -9,7 +9,7 @@ use sha2::{Digest, Sha256}; /// One occurrence, named by the producer that persists it (an act, a message, an engram): /// stable across epochs and restarts, never an in-view position. Two reads of one file are two /// occurrences with two ids; the file they read is the item's `key`. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] pub struct ElementId(u128); impl ElementId { diff --git a/core/continuum-context/src/epoch.rs b/core/continuum-context/src/epoch.rs index 543bbe6e5b..401fb7472a 100644 --- a/core/continuum-context/src/epoch.rs +++ b/core/continuum-context/src/epoch.rs @@ -34,6 +34,11 @@ impl Block for String { #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct Event { pub source: SourceId, + /// The occurrence this block renders (`crate::cause`); `None` for a source's fold block, + /// which stands for a range of items. + pub element: Option, + /// The level the view rendered it at: what a render receipt reports she was shown. + pub level: crate::levels::Level, pub version: u32, pub text: T, /// The source ended with this notice; turnover drops it entirely. @@ -77,7 +82,7 @@ impl Epoch { /// Record a source's current rendering. Appends only when it differs from that source's /// latest version; never edits an earlier block. - pub fn observe(&mut self, source: SourceId, text: T) -> Observed { + pub fn observe(&mut self, source: SourceId, element: Option, level: crate::levels::Level, text: T) -> Observed { let latest = self.events.iter().rposition(|e| e.source == source); if let Some(i) = latest { if self.events[i].text == text { @@ -86,7 +91,7 @@ impl Epoch { self.superseded_chars += self.events[i].text.chars(); } let version = latest.map_or(0, |i| self.events[i].version + 1); - self.events.push(Event { source, version, text, retired: false }); + self.events.push(Event { source, element, level, version, text, retired: false }); Observed::Appended { version } } @@ -102,8 +107,8 @@ impl Epoch { return Observed::Unchanged; } self.superseded_chars += self.events[i].text.chars(); - let version = self.events[i].version + 1; - self.events.push(Event { source, version, text: notice, retired: true }); + let (element, version) = (self.events[i].element, self.events[i].version + 1); + self.events.push(Event { source, element, level: crate::levels::Level::Pointer, version, text: notice, retired: true }); Observed::Appended { version } } @@ -124,6 +129,12 @@ impl Epoch { self.events.iter().any(|e| &e.source == source) } + /// Every block after the head, in prompt order, superseded versions included: what a render + /// receipt projects. + pub fn events(&self) -> &[Event] { + &self.events + } + /// The view in order: the head, then every event as it arrived. pub fn render(&self) -> impl Iterator { self.head.iter().chain(self.events.iter().map(|e| &e.text)) @@ -142,6 +153,11 @@ impl Epoch { #[cfg(test)] mod tests { + /// A test block: whole, standing for no particular occurrence. + fn seen(e: &mut Epoch, source: SourceId, text: String) -> Observed { + e.observe(source, None, crate::levels::Level::Full, text) + } + use super::*; fn src(s: &str) -> SourceId { @@ -166,7 +182,7 @@ mod tests { let mut previous = joined(&e); for act in acts { for (s, t) in act { - e.observe(src(s), t.to_string()); + seen(&mut e, src(s), t.to_string()); } let now = joined(&e); assert!(now.starts_with(&previous), "an act rewrote the prefix:\n{previous}\n---\n{now}"); @@ -178,9 +194,9 @@ mod tests { #[test] fn an_unchanged_source_appends_nothing() { let mut e = Epoch::::new(1, vec![]); - assert_eq!(e.observe(src("kanban"), "v1".into()), Observed::Appended { version: 0 }); - assert_eq!(e.observe(src("kanban"), "v1".into()), Observed::Unchanged); - assert_eq!(e.observe(src("kanban"), "v2".into()), Observed::Appended { version: 1 }); + assert_eq!(seen(&mut e, src("kanban"), "v1".into()), Observed::Appended { version: 0 }); + assert_eq!(seen(&mut e, src("kanban"), "v1".into()), Observed::Unchanged); + assert_eq!(seen(&mut e, src("kanban"), "v2".into()), Observed::Appended { version: 1 }); assert_eq!(e.superseded_chars(), 2); } @@ -191,12 +207,12 @@ mod tests { fn per_item_sources_append_only_the_item_that_changed() { let mut e = Epoch::::new(1, vec![]); for view in ["a.rs", "b.rs", "c.rs"] { - e.observe(src(&format!("open-views/{view}")), format!("{view} v1 {}", "x".repeat(1000))); + seen(&mut e, src(&format!("open-views/{view}")), format!("{view} v1 {}", "x".repeat(1000))); } let before: usize = e.chars(); - e.observe(src("open-views/a.rs"), "a.rs v1 ".to_string() + &"x".repeat(1000)); - e.observe(src("open-views/b.rs"), "b.rs v2".into()); - e.observe(src("open-views/c.rs"), "c.rs v1 ".to_string() + &"x".repeat(1000)); + seen(&mut e, src("open-views/a.rs"), "a.rs v1 ".to_string() + &"x".repeat(1000)); + seen(&mut e, src("open-views/b.rs"), "b.rs v2".into()); + seen(&mut e, src("open-views/c.rs"), "c.rs v1 ".to_string() + &"x".repeat(1000)); let after: usize = e.chars(); assert_eq!(after - before, "b.rs v2".len(), "only the changed view was appended"); } @@ -206,7 +222,7 @@ mod tests { #[test] fn retiring_a_source_appends_its_notice_once() { let mut e = Epoch::::new(1, vec![]); - e.observe(src("open-views/a.rs"), "a.rs contents".into()); + seen(&mut e, src("open-views/a.rs"), "a.rs contents".into()); let before = joined(&e); assert_eq!(e.retire(src("open-views/a.rs"), "[closed a.rs]".into()), Observed::Appended { version: 1 }); assert!(joined(&e).starts_with(&before)); diff --git a/core/continuum-context/src/levels.rs b/core/continuum-context/src/levels.rs index 7a221f20e0..701dff3a32 100644 --- a/core/continuum-context/src/levels.rs +++ b/core/continuum-context/src/levels.rs @@ -131,6 +131,17 @@ fn head(full: &str, budget: usize) -> Option { (kept > 0 && more > 0).then(|| format!("{}\n… and {more} more (expand to read them)", lines[..kept].join("\n"))) } +/// How much of an item the view renders: whole, its summary, its pointer, or inside its +/// source's one fold block with the rest of the oldest run. The view decides it; the epoch +/// records it on each block, so a render receipt says what she was actually shown. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub enum Level { + Full, + Summary, + Pointer, + Folded, +} + #[cfg(test)] mod tests { use super::*; @@ -185,3 +196,4 @@ mod tests { assert_eq!(summarize("one\ntwo\n", Shape::List), None); } } + diff --git a/core/continuum-context/src/view.rs b/core/continuum-context/src/view.rs index 4f953ff94b..d20cd0d192 100644 --- a/core/continuum-context/src/view.rs +++ b/core/continuum-context/src/view.rs @@ -20,7 +20,8 @@ use crate::source::{Item, Source}; mod allot; -use allot::{allot, rank, Level}; +use allot::{allot, rank}; +pub use crate::levels::Level; pub use allot::floor; /// The item key a source's fold block is observed under: no source keys an item with it. @@ -75,6 +76,26 @@ pub struct Start { pub folded: usize, } +/// One block she was shown, as the view rendered it (`View::receipt`). +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct Rendered { + pub source: SourceId, + /// The occurrence it renders; `None` for a fold block, which stands for a range. + pub element: Option, + pub level: Level, + pub version: u32, + /// A superseding notice for a source that ended. + pub retired: bool, + pub chars: usize, +} + +/// What one submitted prompt showed her, in prompt order (the view's half of the render receipt). +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct Receipt { + pub epoch: u64, + pub items: Vec, +} + /// Serializable, so a mind's view survives her restart with the rest of her volatile state: /// restored, it renders the same bytes, and the engine's saved page for it still matches. #[derive(Clone, Debug, serde::Serialize, serde::Deserialize)] @@ -99,6 +120,11 @@ pub struct View { /// redoes. Never saved: a restored view has no unsent act. #[serde(skip)] act: Option, + /// What the last sent prompt showed her, until the request that carried it is served: + /// taken there ([`View::take_submitted`]), so a prompt the engine never accepted is never + /// receipted. Never saved: a restored view has nothing in flight. + #[serde(skip)] + submitted: Option, } fn key(source: &str, item: &str) -> SourceId { @@ -216,12 +242,14 @@ impl View { appended: Vec::new(), motion: Motion::default(), act: None, + submitted: None, }; for ((source, items), grant) in sources.iter().zip(offered).zip(grants) { let allot::Allotment { levels, mut fold } = allot(&**source, &items, grant); let mut rendered = Vec::with_capacity(items.len()); for (item, level) in items.into_iter().zip(levels) { let id = key(source.name(), &item.key); + let element = item.id(); let item_key = item.key.clone(); // its fingerprint after the level consumed it; once per item per start let text = match level { Level::Full => Some(crate::source::whole(&**source, item)), @@ -239,14 +267,14 @@ impl View { view.folded.insert(id); if let Some(block) = fold.take() { rendered.push((fingerprint(FOLD_KEY, &block), block.chars())); - view.epoch.observe(key(source.name(), FOLD_KEY), block); + view.epoch.observe(key(source.name(), FOLD_KEY), None, Level::Folded, block); } continue; } }; if let Some(text) = text { rendered.push((fingerprint(&item_key, &text), text.chars())); - view.epoch.observe(id, text); + view.epoch.observe(id, Some(element), level, text); } } motion.record(source.name(), rendered); @@ -304,6 +332,13 @@ impl View { /// so nothing may rewind past it and [`View::readmit`] answers `None` until the next act. pub fn sent(&mut self) { self.act = None; + self.submitted = Some(self.receipt()); + } + + /// The receipt of the last sent prompt, once: the caller takes it where the request that + /// carried it was served, and drops it when the request failed. + pub fn take_submitted(&mut self) -> Option { + self.submitted.take() } fn append(&mut self, sources: &[&dyn Source], limit: Option<(usize, usize)>) -> Advance { @@ -319,7 +354,7 @@ impl View { // An item with no pointer would leave her view entirely if collapsed (a peer's // new turn), so it always arrives whole: admission never drops what she has // not seen. - let fits = |chars: usize| limit.map_or(true, |(limit, _)| self.epoch.chars() + chars <= limit); // map_or: no limit admits every arrival whole + let fits = |chars: usize| limit.is_none_or(|(limit, _)| self.epoch.chars() + chars <= limit); // no limit admits every arrival whole let oversized = limit.is_some_and(|(_, oversized)| crate::source::whole_chars(&item) > oversized); let level = if self.collapsed.contains(&id) { Level::Pointer @@ -334,6 +369,7 @@ impl View { self.collapsed.insert(id.clone()); Level::Pointer }; + let element = item.id(); let text = match level { Level::Full => Some(crate::source::whole(&**source, item)), Level::Summary => item.summary.or(item.pointer), @@ -341,7 +377,7 @@ impl View { }; if let Some(text) = text { let chars = text.chars(); - if let Observed::Appended { .. } = self.epoch.observe(id, text) { + if let Observed::Appended { .. } = self.epoch.observe(id, Some(element), level, text) { advance.items += 1; advance.chars += chars; } @@ -364,6 +400,29 @@ impl View { self.epoch.render() } + /// What she is shown, in prompt order: each block after the head with its occurrence, the + /// level the view rendered it at, its version and its size. Taken where the prompt is + /// SUBMITTED (the caller binds owner, memory incarnation and request there), never at + /// rendering: a prompt built but not accepted was not seen (HER-TOOLS, the render receipt). + pub fn receipt(&self) -> Receipt { + Receipt { + epoch: self.epoch.id(), + items: self + .epoch + .events() + .iter() + .map(|event| Rendered { + source: event.source.clone(), + element: event.element, + level: event.level, + version: event.version, + retired: event.retired, + chars: event.text.chars(), + }) + .collect(), + } + } + /// How each source moved across this view's starts. pub fn motion(&self) -> &Motion { &self.motion diff --git a/core/continuum-context/src/view/allot.rs b/core/continuum-context/src/view/allot.rs index 7349e7eb25..1733a05edf 100644 --- a/core/continuum-context/src/view/allot.rs +++ b/core/continuum-context/src/view/allot.rs @@ -9,15 +9,7 @@ use crate::epoch::Block; use crate::source::{whole_chars, Item, Source}; -/// How much of an item the view renders: whole, its summary, its pointer, or inside its -/// source's one fold block with the rest of the oldest run. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(super) enum Level { - Full, - Summary, - Pointer, - Folded, -} +pub(super) use crate::levels::Level; /// How much of an item a level shows, for comparing two levels of one item. pub(super) fn rank(level: &Level) -> u8 { diff --git a/core/continuum-context/src/view/tests.rs b/core/continuum-context/src/view/tests.rs index 86905e2da0..0915573e2f 100644 --- a/core/continuum-context/src/view/tests.rs +++ b/core/continuum-context/src/view/tests.rs @@ -563,3 +563,32 @@ fn an_act_appends_one_result_and_neither_turns_over_nor_grows_the_floor() -> Res assert!(!view.start_would_restore(&[&actions], |_| vec![grant])?, "the same grant restores nothing"); Ok(()) } + +// what this catches: a receipt that cannot say which occurrence she was shown, or at what level, +// or in what order (the acknowledgement of a task's end reads exactly this, HER-TASKS; the +// allocator reads it to learn what a grant bought). +#[test] +fn the_receipt_names_each_shown_occurrence_and_its_level_in_prompt_order() -> Result<(), GrantMismatch> { + let mut results = Fake::new("results", 1); + results.push("r1", &"a".repeat(3_000)); + results.push("r2", "two"); + let (mut view, _) = View::start(Vec::new(), &[&results as &dyn Source], |_| vec![100])?; + results.push("r3", "three"); + view.advance(&[&results]); + let receipt = view.receipt(); + let id = |k: &str| Some(ElementId::of(&[k.as_bytes()])); + let shown: Vec<_> = receipt.items.iter().map(|r| (r.element, r.level)).collect(); + assert_eq!(shown[shown.len() - 2..], [(id("r2"), Level::Full), (id("r3"), Level::Full)], "{shown:?}"); + match shown[0] { + (element, Level::Pointer) => assert_eq!(element, id("r1")), + (None, Level::Folded) => {} + other => panic!("the oldest, too large for the grant, is not whole: {other:?}"), + } + assert_eq!(receipt.epoch, view.epoch_id()); + assert_eq!(receipt.items.iter().map(|r| r.chars).sum::(), view.chars(), "the receipt accounts for every block after the head"); + assert_eq!(view.take_submitted(), None, "nothing was sent yet"); + view.sent(); + assert_eq!(view.take_submitted(), Some(receipt), "the sent prompt's receipt, taken once"); + assert_eq!(view.take_submitted(), None); + Ok(()) +} From 4866823d7e7bfb04d14762a686545b0443e58660 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 31 Oct 2026 01:21:29 -0500 Subject: [PATCH 2/4] render receipt: Level gets its own module (levels.rs untouched); the sink is installed per mind in render_receipt (the faculty file untouched); a fork never delivers Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/cognition/llm_deliberation_faculty.rs | 9 -------- .../llm_deliberation_faculty/request.rs | 11 ++++++---- .../src/cognition/render_receipt.rs | 21 +++++++++++++++++-- core/continuum-context/src/epoch.rs | 8 +++---- core/continuum-context/src/level.rs | 12 +++++++++++ core/continuum-context/src/levels.rs | 12 ----------- core/continuum-context/src/lib.rs | 2 ++ core/continuum-context/src/view.rs | 2 +- core/continuum-context/src/view/allot.rs | 2 +- 9 files changed, 46 insertions(+), 33 deletions(-) create mode 100644 core/continuum-context/src/level.rs diff --git a/core/continuum-cognition/src/cognition/llm_deliberation_faculty.rs b/core/continuum-cognition/src/cognition/llm_deliberation_faculty.rs index c9c559661a..9d6a932a44 100644 --- a/core/continuum-cognition/src/cognition/llm_deliberation_faculty.rs +++ b/core/continuum-cognition/src/cognition/llm_deliberation_faculty.rs @@ -236,8 +236,6 @@ pub struct LlmDeliberationFaculty { pub working_set: Option, /// Her context view across acts (`prompt/epoch.rs`): one epoch that only appends, turned /// over when it outgrows her history's grant. - /// Where her render receipts go (`crate::cognition::render_receipt`); `None` drops them. - receipt_sink: Option>, context_view: parking_lot::Mutex< Option>, >, @@ -274,7 +272,6 @@ impl LlmDeliberationFaculty { genome: empty_genome(), decoding: relaxed_decoding(), working_set: None, - receipt_sink: None, context_view: parking_lot::Mutex::new(None), tools_epoch: parking_lot::Mutex::new(None), forked: false, @@ -356,12 +353,6 @@ impl LlmDeliberationFaculty { /// browses, and the model loads any one tool's schema on demand via /// `commands/help`. An emitted call becomes a [`Decision::Act`] verdict the /// act→observe driver runs (the faculty itself never executes). - /// Install the one sink her render receipts go to (the task ledger, #5585). - pub fn with_receipt_sink(mut self, sink: Arc) -> Self { - self.receipt_sink = Some(sink); - self - } - pub fn with_tools(mut self, tools: Vec) -> Self { self.tools = tools; self.rebuild_tool_surface(); diff --git a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs index 4b5a76cf96..08c70ed9be 100644 --- a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs +++ b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs @@ -84,8 +84,6 @@ impl LlmDeliberationFaculty { /// (`slots::PageKey::Fork`). Set only by `fork_eval_cycle`. pub fn forked(mut self) -> Self { self.forked = true; - // A fork's prompts are not hers: they never acknowledge what she was shown. - self.receipt_sink = None; self } @@ -302,8 +300,13 @@ impl LlmDeliberationFaculty { // window reads: in the window it was served in, whether or not her turn settles soon. if matches!(receipt.outcome, crate::ai::provenance::GenerationOutcome::Served { .. }) { crate::cognition::resident_service::note_generation(self.persona_id); - if let (Some(view), Some(sink)) = (submitted, self.receipt_sink.as_ref()) { - sink.record(crate::cognition::render_receipt::RenderReceipt { owner: self.persona_id, request: receipted_request, view }); + // A measurement fork's prompts are not hers: they never acknowledge what she was shown. + if let (Some(view), false) = (submitted, self.forked) { + crate::cognition::render_receipt::deliver(crate::cognition::render_receipt::RenderReceipt { + owner: self.persona_id, + request: receipted_request, + view, + }); } } receipts.push( diff --git a/core/continuum-cognition/src/cognition/render_receipt.rs b/core/continuum-cognition/src/cognition/render_receipt.rs index 291a0de59d..0d1937b8e6 100644 --- a/core/continuum-cognition/src/cognition/render_receipt.rs +++ b/core/continuum-cognition/src/cognition/render_receipt.rs @@ -16,8 +16,25 @@ pub struct RenderReceipt { pub view: continuum_context::view::Receipt, } -/// Where render receipts go. One per mind, installed at assembly; none installed, a receipt is -/// dropped (nothing consumes it yet). +/// Where render receipts go. One per mind, installed at assembly ([`install`]); none installed, +/// a receipt is dropped (nothing consumes it yet). pub trait RenderReceiptSink: Send + Sync { fn record(&self, receipt: RenderReceipt); } + +static SINKS: parking_lot::RwLock>>> = + parking_lot::RwLock::new(None); + +/// Install the one sink `owner`'s receipts go to (the task ledger, #5585). A second install for +/// the same mind replaces the first. +pub fn install(owner: Uuid, sink: std::sync::Arc) { + SINKS.write().get_or_insert_with(Default::default).insert(owner, sink); +} + +/// Hand a served prompt's receipt to its owner's sink, if one is installed. +pub(crate) fn deliver(receipt: RenderReceipt) { + let sink = SINKS.read().as_ref().and_then(|sinks| sinks.get(&receipt.owner).cloned()); + if let Some(sink) = sink { + sink.record(receipt); + } +} diff --git a/core/continuum-context/src/epoch.rs b/core/continuum-context/src/epoch.rs index 401fb7472a..8adde1c381 100644 --- a/core/continuum-context/src/epoch.rs +++ b/core/continuum-context/src/epoch.rs @@ -38,7 +38,7 @@ pub struct Event { /// which stands for a range of items. pub element: Option, /// The level the view rendered it at: what a render receipt reports she was shown. - pub level: crate::levels::Level, + pub level: crate::level::Level, pub version: u32, pub text: T, /// The source ended with this notice; turnover drops it entirely. @@ -82,7 +82,7 @@ impl Epoch { /// Record a source's current rendering. Appends only when it differs from that source's /// latest version; never edits an earlier block. - pub fn observe(&mut self, source: SourceId, element: Option, level: crate::levels::Level, text: T) -> Observed { + pub fn observe(&mut self, source: SourceId, element: Option, level: crate::level::Level, text: T) -> Observed { let latest = self.events.iter().rposition(|e| e.source == source); if let Some(i) = latest { if self.events[i].text == text { @@ -108,7 +108,7 @@ impl Epoch { } self.superseded_chars += self.events[i].text.chars(); let (element, version) = (self.events[i].element, self.events[i].version + 1); - self.events.push(Event { source, element, level: crate::levels::Level::Pointer, version, text: notice, retired: true }); + self.events.push(Event { source, element, level: crate::level::Level::Pointer, version, text: notice, retired: true }); Observed::Appended { version } } @@ -155,7 +155,7 @@ impl Epoch { mod tests { /// A test block: whole, standing for no particular occurrence. fn seen(e: &mut Epoch, source: SourceId, text: String) -> Observed { - e.observe(source, None, crate::levels::Level::Full, text) + e.observe(source, None, crate::level::Level::Full, text) } use super::*; diff --git a/core/continuum-context/src/level.rs b/core/continuum-context/src/level.rs new file mode 100644 index 0000000000..b802fd3387 --- /dev/null +++ b/core/continuum-context/src/level.rs @@ -0,0 +1,12 @@ +//! How much of an item the view renders. The view decides it; the epoch records it on each block, +//! so a render receipt says what she was actually shown. + +/// Whole, its summary, its pointer, or inside its source's one fold block with the rest of the +/// oldest run. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub enum Level { + Full, + Summary, + Pointer, + Folded, +} diff --git a/core/continuum-context/src/levels.rs b/core/continuum-context/src/levels.rs index 701dff3a32..7a221f20e0 100644 --- a/core/continuum-context/src/levels.rs +++ b/core/continuum-context/src/levels.rs @@ -131,17 +131,6 @@ fn head(full: &str, budget: usize) -> Option { (kept > 0 && more > 0).then(|| format!("{}\n… and {more} more (expand to read them)", lines[..kept].join("\n"))) } -/// How much of an item the view renders: whole, its summary, its pointer, or inside its -/// source's one fold block with the rest of the oldest run. The view decides it; the epoch -/// records it on each block, so a render receipt says what she was actually shown. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] -pub enum Level { - Full, - Summary, - Pointer, - Folded, -} - #[cfg(test)] mod tests { use super::*; @@ -196,4 +185,3 @@ mod tests { assert_eq!(summarize("one\ntwo\n", Shape::List), None); } } - diff --git a/core/continuum-context/src/lib.rs b/core/continuum-context/src/lib.rs index a4e61ea425..d22b6382dd 100644 --- a/core/continuum-context/src/lib.rs +++ b/core/continuum-context/src/lib.rs @@ -4,12 +4,14 @@ //! - [`cause`]: what each element follows from: its occurrence id, its cause, its content. //! - [`epoch`]: a stable head, then keyed blocks that only append. //! - [`source`]: what a context source offers: its current items, each under a stable key. +//! - [`level`]: how much of an item the view rendered (whole, summary, pointer, folded). //! - [`levels`]: each item's summary level, generated from its shape (mipmaps for context). //! - [`motion`]: how each source moves between epoch starts, which orders the next start. //! - [`view`]: one mind's epoch fed by its sources; turnover is the only rewrite. pub mod cause; pub mod epoch; +pub mod level; pub mod levels; pub mod motion; pub mod source; diff --git a/core/continuum-context/src/view.rs b/core/continuum-context/src/view.rs index d20cd0d192..d3d47bf858 100644 --- a/core/continuum-context/src/view.rs +++ b/core/continuum-context/src/view.rs @@ -21,7 +21,7 @@ use crate::source::{Item, Source}; mod allot; use allot::{allot, rank}; -pub use crate::levels::Level; +pub use crate::level::Level; pub use allot::floor; /// The item key a source's fold block is observed under: no source keys an item with it. diff --git a/core/continuum-context/src/view/allot.rs b/core/continuum-context/src/view/allot.rs index 1733a05edf..42ac556d15 100644 --- a/core/continuum-context/src/view/allot.rs +++ b/core/continuum-context/src/view/allot.rs @@ -9,7 +9,7 @@ use crate::epoch::Block; use crate::source::{whole_chars, Item, Source}; -pub(super) use crate::levels::Level; +pub(super) use crate::level::Level; /// How much of an item a level shows, for comparing two levels of one item. pub(super) fn rank(level: &Level) -> u8 { From f1e9bf58334ca53783e469a7734ddb77d0702c2d Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 31 Oct 2026 01:26:44 -0500 Subject: [PATCH 3/4] Epoch::observe: identical bytes that now stand for another occurrence or level update the block in place (no append), so the receipt never reports stale evidence (Codex on #5639) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- core/continuum-context/src/epoch.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/continuum-context/src/epoch.rs b/core/continuum-context/src/epoch.rs index 8adde1c381..1f5314e52f 100644 --- a/core/continuum-context/src/epoch.rs +++ b/core/continuum-context/src/epoch.rs @@ -86,6 +86,13 @@ impl Epoch { let latest = self.events.iter().rposition(|e| e.source == source); if let Some(i) = latest { if self.events[i].text == text { + // The same bytes now stand for another occurrence or level (a short item whose + // pointer is itself, a re-read of unchanged content): the prompt is unchanged, so + // nothing appends, but what the block IS updates in place, or a receipt would + // report the old occurrence or level (Codex on #5639). + let event = &mut self.events[i]; + event.element = element; + event.level = level; return Observed::Unchanged; } self.superseded_chars += self.events[i].text.chars(); @@ -153,6 +160,22 @@ impl Epoch { #[cfg(test)] mod tests { + // what this catches: a receipt reporting stale evidence when identical bytes change meaning: + // a block first shown as a pointer whose whole is the same bytes, or a re-read of unchanged + // content by a new occurrence (Codex on #5639). The prompt must not grow; the metadata must. + #[test] + fn identical_bytes_with_a_new_level_or_occurrence_update_the_block_without_appending() { + use crate::cause::ElementId; + use crate::level::Level; + let mut e = Epoch::::new(1, Vec::new()); + let (first, second) = (ElementId::of(&[b"read 1"]), ElementId::of(&[b"read 2"])); + assert_eq!(e.observe(src("open-views/a.rs"), Some(first), Level::Pointer, "a.rs: 3 lines".into()), Observed::Appended { version: 0 }); + assert_eq!(e.observe(src("open-views/a.rs"), Some(first), Level::Full, "a.rs: 3 lines".into()), Observed::Unchanged); + assert_eq!((e.events().len(), e.events()[0].level), (1, Level::Full), "same bytes, now its whole"); + assert_eq!(e.observe(src("open-views/a.rs"), Some(second), Level::Full, "a.rs: 3 lines".into()), Observed::Unchanged); + assert_eq!((e.events().len(), e.events()[0].element), (1, Some(second)), "same bytes, now the newer occurrence"); + } + /// A test block: whole, standing for no particular occurrence. fn seen(e: &mut Epoch, source: SourceId, text: String) -> Observed { e.observe(source, None, crate::level::Level::Full, text) From a5122bdaf9e3420d5606ee07b7a574b2a9c6ead0 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 31 Oct 2026 01:55:00 -0500 Subject: [PATCH 4/4] render receipt: this PR carries the view's receipt only; delivery joins the owned Contribution -> Workspace path in Codex's #5585 integration (no second registry) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../llm_deliberation_faculty/request.rs | 12 ------ core/continuum-cognition/src/cognition/mod.rs | 1 - .../src/cognition/render_receipt.rs | 40 ------------------- 3 files changed, 53 deletions(-) delete mode 100644 core/continuum-cognition/src/cognition/render_receipt.rs diff --git a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs index 08c70ed9be..9a3b832064 100644 --- a/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs +++ b/core/continuum-cognition/src/cognition/llm_deliberation_faculty/request.rs @@ -288,10 +288,6 @@ impl LlmDeliberationFaculty { .and_then(|r| r.timing.as_ref()) .map(|t| (t.cached_tokens, t.prefill_tokens)), ); - // The render receipt: taken on every outcome, so a failed request's prompt is never - // receipted, and delivered only where the request was served. - let submitted = self.context_view.lock().as_mut().and_then(continuum_context::view::View::take_submitted); - let receipted_request = request_id.clone(); let receipt = match &gen_result { Ok(response) => crate::ai::provenance::GenerationReceipt::from_response(request_id, response), Err(error) => crate::ai::provenance::GenerationReceipt::faulted(request_id, error.to_string()), @@ -300,14 +296,6 @@ impl LlmDeliberationFaculty { // window reads: in the window it was served in, whether or not her turn settles soon. if matches!(receipt.outcome, crate::ai::provenance::GenerationOutcome::Served { .. }) { crate::cognition::resident_service::note_generation(self.persona_id); - // A measurement fork's prompts are not hers: they never acknowledge what she was shown. - if let (Some(view), false) = (submitted, self.forked) { - crate::cognition::render_receipt::deliver(crate::cognition::render_receipt::RenderReceipt { - owner: self.persona_id, - request: receipted_request, - view, - }); - } } receipts.push( receipt diff --git a/core/continuum-cognition/src/cognition/mod.rs b/core/continuum-cognition/src/cognition/mod.rs index 1b42ce42a1..00fe7356d6 100644 --- a/core/continuum-cognition/src/cognition/mod.rs +++ b/core/continuum-cognition/src/cognition/mod.rs @@ -91,7 +91,6 @@ pub use continuum_capture::prompt_capture; pub mod rag_source_faculty; pub mod rate_proposals; pub mod recall_faculty; -pub mod render_receipt; pub use continuum_prompt::audience; pub use continuum_engram::recall_ranker; pub mod replay; diff --git a/core/continuum-cognition/src/cognition/render_receipt.rs b/core/continuum-cognition/src/cognition/render_receipt.rs deleted file mode 100644 index 0d1937b8e6..0000000000 --- a/core/continuum-cognition/src/cognition/render_receipt.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! The render receipt: what one submitted prompt showed her, bound to whose mind it was and -//! which request carried it (HER-TOOLS, "The render receipt"). The view takes its half when the -//! prompt is sent (`View::sent`); the deliberation faculty binds it and hands it to the one sink -//! where the request was served, so a prompt the engine never accepted is never receipted. -//! The task ledger (#5585) is the sink: it acknowledges a task's end from the first receipt that -//! shows that task's item, and writes nothing else. The memory incarnation joins the binding -//! with that ledger's `WorkingMemory::incarnation`. - -use uuid::Uuid; - -/// One submitted, served prompt: whose, which request, and what it showed her in order. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct RenderReceipt { - pub owner: Uuid, - pub request: String, - pub view: continuum_context::view::Receipt, -} - -/// Where render receipts go. One per mind, installed at assembly ([`install`]); none installed, -/// a receipt is dropped (nothing consumes it yet). -pub trait RenderReceiptSink: Send + Sync { - fn record(&self, receipt: RenderReceipt); -} - -static SINKS: parking_lot::RwLock>>> = - parking_lot::RwLock::new(None); - -/// Install the one sink `owner`'s receipts go to (the task ledger, #5585). A second install for -/// the same mind replaces the first. -pub fn install(owner: Uuid, sink: std::sync::Arc) { - SINKS.write().get_or_insert_with(Default::default).insert(owner, sink); -} - -/// Hand a served prompt's receipt to its owner's sink, if one is installed. -pub(crate) fn deliver(receipt: RenderReceipt) { - let sink = SINKS.read().as_ref().and_then(|sinks| sinks.get(&receipt.owner).cloned()); - if let Some(sink) = sink { - sink.record(receipt); - } -}