Bind tool executions to runtime ownership

This commit is contained in:
Meta Vens 2026-08-10 01:18:23 +01:00
commit f565ad6a73
9 changed files with 641 additions and 39 deletions

View file

@ -985,6 +985,7 @@ pub use runtime_spine::EpiphanyRuntimeJobResult;
pub use runtime_spine::EpiphanyRuntimeJobSnapshot;
pub use runtime_spine::EpiphanyRuntimeJobStatus;
pub use runtime_spine::EpiphanyRuntimeModelExecutionBinding;
pub use runtime_spine::EpiphanyRuntimeToolExecutionBinding;
pub use runtime_spine::EpiphanyRuntimeReorientWorkerResult;
pub use runtime_spine::EpiphanyRuntimeRoleWorkerResult;
pub use runtime_spine::EpiphanyRuntimeSession;
@ -1001,6 +1002,8 @@ pub use runtime_spine::RUNTIME_JOB_RESULT_TYPE;
pub use runtime_spine::RUNTIME_JOB_TYPE;
pub use runtime_spine::RUNTIME_MODEL_EXECUTION_BINDING_SCHEMA_VERSION;
pub use runtime_spine::RUNTIME_MODEL_EXECUTION_BINDING_TYPE;
pub use runtime_spine::RUNTIME_TOOL_EXECUTION_BINDING_SCHEMA_VERSION;
pub use runtime_spine::RUNTIME_TOOL_EXECUTION_BINDING_TYPE;
pub use runtime_spine::RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION;
pub use runtime_spine::RUNTIME_REORIENT_WORKER_RESULT_TYPE;
pub use runtime_spine::RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION;
@ -1073,11 +1076,14 @@ pub use runtime_spine::put_repo_frontier_work_proposal;
pub use runtime_spine::put_runtime_reorient_worker_result;
pub use runtime_spine::put_runtime_role_worker_result;
pub use runtime_spine::open_runtime_model_execution;
pub use runtime_spine::put_runtime_tool_execution_intent;
pub use runtime_spine::put_runtime_tool_execution_receipt;
pub use runtime_spine::put_soul_verdict_receipt;
pub use runtime_spine::put_substrate_gate_repo_access_grant_receipt;
pub use runtime_spine::relinquish_repo_frontier_hands_route;
pub use runtime_spine::replace_or_append_epiphany_job_binding;
pub use runtime_spine::runtime_continuity_recovery_receipt;
pub use runtime_spine::require_runtime_tool_execution_binding;
pub use runtime_spine::runtime_current_repo_model;
pub use runtime_spine::runtime_eyes_evidence_packet;
pub use runtime_spine::runtime_hands_action_intent;

View file

