Preserve auditable decisions through retention

This commit is contained in:
Meta Vens 2026-08-18 08:05:48 +02:00
commit f8412b697f
4 changed files with 532 additions and 31 deletions

View file

@ -905,6 +905,7 @@ pub use runtime_spine::COORDINATOR_RUN_RECEIPT_TYPE;
pub use runtime_spine::EPIPHANY_RUNTIME_ROOT_SESSION_ID;
pub use runtime_spine::EpiphanyArchivedRuntimeSession;
pub use runtime_spine::EpiphanyArchivedRuntimeWorkerAttempt;
pub use runtime_spine::EpiphanyArchivedRuntimeWorkerDecision;
pub use runtime_spine::EpiphanyCoordinatorDeathRecovery;
pub use runtime_spine::EpiphanyCoordinatorRunReceipt;
pub use runtime_spine::EpiphanyCoordinatorRunReceiptRetentionHead;

View file

@ -23,6 +23,7 @@ pub const MIND_COMMIT_RECEIPT_SCHEMA_VERSION: &str = "epiphany.mind_commit_recei
pub const REASONING_BASIS_TYPE: &str = "epiphany.reasoning_basis.v1";
pub const DECISION_CONTEXT_TYPE: &str = "epiphany.decision_context.v1";
pub const MIND_COMMIT_RECEIPT_TYPE: &str = "epiphany.mind_commit_receipt.v1";
pub const DECISION_AUDIT_PROJECTION_SCHEMA_VERSION: &str = "epiphany.decision_audit_projection.v1";
pub const WORKER_REASONING_PROJECTION_POLICY: &str =
"epiphany.reasoning_projection.worker_launch.v2";
@ -508,6 +509,276 @@ pub enum EpiphanyMindCommitOutcome {
},
}
/// Read-only reconstruction of the durable records that make one model
/// decision auditable. This is an operator projection, never a stored owner.
#[derive(Clone, Debug, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EpiphanyDecisionAuditProjection {
pub schema_version: String,
pub context_id: String,
pub reasoning_basis: EpiphanyReasoningBasis,
pub decision_context: EpiphanyDecisionContext,
pub reasoning_projection: EpiphanyReasoningProjection,
pub terminal_native_request: EpiphanyModelRequest,
pub terminal_provider_request: EpiphanyOpenAiModelRequest,
pub tool_observations: Vec<EpiphanyDecisionToolObservation>,
pub terminal_records: EpiphanyDecisionTerminalRecords,
pub mind_commit_receipts: Vec<EpiphanyMindCommitReceipt>,
pub transcript_required: bool,
}
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct EpiphanyDecisionTerminalRecords {
pub role_worker_results: Vec<crate::EpiphanyRuntimeRoleWorkerResult>,
pub reorient_worker_results: Vec<crate::EpiphanyRuntimeReorientWorkerResult>,
pub runtime_job_results: Vec<crate::EpiphanyRuntimeJobResult>,
pub archived_worker_attempts: Vec<crate::EpiphanyArchivedRuntimeWorkerAttempt>,
pub persona_stage_receipts: Vec<crate::PersonaModelStageReceipt>,
pub persona_effect_documents: Vec<crate::PersonaInterpreterEffectDocument>,
pub persona_terminal_receipts: Vec<crate::PersonaModelTerminalReceipt>,
pub persona_conversation_receipts: Vec<crate::PersonaConversationExecutionReceipt>,
pub reorientation_decisions: Vec<crate::EpiphanyMindReorientationDecisionDocument>,
pub reorientation_failures: Vec<crate::EpiphanyMindReorientationPassFailureDocument>,
}
impl EpiphanyDecisionTerminalRecords {
fn len(&self) -> usize {
self.role_worker_results.len()
+ self.reorient_worker_results.len()
+ self.runtime_job_results.len()
+ self.archived_worker_attempts.len()
+ self.persona_stage_receipts.len()
+ self.persona_effect_documents.len()
+ self.persona_terminal_receipts.len()
+ self.persona_conversation_receipts.len()
+ self.reorientation_decisions.len()
+ self.reorientation_failures.len()
}
fn canonicalize(&mut self) {
self.role_worker_results
.sort_by(|left, right| left.result_id.cmp(&right.result_id));
self.reorient_worker_results
.sort_by(|left, right| left.result_id.cmp(&right.result_id));
self.runtime_job_results
.sort_by(|left, right| left.result_id.cmp(&right.result_id));
self.archived_worker_attempts
.sort_by(|left, right| left.archive_id.cmp(&right.archive_id));
self.persona_stage_receipts
.sort_by(|left, right| left.receipt_id.cmp(&right.receipt_id));
self.persona_effect_documents
.sort_by(|left, right| left.document_id.cmp(&right.document_id));
self.persona_terminal_receipts
.sort_by(|left, right| left.receipt_id.cmp(&right.receipt_id));
self.persona_conversation_receipts
.sort_by(|left, right| left.receipt_id.cmp(&right.receipt_id));
self.reorientation_decisions
.sort_by(|left, right| left.decision_id.cmp(&right.decision_id));
self.reorientation_failures
.sort_by(|left, right| left.failure_id.cmp(&right.failure_id));
}
}
/// Reconstruct one decision solely from durable typed state. Current Mind
/// contents, model stream events, assistant deltas, and runtime event order are
/// deliberately outside this query.
pub fn audit_decision_context(
store_path: impl AsRef<Path>,
context_id: &str,
) -> Result<EpiphanyDecisionAuditProjection> {
require_non_empty(context_id, "decision audit context id")?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let context = cache
.get::<EpiphanyDecisionContext>(context_id)?
.ok_or_else(|| anyhow!("decision audit context is absent"))?;
let basis = cache
.get::<EpiphanyReasoningBasis>(&context.basis_id)?
.ok_or_else(|| anyhow!("decision audit context lost its reasoning basis"))?;
context.validate(&basis)?;
let mut terminal_records = EpiphanyDecisionTerminalRecords {
role_worker_results: cache
.get_all::<crate::EpiphanyRuntimeRoleWorkerResult>()?
.into_iter()
.filter(|record| record.decision_context_id == context_id)
.collect(),
reorient_worker_results: cache
.get_all::<crate::EpiphanyRuntimeReorientWorkerResult>()?
.into_iter()
.filter(|record| record.decision_context_id == context_id)
.collect(),
runtime_job_results: cache
.get_all::<crate::EpiphanyRuntimeJobResult>()?
.into_iter()
.filter(|record| record.decision_context_id.as_deref() == Some(context_id))
.collect(),
archived_worker_attempts: cache
.get_all::<crate::EpiphanyArchivedRuntimeWorkerAttempt>()?
.into_iter()
.filter(|record| record.decision_context_id() == Some(context_id))
.collect(),
persona_stage_receipts: cache
.get_all::<crate::PersonaModelStageReceipt>()?
.into_iter()
.filter(|record| record.decision_context_id == context_id)
.collect(),
persona_effect_documents: cache
.get_all::<crate::PersonaInterpreterEffectDocument>()?
.into_iter()
.filter(|record| record.decision_context_id == context_id)
.collect(),
persona_terminal_receipts: cache
.get_all::<crate::PersonaModelTerminalReceipt>()?
.into_iter()
.filter(|record| {
record
.decision_context_ids
.iter()
.any(|candidate| candidate == context_id)
})
.collect(),
persona_conversation_receipts: cache
.get_all::<crate::PersonaConversationExecutionReceipt>()?
.into_iter()
.filter(|record| record.interpreter_decision_context_id.as_deref() == Some(context_id))
.collect(),
reorientation_decisions: cache
.get_all::<crate::EpiphanyMindReorientationDecisionDocument>()?
.into_iter()
.filter(|record| record.decision_context_id == context_id)
.collect(),
reorientation_failures: cache
.get_all::<crate::EpiphanyMindReorientationPassFailureDocument>()?
.into_iter()
.filter(|record| record.decision_context_id == context_id)
.collect(),
};
terminal_records.canonicalize();
if terminal_records.len() == 0 {
return Err(anyhow!(
"decision audit context has no durable terminal decision record"
));
}
validate_decision_terminal_records(&basis, context_id, &terminal_records)?;
let mut mind_commit_receipts = cache
.get_all::<EpiphanyMindCommitReceipt>()?
.into_iter()
.filter(|receipt| {
matches!(
&receipt.authority,
EpiphanyMindCommitAuthority::ModelDecisionContext {
decision_context_id
} if decision_context_id == context_id
)
})
.collect::<Vec<_>>();
for receipt in &mind_commit_receipts {
receipt.validate()?;
}
mind_commit_receipts.sort_by(|left, right| left.receipt_id.cmp(&right.receipt_id));
Ok(EpiphanyDecisionAuditProjection {
schema_version: DECISION_AUDIT_PROJECTION_SCHEMA_VERSION.to_string(),
context_id: context.context_id.clone(),
decision_context: context.clone(),
reasoning_projection: basis.projection()?,
terminal_native_request: context.native_request()?,
terminal_provider_request: context.provider_request()?,
tool_observations: context.tool_observations()?,
reasoning_basis: basis,
terminal_records,
mind_commit_receipts,
transcript_required: false,
})
}
fn validate_decision_terminal_records(
basis: &EpiphanyReasoningBasis,
context_id: &str,
records: &EpiphanyDecisionTerminalRecords,
) -> Result<()> {
if records
.role_worker_results
.iter()
.any(|record| record.job_id != basis.pass_id || record.role_id != basis.organ_id)
|| records
.reorient_worker_results
.iter()
.any(|record| record.job_id != basis.pass_id)
|| records
.runtime_job_results
.iter()
.any(|record| record.job_id != basis.pass_id)
|| records
.archived_worker_attempts
.iter()
.any(|record| record.job_id != basis.pass_id)
|| records
.reorientation_decisions
.iter()
.any(|record| record.job_id != basis.pass_id)
|| records
.reorientation_failures
.iter()
.any(|record| record.job_id != basis.pass_id)
{
return Err(anyhow!(
"decision audit terminal worker record does not belong to its reasoning pass"
));
}
for record in &records.archived_worker_attempts {
let fulfilled = crate::WorkerProcessStatus::parse(&record.terminal_process_status)?
.is_fulfilled_terminal();
record.validate_decision_record(fulfilled)?;
}
if records.persona_stage_receipts.iter().any(|record| {
record.request_id != basis.pass_id || record.reasoning_basis_id != basis.basis_id
}) || records
.persona_effect_documents
.iter()
.any(|record| record.interpreter_request_id != basis.pass_id)
{
return Err(anyhow!(
"decision audit Persona record does not belong to its reasoning pass"
));
}
for terminal in &records.persona_terminal_receipts {
let index = terminal
.decision_context_ids
.iter()
.position(|candidate| candidate == context_id)
.ok_or_else(|| anyhow!("decision audit Persona terminal lost its context"))?;
let receipt_id = terminal
.stage_receipt_ids
.get(index)
.ok_or_else(|| anyhow!("decision audit Persona terminal lost its stage receipt"))?;
if !records
.persona_stage_receipts
.iter()
.any(|record| &record.receipt_id == receipt_id)
{
return Err(anyhow!(
"decision audit Persona terminal does not bind the exact stage receipt"
));
}
}
for conversation in &records.persona_conversation_receipts {
if !records
.persona_effect_documents
.iter()
.any(|effect| effect.document_id == conversation.effect_document_id)
{
return Err(anyhow!(
"decision audit Persona conversation lost its exact effect document"
));
}
}
Ok(())
}
pub fn worker_reasoning_basis(
store_path: &Path,
launch: &EpiphanyRuntimeWorkerLaunchRequest,
@ -1880,6 +2151,74 @@ mod tests {
)?,
EpiphanyMindCommitOutcome::Committed(_)
));
let before_unterminal_audit = backing.pull_all()?;
assert!(audit_decision_context(&store, &context.context_id).is_err());
assert_eq!(backing.pull_all()?, before_unterminal_audit);
let terminal_result = crate::EpiphanyRuntimeJobResult {
schema_version: crate::RUNTIME_SPINE_SCHEMA_VERSION.into(),
result_id: "worker-result-1".into(),
job_id: "pass-1".into(),
session_id: "session-1".into(),
role: "Modeling".into(),
verdict: "completed".into(),
summary: "Structured Modeling decision".into(),
completed_at: "2026-08-14T00:00:03Z".into(),
next_safe_move: "Inspect the durable decision context".into(),
evidence_refs: Vec::new(),
artifact_refs: Vec::new(),
metadata: Default::default(),
decision_context_id: Some(context.context_id.clone()),
};
runtime_spine_cache(&store)?.put(&terminal_result.result_id, &terminal_result)?;
let before_audit = backing.pull_all()?;
let audit = audit_decision_context(&store, &context.context_id)?;
assert_eq!(audit.context_id, context.context_id);
assert_eq!(audit.reasoning_basis, basis);
assert_eq!(audit.terminal_native_request.request_id, "request-1");
assert_eq!(audit.terminal_provider_request.request_id, "request-1");
assert_eq!(
audit.terminal_records.runtime_job_results,
vec![terminal_result.clone()]
);
assert_eq!(audit.mind_commit_receipts.len(), 2);
assert!(!audit.transcript_required);
assert_eq!(backing.pull_all()?, before_audit);
let mut archive_cache = runtime_spine_cache(&store)?;
archive_cache.pull_all_backing_stores()?;
assert!(
archive_cache.delete::<crate::EpiphanyRuntimeJobResult>(&terminal_result.result_id)?
);
let archived = crate::EpiphanyArchivedRuntimeWorkerAttempt {
schema_version: crate::ARCHIVED_RUNTIME_WORKER_ATTEMPT_SCHEMA_VERSION.into(),
archive_id: "pass-1".into(),
job_id: "pass-1".into(),
request_kind: "proposal-modeling".into(),
request_id: "proposal-request-1".into(),
terminal_process_status: "terminal-failure".into(),
archived_at: "2026-08-14T00:00:04Z".into(),
retired_type_counts: Default::default(),
retired_envelope_count: 1,
retired_chain_digest: "sha256:historical-family".into(),
decision: Some(crate::EpiphanyArchivedRuntimeWorkerDecision {
decision_context_id: context.context_id.clone(),
role_result: None,
job_results: vec![terminal_result],
}),
};
archive_cache.put(&archived.archive_id, &archived)?;
let before_archived_audit = backing.pull_all()?;
let archived_audit = audit_decision_context(&store, &context.context_id)?;
assert!(
archived_audit
.terminal_records
.runtime_job_results
.is_empty()
);
assert_eq!(
archived_audit.terminal_records.archived_worker_attempts,
vec![archived]
);
assert_eq!(backing.pull_all()?, before_archived_audit);
let current = backing
.pull_all()?
.into_iter()

