Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/continuum-cognition/src/cognition/working_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ pub struct VolatileSnapshot {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub(crate) actions: Vec<action_log::ActionRecord>,
/// 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<ContextView>,
/// 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
Expand Down Expand Up @@ -600,7 +600,7 @@ pub struct WmEntry {
}


mod derived_view;
mod derived;
mod action_log;
mod continuity;
mod ledger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<continuum_context::cause::Act>,
}

Expand Down
33 changes: 33 additions & 0 deletions core/continuum-cognition/src/cognition/working_memory/derived.rs
Original file line number Diff line number Diff line change
@@ -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<Option<T>, D::Error> {
let Some(raw) = Option::<Box<RawValue>>::deserialize(deserializer)? else {
return Ok(None);
};
match serde_json::from_str::<T>(raw.get()) {
Ok(value) => Ok(Some(value)),
Err(error) => {
continuum_base::probe!(
class = "persona.checkpoint.derived_dropped",
derived = std::any::type_name::<T>(),
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)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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::<ActionRecord>(&corrupt).is_err(), "only the derived act is forgiven");
}
Loading