From f4c62b3596a3c47d3172e586b1b5d6a62469873d Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Wed, 13 May 2026 06:28:39 +0100 Subject: [PATCH] Move Epiphany state update contract into core --- epiphany-core/src/lib.rs | 2 + epiphany-core/src/state_update.rs | 59 ++++++++++++ notes/codex-auth-spine-inventory.md | 8 ++ notes/fresh-workspace-handoff.md | 8 ++ state/ledgers.msgpack | Bin 83147 -> 83458 bytes state/map.yaml | 4 +- .../codex/codex-rs/core/src/codex_thread.rs | 88 ++++++------------ vendor/codex/codex-rs/core/src/lib.rs | 2 +- 8 files changed, 111 insertions(+), 60 deletions(-) create mode 100644 epiphany-core/src/state_update.rs 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 c5c39803b50c9782d6010769bc6877593e86834b..2b0070621da0080ec04b0aedaffc7c765a040082 100644 GIT binary patch delta 256 zcmX@z$=cMzIzgGq^~6TiX^f1wn)fhn-^0lG(`kB?Govtzk-3%W, - 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;