From 3ad42bf644d29f508d5c819487c1679f711b5a8f Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 31 Oct 2026 10:55:24 -0500 Subject: [PATCH 1/3] A checkpoint's context view is derived: one that no longer decodes is dropped with a probe and her next act opens a new epoch, instead of refusing the resident (the 2026-10-31 M5 outage: #5639's new Event.level made every checkpoint undecodable; 32 min with no resident) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/cognition/working_memory.rs | 7 +++-- .../cognition/working_memory/derived_view.rs | 29 +++++++++++++++++++ .../cognition/working_memory/tests/trail.rs | 21 ++++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-) create 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 4704878d98..ecf1588731 100644 --- a/core/continuum-cognition/src/cognition/working_memory.rs +++ b/core/continuum-cognition/src/cognition/working_memory.rs @@ -426,9 +426,9 @@ pub struct VolatileSnapshot { /// for another build: this is the first version, Joel 2026-10-31). #[serde(default, skip_serializing_if = "Vec::is_empty")] pub(crate) actions: Vec, - /// Her context view ([`WorkingMemory`]'s `view`). Absent on snapshots written before it, - /// and then her first act after the restore starts a new one. - #[serde(default, skip_serializing_if = "Option::is_none")] + /// 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")] 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,6 +600,7 @@ pub struct WmEntry { } +mod derived_view; mod action_log; mod continuity; mod ledger; diff --git a/core/continuum-cognition/src/cognition/working_memory/derived_view.rs b/core/continuum-cognition/src/cognition/working_memory/derived_view.rs new file mode 100644 index 0000000000..8b5e3c0454 --- /dev/null +++ b/core/continuum-cognition/src/cognition/working_memory/derived_view.rs @@ -0,0 +1,29 @@ +//! 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 super::ContextView; + +/// `context_view`'s deserializer: the view when it decodes, else none (and a probe saying why). +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_value::(raw) { + 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/trail.rs b/core/continuum-cognition/src/cognition/working_memory/tests/trail.rs index 470361f018..722baf654c 100644 --- a/core/continuum-cognition/src/cognition/working_memory/tests/trail.rs +++ b/core/continuum-cognition/src/cognition/working_memory/tests/trail.rs @@ -289,3 +289,24 @@ fn volatile_snapshot_round_trips_and_renders_the_interruption() { "no fabricated save age on legacy snapshots: {q:?}" ); } + +// what this catches: a checkpoint whose context view no longer decodes (the view's shape changed in +// a later build) refusing the whole restore. On 2026-10-31 a new field on the view's events made +// every resident's checkpoint undecodable and the M5 hosted no one for 32 minutes. The view is +// derived: it is dropped, her memory restores, and her next act opens a new epoch. +#[test] +fn an_undecodable_view_is_dropped_and_her_memory_still_restores() { + let wm = WorkingMemory::new(8); + wm.record("the build failed on the missing import"); + let mut checkpoint = serde_json::to_value(wm.snapshot()).expect("encode"); + checkpoint["context_view"] = serde_json::json!({ "events": [{ "shape": "from another build" }] }); + let snap: VolatileSnapshot = serde_json::from_value(checkpoint).expect("the checkpoint still decodes"); + assert!(snap.context_view.is_none(), "the stale view is dropped"); + let restored = WorkingMemory::new(8); + restored.restore(snap); + assert!( + restored.recent_entries().iter().any(|entry| entry.text.contains("missing import")), + "her memory survives the dropped view" + ); + assert!(restored.take_view().is_none(), "her next act opens a new epoch"); +} From 4cddddc35aeac4313a18b53f0325425df55c49b2 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 31 Oct 2026 10:57:29 -0500 Subject: [PATCH 2/3] The regression test reproduces the outage exactly: a real serialized view with only its level fields removed is dropped, the newest result and settlement restore and survive the next save, and a corrupt authoritative field still refuses (Codex on #5659) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- .../src/cognition/context_streams/tests.rs | 54 +++++++++++++++++++ .../cognition/working_memory/tests/trail.rs | 20 ------- 2 files changed, 54 insertions(+), 20 deletions(-) diff --git a/core/continuum-cognition/src/cognition/context_streams/tests.rs b/core/continuum-cognition/src/cognition/context_streams/tests.rs index 4155df02a1..ed8e82091d 100644 --- a/core/continuum-cognition/src/cognition/context_streams/tests.rs +++ b/core/continuum-cognition/src/cognition/context_streams/tests.rs @@ -67,6 +67,60 @@ fn her_view_survives_a_restart_in_her_checkpoint() { assert!(restored.take_view().is_none(), "taken once, by the act that resumes it"); } +// what this catches: the 2026-10-31 M5 outage. #5639 added `level` to the view's events, so every +// resident's checkpoint (written by the build before) failed to decode and registration refused all +// four for 32 minutes. A real view with only its `level` fields removed must be dropped (it is +// derived) while everything authoritative restores and saves again; a corrupt AUTHORITATIVE field +// must still refuse (Codex on #5659). +#[test] +fn a_view_from_an_older_build_is_dropped_and_authoritative_state_survives() { + use continuum_context::view::{Claim, View}; + use crate::cognition::working_memory::VolatileSnapshot; + + let memory = WorkingMemory::new(8); + memory.record_receipt("I ran code/list Result: 4 files"); + memory.record_settlement("listed the four files", None); + let actions = Actions { memory: &memory, persona: uuid::Uuid::nil() }; + let whole = |claims: &[Claim]| claims.iter().map(|claim| claim.full_chars).collect(); + let (view, _) = View::start(Vec::new(), &[&actions as &dyn Source<_>], whole).unwrap(); + memory.keep_view(Some(view)); + let good = serde_json::to_value(memory.snapshot()).expect("encode"); + + // The older build's shape: the same real view, its `level` fields removed and nothing else. + fn strip_levels(value: &mut serde_json::Value) -> usize { + match value { + serde_json::Value::Object(map) => { + let here = usize::from(map.remove("level").is_some()); + here + map.values_mut().map(strip_levels).sum::() + } + serde_json::Value::Array(items) => items.iter_mut().map(strip_levels).sum(), + _ => 0, + } + } + let mut older = good.clone(); + assert!(strip_levels(&mut older["context_view"]) > 0, "the fixture reproduces the missing-level view"); + + let snap: VolatileSnapshot = serde_json::from_value(older).expect("an older view never refuses the checkpoint"); + let restored = WorkingMemory::new(8); + restored.restore(snap); + assert!(restored.take_view().is_none(), "the stale view is dropped: her next act opens a new epoch"); + assert!(restored.has_receipt(), "her newest result survives"); + let settled = |m: &WorkingMemory| m.recent_entries().iter().any(|entry| entry.text.contains("listed the four files")); + assert!(settled(&restored), "her settlement survives"); + + // The next save keeps every authoritative field and carries no view until she renders one. + let saved = serde_json::to_value(restored.snapshot()).expect("encode"); + assert!(saved.get("context_view").is_none()); + let again = WorkingMemory::new(8); + again.restore(serde_json::from_value(saved).expect("the repaired save decodes")); + assert!(again.has_receipt() && settled(&again), "authoritative state survives the repaired save"); + + // A corrupt authoritative field is still refused: only the derived view is forgiven. + let mut corrupt = good; + corrupt["next_action_seq"] = serde_json::json!("not a number"); + assert!(serde_json::from_value::(corrupt).is_err()); +} + // what this catches (Cormac on #5255): a result kept in memory but never saved under a handle // collapsing at a turnover to its one-line ledger head, which nothing can reopen (goal 7). Its // collapsed form is the whole result, so the view can only keep it, never cut it. diff --git a/core/continuum-cognition/src/cognition/working_memory/tests/trail.rs b/core/continuum-cognition/src/cognition/working_memory/tests/trail.rs index 722baf654c..3f20024dc9 100644 --- a/core/continuum-cognition/src/cognition/working_memory/tests/trail.rs +++ b/core/continuum-cognition/src/cognition/working_memory/tests/trail.rs @@ -290,23 +290,3 @@ fn volatile_snapshot_round_trips_and_renders_the_interruption() { ); } -// what this catches: a checkpoint whose context view no longer decodes (the view's shape changed in -// a later build) refusing the whole restore. On 2026-10-31 a new field on the view's events made -// every resident's checkpoint undecodable and the M5 hosted no one for 32 minutes. The view is -// derived: it is dropped, her memory restores, and her next act opens a new epoch. -#[test] -fn an_undecodable_view_is_dropped_and_her_memory_still_restores() { - let wm = WorkingMemory::new(8); - wm.record("the build failed on the missing import"); - let mut checkpoint = serde_json::to_value(wm.snapshot()).expect("encode"); - checkpoint["context_view"] = serde_json::json!({ "events": [{ "shape": "from another build" }] }); - let snap: VolatileSnapshot = serde_json::from_value(checkpoint).expect("the checkpoint still decodes"); - assert!(snap.context_view.is_none(), "the stale view is dropped"); - let restored = WorkingMemory::new(8); - restored.restore(snap); - assert!( - restored.recent_entries().iter().any(|entry| entry.text.contains("missing import")), - "her memory survives the dropped view" - ); - assert!(restored.take_view().is_none(), "her next act opens a new epoch"); -} From 79ddda0fc1dbcf0c3a24ae896ff1e8da41207ba3 Mon Sep 17 00:00:00 2001 From: Joel Teply Date: Sat, 31 Oct 2026 11:19:31 -0500 Subject: [PATCH 3/3] Derived view decoded from its exact text (RawValue), never through serde_json::Value: a view's ElementIds are u128, which Value cannot hold, so the Value intermediate refused every VALID view (Codex's executed test on #5659); the test works on JSON text, strips only the level pairs, and now also asserts a valid view is kept Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo --- Cargo.toml | 2 +- .../src/cognition/context_streams/tests.rs | 45 ++++++++++--------- .../cognition/working_memory/derived_view.rs | 8 +++- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 34940c3f8f..34cacbbd57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -284,7 +284,7 @@ candle-transformers = { version = "0.9" } # Serialization serde = { version = "1", features = ["derive"] } -serde_json = "1" +serde_json = { version = "1", features = ["raw_value"] } # raw_value: a derived field is held as its exact text until decoded, so u128 ids never pass through Value (#5659) # Database rusqlite = { version = "0.38", features = ["bundled"] } diff --git a/core/continuum-cognition/src/cognition/context_streams/tests.rs b/core/continuum-cognition/src/cognition/context_streams/tests.rs index ed8e82091d..c64b56f6a4 100644 --- a/core/continuum-cognition/src/cognition/context_streams/tests.rs +++ b/core/continuum-cognition/src/cognition/context_streams/tests.rs @@ -84,23 +84,23 @@ fn a_view_from_an_older_build_is_dropped_and_authoritative_state_survives() { let whole = |claims: &[Claim]| claims.iter().map(|claim| claim.full_chars).collect(); let (view, _) = View::start(Vec::new(), &[&actions as &dyn Source<_>], whole).unwrap(); memory.keep_view(Some(view)); - let good = serde_json::to_value(memory.snapshot()).expect("encode"); - - // The older build's shape: the same real view, its `level` fields removed and nothing else. - fn strip_levels(value: &mut serde_json::Value) -> usize { - match value { - serde_json::Value::Object(map) => { - let here = usize::from(map.remove("level").is_some()); - here + map.values_mut().map(strip_levels).sum::() - } - serde_json::Value::Array(items) => items.iter_mut().map(strip_levels).sum(), - _ => 0, + // Text, never `serde_json::Value`: the view's element ids are u128, which a Value cannot hold. + let good = serde_json::to_string(&memory.snapshot()).expect("encode"); + + // The older build's shape: the same real view, its `level` pairs removed and nothing else. + let (head, view_and_rest) = good.split_at(good.find("\"context_view\":").expect("the checkpoint carries her view")); + let mut older_view = view_and_rest.to_owned(); + let mut stripped = 0; + for variant in ["Full", "Summary", "Pointer", "Folded"] { + for pattern in [format!("\"level\":\"{variant}\","), format!(",\"level\":\"{variant}\"")] { + stripped += older_view.matches(pattern.as_str()).count(); + older_view = older_view.replace(pattern.as_str(), ""); } } - let mut older = good.clone(); - assert!(strip_levels(&mut older["context_view"]) > 0, "the fixture reproduces the missing-level view"); + assert!(stripped > 0, "the fixture reproduces the missing-level view"); + let older = format!("{head}{older_view}"); - let snap: VolatileSnapshot = serde_json::from_value(older).expect("an older view never refuses the checkpoint"); + let snap: VolatileSnapshot = serde_json::from_str(&older).expect("an older view never refuses the checkpoint"); let restored = WorkingMemory::new(8); restored.restore(snap); assert!(restored.take_view().is_none(), "the stale view is dropped: her next act opens a new epoch"); @@ -108,17 +108,22 @@ fn a_view_from_an_older_build_is_dropped_and_authoritative_state_survives() { let settled = |m: &WorkingMemory| m.recent_entries().iter().any(|entry| entry.text.contains("listed the four files")); assert!(settled(&restored), "her settlement survives"); + // A VALID view (u128 ids and all) still restores whole: the derived decoder is lossless. + let current: VolatileSnapshot = serde_json::from_str(&good).expect("the current view decodes"); + let resumed = WorkingMemory::new(8); + resumed.restore(current); + assert!(resumed.take_view().is_some(), "a view that decodes is kept"); + // The next save keeps every authoritative field and carries no view until she renders one. - let saved = serde_json::to_value(restored.snapshot()).expect("encode"); - assert!(saved.get("context_view").is_none()); + let saved = serde_json::to_string(&restored.snapshot()).expect("encode"); + assert!(!saved.contains("\"context_view\"")); let again = WorkingMemory::new(8); - again.restore(serde_json::from_value(saved).expect("the repaired save decodes")); + again.restore(serde_json::from_str(&saved).expect("the repaired save decodes")); assert!(again.has_receipt() && settled(&again), "authoritative state survives the repaired save"); // A corrupt authoritative field is still refused: only the derived view is forgiven. - let mut corrupt = good; - corrupt["next_action_seq"] = serde_json::json!("not a number"); - assert!(serde_json::from_value::(corrupt).is_err()); + let corrupt = good.replacen("\"next_action_seq\":", "\"next_action_seq\":\"not a number\",\"_was\":", 1); + assert!(serde_json::from_str::(&corrupt).is_err()); } // what this catches (Cormac on #5255): a result kept in memory but never saved under a handle diff --git a/core/continuum-cognition/src/cognition/working_memory/derived_view.rs b/core/continuum-cognition/src/cognition/working_memory/derived_view.rs index 8b5e3c0454..ccc9145480 100644 --- a/core/continuum-cognition/src/cognition/working_memory/derived_view.rs +++ b/core/continuum-cognition/src/cognition/working_memory/derived_view.rs @@ -7,15 +7,19 @@ //! 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 { + let Some(raw) = Option::>::deserialize(deserializer)? else { return Ok(None); }; - match serde_json::from_value::(raw) { + match serde_json::from_str::(raw.get()) { Ok(view) => Ok(Some(view)), Err(error) => { continuum_base::probe!(