Preserve readiness in resident Self mixed store

This commit is contained in:
Meta Vens 2026-07-19 02:15:01 +01:00
commit 2d4c92d24c
3 changed files with 125 additions and 7 deletions

View file

@ -1,7 +1,10 @@
use anyhow::{Context, Result, anyhow};
use cultcache_rs::{CultCache, DatabaseEntry, SingleFileMessagePackBackingStore};
use cultcache_rs::{
CacheBackingStore, CultCache, DatabaseEntry, SingleFileMessagePackBackingStore,
};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::collections::HashSet;
use std::path::{Path, PathBuf};
pub const RESIDENT_SELF_STATE_KEY: &str = "resident-self";
@ -733,8 +736,46 @@ fn state_cache(path: &Path) -> Result<CultCache> {
cache.register_entry_type::<ResidentSelfHeartbeatGrant>()?;
cache.register_entry_type::<ResidentSelfTerminalAck>()?;
cache.register_entry_type::<ResidentSelfChildClaim>()?;
cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(path));
cache.pull_all_backing_stores()?;
let mut identities = HashSet::new();
for envelope in SingleFileMessagePackBackingStore::new(path).pull_all()? {
let owned = envelope.r#type == ResidentSelfState::TYPE
|| envelope.r#type == ResidentSelfRuntimeReceipt::TYPE
|| envelope.r#type == ResidentSelfPressure::TYPE
|| envelope.r#type == ResidentSelfHeartbeatGrant::TYPE
|| envelope.r#type == ResidentSelfTerminalAck::TYPE
|| envelope.r#type == ResidentSelfChildClaim::TYPE;
if !owned {
continue;
}
if !identities.insert((envelope.r#type.clone(), envelope.key.clone())) {
return Err(anyhow!(
"resident Self store contains duplicate owner entry type {:?} key {:?}",
envelope.r#type,
envelope.key
));
}
match envelope.r#type.as_str() {
ResidentSelfState::TYPE => {
cache.load_envelope::<ResidentSelfState>(envelope)?;
}
ResidentSelfRuntimeReceipt::TYPE => {
cache.load_envelope::<ResidentSelfRuntimeReceipt>(envelope)?;
}
ResidentSelfPressure::TYPE => {
cache.load_envelope::<ResidentSelfPressure>(envelope)?;
}
ResidentSelfHeartbeatGrant::TYPE => {
cache.load_envelope::<ResidentSelfHeartbeatGrant>(envelope)?;
}
ResidentSelfTerminalAck::TYPE => {
cache.load_envelope::<ResidentSelfTerminalAck>(envelope)?;
}
ResidentSelfChildClaim::TYPE => {
cache.load_envelope::<ResidentSelfChildClaim>(envelope)?;
}
_ => unreachable!("owned resident Self type was matched above"),
};
}
Ok(cache)
}
@ -1403,6 +1444,50 @@ mod tests {
use super::*;
use std::collections::BTreeMap;
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
#[cultcache(type = "test.resident.provider_readiness", schema = "ForeignReadiness")]
struct ForeignReadiness {
#[cultcache(key = 0)]
status: String,
}
#[test]
fn resident_owner_view_preserves_foreign_readiness_rows() -> Result<()> {
let temp = tempfile::tempdir()?;
let store = temp.path().join("resident-self.cc");
let mut foreign_cache = CultCache::new();
foreign_cache.register_entry_type::<ForeignReadiness>()?;
let (foreign, _) = foreign_cache.prepare_entry(
"provider-readiness",
&ForeignReadiness {
status: "ready".into(),
},
)?;
let mut backing = SingleFileMessagePackBackingStore::new(&store);
backing.push(&foreign)?;
assert_eq!(
load_resident_self_state(&store)?,
ResidentSelfState::default()
);
enqueue_resident_self_pressure(
&store,
&ResidentSelfPressure {
schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id: "pressure-test".into(),
kind: "persona-feedback".into(),
provenance_ref: "test://pressure".into(),
objective: "preserve foreign row".into(),
created_at_millis: 1,
status: "pending".into(),
consumed_by_grant_id: None,
private_state_exposed: false,
},
)?;
assert!(backing.pull_all()?.contains(&foreign));
Ok(())
}
struct FakePorts {
brake: bool,
next_pid: u32,
@ -1723,7 +1808,9 @@ mod tests {
consumed_by_heartbeat_at_millis: None,
private_state_exposed: false,
};
state_cache(&resident_store)?.put(&ack.ack_id, &ack)?;
let cache = state_cache(&resident_store)?;
let (entry, _) = cache.prepare_entry(&ack.ack_id, &ack)?;
SingleFileMessagePackBackingStore::new(&resident_store).push(&entry)?;
let ack_pulse = crate::pulse_resident_self_heartbeat(
&heartbeat_store,
&resident_store,
@ -1753,7 +1840,9 @@ mod tests {
);
let mut crash_gap_ack = ack.clone();
crash_gap_ack.consumed_by_heartbeat_at_millis = None;
state_cache(&resident_store)?.put(&crash_gap_ack.ack_id, &crash_gap_ack)?;
let cache = state_cache(&resident_store)?;
let (entry, _) = cache.prepare_entry(&crash_gap_ack.ack_id, &crash_gap_ack)?;
SingleFileMessagePackBackingStore::new(&resident_store).push(&entry)?;
assert_eq!(
crate::reconcile_resident_self_heartbeat_ack(&heartbeat_store, &resident_store)?,
Some(crash_gap_ack.ack_id.clone())

View file

@ -2793,3 +2793,31 @@ rehearsal before 2026-07-22: organization feedback -> persistent Modeling map ->
bounded Imagination proposal -> explicit review/adoption -> Hands consequence ->
Bifrost release -> Idunn deployment, plus replay/tamper refusal and the negative
chat-only path. No host reboot is authorized.
## Generation handoff and resident mixed-store cut (2026-07-18)
Candidate `03e1afd24546a7ca37e900c47ca26ae257b14161` proved generation-scoped
packaging and sealed immutable release
`sha256-fe7f25ff60d84ae9316d7b4aa2833bd5d1b65189c9d08cc64e903a83d8f35268`.
Its first application publication failed because the exact commit parent was
still builder-owned mode 0750; cleanup sealed that parent and an automatic
retry reused the exact package and started all three services. The actuator now
seals the exact generation parent root-owned mode 0755 before handing
publication to the application owner.
The candidate was not deployed. Projection and Heartbeat were healthy and
braked, but resident Self treated the shared resident/readiness CultCache store
as if every row belonged to Self and rejected the legitimate provider-readiness
document. The exact process group was terminated, all services were stopped,
`active-release.env` was removed, and no deployment witness exists. Resident
Self now loads only its six owned typed families into its in-memory view,
rejects duplicate owned identities, and leaves foreign readiness rows intact.
Focused resident proof passes 12/12; full core proof passes 572/572 with one
ignored.
Next action: commit and push both cuts, install the exact ops actuator on
Yggdrasil, revoke obsolete Bifrost authority, authorize the new exact Epiphany
commit, and let Idunn deploy under the engaged brake. Require the immutable
package/witness, all three healthy service owners, signed aggregate health, and
`deployment.env`; then prove the ordinary organization loop and its negative
authority boundaries. No host reboot is authorized.

View file

@ -788,5 +788,6 @@ current_status:
- Candidate `86d702002acee8321438f32fb9cf69a29a667d70` built and sealed immutable release `sha256-da19a70a7e8c0229cd59b292bf5867fd1e97fa40643ab772e918c5d49dd7ff22` with witness `sha256-62c65d813837dd4a939e941d798d0842ee5f6c77cddaa645f2c47a18b7c3ec44`. Its first package attempt lost the builder's narrow release-root ownership to a predecessor cleanup race and published nothing; the retry crossed packaging and started all three braked services. Projection and Heartbeat stayed active, but resident Self exposed a second cold-start fatal path in feedback-driven Imagination consideration (`consideration requires thread state`). The Idunn transaction was terminated through rollback; services are inactive and no deployment or active-release witness exists. The package remains immutable evidence only.
- Feedback-driven Imagination consideration now shares the cold-runtime prerequisite semantics of admitted-model direction: absent thread state yields no request yet, preserves admitted feedback for later ingestion, and performs no write. Resident Self skips only that not-yet-constructible request and will retry it on a later pulse. The causal feedback smoke explicitly requires its fixture thread and all binaries compile. This is prerequisite absence, not feedback loss, Mind adoption, or action authority.
- Exact successor `aa3d2330062a34145cb70b527e02fa00215eac1b` passed local proof but was revoked before deployment because live packaging repeated `Permission denied` when creating a random staging directory directly under the shared root-owned release directory. This disproved the predecessor-cleanup race hypothesis. The builder's long-lived ownership lease over `/srv/epiphany/app/releases` was the incoherent boundary; no package, service, or witness was published from this attempt.
- Release construction is now generation-scoped. The packager creates its random staging sibling beneath the exact source-commit directory, then atomically renames to the final release id within that same directory, preserving canonical absolute witness paths. Idunn keeps the shared release root root-owned and grants `epiphany-builder` only the exact commit directory during construction; cleanup removes only nested staging and seals that generation root-owned. Focused package proof passes 12/12, every binary compiles, and the corrected deployment script passes remote Bash syntax. The builder no longer needs a write lease over sibling releases.
next_action: "Commit and push the generation-scoped packaging successor and ops actuator, install the exact root-owned actuator on Yggdrasil, authorize the new exact Epiphany commit through Bifrost, and let Idunn deploy it under the engaged sleep brake. Require immutable package inspection, app-owned release publication, three healthy local service owners, signed aggregate health, and the final deployment.env witness. Then run the Starfire-offline rehearsal before 2026-07-22: persistent Modeling map -> autonomous bounded Imagination proposal, with classified organization feedback through Persona as an additional pressure path; explicit Mind adoption -> Hands consequence -> Bifrost release -> Idunn deployment remain separate gates. Prove replay/tamper refusal and that conversation alone grants no Mind, Hands, Persona-speech, release, or deployment authority. No host reboot is authorized."
- Release construction is now generation-scoped. The packager creates its random staging sibling beneath the exact source-commit directory, then atomically renames to the final release id within that same directory, preserving canonical absolute witness paths. Idunn keeps the shared release root root-owned and grants `epiphany-builder` only the exact commit directory during construction; cleanup removes only nested staging and seals that generation root-owned. Candidate `03e1afd24546a7ca37e900c47ca26ae257b14161` proved this boundary by sealing immutable release `sha256-fe7f25ff60d84ae9316d7b4aa2833bd5d1b65189c9d08cc64e903a83d8f35268`; its first app publication could not traverse the still builder-owned 0750 generation parent. Cleanup sealed the parent and an automatic exact-package retry started all three services. The actuator must seal the exact generation parent root-owned 0755 before app-owned publication, not only during cleanup.
- Candidate `03e1afd24546a7ca37e900c47ca26ae257b14161` was not deployed. Projection and Heartbeat were healthy and braked, but resident Self opened the shared resident store as if every row belonged to its schema catalog and rejected the legitimate `epiphany.resident_cognition.provider_readiness` row. The exact process group was terminated, all three services were stopped, `active-release.env` was removed, and no deployment witness exists. Resident Self now constructs an owner-filtered typed view from raw envelopes, admits only its six owned document families, rejects duplicate owned identities, and preserves foreign readiness rows during writes. Full core proof passes 572/572 with one ignored.
next_action: "Commit and push the resident-Self mixed-store repair and generation-parent sealing actuator, install the exact root-owned actuator on Yggdrasil, revoke obsolete Bifrost authority, authorize the new exact Epiphany commit, and let Idunn deploy it under the engaged sleep brake. Require immutable package inspection, app-owned release publication, three healthy local service owners, signed aggregate health, and the final deployment.env witness. Then run the Starfire-offline rehearsal before 2026-07-22: persistent Modeling map -> autonomous bounded Imagination proposal, with classified organization feedback through Persona as an additional pressure path; explicit Mind adoption -> Hands consequence -> Bifrost release -> Idunn deployment remain separate gates. Prove replay/tamper refusal and that conversation alone grants no Mind, Hands, Persona-speech, release, or deployment authority. No host reboot is authorized."