Purify live semantic projector state

This commit is contained in:
Meta Vens 2026-07-15 10:55:30 +01:00
commit 2c9b904b6c
12 changed files with 657 additions and 21 deletions

View file

@ -2532,6 +2532,8 @@ fn agent_memory_cache(store_path: &Path) -> Result<CultCache> {
cache.register_entry_type::<crate::MemorySemanticProjectionClaim>()?;
cache.register_entry_type::<crate::MemorySemanticProjectionAttempt>()?;
cache.register_entry_type::<crate::MemorySemanticIndexReceipt>()?;
cache.register_entry_type::<crate::MemorySemanticProjectorExecutorGrant>()?;
cache.register_entry_type::<crate::MemorySemanticProjectorRecoveryAuthorization>()?;
cache.register_entry_type::<EpiphanyAgentMemoryEntry>()?;
cache.register_entry_type::<EpiphanyAgentStateSoaEntry>()?;
cache.add_generic_backing_store(SingleFileMessagePackBackingStore::new(store_path));

View file

@ -31,8 +31,15 @@ use epiphany_core::load_epiphany_cultmesh_managed_service_policy;
use epiphany_core::load_epiphany_cultmesh_managed_service_policy_with_digest;
use epiphany_core::load_epiphany_cultmesh_status;
use epiphany_core::load_epiphany_cultmesh_swarm_brake;
use epiphany_core::load_latest_epiphany_cultmesh_daemon_heartbeat;
use epiphany_core::load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt_for_service;
use epiphany_core::migrate_memory_semantic_projection_attempts_v0;
use epiphany_core::observe_native_process as observe_process;
use epiphany_core::query_epiphany_local_verse_context;
use epiphany_core::retire_epiphany_cultmesh_operator_status_documents;
use epiphany_core::retire_memory_semantic_projection_claims_v0;
use epiphany_core::retire_orphaned_memory_semantic_projection_attempts_v0;
use epiphany_core::retire_unowned_memory_semantic_index_receipts;
use epiphany_core::runtime_modeling_semantic_projection_input;
use epiphany_core::seed_epiphany_local_verse_context;
use epiphany_core::write_epiphany_cultmesh_daemon_poke_intent;
@ -66,6 +73,9 @@ fn main() -> Result<()> {
"tick" | "schedule" | "reconcile-all" => tick(args),
"serve" | "loop" | "daemon" => serve(args),
"managed-service-serve" | "service-desired-state-serve" => managed_service_serve(args),
"migrate-retired-operator-status" => migrate_retired_operator_status(args),
"migrate-semantic-attempts-v0" => migrate_semantic_attempts_v0(args),
"semantic-projector-service-status" => semantic_projector_service_status(args),
"service-plan" => service_plan(args),
"service-launch" | "launch-service" | "start-service" => service_launch(args),
"managed-service-policy" | "service-desired-state" => managed_service_policy(args),
@ -147,6 +157,96 @@ fn main() -> Result<()> {
}
}
fn migrate_retired_operator_status(args: Args) -> Result<()> {
let removed_keys = retire_epiphany_cultmesh_operator_status_documents(&args.store)?;
println!(
"{}",
serde_json::to_string_pretty(&json!({
"schemaVersion": "epiphany.cultmesh.retired_document_migration.v0",
"status": "completed",
"retiredDocumentType": "epiphany.cultmesh.operator_status",
"removedKeys": removed_keys,
"privateStateExposed": false,
}))?
);
Ok(())
}
fn migrate_semantic_attempts_v0(args: Args) -> Result<()> {
let agent_store = args
.agent_store
.as_ref()
.context("migrate-semantic-attempts-v0 requires --agent-store")?;
let runtime_store = args
.runtime_store
.as_ref()
.context("migrate-semantic-attempts-v0 requires --runtime-store")?;
if agent_store == runtime_store {
anyhow::bail!("semantic Mind and Modeling stores must remain distinct");
}
let retired_mind_claim_ids = retire_memory_semantic_projection_claims_v0(agent_store)?;
let retired_modeling_claim_ids = retire_memory_semantic_projection_claims_v0(runtime_store)?;
let retired_mind_attempt_ids =
retire_orphaned_memory_semantic_projection_attempts_v0(agent_store)?;
let retired_modeling_attempt_ids =
retire_orphaned_memory_semantic_projection_attempts_v0(runtime_store)?;
let retired_mind_receipt_ids = retire_unowned_memory_semantic_index_receipts(agent_store)?;
let retired_modeling_receipt_ids =
retire_unowned_memory_semantic_index_receipts(runtime_store)?;
let mind_attempt_ids = migrate_memory_semantic_projection_attempts_v0(agent_store)?;
let modeling_attempt_ids = migrate_memory_semantic_projection_attempts_v0(runtime_store)?;
println!(
"{}",
serde_json::to_string_pretty(&json!({
"schemaVersion": "epiphany.memory_semantic_projection_attempt_migration.v0",
"status": "completed",
"retiredMindClaimIds": retired_mind_claim_ids,
"retiredModelingClaimIds": retired_modeling_claim_ids,
"retiredMindAttemptIds": retired_mind_attempt_ids,
"retiredModelingAttemptIds": retired_modeling_attempt_ids,
"retiredMindReceiptIds": retired_mind_receipt_ids,
"retiredModelingReceiptIds": retired_modeling_receipt_ids,
"mindAttemptIds": mind_attempt_ids,
"modelingAttemptIds": modeling_attempt_ids,
"privateStateExposed": false,
}))?
);
Ok(())
}
fn semantic_projector_service_status(args: Args) -> Result<()> {
let receipt = load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt_for_service(
&args.store,
args.runtime_id.clone(),
SEMANTIC_PROJECTOR_SERVICE_ID,
)?
.context("semantic projector launch receipt is absent")?;
let heartbeat = load_latest_epiphany_cultmesh_daemon_heartbeat(
&args.store,
args.runtime_id,
SEMANTIC_PROJECTOR_EXECUTOR_ID,
)?
.context("semantic projector heartbeat is absent")?;
let correlation_matches = heartbeat.startup_lifecycle_receipt_id == receipt.receipt_id;
println!(
"{}",
serde_json::to_string_pretty(&json!({
"schemaVersion": "epiphany.memory_semantic_projector_service_status.v0",
"status": if correlation_matches && heartbeat.status == "ready" { "ready" } else { "degraded" },
"processId": receipt.process_id,
"launchReceiptId": receipt.receipt_id,
"executableSha256": receipt.executable_sha256,
"heartbeatId": heartbeat.heartbeat_id,
"providerIncarnation": heartbeat.provider_incarnation,
"heartbeatStatus": heartbeat.status,
"startupCorrelationMatches": correlation_matches,
"privateStateExposed": false,
"authoritative": false,
}))?
);
Ok(())
}
fn semantic_projection_input(args: &Args) -> Result<(MemorySemanticProjectionInput, &Path)> {
match (&args.agent_store, &args.runtime_store) {
(Some(path), None) => Ok((agent_memory_semantic_projection_input(path)?, path)),
@ -389,13 +489,21 @@ fn service_launch(args: Args) -> Result<()> {
if args.wait_child {
anyhow::bail!("reserved semantic projector launch is an infinite managed child");
}
Some((policy.policy_id, digest, Uuid::new_v4().to_string()))
let executable_sha256 = local_file_sha256(&command_path.display().to_string())
.map(|digest| format!("sha256-{digest}"))
.context("reserved semantic projector executable cannot be fingerprinted")?;
Some((
policy.policy_id,
digest,
Uuid::new_v4().to_string(),
executable_sha256,
))
} else {
None
};
let mut command = Command::new(&command_path);
command.args(&service_args);
if let Some((_, _, receipt_id)) = &reserved_launch {
if let Some((_, _, receipt_id, _)) = &reserved_launch {
command.env("EPIPHANY_STARTUP_LIFECYCLE_RECEIPT_ID", receipt_id);
}
if let Some(stdout_path) = &args.stdout_artifact {
@ -454,12 +562,13 @@ fn service_launch(args: Args) -> Result<()> {
.as_ref()
.map(|path| path.display().to_string()),
);
if let Some((policy_id, policy_digest, receipt_id)) = reserved_launch {
if let Some((policy_id, policy_digest, receipt_id, executable_sha256)) = reserved_launch {
receipt.receipt_id = receipt_id.clone();
receipt.managed_policy_id = policy_id;
receipt.managed_policy_digest = policy_digest;
receipt.provider_daemon_id = SEMANTIC_PROJECTOR_EXECUTOR_ID.to_string();
receipt.startup_correlation_id = receipt_id;
receipt.executable_sha256 = executable_sha256;
}
let written = match write_epiphany_cultmesh_daemon_service_lifecycle_receipt(
&args.store,
@ -4131,6 +4240,9 @@ impl Args {
| "daemon"
| "managed-service-serve"
| "service-desired-state-serve"
| "migrate-retired-operator-status"
| "migrate-semantic-attempts-v0"
| "semantic-projector-service-status"
| "service-plan"
| "install-service"
| "service-launch"

View file

@ -1,15 +1,17 @@
use anyhow::{Context, Result, anyhow};
use epiphany_core::{
EPIPHANY_CULTMESH_DAEMON_HEARTBEAT_EVENT_SCHEMA_VERSION,
EpiphanyCultMeshDaemonHeartbeatEventEntry, MemorySemanticIndexConfig,
MemorySemanticProjectionInput, MemorySemanticProjectorPulseStatus,
EpiphanyCultMeshDaemonHeartbeatEventEntry, EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry,
MemorySemanticIndexConfig, MemorySemanticProjectionInput, MemorySemanticProjectorPulseStatus,
SemanticProjectorServiceBody, authenticate_epiphany_cultmesh_semantic_projector_launch,
load_epiphany_cultmesh_daemon_service_lifecycle_receipt,
publish_epiphany_cultmesh_semantic_projection_health,
write_epiphany_cultmesh_daemon_heartbeat_event,
};
use serde_json::json;
use sha2::{Digest, Sha256};
use std::env;
use std::fs;
use std::path::PathBuf;
use std::thread;
use std::time::Duration;
@ -26,7 +28,27 @@ fn main() -> Result<()> {
"managed projector requires its startup launch receipt id"
));
}
authenticate_managed_launch(&args)?;
let receipt = authenticate_managed_launch(&args)?;
if receipt.process_id != Some(std::process::id()) {
return Err(anyhow!(
"managed projector process disagrees with its launch receipt"
));
}
let executable = env::current_exe().context("failed to resolve projector executable")?;
let executable_sha256 = format!(
"sha256-{:x}",
Sha256::digest(fs::read(&executable).with_context(|| {
format!(
"failed to fingerprint projector executable {}",
executable.display()
)
})?)
);
if receipt.executable_sha256 != executable_sha256 {
return Err(anyhow!(
"managed projector executable disagrees with its launch receipt"
));
}
}
let mut semantic_config = MemorySemanticIndexConfig::from_env();
semantic_config.qdrant_url = args.qdrant_url.clone();
@ -48,21 +70,21 @@ fn main() -> Result<()> {
.clone()
.or_else(|| outcome.inspections.last().map(|row| row.scope_id.clone()));
let mut health_faults = 0_u32;
let mut health_publication_faults = Vec::new();
for input in &inputs {
let store = source_store(&args, input)?;
if publish_epiphany_cultmesh_semantic_projection_health(
if let Err(error) = publish_epiphany_cultmesh_semantic_projection_health(
&args.local_verse_store,
args.runtime_id.clone(),
store,
input,
&provider_incarnation,
)
.is_err()
{
health_faults += 1;
) {
health_publication_faults
.push(format!("{}: {error:#}", input.obligation().partition));
}
}
let health_faults = health_publication_faults.len() as u32;
let degraded = source_faults > 0
|| health_faults > 0
|| matches!(
@ -98,6 +120,7 @@ fn main() -> Result<()> {
"inspectedSourceCount": outcome.inspections.len(),
"sourceFaultCount": source_faults,
"healthPublicationFaultCount": health_faults,
"healthPublicationFaults": health_publication_faults,
"selectedScopeId": outcome.selected_scope_id,
"privateStateExposed": false,
"authoritative": false,
@ -112,7 +135,9 @@ fn main() -> Result<()> {
Ok(())
}
fn authenticate_managed_launch(args: &Args) -> Result<()> {
fn authenticate_managed_launch(
args: &Args,
) -> Result<EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry> {
let deadline = Instant::now() + Duration::from_secs(5);
loop {
if load_epiphany_cultmesh_daemon_service_lifecycle_receipt(
@ -122,12 +147,11 @@ fn authenticate_managed_launch(args: &Args) -> Result<()> {
)?
.is_some()
{
authenticate_epiphany_cultmesh_semantic_projector_launch(
return authenticate_epiphany_cultmesh_semantic_projector_launch(
&args.local_verse_store,
args.runtime_id.clone(),
&args.startup_lifecycle_receipt_id,
)?;
return Ok(());
);
}
if Instant::now() >= deadline {
return Err(anyhow!(

View file

@ -2675,6 +2675,26 @@ pub fn open_epiphany_cultmesh_node(
)
}
/// Removes the extinct ownerless operator-status projection from an existing
/// local Verse so the live schema catalog can open it again.
///
/// This is deliberately explicit migration, never implicit node bootstrap.
pub fn retire_epiphany_cultmesh_operator_status_documents(
store_path: impl AsRef<Path>,
) -> Result<Vec<String>> {
const RETIRED_TYPE: &str = "epiphany.cultmesh.operator_status";
let mut backing = SingleFileMessagePackBackingStore::new(store_path.as_ref());
let retired = backing
.pull_all()?
.into_iter()
.filter(|entry| entry.r#type == RETIRED_TYPE)
.collect::<Vec<_>>();
for entry in &retired {
backing.delete(entry)?;
}
Ok(retired.into_iter().map(|entry| entry.key).collect())
}
fn semantic_projection_health_scope_key(swarm_id: &str, partition: &str) -> String {
use sha2::{Digest, Sha256};
format!(
@ -4251,6 +4271,15 @@ pub fn load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt(
node.get(EPIPHANY_CULTMESH_DAEMON_SERVICE_LIFECYCLE_RECEIPT_LATEST_KEY)
}
pub fn load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt_for_service(
store_path: impl AsRef<Path>,
runtime_id: impl Into<String>,
service_id: &str,
) -> Result<Option<EpiphanyCultMeshDaemonServiceLifecycleReceiptEntry>> {
let node = open_epiphany_cultmesh_node(store_path, runtime_id)?;
node.get(&epiphany_cultmesh_daemon_service_lifecycle_receipt_latest_key(service_id))
}
pub fn load_epiphany_cultmesh_daemon_service_lifecycle_receipts(
store_path: impl AsRef<Path>,
runtime_id: impl Into<String>,
@ -4871,6 +4900,7 @@ fn validate_semantic_projector_launch_receipt(
|| receipt.process_id.is_none()
|| receipt.exit_code.is_some()
|| receipt.completed_at_utc.is_none()
|| !receipt.executable_sha256.starts_with("sha256-")
|| receipt.managed_policy_id.trim().is_empty()
|| !receipt.managed_policy_digest.starts_with("sha256-")
|| receipt.provider_daemon_id != "epiphany-memory-semantic-projector"
@ -8035,8 +8065,40 @@ pub fn write_epiphany_cultmesh_bifrost_contracts(
mod tests {
use super::*;
use cultcache_rs::CacheBackingStore;
use cultcache_rs::CultCacheEnvelope;
use pretty_assertions::assert_eq;
#[test]
fn explicit_migration_removes_only_retired_operator_status_documents() -> Result<()> {
let temp = tempfile::tempdir()?;
let store = temp.path().join("verse.ccmp");
let mut backing = SingleFileMessagePackBackingStore::new(&store);
backing.push(&CultCacheEnvelope {
key: "epiphany-local/operator-status/latest".into(),
r#type: "epiphany.cultmesh.operator_status".into(),
payload: vec![0x80],
stored_at: "2026-07-15T10:00:00Z".into(),
schema_id: Some("epiphany.cultmesh.operator_status".into()),
})?;
backing.push(&CultCacheEnvelope {
key: "epiphany-local/status".into(),
r#type: EPIPHANY_CULTMESH_STATUS_TYPE.into(),
payload: vec![0x80],
stored_at: "2026-07-15T10:00:01Z".into(),
schema_id: Some(EPIPHANY_CULTMESH_STATUS_TYPE.into()),
})?;
assert_eq!(
retire_epiphany_cultmesh_operator_status_documents(&store)?,
vec!["epiphany-local/operator-status/latest"]
);
let remaining = backing.pull_all()?;
assert_eq!(remaining.len(), 1);
assert_eq!(remaining[0].r#type, EPIPHANY_CULTMESH_STATUS_TYPE);
assert!(retire_epiphany_cultmesh_operator_status_documents(&store)?.is_empty());
Ok(())
}
#[test]
fn reserved_semantic_projector_policy_requires_specialized_exact_writer() -> Result<()> {
let temp = tempfile::tempdir()?;
@ -8128,7 +8190,7 @@ mod tests {
operator_artifact_ref: "service://semantic-projector/launch".into(),
private_state_exposed: false,
notes: vec![],
executable_sha256: String::new(),
executable_sha256: "sha256-test-projector".into(),
preflight_witness_id: String::new(),
required_document_types: vec![],
schema_preflight_passed: false,
@ -8716,7 +8778,7 @@ mod tests {
operator_artifact_ref: "artifact://service-lifecycle/first".to_string(),
private_state_exposed: false,
notes: Vec::new(),
executable_sha256: String::new(),
executable_sha256: "sha256-test-projector".into(),
preflight_witness_id: String::new(),
required_document_types: Vec::new(),
schema_preflight_passed: false,
@ -11546,7 +11608,7 @@ mod tests {
operator_artifact_ref: "service://semantic-projector/launch".into(),
private_state_exposed: false,
notes: vec![],
executable_sha256: String::new(),
executable_sha256: "sha256-test-projector".into(),
preflight_witness_id: String::new(),
required_document_types: vec![],
schema_preflight_passed: false,

View file

@ -472,6 +472,7 @@ pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_poke_intent;
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_poke_receipt;
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_scheduler_receipt;
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt;
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt_for_service;
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_tool_invocation_intent;
pub use cultmesh_integration::load_latest_epiphany_cultmesh_daemon_tool_invocation_receipt;
pub use cultmesh_integration::load_latest_epiphany_cultmesh_eve_connection_intent;
@ -495,6 +496,7 @@ pub use cultmesh_integration::open_epiphany_cultmesh_node;
pub use cultmesh_integration::publish_epiphany_cultmesh_provider_state;
pub use cultmesh_integration::publish_epiphany_cultmesh_semantic_projection_health;
pub use cultmesh_integration::query_epiphany_local_verse_context;
pub use cultmesh_integration::retire_epiphany_cultmesh_operator_status_documents;
pub use cultmesh_integration::seed_epiphany_local_verse_context;
pub use cultmesh_integration::write_epiphany_cultmesh_agent_state_soa_summary;
#[cfg(test)]
@ -711,11 +713,15 @@ pub use memory_graph::memory_graph_from_heartbeat_cognition;
pub use memory_graph::memory_graph_model_hash;
pub use memory_graph::memory_graph_node_id;
pub use memory_graph::memory_semantic_projection_query_eligible;
pub use memory_graph::migrate_memory_semantic_projection_attempts_v0;
pub use memory_graph::observe_memory_semantic_projection;
pub use memory_graph::plan_memory_graph_context_cut;
pub use memory_graph::plan_memory_graph_context_cut_with_ranked_ids;
pub use memory_graph::refresh_or_validate_repo_memory_graph;
pub use memory_graph::resolve_semantic_candidate;
pub use memory_graph::retire_memory_semantic_projection_claims_v0;
pub use memory_graph::retire_orphaned_memory_semantic_projection_attempts_v0;
pub use memory_graph::retire_unowned_memory_semantic_index_receipts;
pub use memory_graph::semantic_memory_context;
pub use memory_graph::semantic_point_id;
pub use memory_graph::validate_memory_graph_entry;

View file

@ -11,6 +11,7 @@ use cultcache_rs::{
SingleFileMessagePackBackingStore,
};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use std::path::Path;
@ -21,6 +22,231 @@ pub const MEMORY_SEMANTIC_PROJECTOR_EXECUTOR_GRANT_SCHEMA_VERSION: &str =
pub const MEMORY_SEMANTIC_PROJECTOR_RECOVERY_AUTHORIZATION_SCHEMA_VERSION: &str =
"gamecult.epiphany.memory_semantic_projector_recovery_authorization.v2";
#[derive(Deserialize, Serialize)]
struct LegacyMemorySemanticProjectionAttemptV0 {
schema_version: String,
attempt_id: String,
obligation_id: String,
started_at: String,
completed_at: Option<String>,
status: String,
error: Option<String>,
}
#[derive(Deserialize, Serialize)]
struct LegacyMemorySemanticProjectionClaimV0 {
schema_version: String,
scope_id: String,
claim_id: String,
obligation_id: String,
attempt_id: String,
executor_id: String,
epoch: u64,
status: String,
claimed_at: String,
completed_at: Option<String>,
}
/// Retires pre-Idunn claim/attempt pairs from active authority. Their old
/// receipts remain historical and query-ineligible; current obligations can
/// then receive fresh fenced work.
pub fn retire_memory_semantic_projection_claims_v0(
store_path: impl AsRef<Path>,
) -> Result<Vec<String>> {
const ATTEMPT_TYPE: &str = "gamecult.epiphany.memory_semantic_projection_attempt";
const CLAIM_TYPE: &str = "gamecult.epiphany.memory_semantic_projection_claim";
let backing = SingleFileMessagePackBackingStore::new(store_path.as_ref());
let opening = backing.pull_all()?;
let mut retired = Vec::new();
for claim_envelope in opening.iter().filter(|entry| entry.r#type == CLAIM_TYPE) {
if rmp_serde::from_slice::<MemorySemanticProjectionClaim>(&claim_envelope.payload).is_ok() {
continue;
}
let claim = rmp_serde::from_slice::<LegacyMemorySemanticProjectionClaimV0>(
&claim_envelope.payload,
)?;
if claim.schema_version != "gamecult.epiphany.memory_semantic_projection_claim.v0" {
return Err(anyhow!(
"unsupported legacy semantic claim schema for {:?}",
claim.claim_id
));
}
let attempt_envelope = opening
.iter()
.find(|entry| entry.r#type == ATTEMPT_TYPE && entry.key == claim.attempt_id)
.ok_or_else(|| {
anyhow!(
"legacy semantic claim {:?} has no exact attempt",
claim.claim_id
)
})?;
let attempt = rmp_serde::from_slice::<LegacyMemorySemanticProjectionAttemptV0>(
&attempt_envelope.payload,
)?;
if attempt.attempt_id != claim.attempt_id || attempt.obligation_id != claim.obligation_id {
return Err(anyhow!("legacy semantic claim/attempt pair disagrees"));
}
if !backing
.delete_batch_if_unchanged(&[claim_envelope.clone(), attempt_envelope.clone()])?
{
return Err(anyhow!(
"legacy semantic authority changed during explicit retirement"
));
}
retired.push(claim.claim_id);
}
Ok(retired)
}
/// Retires historical v0 attempts whose scope claim was already superseded or
/// overwritten before fenced claim history existed.
pub fn retire_orphaned_memory_semantic_projection_attempts_v0(
store_path: impl AsRef<Path>,
) -> Result<Vec<String>> {
const ATTEMPT_TYPE: &str = "gamecult.epiphany.memory_semantic_projection_attempt";
const CLAIM_TYPE: &str = "gamecult.epiphany.memory_semantic_projection_claim";
let backing = SingleFileMessagePackBackingStore::new(store_path.as_ref());
let opening = backing.pull_all()?;
let current_claim_attempt_ids = opening
.iter()
.filter(|entry| entry.r#type == CLAIM_TYPE)
.filter_map(|entry| {
rmp_serde::from_slice::<MemorySemanticProjectionClaim>(&entry.payload)
.ok()
.map(|claim| claim.attempt_id)
})
.collect::<std::collections::BTreeSet<_>>();
let mut retired = Vec::new();
for attempt_envelope in opening.iter().filter(|entry| entry.r#type == ATTEMPT_TYPE) {
if rmp_serde::from_slice::<MemorySemanticProjectionAttempt>(&attempt_envelope.payload)
.is_ok()
{
continue;
}
let attempt = rmp_serde::from_slice::<LegacyMemorySemanticProjectionAttemptV0>(
&attempt_envelope.payload,
)?;
if attempt.schema_version != "gamecult.epiphany.memory_semantic_projection_attempt.v0" {
return Err(anyhow!(
"unsupported orphaned semantic attempt schema for {:?}",
attempt.attempt_id
));
}
if current_claim_attempt_ids.contains(&attempt.attempt_id) {
continue;
}
if !backing.delete_batch_if_unchanged(std::slice::from_ref(attempt_envelope))? {
return Err(anyhow!(
"orphaned semantic attempt changed during explicit retirement"
));
}
retired.push(attempt.attempt_id);
}
Ok(retired)
}
/// Retires index receipts whose physical claim namespace is absent from the
/// canonical store. Their Qdrant points are rebuildable cache residue.
pub fn retire_unowned_memory_semantic_index_receipts(
store_path: impl AsRef<Path>,
) -> Result<Vec<String>> {
const RECEIPT_TYPE: &str = "gamecult.epiphany.memory_semantic_index_receipt";
const CLAIM_TYPE: &str = "gamecult.epiphany.memory_semantic_projection_claim";
let backing = SingleFileMessagePackBackingStore::new(store_path.as_ref());
let opening = backing.pull_all()?;
let claim_ids = opening
.iter()
.filter(|entry| entry.r#type == CLAIM_TYPE)
.filter_map(|entry| {
rmp_serde::from_slice::<MemorySemanticProjectionClaim>(&entry.payload)
.ok()
.map(|claim| claim.claim_id)
})
.collect::<std::collections::BTreeSet<_>>();
let mut retired = Vec::new();
for envelope in opening.iter().filter(|entry| entry.r#type == RECEIPT_TYPE) {
let receipt = rmp_serde::from_slice::<MemorySemanticIndexReceipt>(&envelope.payload)?;
if !receipt.claim_id.trim().is_empty()
&& receipt.claim_epoch > 0
&& claim_ids.contains(&receipt.claim_id)
{
continue;
}
if !backing.delete_batch_if_unchanged(std::slice::from_ref(envelope))? {
return Err(anyhow!(
"unowned semantic index receipt changed during explicit retirement"
));
}
retired.push(receipt.receipt_id);
}
Ok(retired)
}
/// Upgrades v0 attempt rows by binding them to the exact persisted claim that
/// already owns their attempt identity. No claim means no migration.
pub fn migrate_memory_semantic_projection_attempts_v0(
store_path: impl AsRef<Path>,
) -> Result<Vec<String>> {
const ATTEMPT_TYPE: &str = "gamecult.epiphany.memory_semantic_projection_attempt";
const CLAIM_TYPE: &str = "gamecult.epiphany.memory_semantic_projection_claim";
let backing = SingleFileMessagePackBackingStore::new(store_path.as_ref());
let opening = backing.pull_all()?;
let claims = opening
.iter()
.filter(|entry| entry.r#type == CLAIM_TYPE)
.map(|entry| rmp_serde::from_slice::<MemorySemanticProjectionClaim>(&entry.payload))
.collect::<std::result::Result<Vec<_>, _>>()?;
let mut migrated = Vec::new();
for envelope in opening.iter().filter(|entry| entry.r#type == ATTEMPT_TYPE) {
if rmp_serde::from_slice::<MemorySemanticProjectionAttempt>(&envelope.payload).is_ok() {
continue;
}
let legacy =
rmp_serde::from_slice::<LegacyMemorySemanticProjectionAttemptV0>(&envelope.payload)?;
if legacy.schema_version != "gamecult.epiphany.memory_semantic_projection_attempt.v0" {
return Err(anyhow!(
"unsupported legacy semantic attempt schema for {:?}",
legacy.attempt_id
));
}
let claim = claims
.iter()
.find(|claim| {
claim.attempt_id == legacy.attempt_id && claim.obligation_id == legacy.obligation_id
})
.ok_or_else(|| {
anyhow!(
"legacy semantic attempt {:?} has no exact owning claim",
legacy.attempt_id
)
})?;
let upgraded = MemorySemanticProjectionAttempt {
schema_version: MEMORY_SEMANTIC_PROJECTION_ATTEMPT_SCHEMA_VERSION.to_string(),
attempt_id: legacy.attempt_id,
obligation_id: legacy.obligation_id,
started_at: legacy.started_at,
completed_at: legacy.completed_at,
status: legacy.status,
error: legacy.error,
claim_id: claim.claim_id.clone(),
claim_epoch: claim.epoch,
executor_id: claim.executor_id.clone(),
executor_incarnation: claim.executor_incarnation.clone(),
authority_id: claim.authority_id.clone(),
};
validate_memory_semantic_projection_attempt(&upgraded)?;
let mut replacement: CultCacheEnvelope = envelope.clone();
replacement.payload = rmp_serde::to_vec_named(&upgraded)?;
if !backing.compare_and_swap_entry(envelope, replacement)? {
return Err(anyhow!(
"semantic attempt changed during explicit migration"
));
}
migrated.push(upgraded.attempt_id);
}
Ok(migrated)
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "gamecult.epiphany.memory_semantic_projector_executor_grant",
@ -73,6 +299,7 @@ mod authority_tests {
use crate::{
MEMORY_SEMANTIC_PROJECTION_OBLIGATION_SCHEMA_VERSION, SEMANTIC_PROJECTION_SCHEMA_VERSION,
};
use anyhow::Context;
use tempfile::tempdir;
fn obligation() -> MemorySemanticProjectionObligation {
@ -126,6 +353,164 @@ mod authority_tests {
})
}
#[test]
fn legacy_attempt_migration_binds_exact_owning_claim() -> Result<()> {
let temp = tempdir()?;
let store = temp.path().join("legacy-attempt.msgpack");
let obligation = obligation();
let mut cache = semantic_projector_cache(&store)?;
cache.put(&obligation.obligation_id, &obligation)?;
let projection_input = input(&store, &obligation)?;
let acquisition = idunn_acquire_memory_semantic_projection(
&store,
&projection_input,
"executor-a",
"executor-a-incarnation",
"execute",
"idunn-incarnation-a",
"2026-07-15T04:01:00Z",
)?;
let backing = SingleFileMessagePackBackingStore::new(&store);
let opening = backing.pull_all()?;
let attempt_envelope = opening
.iter()
.find(|entry| {
entry.r#type == MemorySemanticProjectionAttempt::TYPE
&& entry.key == acquisition.claim.attempt_id
})
.context("attempt missing")?;
let attempt: MemorySemanticProjectionAttempt =
rmp_serde::from_slice(&attempt_envelope.payload)?;
let legacy = LegacyMemorySemanticProjectionAttemptV0 {
schema_version: "gamecult.epiphany.memory_semantic_projection_attempt.v0".into(),
attempt_id: attempt.attempt_id.clone(),
obligation_id: attempt.obligation_id.clone(),
started_at: attempt.started_at,
completed_at: attempt.completed_at,
status: attempt.status,
error: attempt.error,
};
let mut legacy_envelope = attempt_envelope.clone();
legacy_envelope.payload = rmp_serde::to_vec_named(&legacy)?;
assert!(backing.compare_and_swap_entry(attempt_envelope, legacy_envelope)?);
assert_eq!(
migrate_memory_semantic_projection_attempts_v0(&store)?,
vec![attempt.attempt_id.clone()]
);
let (_, _, _, upgraded) = load_running_claim(&store, &acquisition.claim.claim_id)?;
assert_eq!(upgraded.claim_id, acquisition.claim.claim_id);
assert_eq!(upgraded.claim_epoch, acquisition.claim.epoch);
assert_eq!(upgraded.executor_id, acquisition.claim.executor_id);
assert_eq!(
upgraded.executor_incarnation,
acquisition.claim.executor_incarnation
);
assert_eq!(upgraded.authority_id, acquisition.claim.authority_id);
assert!(migrate_memory_semantic_projection_attempts_v0(&store)?.is_empty());
Ok(())
}
#[test]
fn legacy_unfenced_claim_and_attempt_retire_atomically() -> Result<()> {
let temp = tempdir()?;
let store = temp.path().join("legacy-claim.msgpack");
let obligation = obligation();
let mut cache = semantic_projector_cache(&store)?;
cache.put(&obligation.obligation_id, &obligation)?;
let projection_input = input(&store, &obligation)?;
let acquisition = idunn_acquire_memory_semantic_projection(
&store,
&projection_input,
"executor-a",
"executor-a-incarnation",
"execute",
"idunn-incarnation-a",
"2026-07-15T04:01:00Z",
)?;
let backing = SingleFileMessagePackBackingStore::new(&store);
let opening = backing.pull_all()?;
let claim_envelope = exact_envelope(
&opening,
MemorySemanticProjectionClaim::TYPE,
&acquisition.claim.scope_id,
)?;
let attempt_envelope = exact_envelope(
&opening,
MemorySemanticProjectionAttempt::TYPE,
&acquisition.claim.attempt_id,
)?;
let legacy_claim = LegacyMemorySemanticProjectionClaimV0 {
schema_version: "gamecult.epiphany.memory_semantic_projection_claim.v0".into(),
scope_id: acquisition.claim.scope_id.clone(),
claim_id: acquisition.claim.claim_id.clone(),
obligation_id: acquisition.claim.obligation_id.clone(),
attempt_id: acquisition.claim.attempt_id.clone(),
executor_id: acquisition.claim.executor_id.clone(),
epoch: acquisition.claim.epoch,
status: acquisition.claim.status.clone(),
claimed_at: acquisition.claim.claimed_at.clone(),
completed_at: acquisition.claim.completed_at.clone(),
};
let attempt: MemorySemanticProjectionAttempt =
rmp_serde::from_slice(&attempt_envelope.payload)?;
let legacy_attempt = LegacyMemorySemanticProjectionAttemptV0 {
schema_version: "gamecult.epiphany.memory_semantic_projection_attempt.v0".into(),
attempt_id: attempt.attempt_id,
obligation_id: attempt.obligation_id,
started_at: attempt.started_at,
completed_at: attempt.completed_at,
status: attempt.status,
error: attempt.error,
};
let mut legacy_claim_envelope = claim_envelope.clone();
legacy_claim_envelope.payload = rmp_serde::to_vec_named(&legacy_claim)?;
let mut legacy_attempt_envelope = attempt_envelope.clone();
legacy_attempt_envelope.payload = rmp_serde::to_vec_named(&legacy_attempt)?;
assert!(backing.compare_and_swap_batch(
&[claim_envelope, attempt_envelope],
vec![legacy_claim_envelope, legacy_attempt_envelope],
)?);
assert_eq!(
retire_memory_semantic_projection_claims_v0(&store)?,
vec![acquisition.claim.claim_id]
);
let observation = observe_memory_semantic_projection(&store, &projection_input)?;
assert_eq!(observation.status, "pending");
assert!(retire_memory_semantic_projection_claims_v0(&store)?.is_empty());
Ok(())
}
#[test]
fn orphaned_legacy_attempt_retires_without_fabricated_claim() -> Result<()> {
let temp = tempdir()?;
let store = temp.path().join("orphaned-attempt.msgpack");
let legacy = LegacyMemorySemanticProjectionAttemptV0 {
schema_version: "gamecult.epiphany.memory_semantic_projection_attempt.v0".into(),
attempt_id: "orphaned-attempt-1".into(),
obligation_id: "obligation-modeling-7".into(),
started_at: "2026-07-15T04:01:00Z".into(),
completed_at: Some("2026-07-15T04:02:00Z".into()),
status: "succeeded".into(),
error: None,
};
let mut backing = SingleFileMessagePackBackingStore::new(&store);
backing.push(&CultCacheEnvelope {
key: legacy.attempt_id.clone(),
r#type: MemorySemanticProjectionAttempt::TYPE.into(),
payload: rmp_serde::to_vec_named(&legacy)?,
stored_at: "2026-07-15T04:02:00Z".into(),
schema_id: Some(MemorySemanticProjectionAttempt::TYPE.into()),
})?;
assert_eq!(
retire_orphaned_memory_semantic_projection_attempts_v0(&store)?,
vec![legacy.attempt_id]
);
assert!(backing.pull_all()?.is_empty());
Ok(())
}
#[test]
fn concurrent_idunn_acquisition_has_one_winner_and_no_issued_litter() -> Result<()> {
let temp = tempdir()?;

View file

@ -846,6 +846,8 @@ pub fn runtime_spine_cache(store_path: impl AsRef<Path>) -> Result<CultCache> {
cache.register_entry_type::<crate::MemorySemanticProjectionClaim>()?;
cache.register_entry_type::<crate::MemorySemanticProjectionAttempt>()?;
cache.register_entry_type::<crate::MemorySemanticIndexReceipt>()?;
cache.register_entry_type::<crate::MemorySemanticProjectorExecutorGrant>()?;
cache.register_entry_type::<crate::MemorySemanticProjectorRecoveryAuthorization>()?;
cache.register_entry_type::<EpiphanyRuntimeSession>()?;
cache.register_entry_type::<EpiphanyRuntimeJob>()?;
cache.register_entry_type::<EpiphanyRuntimeWorkerLaunchRequest>()?;

View file

@ -1333,3 +1333,46 @@ and Qdrant tunnel under durable Idunn/OS survival ownership. Live proof must
cover real child handshake, bounded pulse, heartbeat and health, forced
restart/correlation, singleton refusal, and safe exact recovery/resumption
where an abandoned claim can be created without forging canonical work.
## Live semantic projector proof and canonical purification (2026-07-15)
The reserved policy is live against shared Yggdrasil Qdrant through
`127.0.0.1:16333` and Yggdrasil Ollama through `10.77.0.1:11435`. Live launch
pressure exposed three fossils that narrow tests had not reached:
- local Verse still contained the deleted ownerless
`epiphany.cultmesh.operator_status`; an explicit backed-up migration removed
its one key instead of registering extinct authority;
- both canonical stores contained v0 claims/attempts and index receipts from
before Idunn fencing; explicit migration atomically retired those rows from
active authority rather than inventing missing incarnation or grant fields;
- Mind and Modeling canonical cache catalogs registered claims, attempts, and
receipts but not the executor-grant/recovery types now written into the same
physical stores; both readers now register the whole semantic authority
family.
CultCache now provides an atomic exact-envelope batch deletion primitive for
these migrations. The projector launch receipt also binds executable SHA-256,
and the child verifies both its own PID and its bytes against that receipt
before constructing the service body. Health publication errors are bounded in
the pulse output instead of disappearing into a count.
Fresh Idunn-granted projection rebuilt Mind (43 documents) and Modeling (3
documents), both 1024-dimensional and query-eligible. Live semantic context
queries ranked canonical documents for both partitions while ignoring Qdrant
payload text. A clean steady pulse inspected both sources, remained idle, and
published a ready heartbeat with no source or health faults. A second
interactive projector was refused by the host singleton. Killing child PID
22992 caused the reconciler to launch PID 29868 with receipt
`daa89e4f-4301-40eb-aa87-5b52c5017221`; the typed service-status readback proved
the new ready heartbeat names that exact receipt and executable hash.
Full proof is 375 library tests passed/1 ignored, 7/7 supervisor tests, and all
binaries compiling. The live child and reconciler remain running, but survival
is not yet deployable physiology: reconciler PID 22072 and SSH tunnel PID 22728
are detached processes, not durable OS-owned services. The existing generic
Windows `sc.exe create` path is not sufficient because this console binary does
not implement the Windows service-control handshake. Build a real service host
or explicit Task Scheduler owner with restart policy, give the Qdrant tunnel
the same durable treatment, and prove startup/reboot recovery. Live abandoned
claim recovery remains unproven; use a safe fixture rather than forging work.

Binary file not shown.

Binary file not shown.

View file

@ -714,4 +714,4 @@ current_status:
- Service lifecycle receipt history is now event-only: `load_epiphany_cultmesh_daemon_service_lifecycle_receipts` filters out the `epiphany-local/daemon-service-lifecycle-receipt/latest` mirror, while `load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt` remains the latest-state reader. Focused unit test `service_lifecycle_receipt_history_excludes_latest_mirror` proves two per-receipt writes return exactly two history records and latest points at the second. Fresh smoke `verse-query-lifecycle-history-filter-smoke` and live overview/triage `local-20260618-145632-497-efac6f0d` / `local-20260618-145632-321-867947af` prove compact swarm sights still expose service lifecycle attention plus the present elevated runbook artifact without daemon pokes or service mutation. Do not use a broad unscoped cargo test filter for this check on Windows; it fans out across bin harnesses and hit a broken pipe during this pass.
- `epiphany-verse-query seed-compact` is the compact seed receipt for wrappers and read-only rites. The older `seed` command still prints the full local Verse context for explicit debugging, but compact wrapper modes now avoid full `seed`/final `query` readback after the combined overview proof exposed Windows debug stack overflow from full-context serialization pressure.
last_completed_repo_swarm_cut: Huginn live-fire has crossed the first real repo Body from Persona pressure to branch-local Hands commit and Soul/Mind closure, and now has repeatable closure and redacted-public-proof mouths. On `E:\Projects\Huginn` branch `epiphany/huginn/first-awakening`, `tools/epiphany_local_run.ps1 -Mode repo-persona-intake` accepted item `huginn-inspection-readback-livefire`, Weksa/Persona intake remained sealed, and `epiphany-work derive-plan` lowered it to model-authored safe family `repo.status_section` for `README.md` only. `tools/epiphany_local_run.ps1 -Mode repo-swarm-run` advanced four bounded pulses: run-from-plan, adopt-from-plan, execute-from-plan, and close-from-execute. Huginn commit `e9b07c38fceabbdc89ea35c2156326c80c0393a2` updated only `README.md`; closure receipt `.epiphany\work\work-close-huginn-inspection-readback-livefire.json` records status `closed`, Soul verdict `passed`, Mind state commit `repo-work-close-huginn-inspection-readback-livefire-mind-commit`, safe family `repo.status_section`, path scope `README.md`, Bifrost publication gate, and `privateStateExposed=false`. Verification also ran Huginn's TypeScript compiler through concrete Node path: `C:\Program Files\nodejs\node.exe E:\Projects\Huginn\node_modules\typescript\bin\tsc -p tsconfig.json` passed. Native verifier `epiphany-repo-livefire-closure-smoke --workspace E:\Projects\Huginn --item huginn-inspection-readback-livefire --expected-path README.md --expected-family repo.status_section --expected-gate awaiting-publication --expected-blocker bifrost-publication-missing` checks closure receipt, Mind map entry, overview gate/blocker, authority seals, and `git show` changed paths, returning `status=ok`, `soulVerdict=passed`, `publicationGate=Bifrost`, and `privateStateExposed=false`. Wrapper `tools/epiphany_local_run.ps1 -Mode repo-livefire-closure -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exposes the same read-only proof through the local operator mouth; artifact `local-20260621-190156-803-2f85ba15` printed commit, path, gate, blocker, Soul verdict, Mind commit receipt, and `privateStateExposed=False` without push, merge, publication, or target mutation. New wrapper `tools/epiphany_local_run.ps1 -Mode repo-work-public-proof -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exports the redacted proof bundle and repo-local Verse index without publishing; artifact `local-20260621-190645-345-4555b1dc` wrote `.epiphany\public\proof-bundles\repo-work-public-proof-huginn-inspection-readback-livefire.json`, proof id `repo-work-public-proof-huginn-inspection-readback-livefire`, SHA-256 `857545b199f3e37eb06c2e757e5cfc201958e46667bb1f8403fd333a22620f63`, nine artifact rows, zero publication rows, and `privateStateExposed=False`. swarm overview readback `local-20260621-190701-140-b9519ec6` sees the `REPO-WORK-PUBLIC-PROOF` row and action row from Huginn's repo-local Verse with the same SHA-256 while Bifrost publication remains missing. Launcher compact modes are now named compact operator-context modes instead of read-only modes, and `bifrost-public-proof` summaries print item, target public Verse, room, proof SHA-256, review receipts, and credit receipts so publication receipts are auditable without claiming upstream sync.
next_action: Complete the live survival proof for the workstation semantic projector service body. The shared Yggdrasil Qdrant is authoritative and reachable through the ops-owned workstation tunnel at `127.0.0.1:16333`; Yggdrasil Ollama is reachable on WireGuard at `10.77.0.1:11435`, and both Epiphany collections are green, 1024-dimensional cosine collections owned by the configured Qwen embedding model. Idunn's reserved policy now binds those endpoints and is the sole desired-state owner. Managed launch preallocates a UUID, injects it before spawn, and atomically seals an immutable v1 PID-bound launch receipt against the exact current policy envelope; a child cannot construct its service body, pulse, or heartbeat until that receipt authenticates, and failed sealing kills and waits for the child. Semantic recovery v2 accepts only the current policy -> exact launch receipt -> causally later correlated provider heartbeat chain; daemon poke receipts cannot mint claim authority. One packaged process still owns fair bounded execution across distinct same-swarm Mind and Modeling stores, with canonical grants/claims/attempts/receipts as query authority and provider health as sight only. Library proof is green (371 passed, 1 ignored), supervisor authority proof is green (7 passed), and all binaries compile. Next publish the reserved policy, place the reconciler and Qdrant tunnel under durable Idunn/OS survival ownership, then prove a real child launch and handshake, bounded pulse, provider heartbeat, both health rows, forced restart with new correlated heartbeat, exact recovery/resumption where a safe abandoned claim can be created, and host singleton refusal. Do not call deployment complete until those live proofs pass.
next_action: Finish durable survival ownership for the now-live workstation semantic projector. The reserved policy is published against Yggdrasil Qdrant at `127.0.0.1:16333` and Ollama at `10.77.0.1:11435`. Explicit migrations removed the extinct ownerless operator-status projection and retired pre-Idunn claims, attempts, and index receipts from active semantic authority without fabricating grants; current Mind and Modeling projections were rebuilt through fresh Idunn grants and are query-eligible at 1024 dimensions (43 and 3 documents). Launch receipts now bind exact policy digest, child PID, executable SHA-256, fixed provider, and startup correlation; the child checks its own PID and bytes before constructing the body. Live proof shows a clean two-source idle pulse, ready correlated heartbeat, semantic ranking for both partitions, host singleton refusal, and Idunn restart after a forced child kill from PID 22992 to 29868 with launch receipt `daa89e4f-4301-40eb-aa87-5b52c5017221` and matching ready heartbeat. Library proof is 375 passed/1 ignored, supervisor proof 7/7, all binaries compile. Remaining deployment gap: the currently detached reconciler PID 22072 and ops SSH tunnel PID 22728 are not durable OS-owned physiology. Replace the false ordinary-console `sc.exe` service path with a real service host or explicit Task Scheduler ownership and restart policy, make the Qdrant tunnel equally durable, then prove reboot/startup recovery. Exact abandoned-claim recovery is unit/hostile proved but still needs a safe live recovery fixture; do not forge canonical work merely to make the dashboard green.

2
vendor/cultcache-rs vendored

@ -1 +1 @@
Subproject commit 1383a74becfd17f49879e574c48995b0e2b502aa
Subproject commit deec76be73548867f9276e9c3a4bdcfa265f90e0