diff --git a/epiphany-core/src/lib.rs b/epiphany-core/src/lib.rs index 227a54e1..47a16974 100644 --- a/epiphany-core/src/lib.rs +++ b/epiphany-core/src/lib.rs @@ -8,6 +8,7 @@ mod retrieval; mod rollout; mod runtime_spine; mod state_ledger; +mod state_update; mod surfaces; pub use agent_memory::AgentCanonicalTraitSeed; @@ -136,6 +137,7 @@ pub use state_ledger::append_state_evidence; pub use state_ledger::close_state_branch; pub use state_ledger::load_state_ledger; pub use state_ledger::state_ledger_status; +pub use state_update::EpiphanyStateUpdate; pub use surfaces::EpiphanyAcceptanceBundle; pub use surfaces::EpiphanyContext; pub use surfaces::EpiphanyContextMissing; diff --git a/epiphany-core/src/state_update.rs b/epiphany-core/src/state_update.rs new file mode 100644 index 00000000..2ef4486a --- /dev/null +++ b/epiphany-core/src/state_update.rs @@ -0,0 +1,59 @@ +use codex_protocol::protocol::EpiphanyAcceptanceReceipt; +use codex_protocol::protocol::EpiphanyChurnState; +use codex_protocol::protocol::EpiphanyEvidenceRecord; +use codex_protocol::protocol::EpiphanyGraphCheckpoint; +use codex_protocol::protocol::EpiphanyGraphFrontier; +use codex_protocol::protocol::EpiphanyGraphs; +use codex_protocol::protocol::EpiphanyInvariant; +use codex_protocol::protocol::EpiphanyInvestigationCheckpoint; +use codex_protocol::protocol::EpiphanyJobBinding; +use codex_protocol::protocol::EpiphanyModeState; +use codex_protocol::protocol::EpiphanyObservation; +use codex_protocol::protocol::EpiphanyPlanningState; +use codex_protocol::protocol::EpiphanyRuntimeLink; +use codex_protocol::protocol::EpiphanyScratchPad; +use codex_protocol::protocol::EpiphanySubgoal; + +#[derive(Debug, Clone, Default)] +pub struct EpiphanyStateUpdate { + pub expected_revision: Option, + pub objective: Option, + pub active_subgoal_id: Option, + pub subgoals: Option>, + pub invariants: Option>, + pub graphs: Option, + pub graph_frontier: Option, + pub graph_checkpoint: Option, + pub scratch: Option, + pub investigation_checkpoint: Option, + pub job_bindings: Option>, + pub acceptance_receipts: Vec, + pub runtime_links: Vec, + pub observations: Vec, + pub evidence: Vec, + pub churn: Option, + pub mode: Option, + pub planning: Option, +} + +impl EpiphanyStateUpdate { + pub fn is_empty(&self) -> bool { + self.objective.is_none() + && self.active_subgoal_id.is_none() + && self.subgoals.is_none() + && self.invariants.is_none() + && self.graphs.is_none() + && self.graph_frontier.is_none() + && self.graph_checkpoint.is_none() + && self.scratch.is_none() + && self.investigation_checkpoint.is_none() + && self.job_bindings.is_none() + && self.acceptance_receipts.is_empty() + && self.runtime_links.is_empty() + && self.observations.is_empty() + && self.evidence.is_empty() + && self.churn.is_none() + && self.mode.is_none() + && self.planning.is_none() + } +} diff --git a/notes/codex-auth-spine-inventory.md b/notes/codex-auth-spine-inventory.md index a5a166f4..136b9f8a 100644 --- a/notes/codex-auth-spine-inventory.md +++ b/notes/codex-auth-spine-inventory.md @@ -171,6 +171,14 @@ contract and active runtime-link conflicts, then returns the durable job binding and runtime link. Vendored `CodexThread` is still a persistence adapter for the compatibility route, not the owner of that state mechanics. +The Epiphany state-update contract shape has also left vendored Codex. +`epiphany-core::EpiphanyStateUpdate` now owns the update document used by the +compatibility `thread/epiphany/update`, promotion, accept, and launch paths. +`codex-core` re-exports it only as a compatibility alias. Validation and +mutation application are still in `CodexThread`; those are the next state-write +mechanics to extract before the Codex thread can honestly call itself a +persistence adapter. + The bad news is useful: the current spine still drags in `codex-api` and its large transport dependency stack. That is tolerable as a sealed compatibility reliquary, but not as the final shape. The next purification should shrink the diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index c0ec3ac9..1b072a7a 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -603,6 +603,14 @@ runtime-link conflicts, and projects the durable job binding plus runtime link. Vendored `CodexThread` now performs only revision checking, persistence validation, and rollout/session writeback around that native plan. +The Epiphany state-update document shape has now left vendored Codex too. +`epiphany-core::EpiphanyStateUpdate` owns the update contract used by update, +promote, role/reorient accept, and launch compatibility paths; `codex-core` +re-exports it only so older callers keep compiling. The remaining impurity is +the important one: `CodexThread` still owns validation, application, revisioned +writeback, and route-facing orchestration around that native update document. +Move those mechanics next. + Also: MCP itself is allowed to be JSON. The target is not "replace MCP JSON"; the target is an Epiphany-owned boundary that speaks typed Epiphany intent/result/receipt documents internally and normal MCP JSON-RPC externally. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index c5c39803..2b007062 100644 Binary files a/state/ledgers.msgpack and b/state/ledgers.msgpack differ diff --git a/state/map.yaml b/state/map.yaml index 887d001d..52e6ff2d 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -279,5 +279,5 @@ rejected_paths: reason: making Epiphany cleaner inside Codex still preserves the wrong organ; Codex must be starved down to OpenAI subscription auth/model transport, while Epiphany data and subsystem communication move to typed CultCache/CultNet. current_status: - summary: The Codex starvation pass has five typing receipts, seventeen processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, and native heartbeat launch planning/job opening in `epiphany-core`. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch and mutation orchestration. The processor is about 10,339 lines, `epiphany_mutation_routes.rs` is about 1,071 lines, and `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, and maps deltas/completion into typed stream events and receipts. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, and its smoke proves the route without network. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, and rollout/session writeback for the compatibility route. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after live callers move. - next_action: Continue Codex starvation by moving the remaining Epiphany state update validation/revisioned write mechanics and mutation route orchestration out of vendored `codex_core::CodexThread` and `codex_message_processor.rs`, leaving Codex as persistence/JSON-RPC compatibility only. Then move live model-turn callers onto `epiphany-openai-runtime` or the same native CultNet contract and shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility. + summary: The Codex starvation pass has five typing receipts, seventeen processor cuts, a real physical extraction in `epiphany-codex-bridge`, a source-grounded Codex auth spine inventory, the native `epiphany-openai-adapter` document boundary, a buildable Codex auth/model wrapper in `epiphany-openai-codex-spine`, the first native runtime caller in `epiphany-openai-runtime`, native heartbeat launch planning/job opening in `epiphany-core`, and the native `epiphany-core::EpiphanyStateUpdate` contract. The bridge owns Codex-facing Epiphany adapters for scene, jobs, context/planning/graph query, retrieval, result projection, runtime-spine result adaptation, launch/prompt doctrine, mutation document mechanics, live-state projection, pressure/pre-compaction rendering, freshness/reorientation projection, CRRC/coordinator/role-board projection, and acceptance/evidence signal helpers. Vendored app-server now retains only `epiphany_invalidation.rs` as a root Epiphany module because watcher lifecycle is still app-server machinery; `codex_message_processor.rs` still contains route dispatch and mutation orchestration. The processor is about 10,339 lines, `epiphany_mutation_routes.rs` is about 1,071 lines, and `epiphany_state_helpers.rs` is down to a 19-line rollout-state loader. `epiphany-openai-adapter` defines CultCache `DatabaseEntry` request/event/receipt/auth-status documents with no Codex app-server or generic JSON dependency. `epiphany-openai-codex-spine` projects `AuthManager` / `CodexAuth` into typed `EpiphanyOpenAiAdapterStatus`, maps typed `EpiphanyOpenAiModelRequest` into Codex API `ResponsesApiRequest`, resolves auth/provider through keeper Codex crates, opens HTTP Responses streams through `codex-api`, and maps deltas/completion into typed stream events and receipts. `epiphany-openai-runtime` writes OpenAI status/request/stream-event/receipt records plus runtime sessions/jobs/results/events into `epiphany-core::runtime_spine_cache`, and its smoke proves the route without network. `epiphany-core::plan_runtime_spine_heartbeat_launch` validates launch contracts/conflicts and projects durable job bindings/runtime links; `epiphany-core::open_runtime_spine_heartbeat_job` owns the initialize-runtime/ensure-session/create-job sequence; `epiphany-core::EpiphanyStateUpdate` now owns the state-update document shape while `codex-core` re-exports it for compatibility. Vendored `CodexThread::epiphany_launch_job` is now mostly revision check, persistence validation, and rollout/session writeback for the compatibility route, but `CodexThread` still owns state-update validation/application and revisioned persistence mechanics. `epiphany-runtime-spine` advertises OpenAI adapter status/model-request/stream-event/receipt CultNet schemas and mutation contracts, so the native caller now has a real storage route instead of only JSON-RPC. MCP itself is correctly JSON at its protocol edge; the target is typed Epiphany intent/result/receipt wrappers around MCP, not replacing MCP JSON. The current OpenAI spine still pulls `codex-api` and a large transport dependency stack, so its next cut is dependency starvation after live callers move. + next_action: Continue Codex starvation by moving Epiphany state-update validation/application and revisioned write mechanics out of vendored `codex_core::CodexThread` into `epiphany-core`, leaving Codex as persistence/JSON-RPC compatibility only. Then move mutation route orchestration out of `codex_message_processor.rs`, move live model-turn callers onto `epiphany-openai-runtime` or the same native CultNet contract, and shrink the surviving Codex dependency surface to credential refresh, provider/model routing, and the smallest OpenAI Responses call required for Codex subscription compatibility. diff --git a/vendor/codex/codex-rs/core/src/codex_thread.rs b/vendor/codex/codex-rs/core/src/codex_thread.rs index 49b44314..7b6fbd67 100644 --- a/vendor/codex/codex-rs/core/src/codex_thread.rs +++ b/vendor/codex/codex-rs/core/src/codex_thread.rs @@ -26,23 +26,24 @@ use codex_protocol::models::ResponseItem; use codex_protocol::openai_models::ReasoningEffort; use codex_protocol::protocol::AskForApproval; use codex_protocol::protocol::EpiphanyAcceptanceReceipt; +#[cfg(test)] use codex_protocol::protocol::EpiphanyChurnState; +#[cfg(test)] use codex_protocol::protocol::EpiphanyEvidenceRecord; -use codex_protocol::protocol::EpiphanyGraphCheckpoint; +#[cfg(test)] use codex_protocol::protocol::EpiphanyGraphFrontier; +#[cfg(test)] use codex_protocol::protocol::EpiphanyGraphs; -use codex_protocol::protocol::EpiphanyInvariant; +#[cfg(test)] use codex_protocol::protocol::EpiphanyInvestigationCheckpoint; use codex_protocol::protocol::EpiphanyJobBinding; use codex_protocol::protocol::EpiphanyJobKind; -use codex_protocol::protocol::EpiphanyModeState; +#[cfg(test)] use codex_protocol::protocol::EpiphanyObservation; use codex_protocol::protocol::EpiphanyPlanningState; use codex_protocol::protocol::EpiphanyRetrievalState; use codex_protocol::protocol::EpiphanyRuntimeLink; -use codex_protocol::protocol::EpiphanyScratchPad; use codex_protocol::protocol::EpiphanyStateItem; -use codex_protocol::protocol::EpiphanySubgoal; use codex_protocol::protocol::EpiphanyThreadState; use codex_protocol::protocol::Event; use codex_protocol::protocol::Op; @@ -56,6 +57,7 @@ use codex_protocol::protocol::TokenUsageInfo; use codex_protocol::protocol::W3cTraceContext; use codex_protocol::user_input::UserInput; use codex_utils_absolute_path::AbsolutePathBuf; +use epiphany_core::EpiphanyStateUpdate; use epiphany_core::EpiphanyWorkerLaunchDocument; use epiphany_core::RuntimeSpineHeartbeatLaunchPlanOptions; use epiphany_core::RuntimeSpineHeartbeatJobOptions; @@ -111,28 +113,6 @@ pub struct CodexThread { _watch_registration: WatchRegistration, } -#[derive(Debug, Clone, Default)] -pub struct EpiphanyStateUpdate { - pub expected_revision: Option, - pub objective: Option, - pub active_subgoal_id: Option, - pub subgoals: Option>, - pub invariants: Option>, - pub graphs: Option, - pub graph_frontier: Option, - pub graph_checkpoint: Option, - pub scratch: Option, - pub investigation_checkpoint: Option, - pub job_bindings: Option>, - pub acceptance_receipts: Vec, - pub runtime_links: Vec, - pub observations: Vec, - pub evidence: Vec, - pub churn: Option, - pub mode: Option, - pub planning: Option, -} - #[derive(Debug, Clone)] pub struct EpiphanyJobLaunchRequest { pub expected_revision: Option, @@ -172,28 +152,6 @@ pub struct EpiphanyJobInterruptResult { pub interrupted_thread_ids: Vec, } -impl EpiphanyStateUpdate { - fn is_empty(&self) -> bool { - self.objective.is_none() - && self.active_subgoal_id.is_none() - && self.subgoals.is_none() - && self.invariants.is_none() - && self.graphs.is_none() - && self.graph_frontier.is_none() - && self.graph_checkpoint.is_none() - && self.scratch.is_none() - && self.investigation_checkpoint.is_none() - && self.job_bindings.is_none() - && self.acceptance_receipts.is_empty() - && self.runtime_links.is_empty() - && self.observations.is_empty() - && self.evidence.is_empty() - && self.churn.is_none() - && self.mode.is_none() - && self.planning.is_none() - } -} - /// Conduit for the bidirectional stream of messages that compose a thread /// (formerly called a conversation) in Codex. impl CodexThread { @@ -1884,7 +1842,7 @@ mod epiphany_update_tests { } #[test] - fn build_epiphany_job_launch_binding_leaves_lifecycle_to_runtime_links() { + fn plan_epiphany_job_launch_leaves_lifecycle_to_runtime_links() { let request = EpiphanyJobLaunchRequest { expected_revision: Some(7), binding_id: "modeling-checkpoint-worker".to_string(), @@ -1920,20 +1878,36 @@ mod epiphany_update_tests { max_runtime_seconds: Some(60), }; - let binding = build_epiphany_job_launch_binding(&request); - let runtime_link = build_epiphany_runtime_link(&request, "turn-1"); + let launch_plan = plan_runtime_spine_heartbeat_launch( + &EpiphanyThreadState::default(), + RuntimeSpineHeartbeatLaunchPlanOptions { + binding_id: request.binding_id, + kind: request.kind, + scope: request.scope, + owner_role: request.owner_role, + authority_scope: request.authority_scope, + linked_subgoal_ids: request.linked_subgoal_ids, + linked_graph_node_ids: request.linked_graph_node_ids, + instruction: request.instruction, + launch_document: request.launch_document, + output_contract_id: request.output_contract_id, + max_runtime_seconds: request.max_runtime_seconds, + runtime_job_id: "turn-1".to_string(), + }, + ) + .expect("launch planning should build binding and runtime link"); assert_eq!( - binding.authority_scope.as_deref(), + launch_plan.binding.authority_scope.as_deref(), Some("epiphany.role.modeling") ); assert_eq!( - runtime_link.id, + launch_plan.runtime_link.id, "runtime-link-modeling-checkpoint-worker-turn-1" ); - assert_eq!(runtime_link.runtime_job_id, "turn-1"); - assert_eq!(runtime_link.runtime_result_id, None); - assert_eq!(runtime_link.role_id, "epiphany-modeler"); + assert_eq!(launch_plan.runtime_link.runtime_job_id, "turn-1"); + assert_eq!(launch_plan.runtime_link.runtime_result_id, None); + assert_eq!(launch_plan.runtime_link.role_id, "epiphany-modeler"); } } diff --git a/vendor/codex/codex-rs/core/src/lib.rs b/vendor/codex/codex-rs/core/src/lib.rs index 9601d833..3248d123 100644 --- a/vendor/codex/codex-rs/core/src/lib.rs +++ b/vendor/codex/codex-rs/core/src/lib.rs @@ -26,7 +26,7 @@ pub use codex_thread::CodexThread; pub use codex_thread::CodexThreadTurnContextOverrides; pub use codex_thread::EpiphanyJobInterruptRequest; pub use codex_thread::EpiphanyJobLaunchRequest; -pub use codex_thread::EpiphanyStateUpdate; +pub use epiphany_core::EpiphanyStateUpdate; pub use codex_thread::ThreadConfigSnapshot; pub use epiphany_distillation::EpiphanyDistillInput; pub use epiphany_distillation::EpiphanyDistillProposal;