Persist Mind acceptance receipts
This commit is contained in:
parent
2b3b446489
commit
93577e8532
8 changed files with 267 additions and 19 deletions
|
|
@ -322,11 +322,13 @@ pub use mind_gateway::MindCultNetContract;
|
|||
pub use mind_gateway::MindGatewayDecision;
|
||||
pub use mind_gateway::MindGatewayReview;
|
||||
pub use mind_gateway::MindInterpreterPromptInput;
|
||||
pub use mind_gateway::MindStateCommitReceipt;
|
||||
pub use mind_gateway::build_mind_interpreter_prompt;
|
||||
pub use mind_gateway::default_mind_cultnet_contracts;
|
||||
pub use mind_gateway::mind_review_allows_state;
|
||||
pub use mind_gateway::mind_review_reorient_acceptance;
|
||||
pub use mind_gateway::mind_review_role_acceptance;
|
||||
pub use mind_gateway::mind_state_commit_receipt;
|
||||
pub use organ_dependencies::EPIPHANY_LAUNCH_ORGAN_CONTRACT_SCHEMA_VERSION;
|
||||
pub use organ_dependencies::EPIPHANY_ORGAN_DEPENDENCY_SCHEMA_VERSION;
|
||||
pub use organ_dependencies::EPIPHANY_STANDING_ORGANS;
|
||||
|
|
@ -407,11 +409,15 @@ pub use runtime_spine::initialize_runtime_spine;
|
|||
pub use runtime_spine::open_runtime_spine_heartbeat_job;
|
||||
pub use runtime_spine::plan_runtime_spine_heartbeat_launch;
|
||||
pub use runtime_spine::put_coordinator_run_receipt;
|
||||
pub use runtime_spine::put_mind_gateway_review;
|
||||
pub use runtime_spine::put_mind_state_commit_receipt;
|
||||
pub use runtime_spine::put_runtime_reorient_worker_result;
|
||||
pub use runtime_spine::put_runtime_role_worker_result;
|
||||
pub use runtime_spine::replace_or_append_epiphany_job_binding;
|
||||
pub use runtime_spine::runtime_hello_frame;
|
||||
pub use runtime_spine::runtime_job_snapshot;
|
||||
pub use runtime_spine::runtime_mind_gateway_review;
|
||||
pub use runtime_spine::runtime_mind_state_commit_receipt;
|
||||
pub use runtime_spine::runtime_reorient_worker_result;
|
||||
pub use runtime_spine::runtime_role_worker_result;
|
||||
pub use runtime_spine::runtime_schema_catalog_response;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use crate::EpiphanyReorientAcceptanceFinding;
|
|||
use crate::EpiphanyRoleFindingInterpretation;
|
||||
use crate::EpiphanyRoleResultRoleId;
|
||||
use crate::EpiphanyRoleStatePatchDocument;
|
||||
use cultcache_rs::DatabaseEntry;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
|
|
@ -30,20 +31,75 @@ pub enum MindGatewayDecision {
|
|||
Hold,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(type = "epiphany.mind.gateway_review", schema = "MindGatewayReview")]
|
||||
pub struct MindGatewayReview {
|
||||
#[cultcache(key = 0)]
|
||||
pub schema_version: String,
|
||||
#[cultcache(key = 1)]
|
||||
pub gateway_id: String,
|
||||
#[cultcache(key = 2)]
|
||||
pub source_kind: String,
|
||||
#[cultcache(key = 3)]
|
||||
pub source_role_id: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub decision: MindGatewayDecision,
|
||||
#[cultcache(key = 5)]
|
||||
pub allowed_effects: Vec<String>,
|
||||
#[cultcache(key = 6)]
|
||||
pub refused_effects: Vec<String>,
|
||||
#[cultcache(key = 7)]
|
||||
pub reasons: Vec<String>,
|
||||
#[cultcache(key = 8)]
|
||||
pub contract: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "epiphany.mind.state_commit_receipt",
|
||||
schema = "MindStateCommitReceipt"
|
||||
)]
|
||||
pub struct MindStateCommitReceipt {
|
||||
#[cultcache(key = 0)]
|
||||
pub schema_version: String,
|
||||
#[cultcache(key = 1)]
|
||||
pub receipt_id: String,
|
||||
#[cultcache(key = 2)]
|
||||
pub gateway_id: String,
|
||||
#[cultcache(key = 3)]
|
||||
pub source_kind: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub source_role_id: String,
|
||||
#[cultcache(key = 5)]
|
||||
pub state_revision: u64,
|
||||
#[cultcache(key = 6)]
|
||||
pub changed_fields: Vec<String>,
|
||||
#[cultcache(key = 7)]
|
||||
pub committed_at: String,
|
||||
#[cultcache(key = 8)]
|
||||
pub contract: String,
|
||||
}
|
||||
|
||||
pub fn mind_state_commit_receipt(
|
||||
receipt_id: String,
|
||||
review: &MindGatewayReview,
|
||||
state_revision: u64,
|
||||
changed_fields: Vec<String>,
|
||||
committed_at: String,
|
||||
) -> MindStateCommitReceipt {
|
||||
MindStateCommitReceipt {
|
||||
schema_version: MIND_STATE_COMMIT_RECEIPT_SCHEMA_VERSION.to_string(),
|
||||
receipt_id,
|
||||
gateway_id: review.gateway_id.clone(),
|
||||
source_kind: review.source_kind.clone(),
|
||||
source_role_id: review.source_role_id.clone(),
|
||||
state_revision,
|
||||
changed_fields,
|
||||
committed_at,
|
||||
contract: "Mind admitted reviewed state effects into durable Epiphany state; this receipt is the state-commit proof paired with the gateway review.".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MindInterpreterPromptInput {
|
||||
|
|
@ -231,7 +287,15 @@ pub fn mind_review_role_acceptance(
|
|||
}
|
||||
MindGatewayReview {
|
||||
schema_version: MIND_GATEWAY_REVIEW_SCHEMA_VERSION.to_string(),
|
||||
gateway_id: format!("mind-role-{binding_id}"),
|
||||
gateway_id: format!(
|
||||
"mind-role-{}-{}",
|
||||
binding_id,
|
||||
finding
|
||||
.runtime_job_id
|
||||
.as_deref()
|
||||
.filter(|job_id| !job_id.trim().is_empty())
|
||||
.unwrap_or("missing-job")
|
||||
),
|
||||
source_kind: "roleWorkerResult".to_string(),
|
||||
source_role_id: role_label(role_id).to_string(),
|
||||
decision: if reasons.is_empty() {
|
||||
|
|
@ -293,7 +357,15 @@ pub fn mind_review_reorient_acceptance(
|
|||
}
|
||||
MindGatewayReview {
|
||||
schema_version: MIND_GATEWAY_REVIEW_SCHEMA_VERSION.to_string(),
|
||||
gateway_id: format!("mind-reorient-{binding_id}"),
|
||||
gateway_id: format!(
|
||||
"mind-reorient-{}-{}",
|
||||
binding_id,
|
||||
finding
|
||||
.runtime_job_id
|
||||
.as_deref()
|
||||
.filter(|job_id| !job_id.trim().is_empty())
|
||||
.unwrap_or("missing-job")
|
||||
),
|
||||
source_kind: "reorientWorkerResult".to_string(),
|
||||
source_role_id: "reorientation".to_string(),
|
||||
decision: if reasons.is_empty() {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,8 @@ use crate::mind_gateway::MIND_THOUGHT_SCHEMA_VERSION;
|
|||
use crate::mind_gateway::MIND_THOUGHT_TYPE;
|
||||
use crate::mind_gateway::MIND_VERSE_ADOPTION_RECEIPT_SCHEMA_VERSION;
|
||||
use crate::mind_gateway::MIND_VERSE_ADOPTION_RECEIPT_TYPE;
|
||||
use crate::mind_gateway::MindGatewayReview;
|
||||
use crate::mind_gateway::MindStateCommitReceipt;
|
||||
use crate::organ_dependencies::EpiphanyLaunchOrganContract;
|
||||
use crate::soul_gateway::*;
|
||||
use crate::state_ledger::STATE_LEDGER_SCHEMA_VERSION;
|
||||
|
|
@ -707,6 +709,8 @@ pub fn runtime_spine_cache(store_path: impl AsRef<Path>) -> Result<CultCache> {
|
|||
cache.register_entry_type::<EpiphanyRuntimeJobResult>()?;
|
||||
cache.register_entry_type::<EpiphanyRuntimeEvent>()?;
|
||||
cache.register_entry_type::<EpiphanyCoordinatorRunReceipt>()?;
|
||||
cache.register_entry_type::<MindGatewayReview>()?;
|
||||
cache.register_entry_type::<MindStateCommitReceipt>()?;
|
||||
cache.register_entry_type::<EpiphanyOpenAiAdapterStatus>()?;
|
||||
cache.register_entry_type::<EpiphanyOpenAiModelRequest>()?;
|
||||
cache.register_entry_type::<EpiphanyOpenAiStreamEvent>()?;
|
||||
|
|
@ -1118,6 +1122,56 @@ pub fn runtime_reorient_worker_result(
|
|||
cache.get::<EpiphanyRuntimeReorientWorkerResult>(job_id)
|
||||
}
|
||||
|
||||
pub fn put_mind_gateway_review(
|
||||
store_path: impl AsRef<Path>,
|
||||
review: &MindGatewayReview,
|
||||
) -> Result<()> {
|
||||
validate_non_empty(&review.gateway_id, "Mind gateway review id")?;
|
||||
validate_non_empty(&review.source_kind, "Mind gateway review source kind")?;
|
||||
validate_non_empty(&review.source_role_id, "Mind gateway review source role")?;
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
require_identity(&cache)?;
|
||||
cache.put(&review.gateway_id, review)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn runtime_mind_gateway_review(
|
||||
store_path: impl AsRef<Path>,
|
||||
gateway_id: &str,
|
||||
) -> Result<Option<MindGatewayReview>> {
|
||||
validate_non_empty(gateway_id, "Mind gateway review id")?;
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
cache.get::<MindGatewayReview>(gateway_id)
|
||||
}
|
||||
|
||||
pub fn put_mind_state_commit_receipt(
|
||||
store_path: impl AsRef<Path>,
|
||||
receipt: &MindStateCommitReceipt,
|
||||
) -> Result<()> {
|
||||
validate_non_empty(&receipt.receipt_id, "Mind state commit receipt id")?;
|
||||
validate_non_empty(&receipt.gateway_id, "Mind state commit gateway id")?;
|
||||
validate_non_empty(&receipt.source_kind, "Mind state commit source kind")?;
|
||||
validate_non_empty(&receipt.source_role_id, "Mind state commit source role")?;
|
||||
validate_non_empty(&receipt.committed_at, "Mind state commit timestamp")?;
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
require_identity(&cache)?;
|
||||
cache.put(&receipt.receipt_id, receipt)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn runtime_mind_state_commit_receipt(
|
||||
store_path: impl AsRef<Path>,
|
||||
receipt_id: &str,
|
||||
) -> Result<Option<MindStateCommitReceipt>> {
|
||||
validate_non_empty(receipt_id, "Mind state commit receipt id")?;
|
||||
let mut cache = runtime_spine_cache(store_path)?;
|
||||
cache.pull_all_backing_stores()?;
|
||||
cache.get::<MindStateCommitReceipt>(receipt_id)
|
||||
}
|
||||
|
||||
pub fn put_coordinator_run_receipt(
|
||||
store_path: impl AsRef<Path>,
|
||||
receipt: &EpiphanyCoordinatorRunReceipt,
|
||||
|
|
@ -3028,6 +3082,49 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_spine_persists_mind_gateway_review_receipts() -> Result<()> {
|
||||
let temp = tempdir()?;
|
||||
let store = temp.path().join("runtime.msgpack");
|
||||
initialize_runtime_spine(
|
||||
&store,
|
||||
RuntimeSpineInitOptions {
|
||||
runtime_id: "epiphany-test".to_string(),
|
||||
display_name: "Epiphany Test".to_string(),
|
||||
created_at: "2026-05-06T00:00:00Z".to_string(),
|
||||
},
|
||||
)?;
|
||||
let review = MindGatewayReview {
|
||||
schema_version: crate::MIND_GATEWAY_REVIEW_SCHEMA_VERSION.to_string(),
|
||||
gateway_id: "mind-role-modeling-job-1".to_string(),
|
||||
source_kind: "roleWorkerResult".to_string(),
|
||||
source_role_id: "modeling".to_string(),
|
||||
decision: crate::mind_gateway::MindGatewayDecision::Accept,
|
||||
allowed_effects: vec!["statePatch".to_string()],
|
||||
refused_effects: Vec::new(),
|
||||
reasons: Vec::new(),
|
||||
contract: "Mind review is persisted before state admission.".to_string(),
|
||||
};
|
||||
|
||||
put_mind_gateway_review(&store, &review)?;
|
||||
let commit = crate::mind_state_commit_receipt(
|
||||
"mind-commit-1".to_string(),
|
||||
&review,
|
||||
42,
|
||||
vec!["GraphCheckpoint".to_string()],
|
||||
"2026-05-06T00:04:00Z".to_string(),
|
||||
);
|
||||
put_mind_state_commit_receipt(&store, &commit)?;
|
||||
|
||||
let stored = runtime_mind_gateway_review(&store, "mind-role-modeling-job-1")?
|
||||
.expect("Mind review receipt should persist");
|
||||
assert_eq!(stored, review);
|
||||
let stored_commit = runtime_mind_state_commit_receipt(&store, "mind-commit-1")?
|
||||
.expect("Mind state commit receipt should persist");
|
||||
assert_eq!(stored_commit, commit);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runtime_spine_opens_heartbeat_job_from_single_typed_call() -> Result<()> {
|
||||
let temp = tempdir()?;
|
||||
|
|
|
|||
Reference in a new issue