View file

@ -150,7 +150,7 @@ pub const ARCHIVED_RUNTIME_SESSION_TYPE: &str = "epiphany.runtime.archived_sessi
pub const RUNTIME_WORKER_LAUNCH_REQUEST_TYPE: &str = "epiphany.runtime.worker_launch_request";
pub const RUNTIME_WORKER_PROCESS_CLAIM_TYPE: &str = "epiphany.runtime.worker_process_claim.v0";
pub const ARCHIVED_RUNTIME_WORKER_ATTEMPT_TYPE: &str =
"epiphany.runtime.archived_worker_attempt.v0";
"epiphany.runtime.archived_worker_attempt.v1";
pub const RUNTIME_ROLE_WORKER_RESULT_TYPE: &str = "epiphany.runtime.role_worker_result";
pub const RUNTIME_REORIENT_WORKER_RESULT_TYPE: &str = "epiphany.runtime.reorient_worker_result";
pub const RUNTIME_JOB_RESULT_TYPE: &str = "epiphany.runtime.job_result";
@ -173,7 +173,7 @@ pub const TOOL_INVOCATION_RECEIPT_TYPE: &str = "epiphany.tool_invocation_receipt
pub const RUNTIME_IDENTITY_KEY: &str = "self";
pub const RUNTIME_SWARM_BINDING_KEY: &str = "runtime-swarm-binding";
pub const RUNTIME_SWARM_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.swarm_binding.v0";
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v1";
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v2";
pub const EPIPHANY_RUNTIME_ROOT_SESSION_ID: &str = "epiphany-main";
pub const RUNTIME_MODEL_EXECUTION_BINDING_SCHEMA_VERSION: &str =
"epiphany.runtime.model_execution_binding.v0";
@ -185,7 +185,7 @@ pub const RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION: &str =
pub const RUNTIME_WORKER_PROCESS_CLAIM_SCHEMA_VERSION: &str =
"epiphany.runtime.worker_process_claim.v0";
pub const ARCHIVED_RUNTIME_WORKER_ATTEMPT_SCHEMA_VERSION: &str =
"epiphany.runtime.archived_worker_attempt.v0";
"epiphany.runtime.archived_worker_attempt.v1";
pub const RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION: &str =
"epiphany.runtime.role_worker_result.v4";
pub const RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION: &str =
@ -480,9 +480,9 @@ pub struct EpiphanyRuntimeWorkerProcessClaim {
pub terminal_authority_id: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "epiphany.runtime.archived_worker_attempt.v0",
type = "epiphany.runtime.archived_worker_attempt.v1",
schema = "EpiphanyArchivedRuntimeWorkerAttempt"
)]
pub struct EpiphanyArchivedRuntimeWorkerAttempt {
@ -498,18 +498,77 @@ pub struct EpiphanyArchivedRuntimeWorkerAttempt {
pub request_id: String,
#[cultcache(key = 5)]
pub terminal_process_status: String,
#[cultcache(key = 6, default)]
pub result_id: Option<String>,
#[cultcache(key = 7)]
#[cultcache(key = 6)]
pub archived_at: String,
#[cultcache(key = 8)]
#[cultcache(key = 7)]
pub retired_type_counts: BTreeMap<String, u64>,
#[cultcache(key = 9)]
#[cultcache(key = 8)]
pub retired_envelope_count: u64,
#[cultcache(key = 10)]
#[cultcache(key = 9)]
pub retired_chain_digest: String,
#[cultcache(key = 11, default)]
pub decision_context_id: Option<String>,
#[cultcache(key = 10)]
pub decision: Option<EpiphanyArchivedRuntimeWorkerDecision>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct EpiphanyArchivedRuntimeWorkerDecision {
pub decision_context_id: String,
pub role_result: Option<EpiphanyRuntimeRoleWorkerResult>,
pub job_results: Vec<EpiphanyRuntimeJobResult>,
}
impl EpiphanyArchivedRuntimeWorkerAttempt {
pub fn decision_context_id(&self) -> Option<&str> {
self.decision
.as_ref()
.map(|decision| decision.decision_context_id.as_str())
}
pub fn fulfilled_result_id(&self) -> Option<&str> {
self.decision
.as_ref()
.and_then(|decision| decision.role_result.as_ref())
.map(|result| result.result_id.as_str())
}
pub(crate) fn validate_decision_record(&self, fulfilled: bool) -> Result<()> {
let Some(decision) = &self.decision else {
if fulfilled {
return Err(anyhow!(
"fulfilled worker archive lost its structured decision"
));
}
return Ok(());
};
validate_non_empty(
&decision.decision_context_id,
"archived worker decision context id",
)?;
if decision.job_results.is_empty()
|| decision.job_results.iter().any(|result| {
result.job_id != self.job_id
|| result.decision_context_id.as_deref()
!= Some(decision.decision_context_id.as_str())
})
{
return Err(anyhow!(
"archived worker decision lost its exact generic result family"
));
}
match &decision.role_result {
Some(result)
if fulfilled
&& result.job_id == self.job_id
&& result.decision_context_id == decision.decision_context_id =>
{
Ok(())
}
None if !fulfilled => Ok(()),
_ => Err(anyhow!(
"archived worker decision terminal result shape is invalid"
)),
}
}
}
fn worker_process_claim_id(job_id: &str) -> String {
@ -5456,7 +5515,9 @@ pub fn runtime_typed_request_fulfillment(
let archived_matches = cache
.get_all::<EpiphanyArchivedRuntimeWorkerAttempt>()?
.into_iter()
.filter(|attempt| attempt.request_id == request_id && attempt.result_id.is_some())
.filter(|attempt| {
attempt.request_id == request_id && attempt.fulfilled_result_id().is_some()
})
.collect::<Vec<_>>();
if archived_matches.len() > 1 {
return Err(anyhow!(
@ -5473,6 +5534,17 @@ pub fn runtime_typed_request_fulfillment(
{
return Err(anyhow!("archived typed fulfillment tombstone is invalid"));
}
attempt.validate_decision_record(true)?;
let archived_role_result = attempt
.decision
.as_ref()
.and_then(|decision| decision.role_result.as_ref())
.ok_or_else(|| anyhow!("archived typed fulfillment lost its structured result"))?;
if !request.matches_result(archived_role_result) {
return Err(anyhow!(
"archived typed fulfillment substituted its structured result"
));
}
if cache
.get::<EpiphanyRuntimeWorkerLaunchRequest>(&attempt.job_id)?
.is_some()
@ -5492,8 +5564,8 @@ pub fn runtime_typed_request_fulfillment(
return Ok(Some(RuntimeTypedFulfillmentEvidence {
job_id: attempt.job_id.clone(),
result_id: attempt
.result_id
.clone()
.fulfilled_result_id()
.map(str::to_string)
.expect("validated archived result"),
request_id: request_id.to_string(),
}));
@ -8327,9 +8399,14 @@ fn repo_frontier_research_request_is_covered(
let exact_archived = archived.as_ref().is_some_and(|attempt| {
attempt.request_kind == "frontier-research"
&& attempt.request_id == request.request_id
&& attempt.result_id.as_deref() == Some(packet.source_result_id.as_str())
&& attempt.decision_context_id.as_deref()
== Some(packet.decision_context_id.as_str())
&& attempt.fulfilled_result_id() == Some(packet.source_result_id.as_str())
&& attempt.decision_context_id() == Some(packet.decision_context_id.as_str())
&& attempt.decision.as_ref().is_some_and(|decision| {
decision.role_result.as_ref().is_some_and(|result| {
result.repo_frontier_research_request_id.as_deref()
== Some(request.request_id.as_str())
})
})
});
if exact_live || exact_archived {
return Ok(true);
@ -11152,11 +11229,11 @@ where
if existing.schema_version != ARCHIVED_RUNTIME_WORKER_ATTEMPT_SCHEMA_VERSION
|| existing.archive_id != job_id
|| existing.job_id != job_id
|| existing.result_id.is_some() != fulfilled
|| !existing.retired_chain_digest.starts_with("sha256:")
{
return Err(anyhow!("archived worker attempt tombstone is invalid"));
}
existing.validate_decision_record(fulfilled)?;
if cache
.get::<EpiphanyRuntimeWorkerLaunchRequest>(job_id)?
.is_some()
@ -11224,7 +11301,7 @@ where
"worker attempt archive requires matching terminal runtime job"
));
}
let archived_result_id = if fulfilled {
if fulfilled {
let request_ref = match request_kind {
"proposal-modeling" => RuntimeTypedRequestRef::ProposalModeling(request_id),
"frontier-verdict-modeling" => {
@ -11267,10 +11344,7 @@ where
"proposal Modeling attempt remains live until Mind admission owns its result"
));
}
Some(evidence.result_id)
} else {
None
};
}
let snapshot = cache.snapshot_envelopes();
let proposal_bindings = cache
.get_all::<RepoFrontierProposalModelingLaunchBinding>()?
@ -11293,9 +11367,9 @@ where
.iter()
.map(|item| item.result_id.clone())
.collect::<BTreeSet<_>>();
let role_decision_context_id = cache
.get::<EpiphanyRuntimeRoleWorkerResult>(job_id)?
.map(|result| result.decision_context_id);
let role_decision_context_id = role_result
.as_ref()
.map(|result| result.decision_context_id.clone());
let mut decision_context_ids = worker_job_results
.iter()
.filter_map(|result| result.decision_context_id.clone())
@ -11315,6 +11389,13 @@ where
if let Some(context_id) = decision_context_id.as_deref() {
require_worker_decision_context(&cache, context_id, job_id)?;
}
let mut archived_job_results = worker_job_results.clone();
archived_job_results.sort_by(|left, right| left.result_id.cmp(&right.result_id));
let decision = decision_context_id.map(|context_id| EpiphanyArchivedRuntimeWorkerDecision {
decision_context_id: context_id,
role_result: role_result.clone(),
job_results: archived_job_results,
});
let events = cache
.get_all::<EpiphanyRuntimeEvent>()?
.into_iter()
@ -11375,13 +11456,13 @@ where
request_kind: request_kind.into(),
request_id: request_id.into(),
terminal_process_status: claim.status,
result_id: archived_result_id,
archived_at: archived_at.into(),
retired_type_counts: counts,
retired_envelope_count: deletions.len() as u64,
retired_chain_digest: format!("sha256:{:x}", digest.finalize()),
decision_context_id,
decision,
};
tombstone.validate_decision_record(fulfilled)?;
let replacement = cache.prepare_entry(job_id, &tombstone)?.0;
before_commit()?;
if !runtime_spine_backing_store(store_path)?.replace_and_delete_if_snapshot_unchanged(
@ -13881,6 +13962,38 @@ pub(crate) mod tests {
.is_err()
);
assert_eq!(runtime_spine_backing_store(&store)?.pull_all()?, before);
let archive_v0_store = temp.path().join("archive-v0-runtime.cc");
let mut archive_v0 = CultCache::new();
archive_v0.register_entry_type::<crate::EpiphanyMindIdentity>()?;
archive_v0.register_entry_type::<EpiphanyRuntimeIdentity>()?;
archive_v0.add_generic_backing_store(runtime_spine_backing_store(&archive_v0_store)?);
archive_v0.put(
crate::MIND_SCHEMA_EPOCH,
&crate::EpiphanyMindIdentity {
schema_epoch: crate::MIND_SCHEMA_EPOCH.into(),
runtime_id: "archive-v0-runtime".into(),
},
)?;
archive_v0.put(
RUNTIME_IDENTITY_KEY,
&EpiphanyRuntimeIdentity {
schema_version: "epiphany.runtime_spine.v1".into(),
runtime_id: "archive-v0-runtime".into(),
display_name: "Archive v0 runtime".into(),
runtime_kind: "epiphany.native".into(),
created_at: "2026-08-18T00:00:00Z".into(),
updated_at: "2026-08-18T00:00:00Z".into(),
supported_document_types: Vec::new(),
metadata: BTreeMap::new(),
},
)?;
let archive_v0_before = runtime_spine_backing_store(&archive_v0_store)?.pull_all()?;
assert!(runtime_spine_cache(&archive_v0_store).is_err());
assert_eq!(
runtime_spine_backing_store(&archive_v0_store)?.pull_all()?,
archive_v0_before
);
Ok(())
}
}

View file

@ -118,6 +118,54 @@ async fn main() -> Result<()> {
"privateStateExposed": false
}))?;
}
"audit-decision" => {
let mut store = PathBuf::from(DEFAULT_STORE);
let mut context_id = None;
let mut output = None;
let mut args = args.peekable();
while let Some(arg) = args.next() {
match arg.as_str() {
"--store" => {
store = PathBuf::from(
args.next()
.context("audit-decision missing --store value")?,
)
}
"--context-id" => {
context_id = Some(
args.next()
.context("audit-decision missing --context-id value")?,
)
}
"--output" => {
output = Some(PathBuf::from(
args.next()
.context("audit-decision missing --output value")?,
))
}
other => return Err(anyhow!("unknown audit-decision argument: {other}")),
}
}
let context_id = context_id.context("audit-decision requires --context-id")?;
let audit = epiphany_core::audit_decision_context(&store, &context_id)?;
if let Some(path) = output {
if let Some(parent) = path.parent() {
fs::create_dir_all(parent)
.with_context(|| format!("failed to create {}", parent.display()))?;
}
fs::write(&path, serde_json::to_vec_pretty(&audit)?)
.with_context(|| format!("failed to write {}", path.display()))?;
print_json(&json!({
"schemaVersion": "epiphany.decision_audit_written.v1",
"contextId": audit.context_id,
"output": path,
"transcriptRequired": false,
"privateStateExposed": false,
}))?;
} else {
print_json(&audit)?;
}
}
"model-turn" => {
let options = parse_model_turn_options(args.collect())?;
require_supported_provider(&options.provider)?;
@ -2088,5 +2136,5 @@ fn now() -> String {
}
fn usage() -> &'static str {
"usage: epiphany-model-runtime <model-turn|run-worker|tool-followup|tool-followup-turn|smoke> [--provider openai-codex] [--store path] [--codex-home path] [--request path] [--request-id id] [--followup-request-id id] [--output path] [--session-id id] [--job-id id] [--activation-token-sha256 hex] [--objective text] [--default-model model] [--output-last-message path] [--auto-tools --tool-adapter-bin path --mcp-config path --cwd path --max-tool-rounds n]"
"usage: epiphany-model-runtime <audit-decision|model-turn|run-worker|tool-followup|tool-followup-turn|smoke> [--provider openai-codex] [--store path] [--codex-home path] [--request path] [--request-id id] [--context-id id] [--followup-request-id id] [--output path] [--session-id id] [--job-id id] [--activation-token-sha256 hex] [--objective text] [--default-model model] [--output-last-message path] [--auto-tools --tool-adapter-bin path --mcp-config path --cwd path --max-tool-rounds n]"
}