From 4106c1447b25033bdc57f600d52b180dc7ffd2b6 Mon Sep 17 00:00:00 2001 From: joelteply Date: Sat, 31 Oct 2026 12:53:43 -0500 Subject: [PATCH] A checkpoint's derived fields share one decoder: derived::or_none drops a field that no longer decodes (with a probe naming its type), and ActionRecord.act now uses it beside context_view (card c990acbe) derived_view.rs held the rule for one field. ActionRecord.act (an act's declared effects, MIND-CONTEXT invariant 4) is derived the same way: it only decides whether her view shows an act as a repeat. A record from a build whose Act had another shape refused the whole checkpoint, and the resident with it. That is the 2026-10-31 M5 outage shape (#5639 -> #5659), still open for this field. - working_memory/derived.rs (renamed from derived_view.rs): or_none. It reads the field's exact text (Box) and decodes it with from_str, never through serde_json::Value, which cannot hold a view's u128 ids. The probe persona.checkpoint.derived_dropped names std::any::type_name::() and the error. - context_view and ActionRecord.act both use deserialize_with = derived::or_none. Every authoritative field still refuses a corrupt value. Test: an_act_from_an_older_build_is_dropped_and_its_record_survives. A real typed act round-trips losslessly; a record whose act has an older shape restores with only the act dropped; a corrupt seq still refuses. Mutation: without deserialize_with on act it panics at actions.rs:414. Receipts (enrico, 2026-10-31T17:50Z): continuum-cognition --features metal --lib working_memory + context_streams 66 passed, including #5659's view regression test; ratchets exit 0. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE --- .../src/cognition/working_memory.rs | 6 ++-- .../cognition/working_memory/action_log.rs | 4 ++- .../src/cognition/working_memory/derived.rs | 33 +++++++++++++++++++ .../cognition/working_memory/derived_view.rs | 33 ------------------- .../cognition/working_memory/tests/actions.rs | 28 ++++++++++++++++ 5 files changed, 67 insertions(+), 37 deletions(-) create mode 100644 core/continuum-cognition/src/cognition/working_memory/derived.rs delete mode 100644 core/continuum-cognition/src/cognition/working_memory/derived_view.rs diff --git a/core/continuum-cognition/src/cognition/working_memory.rs b/core/continuum-cognition/src/cognition/working_memory.rs index ecf1588731..85b59b4730 100644 --- a/core/continuum-cognition/src/cognition/working_memory.rs +++ b/core/continuum-cognition/src/cognition/working_memory.rs @@ -427,8 +427,8 @@ pub struct VolatileSnapshot { #[serde(default, skip_serializing_if = "Vec::is_empty")] pub(crate) actions: Vec, /// Her context view ([`WorkingMemory`]'s `view`), derived: absent, or no longer decodable - /// (`derived_view`), her first act after the restore starts a new one. - #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "derived_view::or_new_epoch")] + /// (`derived::or_none`), her first act after the restore starts a new one. + #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "derived::or_none")] pub(crate) context_view: Option, /// Each retained receipt's per-call dependencies ([`WorkingMemory`]'s `receipt_children`), /// so a restart keeps what a restored receipt points at reachable. Empty on snapshots @@ -600,7 +600,7 @@ pub struct WmEntry { } -mod derived_view; +mod derived; mod action_log; mod continuity; mod ledger; diff --git a/core/continuum-cognition/src/cognition/working_memory/action_log.rs b/core/continuum-cognition/src/cognition/working_memory/action_log.rs index 6d64871507..59388e24cb 100644 --- a/core/continuum-cognition/src/cognition/working_memory/action_log.rs +++ b/core/continuum-cognition/src/cognition/working_memory/action_log.rs @@ -68,7 +68,9 @@ pub(crate) struct ActionRecord { /// What the act asked for and what its commands declare they do (MIND-CONTEXT invariant 4): /// the view renders an unchanged observation as a repeat from this. `None` for a record from /// a build before it was kept, or a legacy text receipt: such an act is never a repeat. - #[serde(default, skip_serializing_if = "Option::is_none")] + /// Derived: one that no longer decodes is dropped (`derived::or_none`), so that act is never a + /// repeat, and the checkpoint still restores. + #[serde(default, skip_serializing_if = "Option::is_none", deserialize_with = "super::derived::or_none")] pub act: Option, } diff --git a/core/continuum-cognition/src/cognition/working_memory/derived.rs b/core/continuum-cognition/src/cognition/working_memory/derived.rs new file mode 100644 index 0000000000..e283d3f7dc --- /dev/null +++ b/core/continuum-cognition/src/cognition/working_memory/derived.rs @@ -0,0 +1,33 @@ +//! A checkpoint field that is DERIVED is a cache, never the record: her context view is re-rendered +//! at a new epoch from her working memory, and an act's declared effects only decide whether her +//! view shows it as a repeat. A derived field that no longer decodes (its shape changed in a later +//! build) is dropped like an absent one, with a probe naming its type, and never fails the checkpoint +//! it rides in: on 2026-10-31 a new field on the view's events (#5639) made every resident's +//! checkpoint undecodable and the M5 hosted no one for 32 minutes ("workspace registration failed: +//! missing field `level`"). Nothing old is read here; the stale value is discarded. + +use serde::de::DeserializeOwned; +use serde::{Deserialize, Deserializer}; +use serde_json::value::RawValue; + +/// A derived field's deserializer: the value when it decodes, else none (and a probe saying which +/// type and why). The value is read as its exact source text first (`RawValue`), never as a +/// `serde_json::Value`: a view's element ids are u128, which a `Value` cannot hold ("number out of +/// range"), so a `Value` intermediate would refuse every valid view (Codex on #5659, executed test). +pub(crate) fn or_none<'de, D: Deserializer<'de>, T: DeserializeOwned>(deserializer: D) -> Result, D::Error> { + let Some(raw) = Option::>::deserialize(deserializer)? else { + return Ok(None); + }; + match serde_json::from_str::(raw.get()) { + Ok(value) => Ok(Some(value)), + Err(error) => { + continuum_base::probe!( + class = "persona.checkpoint.derived_dropped", + derived = std::any::type_name::(), + error = %error, + "a checkpoint's derived field no longer decodes (its shape changed); it is a cache, so it is dropped and rebuilt" + ); + Ok(None) + } + } +} diff --git a/core/continuum-cognition/src/cognition/working_memory/derived_view.rs b/core/continuum-cognition/src/cognition/working_memory/derived_view.rs deleted file mode 100644 index ccc9145480..0000000000 --- a/core/continuum-cognition/src/cognition/working_memory/derived_view.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! A checkpoint's context view is DERIVED: her view is re-rendered at a new epoch from her working -//! memory, so it is a cache of what she last saw, never the record of it. A view that no longer -//! decodes (its shape changed in a later build) is dropped like an absent one, with a probe, and her -//! next act opens a new epoch. It never fails the checkpoint it rides in: on 2026-10-31 a new field on -//! the view's events (#5639) made every resident's checkpoint undecodable and the M5 hosted no one -//! for 32 minutes ("workspace registration failed: missing field `level`"). Nothing old is read here; -//! the stale view is discarded. - -use serde::{Deserialize, Deserializer}; -use serde_json::value::RawValue; - -use super::ContextView; - -/// `context_view`'s deserializer: the view when it decodes, else none (and a probe saying why). -/// The view is read as its exact source text first (`RawValue`), never as a `serde_json::Value`: -/// a view's element ids are u128, which a `Value` cannot hold ("number out of range"), so a -/// `Value` intermediate would refuse every valid view (Codex on #5659, executed test). -pub(crate) fn or_new_epoch<'de, D: Deserializer<'de>>(deserializer: D) -> Result, D::Error> { - let Some(raw) = Option::>::deserialize(deserializer)? else { - return Ok(None); - }; - match serde_json::from_str::(raw.get()) { - Ok(view) => Ok(Some(view)), - Err(error) => { - continuum_base::probe!( - class = "persona.checkpoint.view_dropped", - error = %error, - "a checkpoint's context view no longer decodes (its shape changed); it is derived, so it is dropped and her next act opens a new epoch" - ); - Ok(None) - } - } -} diff --git a/core/continuum-cognition/src/cognition/working_memory/tests/actions.rs b/core/continuum-cognition/src/cognition/working_memory/tests/actions.rs index 9b847bb105..8866b75972 100644 --- a/core/continuum-cognition/src/cognition/working_memory/tests/actions.rs +++ b/core/continuum-cognition/src/cognition/working_memory/tests/actions.rs @@ -389,3 +389,31 @@ fn a_batch_receipts_summary_keeps_every_operation() { let shell = summary_of(vec![act("code/shell", serde_json::json!({ "command": "cargo build" }), serde_json::json!({ "success": false, "stdout": log }).to_string())]).unwrap_or_default(); assert!(shell.contains("error[E0308]: mismatched types") && !shell.contains("[outline"), "an output keeps its ends: {shell}"); } + +// what this catches: an act's declared effects (`ActionRecord.act`, MIND-CONTEXT invariant 4) are +// derived, like her view: a record written by a build whose `Act` had another shape must restore +// with no act (that act is simply never a repeat), never refuse the checkpoint and the resident +// with it (the 2026-10-31 M5 outage's shape, card c990acbe). A valid act stays whole, and a corrupt +// AUTHORITATIVE field still refuses. +#[test] +fn an_act_from_an_older_build_is_dropped_and_its_record_survives() { + use crate::cognition::working_memory::action_log::ActionRecord; + let wm = WorkingMemory::new(8); + let listed = act("code/list", serde_json::json!({"path": "."}), "4 files".into()); + wm.record_receipt_typed(&[listed], "I ran code/list Result: 4 files", None, Default::default()); + let record = wm.snapshot().action_records().pop().expect("the act is on record"); + assert!(record.act.is_some(), "a typed act records what it asked for"); + + let whole = serde_json::to_string(&record).expect("encode"); + let decoded: ActionRecord = serde_json::from_str(&whole).expect("a current act decodes"); + assert_eq!(decoded, record, "the derived decoder is lossless"); + + let mut stale = record.clone(); + stale.act = None; + let older = serde_json::to_string(&stale).expect("encode").replacen('{', "{\"act\":\"an older shape\",", 1); + let restored: ActionRecord = serde_json::from_str(&older).expect("an older act never refuses its record"); + assert_eq!(restored, stale, "only the act is dropped"); + + let corrupt = older.replacen("\"seq\":", "\"seq\":\"not a number\",\"_was\":", 1); + assert!(serde_json::from_str::(&corrupt).is_err(), "only the derived act is forgiven"); +}