Remove Codex protocol from Epiphany core

This commit is contained in:
Meta Vens 2026-05-13 11:26:41 +01:00
commit 0687c74504
14 changed files with 54 additions and 55 deletions

View file

@ -7,6 +7,7 @@ use epiphany_core::EpiphanyPressure;
use epiphany_core::EpiphanyPressureBasis as CoreEpiphanyPressureBasis;
use epiphany_core::EpiphanyPressureLevel as CoreEpiphanyPressureLevel;
use epiphany_core::EpiphanyPressureStatus as CoreEpiphanyPressureStatus;
use epiphany_core::EpiphanyTokenUsageSnapshot;
use epiphany_core::derive_pressure_view;
use crate::launch::epiphany_agent_prompt_with_memory;
@ -14,7 +15,13 @@ use crate::launch::epiphany_specialist_prompt_config;
use crate::launch::pressure_level_label;
pub fn map_epiphany_pressure(info: Option<&CoreTokenUsageInfo>) -> ThreadEpiphanyPressure {
map_core_epiphany_pressure(derive_pressure_view(info))
let snapshot = info.map(|info| EpiphanyTokenUsageSnapshot {
total_tokens: info.total_token_usage.total_tokens,
last_turn_tokens: info.last_token_usage.total_tokens,
model_context_window: info.model_context_window,
model_auto_compact_token_limit: info.model_auto_compact_token_limit,
});
map_core_epiphany_pressure(derive_pressure_view(snapshot.as_ref()))
}
fn map_core_epiphany_pressure(pressure: EpiphanyPressure) -> ThreadEpiphanyPressure {

View file

@ -14,7 +14,6 @@ anyhow = "1"
bm25 = "2.3.2"
chrono = "0.4.44"
codex-file-search = { path = "../vendor/codex/codex-rs/file-search" }
codex-protocol = { path = "../vendor/codex/codex-rs/protocol" }
cultcache-rs = { path = "../vendor/cultcache-rs" }
cultnet-rs = { path = "../vendor/cultnet-rs" }
epiphany-openai-adapter = { path = "../epiphany-openai-adapter" }

View file

@ -5,7 +5,6 @@ mod promotion;
mod prompt;
mod proposal;
mod retrieval;
mod rollout;
mod runtime_spine;
mod state_ledger;
mod state_update;
@ -89,7 +88,6 @@ pub use retrieval::EpiphanyRetrieveResultKind;
pub use retrieval::index_workspace;
pub use retrieval::retrieval_state_for_workspace;
pub use retrieval::retrieve_workspace;
pub use rollout::latest_epiphany_state_from_rollout_items;
pub use runtime_spine::EpiphanyRuntimeEvent;
pub use runtime_spine::EpiphanyRuntimeIdentity;
pub use runtime_spine::EpiphanyRuntimeJob;
@ -241,6 +239,7 @@ pub use surfaces::EpiphanySceneSource;
pub use surfaces::EpiphanySceneStateStatus;
pub use surfaces::EpiphanySceneStatusCount;
pub use surfaces::EpiphanySceneSubgoal;
pub use surfaces::EpiphanyTokenUsageSnapshot;
pub use surfaces::EpiphanyWorkerLaunchDocument;
pub use surfaces::REORIENT_WORKER_OUTPUT_CONTRACT_ID;
pub use surfaces::ROLE_WORKER_OUTPUT_CONTRACT_ID;

View file

@ -798,7 +798,6 @@ fn push_omitted_count(lines: &mut Vec<String>, total: usize, shown: usize, label
#[cfg(test)]
mod tests {
use super::render_epiphany_state;
use codex_protocol::config_types::ModeKind;
use epiphany_state_model::EpiphanyChurnState;
use epiphany_state_model::EpiphanyCodeRef;
use epiphany_state_model::EpiphanyGraph;
@ -809,6 +808,7 @@ mod tests {
use epiphany_state_model::EpiphanyGraphs;
use epiphany_state_model::EpiphanyInvestigationCheckpoint;
use epiphany_state_model::EpiphanyInvestigationDisposition;
use epiphany_state_model::EpiphanyModeKind;
use epiphany_state_model::EpiphanyModeState;
use epiphany_state_model::EpiphanyThreadState;
use std::path::PathBuf;
@ -918,7 +918,7 @@ mod tests {
}),
mode: Some(EpiphanyModeState {
name: "epiphany".to_string(),
kind: Some(ModeKind::Default),
kind: Some(EpiphanyModeKind::Default),
}),
..Default::default()
};

View file

@ -71,6 +71,7 @@ pub use pressure::EpiphanyPressure;
pub use pressure::EpiphanyPressureBasis;
pub use pressure::EpiphanyPressureLevel;
pub use pressure::EpiphanyPressureStatus;
pub use pressure::EpiphanyTokenUsageSnapshot;
pub use pressure::derive_pressure_view;
pub use reorient::EpiphanyReorientAction;
pub use reorient::EpiphanyReorientCheckpointStatus;

View file

@ -1,9 +1,15 @@
use codex_protocol::protocol::TokenUsageInfo;
const EPIPHANY_PRESSURE_ELEVATED_PER_MILLE: u32 = 650;
const EPIPHANY_PRESSURE_PREPARE_COMPACTION_PER_MILLE: u32 = 800;
const EPIPHANY_PRESSURE_CRITICAL_PER_MILLE: u32 = 950;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EpiphanyTokenUsageSnapshot {
pub total_tokens: i64,
pub last_turn_tokens: i64,
pub model_context_window: Option<i64>,
pub model_auto_compact_token_limit: Option<i64>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EpiphanyPressure {
pub status: EpiphanyPressureStatus,
@ -40,7 +46,7 @@ pub enum EpiphanyPressureBasis {
ModelContextWindow,
}
pub fn derive_pressure_view(info: Option<&TokenUsageInfo>) -> EpiphanyPressure {
pub fn derive_pressure_view(info: Option<&EpiphanyTokenUsageSnapshot>) -> EpiphanyPressure {
let Some(info) = info else {
return EpiphanyPressure {
status: EpiphanyPressureStatus::Unknown,
@ -56,8 +62,8 @@ pub fn derive_pressure_view(info: Option<&TokenUsageInfo>) -> EpiphanyPressure {
};
};
let used_tokens = info.last_token_usage.total_tokens.max(0);
if used_tokens == 0 && info.total_token_usage.total_tokens > 0 {
let used_tokens = info.last_turn_tokens.max(0);
if used_tokens == 0 && info.total_tokens > 0 {
return EpiphanyPressure {
status: EpiphanyPressureStatus::Unknown,
level: EpiphanyPressureLevel::Unknown,
@ -141,29 +147,16 @@ pub fn derive_pressure_view(info: Option<&TokenUsageInfo>) -> EpiphanyPressure {
#[cfg(test)]
mod tests {
use super::*;
use codex_protocol::protocol::TokenUsage;
fn token_usage_info(
total_tokens: i64,
last_tokens: i64,
model_context_window: Option<i64>,
model_auto_compact_token_limit: Option<i64>,
) -> TokenUsageInfo {
TokenUsageInfo {
total_token_usage: TokenUsage {
input_tokens: 0,
cached_input_tokens: 0,
output_tokens: 0,
reasoning_output_tokens: 0,
total_tokens,
},
last_token_usage: TokenUsage {
input_tokens: 0,
cached_input_tokens: 0,
output_tokens: 0,
reasoning_output_tokens: 0,
total_tokens: last_tokens,
},
) -> EpiphanyTokenUsageSnapshot {
EpiphanyTokenUsageSnapshot {
total_tokens,
last_turn_tokens: last_tokens,
model_context_window,
model_auto_compact_token_limit,
}

View file

@ -36,7 +36,7 @@ remembers doctrine; the branch remembers the blade.
- 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/CultNet runtime. Codex is a compatibility reliquary for OpenAI subscription auth and model transport, not the host brain.
- `notes/codex-auth-spine-inventory.md` is the source-grounded keeper list for that reliquary: retain `codex-login` credential storage/refresh, `codex-model-provider` auth resolution, the model-transport subset of `codex-core::client`, and the narrow model-catalog subset of `models-manager`; do not treat Codex app-server, apps, skills, marketplace, plugin UX, MCP OAuth handlers, or collaboration-mode surfaces as auth-spine machinery.
- Edge JSON is allowed for schema description, hostile ingress before immediate typed parsing, sealed forensic artifacts, or named quarantine experiments. When both subsystems are ours, runtime data must remain typed CultCache documents and move over CultNet typed contracts. Generic `serde_json::Value` in worker launch/result/selfPatch/runtime flow is contamination until classified and replaced.
- Durable Epiphany state types now live in root crate `epiphany-state-model`. `codex-protocol` re-exports them only so old rollout/API callers keep compiling; do not add new durable `Epiphany*` state structs under `vendor/codex`. `epiphany-core` imports the native model directly. The remaining `epiphany-core` dependency on `codex-protocol` is now limited to Codex rollout/event reconstruction and token-pressure input, and that is the next wound to cut.
- Durable Epiphany state types now live in root crate `epiphany-state-model`. `codex-protocol` re-exports them only so old rollout/API callers keep compiling; do not add new durable `Epiphany*` state structs under `vendor/codex`. `epiphany-core` imports the native model directly and no longer depends on `codex-protocol`. Pressure derives from native `EpiphanyTokenUsageSnapshot`; Codex token telemetry is mapped at the bridge. Codex rollout/event reconstruction now lives in `codex-core::epiphany_rollout`, where the Codex `RolloutItem` / `EventMsg` types belong. The remaining direct vendored Codex dependency in `epiphany-core` is `codex-file-search`.
- The May 2026 foundation migration in `notes/epiphany-ideal-architecture-rebuild-plan.md` is complete enough to defend. Read `notes/epiphany-architectural-teardown.md` before touching Epiphany control-plane code, but do not treat it as an open-ended excuse to keep shaving the altar. The rebuild moved scene projection, freshness derivation, pressure policy, targeted context shards, bounded graph traversal, job/progress view derivation, planning view derivation, reorientation resume/regather verdict policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, role/reorient result interpretation, role self-persistence review policy, and role/reorient acceptance bundle policy into `epiphany-core`; typed acceptance receipts replaced summary-string identity for live accept paths, runtime links are dual-written on launch, and result read-back now prefers runtime links.
- Read `notes/epiphany-ideal-architecture-rebuild-plan.md` immediately after the teardown. It defines the smallest coherent replacement architecture: durable `EpiphanyState`, runtime-spine-owned `RuntimeState`, separate role memory/heartbeat state, `epiphany-core` as policy owner, app-server as adapter, Aquarium as reflector, typed acceptance receipts, and derived view lenses instead of a protocol verb zoo.
- Do not continue Aquarium UI, bridge, Face, or dogfood expansion until the teardown has a source-grounded cleanup slice plan. Epiphany is the foundation; patches on patches are not a purification rite, they are how the altar becomes load-bearing garbage.
@ -737,14 +737,14 @@ 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.
Continue with the actual whale-carcass cut: remove the remaining
`epiphany-core` dependency on `codex-protocol` by extracting or relocating the
Codex rollout adapter and token-pressure input, then keep starving the old model
turn path out of `thread/epiphany/*` JSON-RPC and `codex_message_processor.rs`.
Success is Epiphany calling the model adapter from its own CultCache/CultNet
runtime boundary while Codex survives only as subscription auth/model routing.
Do not resume Rider, Unity, Aquarium, Face, dogfood, planning, app, skill,
marketplace, or bridge expansion until this organ is being cut cleanly.
Continue with the actual whale-carcass cut: remove or isolate the last direct
vendored Codex dependency in `epiphany-core`, currently `codex-file-search`,
then keep starving the old model turn path out of `thread/epiphany/*` JSON-RPC
and `codex_message_processor.rs`. Success is Epiphany calling the model adapter
from its own CultCache/CultNet runtime boundary while Codex survives only as
subscription auth/model routing. Do not resume Rider, Unity, Aquarium, Face,
dogfood, planning, app, skill, marketplace, or bridge expansion until this
organ is being cut cleanly.
The Phase 6 freshness slice is landed. It exposes read-only
`thread/epiphany/freshness` from live retrieval summaries plus graph

Binary file not shown.

File diff suppressed because one or more lines are too long

1
vendor/codex/codex-rs/Cargo.lock generated vendored
View file

@ -5245,7 +5245,6 @@ dependencies = [
"bm25",
"chrono",
"codex-file-search",
"codex-protocol",
"cultcache-rs",
"cultnet-rs",
"epiphany-openai-adapter",

View file

@ -30,7 +30,6 @@ impl ContextualUserFragment for EpiphanyStateInstructions {
mod tests {
use super::EpiphanyStateInstructions;
use crate::context::ContextualUserFragment;
use codex_protocol::config_types::ModeKind;
use codex_protocol::protocol::EpiphanyChurnState;
use codex_protocol::protocol::EpiphanyCodeRef;
use codex_protocol::protocol::EpiphanyGraph;
@ -39,6 +38,7 @@ mod tests {
use codex_protocol::protocol::EpiphanyGraphFrontier;
use codex_protocol::protocol::EpiphanyGraphNode;
use codex_protocol::protocol::EpiphanyGraphs;
use codex_protocol::protocol::EpiphanyModeKind;
use codex_protocol::protocol::EpiphanyModeState;
use codex_protocol::protocol::EpiphanyThreadState;
use std::path::PathBuf;
@ -127,7 +127,7 @@ mod tests {
}),
mode: Some(EpiphanyModeState {
name: "epiphany".to_string(),
kind: Some(ModeKind::Default),
kind: Some(EpiphanyModeKind::Default),
}),
..Default::default()
};

View file

@ -1,7 +1,8 @@
use crate::context_manager;
use codex_protocol::models::ResponseItem;
use codex_protocol::protocol::EpiphanyThreadState;
use codex_protocol::protocol::EventMsg;
use codex_protocol::protocol::RolloutItem;
use epiphany_state_model::EpiphanyThreadState;
#[derive(Debug, Default)]
struct ActiveEpiphanyReplaySegment {
@ -153,20 +154,26 @@ where
epiphany_state
}
pub fn latest_epiphany_state_from_codex_rollout_items(
rollout_items: &[RolloutItem],
) -> Option<EpiphanyThreadState> {
latest_epiphany_state_from_rollout_items(rollout_items, context_manager::is_user_turn_boundary)
}
#[cfg(test)]
mod tests {
use super::latest_epiphany_state_from_rollout_items;
use codex_protocol::models::ContentItem;
use codex_protocol::models::ResponseItem;
use codex_protocol::protocol::CompactedItem;
use codex_protocol::protocol::EpiphanyStateItem;
use codex_protocol::protocol::EpiphanyThreadState;
use codex_protocol::protocol::EventMsg;
use codex_protocol::protocol::RolloutItem;
use codex_protocol::protocol::ThreadRolledBackEvent;
use codex_protocol::protocol::TurnCompleteEvent;
use codex_protocol::protocol::TurnStartedEvent;
use codex_protocol::protocol::UserMessageEvent;
use epiphany_state_model::EpiphanyStateItem;
use epiphany_state_model::EpiphanyThreadState;
fn simple_is_user_turn_boundary(item: &ResponseItem) -> bool {
matches!(

View file

@ -22,6 +22,7 @@ pub use codex_thread::CodexThreadTurnContextOverrides;
pub use codex_thread::EpiphanyJobInterruptRequest;
pub use codex_thread::EpiphanyJobLaunchRequest;
pub use codex_thread::ThreadConfigSnapshot;
mod epiphany_rollout;
pub use epiphany_core::EPIPHANY_RETRIEVAL_DEFAULT_LIMIT;
pub use epiphany_core::EPIPHANY_RETRIEVAL_MAX_LIMIT;
pub use epiphany_core::EpiphanyDistillInput;
@ -38,17 +39,9 @@ pub use epiphany_core::EpiphanyStateUpdate;
pub use epiphany_core::distill_observation;
pub use epiphany_core::evaluate_promotion;
pub use epiphany_core::propose_map_update;
pub use epiphany_rollout::latest_epiphany_state_from_codex_rollout_items as latest_epiphany_state_from_rollout_items;
mod agent;
pub fn latest_epiphany_state_from_rollout_items(
rollout_items: &[codex_protocol::protocol::RolloutItem],
) -> Option<codex_protocol::protocol::EpiphanyThreadState> {
epiphany_core::latest_epiphany_state_from_rollout_items(
rollout_items,
context_manager::is_user_turn_boundary,
)
}
mod codex_delegate;
mod command_canonicalization;
mod commit_attribution;

View file

@ -95,6 +95,7 @@ use codex_protocol::protocol::EpiphanyGraphLink;
use codex_protocol::protocol::EpiphanyGraphNode;
use codex_protocol::protocol::EpiphanyGraphs;
use codex_protocol::protocol::EpiphanyInvariant;
use codex_protocol::protocol::EpiphanyModeKind;
use codex_protocol::protocol::EpiphanyModeState;
use codex_protocol::protocol::EpiphanyObservation;
use codex_protocol::protocol::EpiphanyScratchPad;
@ -417,7 +418,7 @@ fn sample_epiphany_state_for_prompt() -> EpiphanyThreadState {
retrieval: None,
mode: Some(EpiphanyModeState {
name: "epiphany".to_string(),
kind: Some(ModeKind::Default),
kind: Some(EpiphanyModeKind::Default),
}),
planning: Default::default(),
last_updated_turn_id: Some("phase2-turn".to_string()),