@ -145,6 +145,8 @@ use epiphany_state_model::EpiphanyThreadState;
use epiphany_tool_adapter::EpiphanyToolCapability;
use epiphany_tool_adapter::EpiphanyToolInvocationIntent;
use epiphany_tool_adapter::EpiphanyToolInvocationReceipt;
use epiphany_tool_adapter::tool_invocation_intent_key;
use epiphany_tool_adapter::tool_invocation_receipt_key;
use serde::Deserialize;
use serde::Serialize;
use sha2::Digest;
@ -160,6 +162,8 @@ pub const RUNTIME_SESSION_TYPE: &str = "epiphany.runtime.session";
pub const RUNTIME_JOB_TYPE: &str = "epiphany.runtime.job";
pub const RUNTIME_MODEL_EXECUTION_BINDING_TYPE: &str =
"epiphany.runtime.model_execution_binding";
pub const RUNTIME_TOOL_EXECUTION_BINDING_TYPE: &str =
"epiphany.runtime.tool_execution_binding";
pub const RUNTIME_WORKER_LAUNCH_REQUEST_TYPE: &str = "epiphany.runtime.worker_launch_request";
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";
@ -187,6 +191,8 @@ pub const RUNTIME_SWARM_BINDING_SCHEMA_VERSION: &str = "epiphany.runtime.swarm_b
pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v0";
pub const RUNTIME_MODEL_EXECUTION_BINDING_SCHEMA_VERSION: &str =
"epiphany.runtime.model_execution_binding.v0";
pub const RUNTIME_TOOL_EXECUTION_BINDING_SCHEMA_VERSION: &str =
"epiphany.runtime.tool_execution_binding.v0";
pub const RUNTIME_WORKER_LAUNCH_REQUEST_SCHEMA_VERSION: &str =
"epiphany.runtime.worker_launch_request.v1";
pub const RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION: &str =
@ -343,6 +349,28 @@ pub struct EpiphanyRuntimeModelExecutionBinding {
pub bound_at: String,
}
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
#[cultcache(
type = "epiphany.runtime.tool_execution_binding",
schema = "EpiphanyRuntimeToolExecutionBinding"
)]
pub struct EpiphanyRuntimeToolExecutionBinding {
#[cultcache(key = 0)]
pub schema_version: String,
#[cultcache(key = 1)]
pub binding_id: String,
#[cultcache(key = 2)]
pub intent_id: String,
#[cultcache(key = 3)]
pub session_id: String,
#[cultcache(key = 4)]
pub job_id: String,
#[cultcache(key = 5, default)]
pub model_request_id: Option<String>,
#[cultcache(key = 6)]
pub bound_at: String,
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "epiphany.runtime.worker_launch_request",
@ -976,6 +1004,7 @@ pub fn runtime_spine_cache(store_path: impl AsRef<Path>) -> Result<CultCache> {
cache.register_entry_type::<EpiphanyRuntimeSession>()?;
cache.register_entry_type::<EpiphanyRuntimeJob>()?;
cache.register_entry_type::<EpiphanyRuntimeModelExecutionBinding>()?;
cache.register_entry_type::<EpiphanyRuntimeToolExecutionBinding>()?;
cache.register_entry_type::<EpiphanyRuntimeWorkerLaunchRequest>()?;
cache.register_entry_type::<EpiphanyRuntimeRoleWorkerResult>()?;
cache.register_entry_type::<crate::EpiphanyMemoryGraphEntry>()?;
@ -1570,6 +1599,258 @@ pub fn open_runtime_model_execution(
Ok(binding)
}
pub fn put_runtime_tool_execution_intent(
store_path: impl AsRef<Path>,
session_id: &str,
job_id: &str,
intent: &EpiphanyToolInvocationIntent,
bound_at: &str,
) -> Result<EpiphanyRuntimeToolExecutionBinding> {
validate_non_empty(session_id, "tool execution session id")?;
validate_non_empty(job_id, "tool execution job id")?;
validate_non_empty(&intent.intent_id, "tool execution intent id")?;
validate_non_empty(&intent.adapter, "tool execution adapter")?;
validate_non_empty(&intent.server, "tool execution server")?;
validate_non_empty(&intent.tool_name, "tool execution tool name")?;
chrono::DateTime::parse_from_rfc3339(bound_at)
.map_err(|error| anyhow!("tool execution binding time is invalid: {error}"))?;
let store_path = store_path.as_ref();
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
let session = cache
.get::<EpiphanyRuntimeSession>(session_id)?
.ok_or_else(|| anyhow!("tool execution session {session_id:?} does not exist"))?;
if matches!(
session.status,
EpiphanyRuntimeSessionStatus::Completed | EpiphanyRuntimeSessionStatus::Archived
) {
return Err(anyhow!("tool execution session {session_id:?} is terminal"));
}
let job = cache
.get::<EpiphanyRuntimeJob>(job_id)?
.ok_or_else(|| anyhow!("tool execution job {job_id:?} does not exist"))?;
if job.session_id != session_id
|| matches!(
job.status,
EpiphanyRuntimeJobStatus::Completed
| EpiphanyRuntimeJobStatus::Failed
| EpiphanyRuntimeJobStatus::Cancelled
)
{
return Err(anyhow!(
"tool execution job {job_id:?} is foreign or terminal"
));
}
if cache
.get::<EpiphanyRuntimeToolExecutionBinding>(&intent.intent_id)?
.is_some()
|| cache
.get::<EpiphanyToolInvocationIntent>(&tool_invocation_intent_key(&intent.intent_id))?
.is_some()
|| cache
.get::<EpiphanyToolInvocationReceipt>(&tool_invocation_receipt_key(&intent.intent_id))?
.is_some()
{
return Err(anyhow!(
"tool execution intent {:?} already exists",
intent.intent_id
));
}
let identity_envelope = cache
.get_envelope::<EpiphanyRuntimeIdentity>(RUNTIME_IDENTITY_KEY)?
.ok_or_else(|| anyhow!("tool execution lost runtime identity envelope"))?;
let session_envelope = cache
.get_envelope::<EpiphanyRuntimeSession>(session_id)?
.ok_or_else(|| anyhow!("tool execution lost session envelope"))?;
let job_envelope = cache
.get_envelope::<EpiphanyRuntimeJob>(job_id)?
.ok_or_else(|| anyhow!("tool execution lost job envelope"))?;
let mut expected = vec![
identity_envelope.clone(),
session_envelope.clone(),
job_envelope.clone(),
];
let mut replacements = expected.clone();
if let Some(model_request_id) = intent.model_request_id.as_deref() {
let model_binding = cache
.get::<EpiphanyRuntimeModelExecutionBinding>(model_request_id)?
.ok_or_else(|| {
anyhow!(
"model-derived tool intent {:?} has no execution binding",
intent.intent_id
)
})?;
if model_binding.request_id != model_request_id
|| model_binding.session_id != session_id
|| model_binding.job_id != job_id
{
return Err(anyhow!(
"model-derived tool intent {:?} has foreign execution ownership",
intent.intent_id
));
}
for envelope in [
cache
.get_envelope::<EpiphanyRuntimeModelExecutionBinding>(model_request_id)?,
cache.get_envelope::<EpiphanyModelRequest>(model_request_id)?,
cache.get_envelope::<EpiphanyOpenAiModelRequest>(model_request_id)?,
] {
let envelope = envelope.ok_or_else(|| {
anyhow!(
"model-derived tool intent {:?} lost its model execution family",
intent.intent_id
)
})?;
expected.push(envelope.clone());
replacements.push(envelope);
}
}
let binding = EpiphanyRuntimeToolExecutionBinding {
schema_version: RUNTIME_TOOL_EXECUTION_BINDING_SCHEMA_VERSION.to_string(),
binding_id: intent.intent_id.clone(),
intent_id: intent.intent_id.clone(),
session_id: session_id.to_string(),
job_id: job_id.to_string(),
model_request_id: intent.model_request_id.clone(),
bound_at: bound_at.to_string(),
};
replacements.push(cache.prepare_entry(&binding.binding_id, &binding)?.0);
replacements.push(
cache
.prepare_entry(&tool_invocation_intent_key(&intent.intent_id), intent)?
.0,
);
if !runtime_spine_backing_store(store_path)?
.compare_and_swap_batch(&expected, replacements)?
{
return Err(anyhow!(
"tool execution intent publication lost its ownership fence"
));
}
Ok(binding)
}
pub fn require_runtime_tool_execution_binding(
store_path: impl AsRef<Path>,
intent_id: &str,
) -> Result<EpiphanyRuntimeToolExecutionBinding> {
validate_non_empty(intent_id, "tool execution intent id")?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
let binding = cache
.get::<EpiphanyRuntimeToolExecutionBinding>(intent_id)?
.ok_or_else(|| anyhow!("tool execution intent {intent_id:?} is unbound"))?;
if binding.schema_version != RUNTIME_TOOL_EXECUTION_BINDING_SCHEMA_VERSION
|| binding.binding_id != intent_id
|| binding.intent_id != intent_id
|| chrono::DateTime::parse_from_rfc3339(&binding.bound_at).is_err()
{
return Err(anyhow!(
"tool execution intent {intent_id:?} has an invalid binding"
));
}
let intent = cache
.get::<EpiphanyToolInvocationIntent>(&tool_invocation_intent_key(intent_id))?
.ok_or_else(|| anyhow!("tool execution binding {intent_id:?} lost its intent"))?;
if intent.intent_id != intent_id || intent.model_request_id != binding.model_request_id {
return Err(anyhow!(
"tool execution binding {intent_id:?} disagrees with its intent"
));
}
let session = cache
.get::<EpiphanyRuntimeSession>(&binding.session_id)?
.ok_or_else(|| anyhow!("tool execution binding {intent_id:?} lost its session"))?;
let job = cache
.get::<EpiphanyRuntimeJob>(&binding.job_id)?
.ok_or_else(|| anyhow!("tool execution binding {intent_id:?} lost its job"))?;
if session.status == EpiphanyRuntimeSessionStatus::Archived
|| job.session_id != binding.session_id
{
return Err(anyhow!(
"tool execution binding {intent_id:?} has foreign or archived ownership"
));
}
if let Some(model_request_id) = binding.model_request_id.as_deref() {
let model_binding = cache
.get::<EpiphanyRuntimeModelExecutionBinding>(model_request_id)?
.ok_or_else(|| anyhow!("tool execution binding lost its model execution"))?;
if model_binding.session_id != binding.session_id
|| model_binding.job_id != binding.job_id
|| model_binding.request_id != model_request_id
{
return Err(anyhow!(
"tool execution binding {intent_id:?} has foreign model ownership"
));
}
}
Ok(binding)
}
pub fn put_runtime_tool_execution_receipt(
store_path: impl AsRef<Path>,
receipt: &EpiphanyToolInvocationReceipt,
) -> Result<()> {
validate_non_empty(&receipt.receipt_id, "tool execution receipt id")?;
validate_non_empty(&receipt.intent_id, "tool execution receipt intent id")?;
validate_non_empty(&receipt.status, "tool execution receipt status")?;
validate_non_empty(&receipt.completed_at, "tool execution receipt completion time")?;
if !matches!(receipt.status.as_str(), "completed" | "failed") {
return Err(anyhow!("tool execution receipt status is not terminal"));
}
let store_path = store_path.as_ref();
let binding = require_runtime_tool_execution_binding(store_path, &receipt.intent_id)?;
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let intent = cache
.get::<EpiphanyToolInvocationIntent>(&tool_invocation_intent_key(
&receipt.intent_id,
))?
.ok_or_else(|| anyhow!("tool execution receipt lost its intent"))?;
if receipt.adapter != intent.adapter
|| receipt.server != intent.server
|| receipt.tool_name != intent.tool_name
{
return Err(anyhow!(
"tool execution receipt disagrees with its immutable intent"
));
}
let receipt_key = tool_invocation_receipt_key(&receipt.intent_id);
if cache
.get::<EpiphanyToolInvocationReceipt>(&receipt_key)?
.is_some()
{
return Err(anyhow!(
"tool execution intent {:?} already has a receipt",
receipt.intent_id
));
}
let binding_envelope = cache
.get_envelope::<EpiphanyRuntimeToolExecutionBinding>(&binding.binding_id)?
.ok_or_else(|| anyhow!("tool execution receipt lost its binding envelope"))?;
let intent_envelope = cache
.get_envelope::<EpiphanyToolInvocationIntent>(&tool_invocation_intent_key(
&receipt.intent_id,
))?
.ok_or_else(|| anyhow!("tool execution receipt lost its intent envelope"))?;
if !runtime_spine_backing_store(store_path)?.compare_and_swap_batch(
&[binding_envelope.clone(), intent_envelope.clone()],
vec![
binding_envelope,
intent_envelope,
cache.prepare_entry(&receipt_key, receipt)?.0,
],
)? {
return Err(anyhow!(
"tool execution receipt publication lost its ownership fence"
));
}
Ok(())
}
pub fn plan_runtime_spine_heartbeat_launch(
state: &EpiphanyThreadState,
options: RuntimeSpineHeartbeatLaunchPlanOptions,
@ -10179,6 +10460,18 @@ fn epiphany_mutation_contracts() -> Vec<CultNetDocumentMutationContract> {
"Retention must reject unbound model rows rather than infer ownership from request names or conversation ids.",
],
),
mutation_contract(
RUNTIME_TOOL_EXECUTION_BINDING_TYPE,
RUNTIME_TOOL_EXECUTION_BINDING_SCHEMA_VERSION,
vec![CultNetDocumentOperation::Snapshot],
CultNetMutationAuthority::ReadOnly,
vec![],
vec![],
vec![
"Runtime spine atomically binds a tool intent to its session and job before the tool runtime may execute it.",
"Model-derived tool intents must inherit the exact owning model execution; direct intents require explicit runtime ownership.",
],
),
mutation_contract(
MODEL_ADAPTER_STATUS_TYPE,
MODEL_ADAPTER_STATUS_SCHEMA_VERSION,
@ -14667,6 +14960,171 @@ pub(crate) mod tests {
Ok(())
}
#[test]
fn runtime_tool_execution_binding_owns_model_and_direct_intents() -> 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-08-10T02:00:00Z".to_string(),
},
)?;
let session_options = RuntimeSpineSessionOptions {
session_id: "session-tools".to_string(),
objective: "Own tool execution membership.".to_string(),
created_at: "2026-08-10T02:00:01Z".to_string(),
coordinator_note: "test".to_string(),
};
let model_job_options = RuntimeSpineJobOptions {
job_id: "job-tools".to_string(),
session_id: "session-tools".to_string(),
role: "openai-model-adapter".to_string(),
created_at: "2026-08-10T02:00:02Z".to_string(),
summary: "Bound model tool execution.".to_string(),
artifact_refs: Vec::new(),
};
let model_request = EpiphanyModelRequest::new(
"request-tools",
"conversation-tools",
"openai-codex",
"gpt-test",
"Call one tool.",
);
let provider_request = EpiphanyOpenAiModelRequest::new(
"request-tools",
"conversation-tools",
"gpt-test",
"Call one tool.",
);
open_runtime_model_execution(
&store,
session_options.clone(),
model_job_options,
&model_request,
&provider_request,
"2026-08-10T02:00:03Z",
)?;
let model_intent = EpiphanyToolInvocationIntent::new(
"intent-model-tool",
"epiphany-tool-runtime",
"source",
"read",
"{}",
"model-runtime",
"Read source.",
"2026-08-10T02:00:04Z",
)
.with_model_call("call-1", "request-tools");
let model_binding = put_runtime_tool_execution_intent(
&store,
"session-tools",
"job-tools",
&model_intent,
"2026-08-10T02:00:04Z",
)?;
assert_eq!(
require_runtime_tool_execution_binding(&store, "intent-model-tool")?,
model_binding
);
let hostile_intent = EpiphanyToolInvocationIntent::new(
"intent-hostile",
"epiphany-tool-runtime",
"source",
"read",
"{}",
"model-runtime",
"Read foreign source.",
"2026-08-10T02:00:05Z",
)
.with_model_call("call-2", "request-missing");
assert!(put_runtime_tool_execution_intent(
&store,
"session-tools",
"job-tools",
&hostile_intent,
"2026-08-10T02:00:05Z",
)
.is_err());
let mut cache = runtime_spine_cache(&store)?;
cache.pull_all_backing_stores()?;
assert!(cache
.get::<EpiphanyRuntimeToolExecutionBinding>("intent-hostile")?
.is_none());
assert!(cache
.get::<EpiphanyToolInvocationIntent>(&tool_invocation_intent_key(
"intent-hostile"
))?
.is_none());
create_runtime_job(
&store,
RuntimeSpineJobOptions {
job_id: "job-direct-tool".to_string(),
session_id: "session-tools".to_string(),
role: "tool-runtime".to_string(),
created_at: "2026-08-10T02:00:06Z".to_string(),
summary: "Direct tool execution.".to_string(),
artifact_refs: Vec::new(),
},
)?;
let direct_intent = EpiphanyToolInvocationIntent::new(
"intent-direct-tool",
"epiphany-tool-runtime",
"source",
"read",
"{}",
"operator",
"Read source directly.",
"2026-08-10T02:00:07Z",
);
let direct_binding = put_runtime_tool_execution_intent(
&store,
"session-tools",
"job-direct-tool",
&direct_intent,
"2026-08-10T02:00:07Z",
)?;
assert_eq!(direct_binding.model_request_id, None);
assert_eq!(
require_runtime_tool_execution_binding(&store, "intent-direct-tool")?,
direct_binding
);
let receipt = EpiphanyToolInvocationReceipt::new(
"receipt-direct-tool",
"intent-direct-tool",
"epiphany-tool-runtime",
"source",
"read",
"completed",
"unix-ms:1",
);
put_runtime_tool_execution_receipt(&store, &receipt)?;
assert!(put_runtime_tool_execution_receipt(&store, &receipt).is_err());
let hostile_receipt = EpiphanyToolInvocationReceipt::new(
"receipt-hostile",
"intent-model-tool",
"epiphany-tool-runtime",
"foreign",
"read",
"completed",
"unix-ms:2",
);
assert!(put_runtime_tool_execution_receipt(&store, &hostile_receipt).is_err());
let mut cache = runtime_spine_cache(&store)?;
cache.pull_all_backing_stores()?;
assert!(cache
.get::<EpiphanyToolInvocationReceipt>(&tool_invocation_receipt_key(
"intent-model-tool"
))?
.is_none());
assert!(require_runtime_tool_execution_binding(&store, "unbound").is_err());
Ok(())
}
#[test]
fn runtime_spine_opens_and_completes_native_jobs() -> Result<()> {
let temp = tempdir()?;

View file

@ -7,11 +7,10 @@ use anyhow::Result;
use chrono::SecondsFormat;
use epiphany_core::append_runtime_event;
use epiphany_core::complete_runtime_job;
use epiphany_core::create_runtime_job;
use epiphany_core::ensure_runtime_session;
use epiphany_core::initialize_runtime_spine;
use epiphany_core::put_runtime_reorient_worker_result;
use epiphany_core::put_runtime_role_worker_result;
use epiphany_core::put_runtime_tool_execution_intent;
use epiphany_core::open_runtime_model_execution;
use epiphany_core::runtime_spine_cache;
use epiphany_core::runtime_spine_status;
@ -41,7 +40,6 @@ pub use epiphany_openai_codex_spine::default_codex_home;
use epiphany_openai_codex_spine::status_from_auth_manager;
use epiphany_openai_codex_spine::EpiphanyCodexOpenAiTransport;
use epiphany_openai_codex_spine::EpiphanyResponsesFrameObservation;
use epiphany_tool_adapter::tool_invocation_intent_key;
use epiphany_tool_adapter::tool_invocation_receipt_key;
use epiphany_tool_adapter::EpiphanyToolInvocationIntent;
use epiphany_tool_adapter::EpiphanyToolInvocationReceipt;
@ -365,18 +363,23 @@ pub fn record_openai_events(
) -> Result<EpiphanyOpenAiRuntimeRunSummary> {
let store_path = store_path.as_ref();
let events = compact_openai_events_for_storage(events);
let tool_intents = tool_invocation_intents_from_openai_events(DEFAULT_MODEL_PROVIDER, &events);
for intent in &tool_intents {
put_runtime_tool_execution_intent(
store_path,
&options.session_id,
&options.job_id,
intent,
&now(),
)?;
}
let mut receipt = None;
let mut failure = None;
{
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
let model_request = model_request_from_openai_request(DEFAULT_MODEL_PROVIDER, request);
cache.put(model_request_key(&model_request.request_id), &model_request)?;
for event in &events {
let model_event = model_event_from_openai_event(DEFAULT_MODEL_PROVIDER, event);
if let Some(intent) = tool_invocation_intent_from_model_event(&model_event) {
cache.put(tool_invocation_intent_key(&intent.intent_id), &intent)?;
}
cache.put(
model_event_key(&model_event.request_id, model_event.sequence),
&model_event,
@ -465,13 +468,10 @@ pub fn record_openai_events(
summary,
result_id,
receipt_id: receipt.map(|item| openai_receipt_key(&item.request_id)),
tool_intent_ids: tool_invocation_intents_from_openai_events(
DEFAULT_MODEL_PROVIDER,
&events,
)
.into_iter()
.map(|intent| intent.intent_id)
.collect(),
tool_intent_ids: tool_intents
.into_iter()
.map(|intent| intent.intent_id)
.collect(),
})
}
@ -2452,7 +2452,7 @@ mod tests {
);
let options = default_options(store.clone(), PathBuf::from(".codex"), &request);
ensure_openai_runtime_ready(&options)?;
ensure_runtime_session(
open_runtime_model_execution(
&store,
RuntimeSpineSessionOptions {
session_id: options.session_id.clone(),
@ -2460,9 +2460,6 @@ mod tests {
created_at: now(),
coordinator_note: options.coordinator_note.clone(),
},
)?;
create_runtime_job(
&store,
RuntimeSpineJobOptions {
job_id: options.job_id.clone(),
session_id: options.session_id.clone(),
@ -2471,8 +2468,10 @@ mod tests {
summary: "test job".to_string(),
artifact_refs: Vec::new(),
},
&model_request_from_openai_request(DEFAULT_MODEL_PROVIDER, &request),
&request,
&now(),
)?;
store_openai_request(&store, &request)?;
let mut receipt = EpiphanyOpenAiModelReceipt::new("req-1", "gpt-5.4");
receipt.response_id = Some("resp-1".to_string());
receipt.transport = Some("test".to_string());
@ -2858,7 +2857,7 @@ mod tests {
Some(r#"{"type":"object","required":["statePatch"]}"#.to_string());
let options = default_options(store.clone(), PathBuf::from(".codex"), &request);
ensure_openai_runtime_ready(&options)?;
ensure_runtime_session(
open_runtime_model_execution(
&store,
RuntimeSpineSessionOptions {
session_id: options.session_id.clone(),
@ -2866,9 +2865,6 @@ mod tests {
created_at: now(),
coordinator_note: options.coordinator_note.clone(),
},
)?;
create_runtime_job(
&store,
RuntimeSpineJobOptions {
job_id: options.job_id.clone(),
session_id: options.session_id.clone(),
@ -2877,6 +2873,9 @@ mod tests {
summary: "tool test job".to_string(),
artifact_refs: Vec::new(),
},
&model_request_from_openai_request(DEFAULT_MODEL_PROVIDER, &request),
&request,
&now(),
)?;
let mut receipt = EpiphanyOpenAiModelReceipt::new("req-tools", "gpt-5.4");
receipt.response_id = Some("resp-tools".to_string());
@ -2907,6 +2906,13 @@ mod tests {
.clone();
let mut cache = runtime_spine_cache(&store)?;
cache.pull_all_backing_stores()?;
let tool_binding = epiphany_core::require_runtime_tool_execution_binding(
&store,
&intent_id,
)?;
assert_eq!(tool_binding.session_id, options.session_id);
assert_eq!(tool_binding.job_id, options.job_id);
assert_eq!(tool_binding.model_request_id.as_deref(), Some("req-tools"));
let mut tool_receipt = EpiphanyToolInvocationReceipt::new(
"receipt-tool",
intent_id.clone(),
@ -2917,10 +2923,8 @@ mod tests {
now(),
);
tool_receipt.result_json = Some(r#"{"ok":true}"#.to_string());
cache.put(
tool_invocation_receipt_key(&tool_receipt.intent_id),
&tool_receipt,
)?;
drop(cache);
epiphany_core::put_runtime_tool_execution_receipt(&store, &tool_receipt)?;
let followup =
build_tool_followup_model_request(&store, "req-tools", "req-tools-followup")?;

View file

@ -55,7 +55,7 @@ impl Cli {
}
async fn run(options: RunOptions) -> Result<RunSummary> {
let mut cache = open_store(&options.store)?;
let cache = open_store(&options.store)?;
let intent = cache
.get_required::<EpiphanyToolInvocationIntent>(&tool_invocation_intent_key(
&options.intent_id,
@ -64,9 +64,11 @@ async fn run(options: RunOptions) -> Result<RunSummary> {
if intent.intent_id != options.intent_id {
return Err(anyhow!("loaded intent identity mismatch"));
}
epiphany_core::require_runtime_tool_execution_binding(&options.store, &intent.intent_id)
.with_context(|| format!("validating tool intent ownership {:?}", intent.intent_id))?;
let receipt = execute_to_receipt(&intent, &options).await;
cache.put(tool_invocation_receipt_key(&intent.intent_id), &receipt)?;
epiphany_core::put_runtime_tool_execution_receipt(&options.store, &receipt)?;
Ok(RunSummary {
adapter: EPIPHANY_TOOL_RUNTIME_ADAPTER_ID.into(),
store: options.store.display().to_string(),
@ -294,8 +296,33 @@ mod tests {
"prove provider-independent native tools",
"now",
);
let mut cache = open_store(&store)?;
cache.put(tool_invocation_intent_key(&intent.intent_id), &intent)?;
epiphany_core::create_runtime_session(
&store,
epiphany_core::RuntimeSpineSessionOptions {
session_id: "native-tool-session".into(),
objective: "Prove owned native tool execution.".into(),
created_at: "2026-08-10T01:00:01Z".into(),
coordinator_note: "test".into(),
},
)?;
epiphany_core::create_runtime_job(
&store,
epiphany_core::RuntimeSpineJobOptions {
job_id: "native-tool-job".into(),
session_id: "native-tool-session".into(),
role: "tool-runtime".into(),
created_at: "2026-08-10T01:00:02Z".into(),
summary: "Owned native tool execution.".into(),
artifact_refs: Vec::new(),
},
)?;
epiphany_core::put_runtime_tool_execution_intent(
&store,
"native-tool-session",
"native-tool-job",
&intent,
"2026-08-10T01:00:03Z",
)?;
let summary = run(RunOptions {
store: store.clone(),
@ -314,4 +341,50 @@ mod tests {
assert!(receipt.result_json.as_deref().unwrap().contains("awake"));
Ok(())
}
#[tokio::test]
async fn unbound_intent_is_refused_before_tool_execution() -> Result<()> {
let temp = tempfile::tempdir()?;
let store = temp.path().join("runtime.cc");
epiphany_core::initialize_runtime_spine(
&store,
epiphany_core::RuntimeSpineInitOptions {
runtime_id: "unbound-tool-test".into(),
display_name: "Unbound Tool Test".into(),
created_at: "now".into(),
},
)?;
let intent = EpiphanyToolInvocationIntent::new(
"unbound-read",
EPIPHANY_TOOL_RUNTIME_ADAPTER_ID,
"epiphany_source",
"read_file",
r#"{"path":"missing.txt"}"#,
"test",
"prove unbound refusal",
"now",
);
let mut cache = open_store(&store)?;
cache.put(tool_invocation_intent_key(&intent.intent_id), &intent)?;
let error = match run(RunOptions {
store: store.clone(),
intent_id: intent.intent_id.clone(),
mcp_config: None,
cwd: Some(temp.path().to_path_buf()),
})
.await
{
Ok(_) => panic!("unbound tool intent unexpectedly executed"),
Err(error) => error,
};
assert!(error.to_string().contains("validating tool intent ownership"));
let cache = open_store(&store)?;
assert!(cache
.get::<EpiphanyToolInvocationReceipt>(&tool_invocation_receipt_key(
&intent.intent_id
))?
.is_none());
Ok(())
}
}

View file

@ -2397,11 +2397,24 @@ request writers remain available only as unbound compatibility surfaces; their
rows are deliberately ineligible for archival. Core hostile membership tests,
the CultNet Hello/catalog tests, and all 15 OpenAI runtime library tests pass.
Tool execution ownership is the next cut. Model-derived intents can inherit
the exact model binding through `model_request_id`; direct intents need their
own explicit session/job binding. Intent publication and its execution-owner
edge must become one CAS before an archive tombstone or any broad deletion is
implemented.
Tool execution ownership now shares the same cut. Runtime spine owns
`EpiphanyRuntimeToolExecutionBinding`. One CAS publishes an intent with its
exact session/job edge; model-derived intents additionally require the exact
native/provider model execution binding and request family in the fence.
Direct intents require an explicit session/job owner. The tool runtime rejects
an unbound intent before native or MCP execution. Its terminal receipt is also
immutable: runtime spine validates adapter/server/tool identity and publishes
it under a CAS fence containing the exact binding and intent. A hostile or
duplicate receipt cannot become closure evidence. Core tests prove model,
direct, foreign, missing, hostile-receipt, and replay cases; all 15 OpenAI
runtime tests and all 10 tool-runtime tests pass without warnings.
The next archive prerequisite is retained-reference classification. Before a
session family can be deleted, source inspection must enumerate which semantic
documents resolve session job, worker result, model request, tool intent, or
receipt IDs at read time. Those readers either preserve exact execution
members or must first own a self-contained immutable evidence projection. No
generic string scan or age rule may substitute for typed references.
The coordinator receipt accumulator is implemented in source. Runtime owns the
typed head, cumulative status counts, chained digest, and full-snapshot-fenced

View file

@ -1489,3 +1489,15 @@ runtime library tests pass. No archive deletion is authorized yet. Next, give
model-derived and direct tool intents explicit execution ownership atomically;
then map retained semantic references before building the archived-session
tombstone.
Tool execution ownership is now cut too. Runtime spine owns
`EpiphanyRuntimeToolExecutionBinding`; intent plus owner edge publish atomically,
model-derived intents must inherit the exact model execution, and direct
intents require explicit session/job ownership. The tool runtime refuses
unbound intents before execution. Terminal receipts are immutable and CAS
fenced against the exact binding and intent, so a hostile/duplicate receipt
cannot supply closure. Core hostile tests, all 15 OpenAI tests, and all 10 tool
runtime tests pass warning-free. The next pass is source-grounded retained
reference classification across semantic, frontier, Hands/Soul, Persona,
memory, resident, and coordinator readers before any archived-session deletion
is implemented.

View file

@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://gamecult.dev/epiphany/cultnet/epiphany.runtime.tool-execution-binding.schema.json",
"title": "Epiphany Runtime Tool Execution Binding",
"description": "Immutable ownership edge from one tool intent to its runtime session, job, and optional model execution.",
"type": "object",
"additionalProperties": false,
"properties": {
"schemaVersion": { "type": "string", "const": "epiphany.runtime.tool_execution_binding.v0" },
"bindingId": { "type": "string", "minLength": 1 },
"intentId": { "type": "string", "minLength": 1 },
"sessionId": { "type": "string", "minLength": 1 },
"jobId": { "type": "string", "minLength": 1 },
"modelRequestId": { "type": ["string", "null"] },
"boundAt": { "type": "string", "format": "date-time" }
},
"required": [
"schemaVersion",
"bindingId",
"intentId",
"sessionId",
"jobId",
"boundAt"
]
}

View file

@ -48,6 +48,17 @@
"title": "Epiphany Runtime Model Execution Binding",
"path": "epiphany.runtime.model-execution-binding.schema.json"
},
{
"schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.runtime.tool-execution-binding.schema.json",
"kind": "document_payload",
"wireContracts": [
"cultnet.schema.v0"
],
"schemaVersion": "epiphany.runtime.tool_execution_binding.v0",
"documentType": "epiphany.runtime.tool_execution_binding",
"title": "Epiphany Runtime Tool Execution Binding",
"path": "epiphany.runtime.tool-execution-binding.schema.json"
},
{
"schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.runtime.job.schema.json",
"kind": "document_payload",

View file

@ -36,7 +36,7 @@ invariants:
current_status:
summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Exact b8138a6b active-child SIGTERM and restart, exact 9f369528 deterministic warm packaging, exact c930f505 cross-container ownership, exact ed15f83a resident lifecycle retention, and exact 16c4b19f coordinator receipt and Heartbeat artifact retention are proven. Gamecult-ops 059821f makes journald the sole Yggdrasil supervisor/projector stream-retention owner. Exact 16c4b19f genuine idle and exact a987d2f7 active cognition both completed 900-pulse bounded plateaus with clean direct-PID exits. The active run proves restart-persistent cooldown, exact-grant terminality under deliberate missing-ack and marker-regression corruption, multiple later terminal grants without resurrection, bounded artifact retention, and flat terminal resource state. Runtime-owned typed fulfillment is now accepted live: c1b461b2 falsified mutable Body/admission coupling, c9738fdb repaired the owner split, and exact 6dd9b132 packaging completed one autonomous Eyes continuation through coordinator exit, awaiting-fulfillment, one authenticated result, one planned acknowledgement, grant terminality, and clean shutdown. All 50 runtime-spine and 24 resident focused tests pass. Broad session/model/event/tool retention and stable Starfire firewall ownership remain open. Yggdrasil is the small public crossing body, never the release forge.
latest_phase: Exact 6dd9b132 runtime-owned asynchronous fulfillment remains accepted. The broad retention audit proves runtime sessions are not yet complete deletion generations: model requests lack session/job identity, tools are only optionally linked to model requests, and durable semantic documents share the physical store without becoming session exhaust. Runtime spine now owns EpiphanyRuntimeModelExecutionBinding and one atomic open_runtime_model_execution CAS publishing session, job, opened event, binding, native request, and provider request before transport. Hostile collision/foreign-shape tests prove no partial family; CultNet Hello/catalog tests and all 15 OpenAI runtime tests pass. No archive deletion exists yet.
latest_phase: Exact 6dd9b132 runtime-owned asynchronous fulfillment remains accepted. The broad retention audit proves runtime sessions are not yet complete deletion generations and semantic documents in the same store are not session exhaust. Runtime spine now owns atomic model and tool execution membership. open_runtime_model_execution publishes session/job/opened-event/binding/native/provider requests before transport. EpiphanyRuntimeToolExecutionBinding publishes each intent with exact session/job and optional model ownership; the tool runtime refuses unbound execution and publishes immutable terminal receipts through the same owner. Core hostile tests, CultNet Hello/catalog, all 15 OpenAI runtime tests, and all 10 tool-runtime tests pass. No archive deletion exists yet.
operational_state:
local_worktree: coordinator_receipt_retention_packaged_proven
operator_wireguard: restored
@ -69,7 +69,7 @@ current_status:
yggdrasil_epiphany_service_contract: repaired_in_gamecult_ops_812b427_not_installed
resident_physiology: authenticated_9b8df0b4_c005_bound_to_eyes_tools_nervous_system_with_217dd_and_bd96305e_helpers_running
unresolved_authority: Coordinator receipt, Heartbeat pulse-artifact, deployed supervisor/projector log retention, genuine-idle and active resource plateaus, exact-grant terminality, restart-persistent cooldown refusal, schedule/action issuance cardinality, and runtime-owned typed fulfillment are accepted. Broader semantic/runtime session, job, event, model, and tool histories remain unbounded pending a typed archived-session owner. Repository Body observation still performs two authenticated full-tree Git index/manifest passes. Execute-mode workers require a persistent process body. Keyed storage has not earned live migration. One Discord consequence remains blocked by the absent Yggdrasil credential.
next_action: Cut tool execution ownership before archival: model-derived intents must inherit an exact EpiphanyRuntimeModelExecutionBinding through model_request_id, while direct intents require an explicit session/job owner. Publish each intent and owner edge atomically before it can become pending; preserve legacy unbound intents as unarchivable. Then map retained semantic references and implement one typed archived-session tombstone with snapshot-fenced exact deletion. Preserve active c005 and accepted fulfillment receipts. Yggdrasil never builds.
next_action: Classify retained semantic references before archival. Enumerate every production reader that resolves session/job/worker-result/model-request/tool-intent/tool-receipt IDs from RepoModel, frontier, Hands/Soul, Persona, memory projection, resident, or coordinator state. Preserve exact referenced execution members or first replace the dependency with a self-contained immutable evidence projection. Then implement one typed archived-session tombstone with full-snapshot-fenced exact deletion and negative resurrection proof. Legacy unbound model/tool rows remain unarchivable. Preserve active c005. Yggdrasil never builds.
active_subgoals:
- Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually.