Carry organ contracts on worker launches
This commit is contained in:
parent
25fc7b5ab4
commit
a4674df1b1
10 changed files with 280 additions and 17 deletions
|
|
@ -278,9 +278,13 @@ 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 organ_dependencies::EPIPHANY_LAUNCH_ORGAN_CONTRACT_SCHEMA_VERSION;
|
||||
pub use organ_dependencies::EPIPHANY_ORGAN_DEPENDENCY_SCHEMA_VERSION;
|
||||
pub use organ_dependencies::EPIPHANY_STANDING_ORGANS;
|
||||
pub use organ_dependencies::EpiphanyLaunchOrganContract;
|
||||
pub use organ_dependencies::EpiphanyOrganDependency;
|
||||
pub use organ_dependencies::default_launch_organ_contract;
|
||||
pub use organ_dependencies::default_launch_required_receipts;
|
||||
pub use organ_dependencies::default_organ_dependencies_for;
|
||||
pub use organ_dependencies::default_organ_dependency_matrix;
|
||||
pub use organ_dependencies::render_organ_dependencies;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,26 @@
|
|||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::body_gateway::{
|
||||
BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE, BODY_REPO_ACCESS_REFUSAL_RECEIPT_TYPE,
|
||||
BODY_REPO_MUTATION_RECEIPT_TYPE, BODY_REPO_SNAPSHOT_RECEIPT_TYPE,
|
||||
};
|
||||
use crate::eyes_gateway::{EYES_EVIDENCE_PACKET_TYPE, EYES_EVIDENCE_REFUSAL_RECEIPT_TYPE};
|
||||
use crate::hands_gateway::{
|
||||
HANDS_ACTION_REFUSAL_RECEIPT_TYPE, HANDS_COMMIT_RECEIPT_TYPE, HANDS_PATCH_RECEIPT_TYPE,
|
||||
HANDS_ROLLBACK_RECEIPT_TYPE,
|
||||
};
|
||||
use crate::life_gateway::{LIFE_CONTINUITY_REFUSAL_RECEIPT_TYPE, LIFE_RECOVERY_RECEIPT_TYPE};
|
||||
use crate::mind_gateway::{
|
||||
MIND_GATEWAY_REVIEW_TYPE, MIND_STATE_COMMIT_RECEIPT_TYPE, MIND_STATE_REJECTION_RECEIPT_TYPE,
|
||||
};
|
||||
use crate::soul_gateway::{
|
||||
SOUL_REGRESSION_RECEIPT_TYPE, SOUL_REVIEW_RECEIPT_TYPE, SOUL_VERDICT_RECEIPT_TYPE,
|
||||
SOUL_VERIFICATION_REFUSAL_RECEIPT_TYPE,
|
||||
};
|
||||
|
||||
pub const EPIPHANY_ORGAN_DEPENDENCY_SCHEMA_VERSION: &str = "epiphany.organ_dependency.v0";
|
||||
pub const EPIPHANY_LAUNCH_ORGAN_CONTRACT_SCHEMA_VERSION: &str = "epiphany.launch_organ_contract.v0";
|
||||
|
||||
pub const EPIPHANY_STANDING_ORGANS: [&str; 8] = [
|
||||
"self",
|
||||
|
|
@ -23,6 +42,19 @@ pub struct EpiphanyOrganDependency {
|
|||
pub contract: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EpiphanyLaunchOrganContract {
|
||||
pub schema_version: String,
|
||||
pub authority_scope: String,
|
||||
pub document_kind: String,
|
||||
pub output_contract_id: String,
|
||||
pub owner_organ: String,
|
||||
pub dependencies: Vec<EpiphanyOrganDependency>,
|
||||
pub required_receipt_document_types: Vec<String>,
|
||||
pub contract: String,
|
||||
}
|
||||
|
||||
pub fn default_organ_dependencies_for(organ_id: &str) -> EpiphanyOrganDependency {
|
||||
let normalized = organ_id.trim().to_ascii_lowercase();
|
||||
EpiphanyOrganDependency {
|
||||
|
|
@ -44,6 +76,47 @@ pub fn default_organ_dependency_matrix() -> Vec<EpiphanyOrganDependency> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub fn default_launch_organ_contract(
|
||||
authority_scope: &str,
|
||||
document_kind: &str,
|
||||
output_contract_id: &str,
|
||||
) -> EpiphanyLaunchOrganContract {
|
||||
EpiphanyLaunchOrganContract {
|
||||
schema_version: EPIPHANY_LAUNCH_ORGAN_CONTRACT_SCHEMA_VERSION.to_string(),
|
||||
authority_scope: authority_scope.to_string(),
|
||||
document_kind: document_kind.to_string(),
|
||||
output_contract_id: output_contract_id.to_string(),
|
||||
owner_organ: owner_organ_for_authority_scope(authority_scope).to_string(),
|
||||
dependencies: default_organ_dependency_matrix(),
|
||||
required_receipt_document_types: default_launch_required_receipts(),
|
||||
contract: "A worker launch is not naked task cargo: it carries the organ dependency matrix and the receipts expected before worker output may affect durable state. Mind gates state effects, Body gates repo access, Eyes supplies evidence, Hands records action, Soul verifies, and Life preserves continuity.".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_launch_required_receipts() -> Vec<String> {
|
||||
unique_strings(vec![
|
||||
MIND_GATEWAY_REVIEW_TYPE,
|
||||
MIND_STATE_COMMIT_RECEIPT_TYPE,
|
||||
MIND_STATE_REJECTION_RECEIPT_TYPE,
|
||||
BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE,
|
||||
BODY_REPO_ACCESS_REFUSAL_RECEIPT_TYPE,
|
||||
BODY_REPO_SNAPSHOT_RECEIPT_TYPE,
|
||||
BODY_REPO_MUTATION_RECEIPT_TYPE,
|
||||
EYES_EVIDENCE_PACKET_TYPE,
|
||||
EYES_EVIDENCE_REFUSAL_RECEIPT_TYPE,
|
||||
HANDS_PATCH_RECEIPT_TYPE,
|
||||
HANDS_COMMIT_RECEIPT_TYPE,
|
||||
HANDS_ROLLBACK_RECEIPT_TYPE,
|
||||
HANDS_ACTION_REFUSAL_RECEIPT_TYPE,
|
||||
SOUL_VERDICT_RECEIPT_TYPE,
|
||||
SOUL_REGRESSION_RECEIPT_TYPE,
|
||||
SOUL_REVIEW_RECEIPT_TYPE,
|
||||
SOUL_VERIFICATION_REFUSAL_RECEIPT_TYPE,
|
||||
LIFE_RECOVERY_RECEIPT_TYPE,
|
||||
LIFE_CONTINUITY_REFUSAL_RECEIPT_TYPE,
|
||||
])
|
||||
}
|
||||
|
||||
pub fn render_organ_dependency(dependency: &EpiphanyOrganDependency) -> String {
|
||||
let depends_on = if dependency.depends_on.is_empty() {
|
||||
"- none".to_string()
|
||||
|
|
@ -72,6 +145,38 @@ pub fn render_organ_dependencies(dependencies: &[EpiphanyOrganDependency]) -> St
|
|||
.join("\n\n")
|
||||
}
|
||||
|
||||
fn owner_organ_for_authority_scope(authority_scope: &str) -> &'static str {
|
||||
let normalized = authority_scope.trim().to_ascii_lowercase();
|
||||
if normalized.contains("face") {
|
||||
"face"
|
||||
} else if normalized.contains("imagination") {
|
||||
"imagination"
|
||||
} else if normalized.contains("eyes") || normalized.contains("evidence") {
|
||||
"eyes"
|
||||
} else if normalized.contains("body") || normalized.contains("repo") {
|
||||
"body"
|
||||
} else if normalized.contains("hands") || normalized.contains("implementation") {
|
||||
"hands"
|
||||
} else if normalized.contains("verification") || normalized.contains("soul") {
|
||||
"soul"
|
||||
} else if normalized.contains("reorient") || normalized.contains("life") {
|
||||
"life"
|
||||
} else {
|
||||
"self"
|
||||
}
|
||||
}
|
||||
|
||||
fn unique_strings(items: Vec<&'static str>) -> Vec<String> {
|
||||
let mut out = Vec::new();
|
||||
for item in items {
|
||||
let item = item.to_string();
|
||||
if !out.contains(&item) {
|
||||
out.push(item);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -93,4 +198,31 @@ mod tests {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn launch_contract_carries_all_organs_and_gateway_receipts() {
|
||||
let contract = default_launch_organ_contract(
|
||||
"epiphany.role.verification",
|
||||
"role",
|
||||
"epiphany.worker.role_result.v0",
|
||||
);
|
||||
assert_eq!(contract.owner_organ, "soul");
|
||||
assert_eq!(contract.dependencies.len(), EPIPHANY_STANDING_ORGANS.len());
|
||||
assert!(
|
||||
contract
|
||||
.required_receipt_document_types
|
||||
.contains(&MIND_GATEWAY_REVIEW_TYPE.to_string())
|
||||
);
|
||||
assert!(
|
||||
contract
|
||||
.required_receipt_document_types
|
||||
.contains(&BODY_REPO_ACCESS_GRANT_RECEIPT_TYPE.to_string())
|
||||
);
|
||||
assert!(
|
||||
contract
|
||||
.required_receipt_document_types
|
||||
.contains(&SOUL_VERDICT_RECEIPT_TYPE.to_string())
|
||||
);
|
||||
assert!(contract.contract.contains("not naked task cargo"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ 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::organ_dependencies::EpiphanyLaunchOrganContract;
|
||||
use crate::soul_gateway::*;
|
||||
use crate::state_ledger::STATE_LEDGER_SCHEMA_VERSION;
|
||||
use crate::state_ledger::STATE_LEDGER_STORE_TYPE;
|
||||
|
|
@ -258,6 +259,8 @@ pub struct EpiphanyRuntimeWorkerLaunchRequest {
|
|||
pub launch_document_msgpack: Vec<u8>,
|
||||
#[cultcache(key = 9, default)]
|
||||
pub metadata: BTreeMap<String, String>,
|
||||
#[cultcache(key = 10, default)]
|
||||
pub organ_launch_contract: EpiphanyLaunchOrganContract,
|
||||
}
|
||||
|
||||
impl EpiphanyRuntimeWorkerLaunchRequest {
|
||||
|
|
@ -532,6 +535,7 @@ pub struct RuntimeSpineHeartbeatJobOptions {
|
|||
pub instruction: String,
|
||||
pub launch_document: EpiphanyWorkerLaunchDocument,
|
||||
pub output_contract_id: String,
|
||||
pub organ_launch_contract: EpiphanyLaunchOrganContract,
|
||||
pub created_at: String,
|
||||
}
|
||||
|
||||
|
|
@ -547,6 +551,7 @@ pub struct RuntimeSpineHeartbeatLaunchPlanOptions {
|
|||
pub instruction: String,
|
||||
pub launch_document: EpiphanyWorkerLaunchDocument,
|
||||
pub output_contract_id: String,
|
||||
pub organ_launch_contract: EpiphanyLaunchOrganContract,
|
||||
pub max_runtime_seconds: Option<u64>,
|
||||
pub runtime_job_id: String,
|
||||
}
|
||||
|
|
@ -570,6 +575,7 @@ pub struct EpiphanyJobLaunchRequest {
|
|||
pub instruction: String,
|
||||
pub launch_document: EpiphanyWorkerLaunchDocument,
|
||||
pub output_contract_id: String,
|
||||
pub organ_launch_contract: EpiphanyLaunchOrganContract,
|
||||
pub max_runtime_seconds: Option<u64>,
|
||||
}
|
||||
|
||||
|
|
@ -856,6 +862,12 @@ pub fn open_runtime_spine_heartbeat_job(
|
|||
"worker launch output_contract_id must match the typed launch document"
|
||||
));
|
||||
}
|
||||
validate_launch_organ_contract(
|
||||
&options.organ_launch_contract,
|
||||
&options.authority_scope,
|
||||
options.launch_document.document_kind(),
|
||||
&options.output_contract_id,
|
||||
)?;
|
||||
validate_non_empty(&options.created_at, "created at")?;
|
||||
let store_path = store_path.as_ref();
|
||||
let job_id = options.job_id.clone();
|
||||
|
|
@ -864,6 +876,7 @@ pub fn open_runtime_spine_heartbeat_job(
|
|||
let authority_scope = options.authority_scope.clone();
|
||||
let instruction = options.instruction.clone();
|
||||
let output_contract_id = options.output_contract_id.clone();
|
||||
let organ_launch_contract = options.organ_launch_contract.clone();
|
||||
let launch_document = options.launch_document.clone();
|
||||
initialize_runtime_spine(
|
||||
store_path,
|
||||
|
|
@ -918,6 +931,7 @@ pub fn open_runtime_spine_heartbeat_job(
|
|||
document_kind: worker_launch_document_kind(&launch_document).to_string(),
|
||||
launch_document_msgpack: encode_worker_launch_document(&launch_document)?,
|
||||
metadata: BTreeMap::new(),
|
||||
organ_launch_contract,
|
||||
};
|
||||
cache.put(&job_id, &request)?;
|
||||
Ok(job)
|
||||
|
|
@ -2334,16 +2348,55 @@ fn validate_non_empty(value: &str, field: &str) -> Result<()> {
|
|||
}
|
||||
|
||||
fn worker_launch_document_kind(document: &EpiphanyWorkerLaunchDocument) -> &'static str {
|
||||
match document {
|
||||
EpiphanyWorkerLaunchDocument::Role(_) => "role",
|
||||
EpiphanyWorkerLaunchDocument::Reorient(_) => "reorient",
|
||||
}
|
||||
document.document_kind()
|
||||
}
|
||||
|
||||
fn encode_worker_launch_document(document: &EpiphanyWorkerLaunchDocument) -> Result<Vec<u8>> {
|
||||
rmp_serde::to_vec_named(document).context("failed to encode worker launch document MessagePack")
|
||||
}
|
||||
|
||||
fn validate_launch_organ_contract(
|
||||
contract: &EpiphanyLaunchOrganContract,
|
||||
authority_scope: &str,
|
||||
document_kind: &str,
|
||||
output_contract_id: &str,
|
||||
) -> Result<()> {
|
||||
validate_non_empty(
|
||||
&contract.schema_version,
|
||||
"epiphany launch organ contract schema_version",
|
||||
)?;
|
||||
if contract.authority_scope != authority_scope {
|
||||
return Err(anyhow!(
|
||||
"epiphany launch organ contract authority_scope must match the launch request"
|
||||
));
|
||||
}
|
||||
if contract.document_kind != document_kind {
|
||||
return Err(anyhow!(
|
||||
"epiphany launch organ contract document_kind must match the typed launch document"
|
||||
));
|
||||
}
|
||||
if contract.output_contract_id != output_contract_id {
|
||||
return Err(anyhow!(
|
||||
"epiphany launch organ contract output_contract_id must match the launch request"
|
||||
));
|
||||
}
|
||||
validate_non_empty(
|
||||
&contract.owner_organ,
|
||||
"epiphany launch organ contract owner_organ",
|
||||
)?;
|
||||
if contract.dependencies.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"epiphany launch organ contract must carry organ dependencies"
|
||||
));
|
||||
}
|
||||
if contract.required_receipt_document_types.is_empty() {
|
||||
return Err(anyhow!(
|
||||
"epiphany launch organ contract must carry required receipt document types"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn decode_optional_msgpack<T>(payload: Option<&[u8]>, label: &str) -> Result<Option<T>>
|
||||
where
|
||||
T: for<'de> Deserialize<'de>,
|
||||
|
|
@ -2394,6 +2447,12 @@ fn validate_heartbeat_launch_options(
|
|||
"epiphany job launch output_contract_id must match the typed launch document"
|
||||
));
|
||||
}
|
||||
validate_launch_organ_contract(
|
||||
&options.organ_launch_contract,
|
||||
&options.authority_scope,
|
||||
options.launch_document.document_kind(),
|
||||
&options.output_contract_id,
|
||||
)?;
|
||||
if let Some(max_runtime_seconds) = options.max_runtime_seconds
|
||||
&& max_runtime_seconds == 0
|
||||
{
|
||||
|
|
@ -2595,6 +2654,11 @@ mod tests {
|
|||
},
|
||||
),
|
||||
output_contract_id: crate::ROLE_WORKER_OUTPUT_CONTRACT_ID.to_string(),
|
||||
organ_launch_contract: crate::default_launch_organ_contract(
|
||||
"modeling",
|
||||
"role",
|
||||
crate::ROLE_WORKER_OUTPUT_CONTRACT_ID,
|
||||
),
|
||||
created_at: "2026-05-06T00:02:00Z".to_string(),
|
||||
},
|
||||
)?;
|
||||
|
|
@ -2622,6 +2686,13 @@ mod tests {
|
|||
assert_eq!(launch_request.document_kind, "role");
|
||||
assert!(!launch_request.launch_document_msgpack.is_empty());
|
||||
assert_eq!(launch_request.launch_document()?.thread_id(), "thread-1");
|
||||
assert_eq!(launch_request.organ_launch_contract.document_kind, "role");
|
||||
assert!(
|
||||
launch_request
|
||||
.organ_launch_contract
|
||||
.required_receipt_document_types
|
||||
.contains(&crate::MIND_GATEWAY_REVIEW_TYPE.to_string())
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -2660,6 +2731,11 @@ mod tests {
|
|||
},
|
||||
),
|
||||
output_contract_id: "epiphany.worker.role_result.v0".to_string(),
|
||||
organ_launch_contract: crate::default_launch_organ_contract(
|
||||
"epiphany.role.modeling",
|
||||
"role",
|
||||
"epiphany.worker.role_result.v0",
|
||||
),
|
||||
max_runtime_seconds: Some(60),
|
||||
runtime_job_id: "turn-1".to_string(),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -42,6 +42,13 @@ impl EpiphanyWorkerLaunchDocument {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn document_kind(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Role(_) => "role",
|
||||
Self::Reorient(_) => "reorient",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn thread_id(&self) -> &str {
|
||||
match self {
|
||||
Self::Role(document) => &document.thread_id,
|
||||
|
|
@ -163,6 +170,11 @@ pub fn build_reorient_job_launch_request(
|
|||
linked_graph_node_ids.clone(),
|
||||
));
|
||||
let output_contract_id = launch_document.output_contract_id().to_string();
|
||||
let organ_launch_contract = crate::default_launch_organ_contract(
|
||||
reorient_launch_authority_scope(input.decision.action),
|
||||
launch_document.document_kind(),
|
||||
&output_contract_id,
|
||||
);
|
||||
|
||||
EpiphanyJobLaunchRequest {
|
||||
expected_revision: input.expected_revision,
|
||||
|
|
@ -176,6 +188,7 @@ pub fn build_reorient_job_launch_request(
|
|||
instruction: input.instruction,
|
||||
launch_document,
|
||||
output_contract_id,
|
||||
organ_launch_contract,
|
||||
max_runtime_seconds: input.max_runtime_seconds,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue