Add typed coordinator run receipts

This commit is contained in:
Meta Vens 2026-05-27 22:45:38 +01:00
commit 7e31584678
8 changed files with 272 additions and 10 deletions

View file

@ -2,15 +2,20 @@ use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
use chrono::SecondsFormat;
use epiphany_core::COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION;
use epiphany_core::COORDINATOR_RUN_RECEIPT_TYPE;
use epiphany_core::EpiphanyCoordinatorRunReceipt;
use epiphany_core::RuntimeSpineEventOptions;
use epiphany_core::RuntimeSpineInitOptions;
use epiphany_core::RuntimeSpineSessionOptions;
use epiphany_core::append_runtime_event;
use epiphany_core::create_runtime_session;
use epiphany_core::initialize_runtime_spine;
use epiphany_core::put_coordinator_run_receipt;
use epiphany_core::runtime_spine_status;
use serde_json::Value;
use serde_json::json;
use std::collections::BTreeMap;
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
@ -472,6 +477,53 @@ fn run_coordinator(args: &Args) -> Result<Value> {
let runtime_status = runtime_spine_status(&runtime_store)?;
let final_rendered = status_cli::render_status(&operator_final_status);
let operator_steps = status_cli::sanitize_for_operator(Value::Array(steps));
let artifact_manifest = vec![
"coordinator-summary.json".to_string(),
"coordinator-steps.jsonl".to_string(),
"coordinator-final-status.json".to_string(),
"coordinator-final-status.txt".to_string(),
"coordinator-final-action.txt".to_string(),
"agent-function-telemetry.json".to_string(),
"runtime-spine-status.json".to_string(),
];
let sealed_artifact_manifest = vec![
"epiphany-transcript.jsonl".to_string(),
"epiphany-server.stderr.log".to_string(),
];
let receipt_created_at = now();
let coordinator_run_receipt = EpiphanyCoordinatorRunReceipt {
schema_version: COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION.to_string(),
receipt_id: format!(
"coordinator-run-{}-{}",
sanitize_id(&thread_id),
chrono::Utc::now().timestamp_millis()
),
session_id: runtime_session_id.clone(),
thread_id: thread_id.clone(),
mode: args.mode.clone(),
status: coordinator_receipt_status(&args.mode, &final_action),
final_action: final_action_name(&final_action),
final_reason: final_action_reason(&final_action),
step_count: operator_steps
.as_array()
.map_or(0, |items| items.len() as u64),
created_at: receipt_created_at,
model_provider: Some(args.model_provider.clone()),
runtime_store: runtime_store.display().to_string(),
artifact_refs: artifact_manifest.clone(),
sealed_artifact_refs: sealed_artifact_manifest.clone(),
metadata: BTreeMap::from([
(
"artifactDir".to_string(),
artifact_dir.display().to_string(),
),
(
"modelRuntimeBin".to_string(),
model_runtime_bin.display().to_string(),
),
]),
};
put_coordinator_run_receipt(&runtime_store, &coordinator_run_receipt)?;
let summary = json!({
"objective": "Coordinate the Epiphany MVP lanes over existing app-server APIs.",
"artifactDir": artifact_dir,
@ -488,15 +540,12 @@ fn run_coordinator(args: &Args) -> Result<Value> {
"snapshots": snapshots,
"finalAction": status_cli::sanitize_for_operator(final_action),
"finalStatus": operator_final_status,
"artifactManifest": [
"coordinator-summary.json",
"coordinator-steps.jsonl",
"coordinator-final-status.json",
"coordinator-final-status.txt",
"coordinator-final-action.txt",
"agent-function-telemetry.json",
"runtime-spine-status.json"
],
"coordinatorRunReceipt": {
"documentType": COORDINATOR_RUN_RECEIPT_TYPE,
"receiptId": coordinator_run_receipt.receipt_id,
"store": runtime_store,
},
"artifactManifest": artifact_manifest,
"sealedArtifactManifest": [
{"path": "epiphany-transcript.jsonl", "reason": "sealed JSON-RPC audit trail; do not read during normal supervision"},
{"path": "epiphany-server.stderr.log", "reason": "sealed app-server diagnostics; inspect only for explicit debugging"}
@ -885,6 +934,34 @@ fn first_string_at(value: &Value, paths: &[&[&str]]) -> Option<String> {
None
}
fn coordinator_receipt_status(mode: &str, final_action: &Value) -> String {
if mode == "plan" {
return "planned".to_string();
}
if final_action_name(final_action) == "regatherManually" {
"needsReview".to_string()
} else {
"completed".to_string()
}
}
fn final_action_name(final_action: &Value) -> String {
final_action
.get("action")
.and_then(Value::as_str)
.filter(|action| !action.trim().is_empty())
.unwrap_or("unknown")
.to_string()
}
fn final_action_reason(final_action: &Value) -> Option<String> {
final_action
.get("reason")
.and_then(Value::as_str)
.filter(|reason| !reason.trim().is_empty())
.map(ToString::to_string)
}
fn sanitize_id(value: &str) -> String {
value
.chars()

View file

@ -334,6 +334,9 @@ pub use retrieval::index_workspace;
pub use retrieval::normalize_epiphany_retrieve_query;
pub use retrieval::retrieval_state_for_workspace;
pub use retrieval::retrieve_workspace;
pub use runtime_spine::COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION;
pub use runtime_spine::COORDINATOR_RUN_RECEIPT_TYPE;
pub use runtime_spine::EpiphanyCoordinatorRunReceipt;
pub use runtime_spine::EpiphanyJobInterruptRequest;
pub use runtime_spine::EpiphanyJobInterruptResult;
pub use runtime_spine::EpiphanyJobLaunchRequest;
@ -380,6 +383,7 @@ pub use runtime_spine::ensure_runtime_session;
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_runtime_reorient_worker_result;
pub use runtime_spine::put_runtime_role_worker_result;
pub use runtime_spine::replace_or_append_epiphany_job_binding;

View file

@ -98,6 +98,7 @@ pub const RUNTIME_ROLE_WORKER_RESULT_TYPE: &str = "epiphany.runtime.role_worker_
pub const RUNTIME_REORIENT_WORKER_RESULT_TYPE: &str = "epiphany.runtime.reorient_worker_result";
pub const RUNTIME_JOB_RESULT_TYPE: &str = "epiphany.runtime.job_result";
pub const RUNTIME_EVENT_TYPE: &str = "epiphany.runtime.event";
pub const COORDINATOR_RUN_RECEIPT_TYPE: &str = "epiphany.coordinator_run_receipt.v0";
pub const OPENAI_ADAPTER_STATUS_TYPE: &str = "epiphany.openai_adapter_status.v0";
pub const OPENAI_MODEL_REQUEST_TYPE: &str = "epiphany.openai_model_request.v0";
pub const OPENAI_MODEL_STREAM_EVENT_TYPE: &str = "epiphany.openai_model_stream_event.v0";
@ -131,6 +132,7 @@ pub const RUNTIME_ROLE_WORKER_RESULT_SCHEMA_VERSION: &str =
"epiphany.runtime.role_worker_result.v0";
pub const RUNTIME_REORIENT_WORKER_RESULT_SCHEMA_VERSION: &str =
"epiphany.runtime.reorient_worker_result.v0";
pub const COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION: &str = "epiphany.coordinator_run_receipt.v0";
pub const OPENAI_ADAPTER_STATUS_SCHEMA_VERSION: &str = "epiphany.openai_adapter_status.v0";
pub const OPENAI_MODEL_REQUEST_SCHEMA_VERSION: &str = "epiphany.openai_model_request.v0";
pub const OPENAI_MODEL_STREAM_EVENT_SCHEMA_VERSION: &str = "epiphany.openai_model_stream_event.v0";
@ -450,6 +452,44 @@ pub struct EpiphanyRuntimeEvent {
pub metadata: BTreeMap<String, String>,
}
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
#[cultcache(
type = "epiphany.coordinator_run_receipt.v0",
schema = "EpiphanyCoordinatorRunReceipt"
)]
pub struct EpiphanyCoordinatorRunReceipt {
#[cultcache(key = 0)]
pub schema_version: String,
#[cultcache(key = 1)]
pub receipt_id: String,
#[cultcache(key = 2)]
pub session_id: String,
#[cultcache(key = 3)]
pub thread_id: String,
#[cultcache(key = 4)]
pub mode: String,
#[cultcache(key = 5)]
pub status: String,
#[cultcache(key = 6)]
pub final_action: String,
#[cultcache(key = 7, default)]
pub final_reason: Option<String>,
#[cultcache(key = 8)]
pub step_count: u64,
#[cultcache(key = 9)]
pub created_at: String,
#[cultcache(key = 10, default)]
pub model_provider: Option<String>,
#[cultcache(key = 11, default)]
pub runtime_store: String,
#[cultcache(key = 12, default)]
pub artifact_refs: Vec<String>,
#[cultcache(key = 13, default)]
pub sealed_artifact_refs: Vec<String>,
#[cultcache(key = 14, default)]
pub metadata: BTreeMap<String, String>,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum EpiphanyRuntimeSessionStatus {
@ -635,6 +675,7 @@ pub fn runtime_spine_cache(store_path: impl AsRef<Path>) -> Result<CultCache> {
cache.register_entry_type::<EpiphanyRuntimeReorientWorkerResult>()?;
cache.register_entry_type::<EpiphanyRuntimeJobResult>()?;
cache.register_entry_type::<EpiphanyRuntimeEvent>()?;
cache.register_entry_type::<EpiphanyCoordinatorRunReceipt>()?;
cache.register_entry_type::<EpiphanyOpenAiAdapterStatus>()?;
cache.register_entry_type::<EpiphanyOpenAiModelRequest>()?;
cache.register_entry_type::<EpiphanyOpenAiStreamEvent>()?;
@ -1043,6 +1084,27 @@ pub fn runtime_reorient_worker_result(
cache.get::<EpiphanyRuntimeReorientWorkerResult>(job_id)
}
pub fn put_coordinator_run_receipt(
store_path: impl AsRef<Path>,
receipt: &EpiphanyCoordinatorRunReceipt,
) -> Result<()> {
validate_non_empty(&receipt.receipt_id, "coordinator run receipt id")?;
validate_non_empty(&receipt.session_id, "coordinator run receipt session id")?;
validate_non_empty(&receipt.thread_id, "coordinator run receipt thread id")?;
validate_non_empty(&receipt.mode, "coordinator run receipt mode")?;
validate_non_empty(&receipt.status, "coordinator run receipt status")?;
validate_non_empty(
&receipt.final_action,
"coordinator run receipt final action",
)?;
validate_non_empty(&receipt.created_at, "coordinator run receipt created at")?;
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 complete_runtime_job(
store_path: impl AsRef<Path>,
options: RuntimeSpineJobResultOptions,
@ -2046,6 +2108,17 @@ fn epiphany_mutation_contracts() -> Vec<CultNetDocumentMutationContract> {
vec![],
vec!["Runtime events are append-only projections for inspection."],
),
mutation_contract(
COORDINATOR_RUN_RECEIPT_TYPE,
COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION,
vec![CultNetDocumentOperation::ReceiptWatch],
CultNetMutationAuthority::Coordinator,
vec![],
vec![],
vec![
"Coordinator run receipts are typed summaries of local plan/run decisions; artifact JSON is display evidence, not the only durable account.",
],
),
mutation_contract(
MODEL_ADAPTER_STATUS_TYPE,
MODEL_ADAPTER_STATUS_SCHEMA_VERSION,
@ -2648,6 +2721,26 @@ mod tests {
summary: "Session started.".to_string(),
},
)?;
put_coordinator_run_receipt(
&store,
&EpiphanyCoordinatorRunReceipt {
schema_version: COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION.to_string(),
receipt_id: "coordinator-receipt-1".to_string(),
session_id: "session-1".to_string(),
thread_id: "thread-1".to_string(),
mode: "plan".to_string(),
status: "planned".to_string(),
final_action: "launchModeling".to_string(),
final_reason: Some("Modeling should run.".to_string()),
step_count: 1,
created_at: "2026-05-06T00:03:00Z".to_string(),
model_provider: Some("openai-codex".to_string()),
runtime_store: store.display().to_string(),
artifact_refs: vec!["coordinator-summary.json".to_string()],
sealed_artifact_refs: vec!["epiphany-transcript.jsonl".to_string()],
metadata: BTreeMap::new(),
},
)?;
let status = runtime_spine_status(&store)?;
assert!(status.present);
@ -2655,6 +2748,13 @@ mod tests {
assert_eq!(status.sessions, 1);
assert_eq!(status.active_sessions, 1);
assert_eq!(status.events, 1);
let mut cache = runtime_spine_cache(&store)?;
cache.pull_all_backing_stores()?;
assert!(
cache
.get::<EpiphanyCoordinatorRunReceipt>("coordinator-receipt-1")?
.is_some()
);
Ok(())
}
@ -3079,6 +3179,19 @@ mod tests {
.iter()
.all(|contract| contract.document_type != "epiphany.surface.unity_bridge")
);
let coordinator_run_receipt_contract = contracts
.iter()
.find(|contract| contract.document_type == COORDINATOR_RUN_RECEIPT_TYPE)
.expect("coordinator run receipt should advertise typed receipt contract");
assert_eq!(
coordinator_run_receipt_contract.authority,
CultNetMutationAuthority::Coordinator
);
assert!(
coordinator_run_receipt_contract
.operations
.contains(&CultNetDocumentOperation::ReceiptWatch)
);
let birth_contract = contracts
.iter()
.find(|contract| contract.document_type == SURFACE_REPO_BIRTH_RUNNER_TYPE)
@ -3170,6 +3283,10 @@ mod tests {
schema.document_type.as_deref() == Some("epiphany.swarm_control_receipt.v0")
&& schema.schema_version.as_deref() == Some("epiphany.swarm_control_receipt.v0")
}));
assert!(schemas.iter().any(|schema| {
schema.document_type.as_deref() == Some(COORDINATOR_RUN_RECEIPT_TYPE)
&& schema.schema_version.as_deref() == Some(COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION)
}));
assert!(schemas.iter().any(|schema| {
schema.document_type.as_deref() == Some(MODEL_REQUEST_TYPE)
&& schema.schema_version.as_deref() == Some(MODEL_REQUEST_SCHEMA_VERSION)

View file

@ -38,6 +38,7 @@ remembers doctrine; the branch remembers the blade.
- Status-mode local runs now also write a native CultMesh operator snapshot to `.epiphany-run/cultmesh/operator-snapshots.ccmp` through `epiphany-operator-snapshot`. That snapshot distills the operator-safe MVP status artifact into typed fields such as thread id, state status, coordinator action, CRRC action, reorient action, available actions, and artifact refs; it does not preserve the raw JSON status blob as internal state.
- `epiphany-mvp-status --source native` is the current provider-neutral status boundary. It projects scene, pressure, jobs, roles, planning, reorient, CRRC, and coordinator status from native core surfaces and returns provider/runtime worker results as `backendMissing` placeholders instead of asking Codex for model-worker state. Keep future pluggable model-provider work behind launch/result/runtime documents; do not let provider choice leak into status, prompt authority, scheduler policy, or durable `EpiphanyThreadState`.
- `epiphany-model-runtime` is the current provider-neutral executable boundary. It is built by the `epiphany-openai-runtime` crate for now and accepts `--provider openai-codex`; the old `epiphany-openai-runtime` binary, `--openai-runtime-bin`, and `openai-runtime` executor name survive only as compatibility aliases. Coordinator run mode, local wrapper run mode, and repo birth runner should call `--model-runtime-bin` plus `--model-provider`. The typed request/event/receipt contract is now provider-neutral in `epiphany-model-adapter` as `epiphany.model_request.v0`, `epiphany.model_stream_event.v0`, `epiphany.model_receipt.v0`, and `epiphany.model_adapter_status.v0`; OpenAI/Codex documents are adapter evidence behind that boundary, not scheduler/status/state authority.
- Coordinator plan/run passes now emit `epiphany.coordinator_run_receipt.v0` into runtime-spine. `coordinator-summary.json` and `coordinator-steps.jsonl` remain useful operator artifacts, but the durable receipt of what the coordinator decided is typed CultCache/CultNet state.
- The active foundation directive is now `notes/codex-starvation-and-cultnet-liberation-plan.md`. The previous Codex app-server control-plane rebuild made Epiphany less rotten inside Codex, but that is not the destination. Epiphany must become a native CultCache/CultMesh/CultNet runtime while remaining an honest modified Codex-derived backend for subscription auth/model use. Codex should remain relatively vanilla and keep doing Codex things, including useful app-server and streaming bridge affordances, but it must not own Epiphany state, processes, prompts, scheduler decisions, or policy. The bridge handles interop; Codex and Epiphany do not get to rummage around in each other's organs.
- `notes/epiphany-cultmesh-dreaming-roadmap.md` is the new concrete design for distributed Epiphany dreaming. The invariant is hard: private state stays local; public dreams are separately authored typed documents distributed through CultMesh/CultNet; foreign dreams are thought weather until a reviewed local adoption receipt digests them. The first code slice should be dream schemas plus a local CultMesh-backed store, not public fanout.
- CultMesh is now the preferred Rust abstraction for that local store work. The compile-time Rust substrate is repo-contained: `vendor/cultcache-rs`, `vendor/cultnet-rs`, and `vendor/cultmesh-rs`. The old `E:\Projects\CultLib\crates\*` dependency body is dead in this checkout and must not be revived by accident. Vendored CultCache reads/writes `cultcache.store.v1`, so `state/ledgers.msgpack` and `epiphany-state status` are aligned again. The first integrations are deliberately small: status, Verse policy, global room policy, organ contract policy, native operator status, native operator snapshots, and local operator run intent/receipt round-trip through CultMesh. Use `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-cultmesh-smoke`, `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-cultmesh-status -- smoke --store .\.epiphany-smoke\cultmesh\operator-status.ccmp --runtime-id epiphany-cultmesh-status-smoke`, `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-operator-snapshot -- smoke --store .\.epiphany-smoke\cultmesh\operator-snapshots.ccmp --runtime-id epiphany-operator-snapshot-smoke --snapshot-id smoke-status`, and `cargo run --manifest-path .\epiphany-core\Cargo.toml --bin epiphany-operator-run -- smoke --store .\.epiphany-smoke\cultmesh\operator-runs.ccmp --runtime-id epiphany-operator-run-smoke --run-id smoke-run` for the focused proofs. Future local dream/status/Verse work should start from CultMesh, not raw CultNet, unless the task is polishing the CultMesh internals themselves. Preserve the three Verse tiers: `epiphany-internal` for private sub-agent typed state, `gamecult-local` for trusted LAN/Yggdrasil-tunnel GameCult sharing, and `epiphany-global` for untrusted public dreams plus topic-specific threaded public rooms for Face posts.

View file

@ -0,0 +1,45 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://gamecult.dev/epiphany/cultnet/epiphany.coordinator-run-receipt.schema.json",
"title": "Epiphany Coordinator Run Receipt",
"description": "Typed receipt emitted by the local coordinator after a plan/run/smoke pass. Artifact JSON may display the same facts, but this document is the durable coordinator decision receipt.",
"type": "object",
"required": [
"schema_version",
"receipt_id",
"session_id",
"thread_id",
"mode",
"status",
"final_action",
"step_count",
"created_at"
],
"properties": {
"schema_version": { "const": "epiphany.coordinator_run_receipt.v0" },
"receipt_id": { "type": "string" },
"session_id": { "type": "string" },
"thread_id": { "type": "string" },
"mode": { "enum": ["plan", "run", "smoke", "status"] },
"status": { "type": "string" },
"final_action": { "type": "string" },
"final_reason": { "type": ["string", "null"] },
"step_count": { "type": "integer", "minimum": 0 },
"created_at": { "type": "string" },
"model_provider": { "type": ["string", "null"] },
"runtime_store": { "type": "string" },
"artifact_refs": {
"type": "array",
"items": { "type": "string" }
},
"sealed_artifact_refs": {
"type": "array",
"items": { "type": "string" }
},
"metadata": {
"type": "object",
"additionalProperties": { "type": "string" }
}
},
"additionalProperties": false
}

View file

@ -56,6 +56,17 @@
"title": "Epiphany Runtime Event",
"path": "epiphany.runtime.event.schema.json"
},
{
"schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.coordinator-run-receipt.schema.json",
"kind": "document_payload",
"wireContracts": [
"cultnet.schema.v0"
],
"schemaVersion": "epiphany.coordinator_run_receipt.v0",
"documentType": "epiphany.coordinator_run_receipt.v0",
"title": "Epiphany Coordinator Run Receipt",
"path": "epiphany.coordinator-run-receipt.schema.json"
},
{
"schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.model-adapter-status.schema.json",
"kind": "document_payload",

Binary file not shown.

View file

@ -525,4 +525,11 @@ current_status:
but model turns and worker launches now enter through provider-neutral
requests, store provider-neutral events/receipts, and mirror OpenAI docs
only as transport proof.
next_action: Continue Codex starvation and CultNet liberation by moving coordinator plan/run outputs into typed CultNet receipts, then make the next provider adapter implement the `epiphany.model_*` contract without teaching scheduler/status/state surfaces provider-specific law.
Coordinator plan/run output now has a typed receipt too:
`epiphany.coordinator_run_receipt.v0` is registered in runtime-spine,
advertised in the CultNet schema catalog, and written by
`epiphany-mvp-coordinator` at the end of plan/run/smoke passes. The
existing coordinator artifact JSON remains operator display and sealed
audit evidence, but it is no longer the only durable account of what the
coordinator decided.
next_action: Continue Codex starvation and CultNet liberation by wrapping remaining unavoidable JSON protocol edges, especially MCP/tool execution, in typed Epiphany intent/result/receipt documents before letting them influence scheduler, state, or acceptance authority.