diff --git a/Cargo.toml b/Cargo.toml index 4f7c6291..899cee5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -99,7 +99,7 @@ path = "epiphany-core/src/bin/epiphany-mvp-coordinator.rs" [[bin]] name = "epiphany-model-runtime" -path = "epiphany-openai-runtime/src/bin/epiphany-model-runtime.rs" +path = "epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs" required-features = ["openai-runtime"] [[bin]] diff --git a/epiphany-core/src/reasoning_context.rs b/epiphany-core/src/reasoning_context.rs index 597001ba..b231d3ce 100644 --- a/epiphany-core/src/reasoning_context.rs +++ b/epiphany-core/src/reasoning_context.rs @@ -2330,26 +2330,12 @@ mod tests { text: "optional transcript".into(), }, }; - let provider_delta = epiphany_openai_adapter::EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.into(), - request_id: terminal_native.request_id.clone(), - sequence: 0, - payload: epiphany_openai_adapter::EpiphanyOpenAiStreamPayload::TextDelta { - text: "optional transcript".into(), - }, - }; cache = runtime_spine_cache(&store)?; cache.put("request-2:00000000", &native_delta)?; - cache.put("request-2:00000000", &provider_delta)?; assert!( cache .delete::("request-2:00000000")? ); - assert!( - cache.delete::( - "request-2:00000000" - )? - ); cache.pull_all_backing_stores()?; let retained = cache .get::(&context.context_id)? diff --git a/epiphany-core/src/runtime_spine.rs b/epiphany-core/src/runtime_spine.rs index 722137f8..885d521c 100644 --- a/epiphany-core/src/runtime_spine.rs +++ b/epiphany-core/src/runtime_spine.rs @@ -50,10 +50,7 @@ use epiphany_model_adapter::EpiphanyModelReceipt; use epiphany_model_adapter::EpiphanyModelRequest; use epiphany_model_adapter::EpiphanyModelStreamEvent; use epiphany_model_adapter::EpiphanyModelStreamPayload; -use epiphany_openai_adapter::EpiphanyOpenAiModelReceipt; use epiphany_openai_adapter::EpiphanyOpenAiModelRequest; -use epiphany_openai_adapter::EpiphanyOpenAiStreamEvent; -use epiphany_openai_adapter::EpiphanyOpenAiStreamPayload; use epiphany_tool_adapter::EpiphanyToolInvocationIntent; use epiphany_tool_adapter::EpiphanyToolInvocationReceipt; use epiphany_tool_adapter::TOOL_ADAPTER_INVOCATION_INTENT_SCHEMA_ID; @@ -85,7 +82,7 @@ pub const COORDINATOR_RUN_RECEIPT_TYPE: &str = "epiphany.coordinator_run_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.v1"; -pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v27"; +pub const RUNTIME_SPINE_SCHEMA_VERSION: &str = "epiphany.runtime_spine.v28"; 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"; @@ -860,8 +857,6 @@ fn runtime_spine_schema_cache() -> Result { cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; - cache.register_entry_type::()?; - cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; cache.register_entry_type::()?; @@ -2137,31 +2132,12 @@ fn archive_completed_model_session( ) }) .collect::>(); - let mut provider_events = cache - .get_all::()? - .into_iter() - .filter(|event| event.request_id == *request_id) - .collect::>(); - provider_events.sort_by_key(|event| event.sequence); - let provider_terminals = provider_events - .iter() - .filter(|event| { - matches!( - &event.payload, - EpiphanyOpenAiStreamPayload::Completed { .. } - | EpiphanyOpenAiStreamPayload::Failed { .. } - ) - }) - .collect::>(); if native_terminals.len() != 1 - || provider_terminals.len() != 1 || native_events.last().map(|event| event.sequence) != native_terminals.first().map(|event| event.sequence) - || provider_events.last().map(|event| event.sequence) - != provider_terminals.first().map(|event| event.sequence) { return Err(anyhow!( - "runtime session archive requires one native and provider terminal stream event" + "runtime session archive requires one terminal model stream event" )); } match &native_terminals[0].payload { @@ -2181,30 +2157,6 @@ fn archive_completed_model_session( } _ => unreachable!("terminal event filtered above"), } - match &provider_terminals[0].payload { - EpiphanyOpenAiStreamPayload::Completed { receipt } => { - if cache - .get::(request_id)? - .as_ref() - != Some(receipt) - { - return Err(anyhow!( - "runtime session archive found inconsistent provider model receipt" - )); - } - } - EpiphanyOpenAiStreamPayload::Failed { .. } => { - if cache - .get::(request_id)? - .is_some() - { - return Err(anyhow!( - "failed provider model stream retained a success receipt" - )); - } - } - _ => unreachable!("terminal event filtered above"), - } } let mut tool_bindings = cache @@ -2295,16 +2247,6 @@ fn archive_completed_model_session( format!("{}:{:08}", event.request_id, event.sequence), )); } - for event in cache - .get_all::()? - .into_iter() - .filter(|event| event.request_id == binding.request_id) - { - retired_identities.insert(( - EpiphanyOpenAiStreamEvent::TYPE.to_string(), - format!("{}:{:08}", event.request_id, event.sequence), - )); - } if cache .get::(&binding.request_id)? .is_some() @@ -2314,15 +2256,6 @@ fn archive_completed_model_session( binding.request_id.clone(), )); } - if cache - .get::(&binding.request_id)? - .is_some() - { - retired_identities.insert(( - EpiphanyOpenAiModelReceipt::TYPE.to_string(), - binding.request_id.clone(), - )); - } } for binding in &tool_bindings { retired_identities.insert(( diff --git a/epiphany-openai-adapter/src/lib.rs b/epiphany-openai-adapter/src/lib.rs index 52b7bcd3..2bb7ee0a 100644 --- a/epiphany-openai-adapter/src/lib.rs +++ b/epiphany-openai-adapter/src/lib.rs @@ -4,8 +4,6 @@ use serde::Deserialize; use serde::Serialize; pub const OPENAI_ADAPTER_REQUEST_SCHEMA_ID: &str = "epiphany.openai_model_request.v1"; -pub const OPENAI_ADAPTER_EVENT_SCHEMA_ID: &str = "epiphany.openai_model_stream_event.v0"; -pub const OPENAI_ADAPTER_RECEIPT_SCHEMA_ID: &str = "epiphany.openai_model_receipt.v0"; #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum EpiphanyOpenAiWireDialect { Responses, @@ -164,19 +162,10 @@ pub enum EpiphanyOpenAiInputItem { }, } -#[derive(Debug, Clone, PartialEq, DatabaseEntry)] -#[cultcache( - type = "epiphany.openai_model_stream_event.v0", - schema = "EpiphanyOpenAiStreamEvent" -)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct EpiphanyOpenAiStreamEvent { - #[cultcache(key = 0)] - pub schema_id: String, - #[cultcache(key = 1)] pub request_id: String, - #[cultcache(key = 2)] pub sequence: u64, - #[cultcache(key = 3)] pub payload: EpiphanyOpenAiStreamPayload, } @@ -201,34 +190,20 @@ pub enum EpiphanyOpenAiStreamPayload { }, } -#[derive(Debug, Clone, PartialEq, Eq, DatabaseEntry)] -#[cultcache( - type = "epiphany.openai_model_receipt.v0", - schema = "EpiphanyOpenAiModelReceipt" -)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct EpiphanyOpenAiModelReceipt { - #[cultcache(key = 0)] - pub schema_id: String, - #[cultcache(key = 1)] pub request_id: String, - #[cultcache(key = 2)] pub model: String, - #[cultcache(key = 3, default)] pub response_id: Option, - #[cultcache(key = 4, default)] pub input_tokens: Option, - #[cultcache(key = 5, default)] pub output_tokens: Option, - #[cultcache(key = 6, default)] pub reasoning_output_tokens: Option, - #[cultcache(key = 7, default)] pub transport: Option, } impl EpiphanyOpenAiModelReceipt { pub fn new(request_id: impl Into, model: impl Into) -> Self { Self { - schema_id: OPENAI_ADAPTER_RECEIPT_SCHEMA_ID.to_string(), request_id: request_id.into(), model: model.into(), response_id: None, diff --git a/epiphany-openai-codex-spine/src/lib.rs b/epiphany-openai-codex-spine/src/lib.rs index 7dcfee54..2c9ec7c7 100644 --- a/epiphany-openai-codex-spine/src/lib.rs +++ b/epiphany-openai-codex-spine/src/lib.rs @@ -462,7 +462,6 @@ fn push_openrouter_event( payload: EpiphanyOpenAiStreamPayload, ) { events.push(EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: request_id.to_string(), sequence: events.len() as u64, payload, @@ -1211,7 +1210,6 @@ impl EpiphanyResponsesStreamState { fn push_payload(&mut self, payload: EpiphanyOpenAiStreamPayload) { self.events.push(EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: self.request_id.clone(), sequence: self.sequence, payload, diff --git a/epiphany-openai-runtime/src/bin/epiphany-model-runtime.rs b/epiphany-openai-runtime/src/bin/epiphany-model-runtime.rs deleted file mode 100644 index 00d98da6..00000000 --- a/epiphany-openai-runtime/src/bin/epiphany-model-runtime.rs +++ /dev/null @@ -1 +0,0 @@ -include!("epiphany-openai-runtime.rs"); diff --git a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs index 475eb7ef..20ca5678 100644 --- a/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs +++ b/epiphany-openai-runtime/src/bin/epiphany-openai-runtime.rs @@ -1456,7 +1456,6 @@ mod tests { &model_request, &[ EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: request_id.to_string(), sequence: 0, payload: EpiphanyOpenAiStreamPayload::ToolCall { @@ -1466,7 +1465,6 @@ mod tests { }, }, EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: request_id.to_string(), sequence: 1, payload: EpiphanyOpenAiStreamPayload::Completed { receipt }, diff --git a/epiphany-openai-runtime/src/lib.rs b/epiphany-openai-runtime/src/lib.rs index e43ef6a0..b0f21b48 100644 --- a/epiphany-openai-runtime/src/lib.rs +++ b/epiphany-openai-runtime/src/lib.rs @@ -193,7 +193,6 @@ where match future.await { Ok(events) => events, Err(err) => vec![EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: request.request_id.clone(), sequence: 0, payload: EpiphanyOpenAiStreamPayload::Failed { @@ -368,11 +367,8 @@ fn record_openai_events( if let EpiphanyModelStreamPayload::Completed { receipt } = &model_event.payload { cache.put(model_receipt_key(&receipt.request_id), receipt)?; } - let key = openai_event_key(&event.request_id, event.sequence); - cache.put(key, event)?; match &event.payload { EpiphanyOpenAiStreamPayload::Completed { receipt: completed } => { - cache.put(openai_receipt_key(&completed.request_id), completed)?; receipt = Some(completed.clone()); } EpiphanyOpenAiStreamPayload::Failed { message } => { @@ -434,7 +430,7 @@ fn record_openai_events( verdict: verdict.to_string(), summary, result_id, - receipt_id: receipt.map(|item| openai_receipt_key(&item.request_id)), + receipt_id: receipt.map(|item| item.request_id), tool_intent_ids: tool_intents .into_iter() .map(|intent| intent.intent_id) @@ -527,7 +523,6 @@ fn push_compacted_event( payload: EpiphanyOpenAiStreamPayload, ) { compacted.push(EpiphanyOpenAiStreamEvent { - schema_id: source.schema_id.clone(), request_id: source.request_id.clone(), sequence: compacted.len() as u64, payload, @@ -1069,14 +1064,6 @@ pub fn default_options( } } -pub fn openai_event_key(request_id: &str, sequence: u64) -> String { - format!("{request_id}:{sequence:08}") -} - -pub fn openai_receipt_key(request_id: &str) -> String { - request_id.to_string() -} - pub fn model_request_key(request_id: &str) -> String { request_id.to_string() } @@ -3338,7 +3325,6 @@ mod tests { payload: EpiphanyOpenAiStreamPayload, ) -> EpiphanyOpenAiStreamEvent { EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: request_id.to_string(), sequence, payload, @@ -3404,7 +3390,7 @@ mod tests { } #[test] - fn records_typed_openai_documents_in_runtime_store() -> Result<()> { + fn records_one_native_model_stream_in_runtime_store() -> Result<()> { let temp = tempdir()?; let store = temp.path().join("runtime.msgpack"); let native_request = EpiphanyModelRequest::new( @@ -3438,7 +3424,6 @@ mod tests { receipt.response_id = Some("resp-1".to_string()); receipt.transport = Some("test".to_string()); let events = vec![EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: "req-1".to_string(), sequence: 0, payload: EpiphanyOpenAiStreamPayload::Completed { receipt }, @@ -3459,12 +3444,6 @@ mod tests { ); assert!(cache.get::("req-1")?.is_some()); assert!(cache.get::("req-1")?.is_some()); - assert!( - cache - .get::("req-1:00000000")? - .is_some() - ); - assert!(cache.get::("req-1")?.is_some()); assert_eq!( runtime_job_snapshot(&store, &options.job_id)? .expect("snapshot") @@ -3930,7 +3909,6 @@ mod tests { receipt.transport = Some("test".to_string()); let events = vec![ EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: "req-tools".to_string(), sequence: 0, payload: EpiphanyOpenAiStreamPayload::ToolCall { @@ -3940,7 +3918,6 @@ mod tests { }, }, EpiphanyOpenAiStreamEvent { - schema_id: epiphany_openai_adapter::OPENAI_ADAPTER_EVENT_SCHEMA_ID.to_string(), request_id: "req-tools".to_string(), sequence: 1, payload: EpiphanyOpenAiStreamPayload::Completed { receipt }, diff --git a/notes/codex-auth-spine-inventory.md b/notes/codex-auth-spine-inventory.md index 32565b8a..606fb4c2 100644 --- a/notes/codex-auth-spine-inventory.md +++ b/notes/codex-auth-spine-inventory.md @@ -146,27 +146,24 @@ making the pure document crate depend on Codex. The transport wrapper is now also in that spine. It maps typed `EpiphanyOpenAiModelRequest` documents into a local serializable Responses request body, resolves credentials through vendored `codex-login`, chooses the -ChatGPT/OpenAI base URL from auth mode, opens an HTTP Responses SSE stream with -`codex-client`, and converts stream deltas/completion into typed -`EpiphanyOpenAiStreamEvent` / `EpiphanyOpenAiModelReceipt` documents. It no +ChatGPT/OpenAI base URL from auth mode, opens the selected HTTP stream with +`codex-client`, and converts provider deltas/completion into transient +`EpiphanyOpenAiStreamEvent` / `EpiphanyOpenAiModelReceipt` values. It no longer imports Codex `ResponsesApiRequest`, `ResponsesClient`, `ResponseEvent`, provider config, model-provider, or broad app-server workflow. Its narrow direct imports preserve Codex-compatible auth identity without letting Codex own Epiphany request/state shape. -`schemas/cultnet/` contains publication schemas for OpenAI model request, -stream event, and terminal receipt. Live providers own their -CultMesh/CultNet catalogs. The native runtime accepts the document types -registered by the actual CultCache runtime schema; there is no standalone -hello/catalog CLI or hand-maintained mutation-contract mirror. +`schemas/cultnet/` publishes only the exact OpenAI-compatible provider request. +Provider stream values are normalized immediately into the native model event +and receipt family; they are not a second CultCache or CultNet authority. The native runtime route is the operator and daemon edge. -`epiphany-openai-adapter` documents -derive CultCache `DatabaseEntry`, `epiphany-core::runtime_spine_cache` -registers OpenAI request/stream-event/receipt documents, and the -outside-vendor `epiphany-openai-runtime` crate records typed OpenAI model-turn -requests, stream events, terminal receipts, runtime sessions, jobs, and job -results into the native runtime spine. Its `model-turn` command opens the +`epiphany-openai-adapter` keeps the provider request as a CultCache +`DatabaseEntry`; `epiphany-core::runtime_spine_cache` registers that request +beside the native request/event/receipt family. The outside-vendor +`epiphany-openai-runtime` records those native model documents, runtime +sessions, jobs, and job results into the runtime spine. Its model command opens the Codex-backed transport through the typed spine; its `smoke` command proves the CultCache route without touching the network. This is the first native caller for the advertised OpenAI CultNet contract. diff --git a/schemas/cultnet/epiphany.openai-model-receipt.schema.json b/schemas/cultnet/epiphany.openai-model-receipt.schema.json deleted file mode 100644 index 861c4a8d..00000000 --- a/schemas/cultnet/epiphany.openai-model-receipt.schema.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://gamecult.dev/epiphany/cultnet/epiphany.openai-model-receipt.schema.json", - "title": "Epiphany OpenAI Model Receipt", - "type": "object", - "required": ["schema_id", "request_id", "model"], - "properties": { - "schema_id": { "const": "epiphany.openai_model_receipt.v0" }, - "request_id": { "type": "string" }, - "model": { "type": "string" }, - "response_id": { "type": ["string", "null"] }, - "input_tokens": { "type": ["integer", "null"], "minimum": 0 }, - "output_tokens": { "type": ["integer", "null"], "minimum": 0 }, - "reasoning_output_tokens": { "type": ["integer", "null"], "minimum": 0 }, - "transport": { "type": ["string", "null"] } - }, - "additionalProperties": false -} diff --git a/schemas/cultnet/epiphany.openai-model-stream-event.schema.json b/schemas/cultnet/epiphany.openai-model-stream-event.schema.json deleted file mode 100644 index 265bab5e..00000000 --- a/schemas/cultnet/epiphany.openai-model-stream-event.schema.json +++ /dev/null @@ -1,93 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://gamecult.dev/epiphany/cultnet/epiphany.openai-model-stream-event.schema.json", - "title": "Epiphany OpenAI Model Stream Event", - "type": "object", - "required": ["schema_id", "request_id", "sequence", "payload"], - "properties": { - "schema_id": { "const": "epiphany.openai_model_stream_event.v0" }, - "request_id": { "type": "string" }, - "sequence": { "type": "integer", "minimum": 0 }, - "payload": { - "oneOf": [ - { "$ref": "#/$defs/text_delta" }, - { "$ref": "#/$defs/reasoning_delta" }, - { "$ref": "#/$defs/tool_call" }, - { "$ref": "#/$defs/completed" }, - { "$ref": "#/$defs/failed" } - ] - } - }, - "additionalProperties": false, - "$defs": { - "text_delta": { - "type": "object", - "required": ["TextDelta"], - "properties": { - "TextDelta": { - "type": "object", - "required": ["text"], - "properties": { "text": { "type": "string" } }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - "reasoning_delta": { - "type": "object", - "required": ["ReasoningDelta"], - "properties": { - "ReasoningDelta": { - "type": "object", - "required": ["text"], - "properties": { "text": { "type": "string" } }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - "tool_call": { - "type": "object", - "required": ["ToolCall"], - "properties": { - "ToolCall": { - "type": "object", - "required": ["call_id", "name", "arguments"], - "properties": { - "call_id": { "type": "string" }, - "name": { "type": "string" }, - "arguments": { "type": "string" } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - "completed": { - "type": "object", - "required": ["Completed"], - "properties": { - "Completed": { - "type": "object", - "required": ["receipt"], - "properties": { "receipt": { "$ref": "epiphany.openai-model-receipt.schema.json" } }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - "failed": { - "type": "object", - "required": ["Failed"], - "properties": { - "Failed": { - "type": "object", - "required": ["message"], - "properties": { "message": { "type": "string" } }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - } -} diff --git a/schemas/cultnet/index.json b/schemas/cultnet/index.json index c8e70ac9..e63c6e86 100644 --- a/schemas/cultnet/index.json +++ b/schemas/cultnet/index.json @@ -166,28 +166,6 @@ "title": "Epiphany OpenAI Model Request", "path": "epiphany.openai-model-request.schema.json" }, - { - "schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.openai-model-stream-event.schema.json", - "kind": "document_payload", - "wireContracts": [ - "cultnet.schema.v0" - ], - "schemaVersion": "epiphany.openai_model_stream_event.v0", - "documentType": "epiphany.openai_model_stream_event.v0", - "title": "Epiphany OpenAI Model Stream Event", - "path": "epiphany.openai-model-stream-event.schema.json" - }, - { - "schemaId": "https://gamecult.dev/epiphany/cultnet/epiphany.openai-model-receipt.schema.json", - "kind": "document_payload", - "wireContracts": [ - "cultnet.schema.v0" - ], - "schemaVersion": "epiphany.openai_model_receipt.v0", - "documentType": "epiphany.openai_model_receipt.v0", - "title": "Epiphany OpenAI Model Receipt", - "path": "epiphany.openai-model-receipt.schema.json" - }, { "schemaId": "https://gamecult.dev/cultnet/gamecult.persona_state.v0.schema.json", "kind": "document_payload",