Extract Epiphany jobs view into core

This commit is contained in:
Meta Vens 2026-05-12 21:15:22 +01:00
commit 685a214320
8 changed files with 544 additions and 285 deletions

View file

@ -150,6 +150,9 @@ pub use surfaces::EpiphanyCrrcReorientAction;
pub use surfaces::EpiphanyCrrcResultStatus;
pub use surfaces::EpiphanyCrrcSceneAction;
pub use surfaces::EpiphanyCrrcStateStatus;
pub use surfaces::EpiphanyJobStatus;
pub use surfaces::EpiphanyJobView;
pub use surfaces::EpiphanyJobsInput;
pub use surfaces::EpiphanyPressure;
pub use surfaces::EpiphanyPressureBasis;
pub use surfaces::EpiphanyPressureLevel;
@ -182,6 +185,7 @@ pub use surfaces::build_reorient_acceptance_bundle;
pub use surfaces::build_role_acceptance_bundle;
pub use surfaces::coordinator_automation_action;
pub use surfaces::crrc_scene_action_to_coordinator_scene_action;
pub use surfaces::derive_jobs;
pub use surfaces::derive_pressure_view;
pub use surfaces::derive_role_board;
pub use surfaces::imagination_role_state_patch_policy_errors;

View file

@ -0,0 +1,490 @@
use codex_protocol::protocol::EpiphanyJobBinding;
use codex_protocol::protocol::EpiphanyJobKind;
use codex_protocol::protocol::EpiphanyRetrievalState;
use codex_protocol::protocol::EpiphanyRetrievalStatus;
use codex_protocol::protocol::EpiphanyRuntimeLink;
use codex_protocol::protocol::EpiphanyThreadState;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EpiphanyJobStatus {
Idle,
Needed,
Pending,
Running,
Completed,
Failed,
Cancelled,
Blocked,
Unavailable,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EpiphanyJobView {
pub id: String,
pub kind: EpiphanyJobKind,
pub scope: String,
pub owner_role: String,
pub authority_scope: Option<String>,
pub runtime_job_id: Option<String>,
pub status: EpiphanyJobStatus,
pub items_processed: Option<u32>,
pub items_total: Option<u32>,
pub progress_note: Option<String>,
pub last_checkpoint_at_unix_seconds: Option<i64>,
pub blocking_reason: Option<String>,
pub active_thread_ids: Vec<String>,
pub linked_subgoal_ids: Vec<String>,
pub linked_graph_node_ids: Vec<String>,
}
#[derive(Debug, Clone, Copy)]
pub struct EpiphanyJobsInput<'a> {
pub state: Option<&'a EpiphanyThreadState>,
pub retrieval_override: Option<&'a EpiphanyRetrievalState>,
}
pub fn derive_jobs(input: EpiphanyJobsInput<'_>) -> Vec<EpiphanyJobView> {
let mut jobs = vec![
index_job(input.state, input.retrieval_override),
remap_job(input.state),
verification_job(input.state),
];
let Some(state) = input.state else {
return jobs;
};
for binding in &state.job_bindings {
let runtime_link = latest_runtime_link_for_binding(state, binding.id.as_str());
let replacement = if let Some(existing) = jobs.iter().find(|job| job.id == binding.id) {
overlay_job_binding(existing.clone(), binding, runtime_link)
} else {
bound_job(binding, runtime_link)
};
if let Some(existing) = jobs.iter_mut().find(|job| job.id == binding.id) {
*existing = replacement;
} else {
jobs.push(replacement);
}
}
jobs
}
fn bound_job(
binding: &EpiphanyJobBinding,
runtime_link: Option<&EpiphanyRuntimeLink>,
) -> EpiphanyJobView {
overlay_job_binding(
EpiphanyJobView {
id: binding.id.clone(),
kind: binding.kind,
scope: binding.scope.clone(),
owner_role: binding.owner_role.clone(),
authority_scope: binding.authority_scope.clone(),
runtime_job_id: runtime_link.map(|link| link.runtime_job_id.clone()),
status: if binding.blocking_reason.is_some() {
EpiphanyJobStatus::Blocked
} else {
EpiphanyJobStatus::Idle
},
items_processed: None,
items_total: None,
progress_note: None,
last_checkpoint_at_unix_seconds: None,
blocking_reason: None,
active_thread_ids: Vec::new(),
linked_subgoal_ids: binding.linked_subgoal_ids.clone(),
linked_graph_node_ids: binding.linked_graph_node_ids.clone(),
},
binding,
runtime_link,
)
}
fn overlay_job_binding(
mut job: EpiphanyJobView,
binding: &EpiphanyJobBinding,
runtime_link: Option<&EpiphanyRuntimeLink>,
) -> EpiphanyJobView {
job.kind = binding.kind;
job.scope = binding.scope.clone();
job.owner_role = binding.owner_role.clone();
job.authority_scope = binding.authority_scope.clone();
job.runtime_job_id = runtime_link.map(|link| link.runtime_job_id.clone());
if !binding.linked_subgoal_ids.is_empty() {
job.linked_subgoal_ids = binding.linked_subgoal_ids.clone();
}
if !binding.linked_graph_node_ids.is_empty() {
job.linked_graph_node_ids = binding.linked_graph_node_ids.clone();
}
if let Some(blocking_reason) = binding.blocking_reason.clone() {
job.blocking_reason = Some(blocking_reason);
}
if binding.blocking_reason.is_some() {
job.status = EpiphanyJobStatus::Blocked;
return job;
}
if runtime_link.is_some() {
job.status = EpiphanyJobStatus::Pending;
job.blocking_reason = None;
job.progress_note =
Some("Queued for Epiphany heartbeat activation through runtime_links.".to_string());
return job;
}
job
}
fn index_job(
state: Option<&EpiphanyThreadState>,
retrieval_override: Option<&EpiphanyRetrievalState>,
) -> EpiphanyJobView {
let retrieval = state
.and_then(|state| state.retrieval.as_ref())
.or(retrieval_override);
let linked_subgoal_ids = active_subgoal_ids(state);
let linked_graph_node_ids = active_graph_node_ids(state);
let Some(retrieval) = retrieval else {
return EpiphanyJobView {
id: "retrieval-index".to_string(),
kind: EpiphanyJobKind::Indexing,
scope: "workspace".to_string(),
owner_role: "epiphany-core".to_string(),
authority_scope: None,
runtime_job_id: None,
status: EpiphanyJobStatus::Unavailable,
items_processed: None,
items_total: None,
progress_note: None,
last_checkpoint_at_unix_seconds: None,
blocking_reason: Some("Retrieval state is unavailable for this thread.".to_string()),
active_thread_ids: Vec::new(),
linked_subgoal_ids,
linked_graph_node_ids,
};
};
let dirty_path_count = retrieval.dirty_paths.len();
let progress_note = match retrieval.status {
EpiphanyRetrievalStatus::Ready if dirty_path_count == 0 => {
"Retrieval catalog is ready.".to_string()
}
EpiphanyRetrievalStatus::Ready => {
format!("Retrieval catalog is ready with {dirty_path_count} dirty path(s) noted.")
}
EpiphanyRetrievalStatus::Stale => {
format!("Retrieval catalog is stale; {dirty_path_count} dirty path(s) need refresh.")
}
EpiphanyRetrievalStatus::Indexing => "Retrieval catalog is indexing.".to_string(),
EpiphanyRetrievalStatus::Unavailable => "Retrieval catalog is unavailable.".to_string(),
};
EpiphanyJobView {
id: "retrieval-index".to_string(),
kind: EpiphanyJobKind::Indexing,
scope: retrieval.workspace_root.display().to_string(),
owner_role: "epiphany-core".to_string(),
authority_scope: None,
runtime_job_id: None,
status: job_status_from_retrieval_status(retrieval.status),
items_processed: retrieval.indexed_file_count,
items_total: None,
progress_note: Some(progress_note),
last_checkpoint_at_unix_seconds: retrieval.last_indexed_at_unix_seconds,
blocking_reason: (retrieval.status == EpiphanyRetrievalStatus::Unavailable).then(|| {
"Indexing requires a readable workspace and configured retrieval backend.".to_string()
}),
active_thread_ids: Vec::new(),
linked_subgoal_ids,
linked_graph_node_ids,
}
}
fn job_status_from_retrieval_status(status: EpiphanyRetrievalStatus) -> EpiphanyJobStatus {
match status {
EpiphanyRetrievalStatus::Ready => EpiphanyJobStatus::Idle,
EpiphanyRetrievalStatus::Stale => EpiphanyJobStatus::Needed,
EpiphanyRetrievalStatus::Indexing => EpiphanyJobStatus::Running,
EpiphanyRetrievalStatus::Unavailable => EpiphanyJobStatus::Unavailable,
}
}
fn remap_job(state: Option<&EpiphanyThreadState>) -> EpiphanyJobView {
let Some(state) = state else {
return blocked_state_job(
"graph-remap",
EpiphanyJobKind::Remap,
"architecture/dataflow graphs",
"Epiphany state is missing, so there is no graph to remap.",
);
};
let frontier = state.graph_frontier.as_ref();
let dirty_path_count = frontier
.map(|frontier| frontier.dirty_paths.len())
.unwrap_or_default();
let open_count = frontier
.map(|frontier| frontier.open_question_ids.len() + frontier.open_gap_ids.len())
.unwrap_or_default();
let graph_freshness = state
.churn
.as_ref()
.and_then(|churn| churn.graph_freshness.as_deref());
let freshness_needs_work = graph_freshness
.is_some_and(|freshness| !matches!(freshness, "fresh" | "ready" | "current" | "ok"));
let needs_work = dirty_path_count > 0 || open_count > 0 || freshness_needs_work;
let progress_note = if needs_work {
format!(
"Graph frontier has {dirty_path_count} dirty path(s) and {open_count} open question/gap id(s)."
)
} else {
"Graph frontier has no reflected remap pressure.".to_string()
};
EpiphanyJobView {
id: "graph-remap".to_string(),
kind: EpiphanyJobKind::Remap,
scope: "architecture/dataflow graphs".to_string(),
owner_role: "epiphany-core".to_string(),
authority_scope: None,
runtime_job_id: None,
status: if needs_work {
EpiphanyJobStatus::Needed
} else {
EpiphanyJobStatus::Idle
},
items_processed: None,
items_total: None,
progress_note: Some(progress_note),
last_checkpoint_at_unix_seconds: None,
blocking_reason: None,
active_thread_ids: Vec::new(),
linked_subgoal_ids: active_subgoal_ids(Some(state)),
linked_graph_node_ids: active_graph_node_ids(Some(state)),
}
}
fn verification_job(state: Option<&EpiphanyThreadState>) -> EpiphanyJobView {
let Some(state) = state else {
return blocked_state_job(
"verification",
EpiphanyJobKind::Verification,
"invariants/evidence",
"Epiphany state is missing, so there are no invariants to verify.",
);
};
let total = state.invariants.len() as u32;
let verified = state
.invariants
.iter()
.filter(|invariant| invariant_status_is_accepting(&invariant.status))
.count() as u32;
let status = if total > 0 && verified < total {
EpiphanyJobStatus::Needed
} else {
EpiphanyJobStatus::Idle
};
let progress_note = if total == 0 {
"No invariants are recorded yet.".to_string()
} else if verified == total {
format!("All {total} invariant(s) are currently accepting.")
} else {
format!("{verified} of {total} invariant(s) are currently accepting.")
};
EpiphanyJobView {
id: "verification".to_string(),
kind: EpiphanyJobKind::Verification,
scope: "invariants/evidence".to_string(),
owner_role: "epiphany-harness".to_string(),
authority_scope: None,
runtime_job_id: None,
status,
items_processed: Some(verified),
items_total: Some(total),
progress_note: Some(progress_note),
last_checkpoint_at_unix_seconds: None,
blocking_reason: None,
active_thread_ids: Vec::new(),
linked_subgoal_ids: active_subgoal_ids(Some(state)),
linked_graph_node_ids: active_graph_node_ids(Some(state)),
}
}
fn blocked_state_job(
id: &str,
kind: EpiphanyJobKind,
scope: &str,
blocking_reason: &str,
) -> EpiphanyJobView {
EpiphanyJobView {
id: id.to_string(),
kind,
scope: scope.to_string(),
owner_role: "epiphany-harness".to_string(),
authority_scope: None,
runtime_job_id: None,
status: EpiphanyJobStatus::Blocked,
items_processed: None,
items_total: None,
progress_note: None,
last_checkpoint_at_unix_seconds: None,
blocking_reason: Some(blocking_reason.to_string()),
active_thread_ids: Vec::new(),
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
}
}
fn active_subgoal_ids(state: Option<&EpiphanyThreadState>) -> Vec<String> {
state
.and_then(|state| state.active_subgoal_id.clone())
.map(|id| vec![id])
.unwrap_or_default()
}
fn active_graph_node_ids(state: Option<&EpiphanyThreadState>) -> Vec<String> {
state
.and_then(|state| state.graph_frontier.as_ref())
.map(|frontier| frontier.active_node_ids.clone())
.unwrap_or_default()
}
fn invariant_status_is_accepting(status: &str) -> bool {
matches!(
status,
"ok" | "ready" | "accepted" | "verified" | "pass" | "passed"
)
}
fn latest_runtime_link_for_binding<'a>(
state: &'a EpiphanyThreadState,
binding_id: &str,
) -> Option<&'a EpiphanyRuntimeLink> {
state
.runtime_links
.iter()
.find(|link| link.binding_id == binding_id && !link.runtime_job_id.trim().is_empty())
}
#[cfg(test)]
mod tests {
use super::*;
use codex_protocol::protocol::EpiphanyGraphFrontier;
use codex_protocol::protocol::EpiphanyInvariant;
use std::path::PathBuf;
#[test]
fn derives_builtin_jobs_without_state() {
let jobs = derive_jobs(EpiphanyJobsInput {
state: None,
retrieval_override: None,
});
assert_eq!(jobs.len(), 3);
assert_eq!(jobs[0].id, "retrieval-index");
assert_eq!(jobs[0].status, EpiphanyJobStatus::Unavailable);
assert_eq!(jobs[1].status, EpiphanyJobStatus::Blocked);
assert_eq!(jobs[2].status, EpiphanyJobStatus::Blocked);
}
#[test]
fn reflects_retrieval_and_graph_pressure() {
let state = EpiphanyThreadState {
active_subgoal_id: Some("subgoal-1".to_string()),
retrieval: Some(EpiphanyRetrievalState {
workspace_root: PathBuf::from("E:/repo"),
status: EpiphanyRetrievalStatus::Stale,
dirty_paths: vec![PathBuf::from("src/lib.rs")],
indexed_file_count: Some(7),
..Default::default()
}),
graph_frontier: Some(EpiphanyGraphFrontier {
active_node_ids: vec!["node-1".to_string()],
dirty_paths: vec![PathBuf::from("src/lib.rs")],
open_question_ids: vec!["q-1".to_string()],
..Default::default()
}),
invariants: vec![
EpiphanyInvariant {
id: "inv-1".to_string(),
description: "verified".to_string(),
status: "verified".to_string(),
rationale: None,
},
EpiphanyInvariant {
id: "inv-2".to_string(),
description: "pending".to_string(),
status: "pending".to_string(),
rationale: None,
},
],
..Default::default()
};
let jobs = derive_jobs(EpiphanyJobsInput {
state: Some(&state),
retrieval_override: None,
});
let retrieval = jobs.iter().find(|job| job.id == "retrieval-index").unwrap();
assert_eq!(retrieval.status, EpiphanyJobStatus::Needed);
assert_eq!(retrieval.items_processed, Some(7));
assert_eq!(retrieval.linked_subgoal_ids, vec!["subgoal-1".to_string()]);
let remap = jobs.iter().find(|job| job.id == "graph-remap").unwrap();
assert_eq!(remap.status, EpiphanyJobStatus::Needed);
assert_eq!(remap.linked_graph_node_ids, vec!["node-1".to_string()]);
let verification = jobs.iter().find(|job| job.id == "verification").unwrap();
assert_eq!(verification.status, EpiphanyJobStatus::Needed);
assert_eq!(verification.items_processed, Some(1));
assert_eq!(verification.items_total, Some(2));
}
#[test]
fn overlays_binding_with_runtime_link() {
let state = EpiphanyThreadState {
job_bindings: vec![EpiphanyJobBinding {
id: "binding-1".to_string(),
kind: EpiphanyJobKind::Specialist,
scope: "modeling".to_string(),
owner_role: "body".to_string(),
authority_scope: Some("epiphany.role.modeling".to_string()),
linked_subgoal_ids: vec!["subgoal-1".to_string()],
linked_graph_node_ids: vec!["node-1".to_string()],
blocking_reason: None,
}],
runtime_links: vec![EpiphanyRuntimeLink {
id: "link-1".to_string(),
binding_id: "binding-1".to_string(),
surface: "role".to_string(),
role_id: "modeling".to_string(),
authority_scope: "epiphany.role.modeling".to_string(),
runtime_job_id: "runtime-job-1".to_string(),
runtime_result_id: None,
linked_subgoal_ids: Vec::new(),
linked_graph_node_ids: Vec::new(),
}],
..Default::default()
};
let jobs = derive_jobs(EpiphanyJobsInput {
state: Some(&state),
retrieval_override: None,
});
let binding = jobs.iter().find(|job| job.id == "binding-1").unwrap();
assert_eq!(binding.status, EpiphanyJobStatus::Pending);
assert_eq!(binding.runtime_job_id.as_deref(), Some("runtime-job-1"));
assert_eq!(
binding.progress_note.as_deref(),
Some("Queued for Epiphany heartbeat activation through runtime_links.")
);
}
}

View file

@ -1,5 +1,6 @@
mod coordinator;
mod crrc;
mod jobs;
mod pressure;
mod reorient;
mod role_board;
@ -28,6 +29,10 @@ pub use crrc::EpiphanyCrrcResultStatus;
pub use crrc::EpiphanyCrrcSceneAction;
pub use crrc::EpiphanyCrrcStateStatus;
pub use crrc::recommend_crrc_action;
pub use jobs::EpiphanyJobStatus;
pub use jobs::EpiphanyJobView;
pub use jobs::EpiphanyJobsInput;
pub use jobs::derive_jobs;
pub use pressure::EpiphanyPressure;
pub use pressure::EpiphanyPressureBasis;
pub use pressure::EpiphanyPressureLevel;

View file

@ -23,7 +23,7 @@ The spine exists in more than twenty-five live paths:
- explicit state updates: app-server routes `thread/epiphany/update` through a loaded `CodexThread` update method that rejects malformed appended observation/evidence graph records and structurally invalid replacement fields, including investigation checkpoints that cite missing evidence and planning records with broken ids/source refs/backlog links/draft acceptance criteria, mutates live `SessionState` only after validation, bumps the revision, and persists an immediate `RolloutItem::EpiphanyState` snapshot in [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4620), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:376), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:552), [codex_thread.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/codex_thread.rs:1294), and [promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:44).
- live state notifications and write responses: app-server declares experimental `thread/epiphany/stateUpdated` and emits it with the updated typed state, typed `source`, event-level `revision`, and typed `changedFields` after successful direct updates and accepted promotions, but not after rejected promotions; direct `thread/epiphany/update` and accepted `thread/epiphany/promote` responses expose the same revision/change metadata, accepted promotions always report `Evidence` because verifier evidence is appended even when the patch evidence list is empty, and successful write response/notification states now use the same client-visible live projection as `thread/read`, including retrieval-summary backfill when durable state has no persisted retrieval metadata, in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:1113), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4354), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4419), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4428), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4555), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4608), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4652), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4693), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11327), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11370).
- scene projection: the `scene` view lens reads the same live/stored Epiphany state view used by `thread/read` and derives a compact client scene with objective, active subgoal, invariant status counts, graph focus/counts, retrieval status, investigation-checkpoint summary counts, observation/evidence summaries, churn, live/stored source, and available control-plane actions without mutating or persisting state.
- job/progress reflection: the `jobs` view lens reads the same thread view as scene, optionally fills retrieval state for loaded threads with no Epiphany state, and derives non-authoritative progress slots for retrieval indexing, graph remap, invariant verification, and bound specialist work. Durable `job_bindings` now act as thin Epiphany-owned authority slots with binding id, kind, scope, owner role, authority scope, linked ids, and optional blocking reason only. Runtime job ids project from `runtime_links` and typed runtime-spine records; old `agent_jobs` bindings are sealed instead of live-crawled.
- job/progress reflection: the `jobs` view lens reads the same thread view as scene, optionally fills retrieval state for loaded threads with no Epiphany state, and adapts core-derived non-authoritative progress slots for retrieval indexing, graph remap, invariant verification, and bound specialist work. Durable `job_bindings` now act as thin Epiphany-owned authority slots with binding id, kind, scope, owner role, authority scope, linked ids, and optional blocking reason only. Runtime job ids project from `runtime_links` through core job view policy; old `agent_jobs` bindings are sealed instead of live-crawled in [jobs.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/jobs.rs:1).
- bound-job progress notifications: app-server still declares experimental `thread/epiphany/jobsUpdated` as sealed legacy Codex evacuation telemetry, but the handler no longer emits Epiphany updates from old `agent_job_progress:{json}` background events. Heartbeat-owned activation and typed runtime-spine receipts are now the live Epiphany path.
- explicit job control: app-server declares experimental `thread/epiphany/jobLaunch` and `thread/epiphany/jobInterrupt`, routes them through core launch/interrupt handlers that persist heartbeat-backed durable `job_bindings` revisions through the authoritative Epiphany state path, and emit `thread/epiphany/stateUpdated` with source `jobLaunch` or `jobInterrupt` instead of creating SQLite `agent_jobs` rows or pretending jobs reflection is the scheduler.
- freshness reflection: app-server declares experimental read-only `thread/epiphany/freshness`, reads the same live/stored thread view used by the view lenses and context, fills live retrieval state for loaded threads, and derives one bounded retrieval/graph freshness lens plus, for loaded threads, watcher-backed invalidation inputs with watched root, changed paths, mapped graph-node hits, active-frontier hits, and revision/source identity without mutating, scheduling, notifying, or performing automatic semantic invalidation in [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:350), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4167), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4259), [epiphany_invalidation.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/epiphany_invalidation.rs:19), [epiphany_invalidation.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/epiphany_invalidation.rs:67), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4219), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11073).

View file

@ -32,7 +32,7 @@ remembers doctrine; the branch remembers the blade.
## Current Orientation
- Do not copy exact branch or HEAD from this note. Run `git status --short --branch` and `git log --oneline -5`.
- Top priority is still foundation cleanup, not outward feature work. Read `notes/epiphany-architectural-teardown.md` before touching Epiphany control-plane code. The May 2026 suspicion pass found that the app-server Epiphany control plane had become architectural Jenga: too much policy, projection, lifecycle glue, prompt packet assembly, coordinator sequencing, and test authority lives in `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`. The rebuild has begun: pressure policy, reorientation resume/regather verdict policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, role-result interpretation/self-persistence review policy, and role/reorient acceptance bundle policy moved 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.
- Top priority is still foundation cleanup, not outward feature work. Read `notes/epiphany-architectural-teardown.md` before touching Epiphany control-plane code. The May 2026 suspicion pass found that the app-server Epiphany control plane had become architectural Jenga: too much policy, projection, lifecycle glue, prompt packet assembly, coordinator sequencing, and test authority lives in `vendor/codex/codex-rs/app-server/src/codex_message_processor.rs`. The rebuild has begun: pressure policy, job/progress view derivation, reorientation resume/regather verdict policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, role-result interpretation/self-persistence review policy, and role/reorient acceptance bundle policy moved 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.
- Phase 1 through Phase 5 are complete enough.
@ -369,7 +369,7 @@ Phase 6 bridge/UI trail. Landed rebuild cuts: `epiphany-core/src/surfaces/`
exists, pressure view derivation/tests, pure CRRC recommendation policy/tests,
fixed-lane coordinator decision policy/tests, role-board projection policy/tests,
role-result interpretation/self-persistence review policy/tests, and role/reorient
acceptance bundle policy/tests, and reorientation resume/regather verdict policy/tests live in core, live acceptance writes typed receipts keyed by runtime result id,
acceptance bundle policy/tests, reorientation resume/regather verdict policy/tests, and job/progress view derivation/tests live in core, live acceptance writes typed receipts keyed by runtime result id,
summary-string acceptance identity is gone for live paths, launches dual-write
runtime links, result read-back prefers those runtime links, normal public
`raw_result` is sealed, MVP consumers use `thread/epiphany/view`, heartbeat

Binary file not shown.

View file

@ -100,7 +100,7 @@ accepted_design:
- `thread/epiphany/retrieve`, `thread/epiphany/distill`, `thread/epiphany/propose`, `thread/epiphany/freshness`, `thread/epiphany/context`, `thread/epiphany/graphQuery`, and `thread/epiphany/view` stay read-only.
- `thread/epiphany/index` writes the retrieval catalog, not durable Epiphany understanding; catalog is auspex output, not doctrine.
- Qdrant is the preferred persistent semantic backend; BM25 remains the bootstrap/fallback/control path.
- `epiphany-core` owns prompt rendering, rollout replay helpers, retrieval/indexing, distillation, proposal, promotion policy, pressure derivation, reorientation resume/regather verdict policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy where possible.
- `epiphany-core` owns prompt rendering, rollout replay helpers, retrieval/indexing, distillation, proposal, promotion policy, pressure derivation, job/progress view derivation, reorientation resume/regather verdict policy, pure CRRC recommendation policy, fixed-lane coordinator decision policy, role-board projection policy, and role-result interpretation/self-persistence review policy where possible.
- Vendored Codex keeps the thin typed host seam: protocol types, thread bridges, app-server protocol, request routing, and rollout integration.
- The current algorithmic map is the source-grounded description of live control flow.
- Compact-Rehydrate-Reorient-Continue is an architecture primitive; automatic runtime coordination is not landed yet.
@ -272,5 +272,5 @@ rejected_paths:
reason: persistent state that accumulates every local truth becomes memory cruft and weakens rehydration
current_status:
summary: Phase 1 durable state through Phase 6 coordinator/specialist/CRRC/backend organs are landed, and the May 2026 rebuild has started cutting the app-server control-plane tumor. Pressure, reorientation resume/regather verdicts, CRRC, coordinator, role-board, role-result interpretation/self-persistence review, and role/reorient acceptance bundle policy now live in `epiphany-core`; live duplicate-acceptance checks use runtime result receipt identity instead of summary strings; launch writes durable `runtime_links`; role/reorient result read-back follows runtime links; and `jobBindings` no longer store launcher/backend/progress lifecycle fields.
next_action: Continue the teardown/rebuild migration from `notes/epiphany-ideal-architecture-rebuild-plan.md`. Landed cuts now shrink `jobBindings`, remove normal public `raw_result`, add the canonical `thread/epiphany/view` lens wrapper, migrate MVP consumers, quarantine heartbeat cognition blobs, delete the old scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator read wrappers, and move pure CRRC, fixed-lane coordinator decision policy, reorientation resume/regather verdict policy, role-board projection policy, role-result interpretation/self-persistence review policy, and role/reorient acceptance bundle policy into `epiphany-core`. The next pass is to audit the plan's remaining success criteria and cut whatever still makes app-server more than routing/adaptation. Do not resume outward Aquarium/bridge/Face/dogfood expansion until this foundation cleanup is complete enough to defend.
summary: Phase 1 durable state through Phase 6 coordinator/specialist/CRRC/backend organs are landed, and the May 2026 rebuild has started cutting the app-server control-plane tumor. Pressure, job/progress view derivation, reorientation resume/regather verdicts, CRRC, coordinator, role-board, role-result interpretation/self-persistence review, and role/reorient acceptance bundle policy now live in `epiphany-core`; live duplicate-acceptance checks use runtime result receipt identity instead of summary strings; launch writes durable `runtime_links`; role/reorient result read-back follows runtime links; and `jobBindings` no longer store launcher/backend/progress lifecycle fields.
next_action: Continue the teardown/rebuild migration from `notes/epiphany-ideal-architecture-rebuild-plan.md`. Landed cuts now shrink `jobBindings`, remove normal public `raw_result`, add the canonical `thread/epiphany/view` lens wrapper, migrate MVP consumers, quarantine heartbeat cognition blobs, delete the old scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator read wrappers, and move pure CRRC, fixed-lane coordinator decision policy, job/progress view derivation, reorientation resume/regather verdict policy, role-board projection policy, role-result interpretation/self-persistence review policy, and role/reorient acceptance bundle policy into `epiphany-core`. The next pass is to audit the plan's remaining success criteria and cut whatever still makes app-server more than routing/adaptation. Do not resume outward Aquarium/bridge/Face/dogfood expansion until this foundation cleanup is complete enough to defend.

View file

@ -444,7 +444,6 @@ use codex_protocol::protocol::EpiphanyCodeRef;
use codex_protocol::protocol::EpiphanyEvidenceRecord;
use codex_protocol::protocol::EpiphanyInvestigationCheckpoint;
use codex_protocol::protocol::EpiphanyInvestigationDisposition;
use codex_protocol::protocol::EpiphanyJobBinding;
use codex_protocol::protocol::EpiphanyJobKind as CoreEpiphanyJobKind;
use codex_protocol::protocol::EpiphanyPlanningState;
use codex_protocol::protocol::EpiphanyRetrievalState;
@ -512,6 +511,9 @@ use epiphany_core::EpiphanyCrrcReorientAction as CoreEpiphanyCrrcReorientAction;
use epiphany_core::EpiphanyCrrcResultStatus as CoreEpiphanyCrrcResultStatus;
use epiphany_core::EpiphanyCrrcSceneAction as CoreEpiphanyCrrcSceneAction;
use epiphany_core::EpiphanyCrrcStateStatus as CoreEpiphanyCrrcStateStatus;
use epiphany_core::EpiphanyJobStatus as CoreEpiphanyJobStatus;
use epiphany_core::EpiphanyJobView;
use epiphany_core::EpiphanyJobsInput;
use epiphany_core::EpiphanyPressure;
use epiphany_core::EpiphanyPressureBasis as CoreEpiphanyPressureBasis;
use epiphany_core::EpiphanyPressureLevel as CoreEpiphanyPressureLevel;
@ -541,6 +543,7 @@ use epiphany_core::EpiphanyRuntimeJobStatus;
use epiphany_core::build_reorient_acceptance_bundle;
use epiphany_core::build_role_acceptance_bundle;
use epiphany_core::coordinator_automation_action;
use epiphany_core::derive_jobs;
use epiphany_core::derive_pressure_view;
use epiphany_core::derive_role_board;
use epiphany_core::imagination_role_state_patch_policy_errors;
@ -16427,100 +16430,34 @@ fn map_epiphany_jobs(
state: Option<&EpiphanyThreadState>,
retrieval_override: Option<&EpiphanyRetrievalState>,
) -> Vec<ThreadEpiphanyJob> {
let mut jobs = vec![
map_epiphany_index_job(state, retrieval_override),
map_epiphany_remap_job(state),
map_epiphany_verification_job(state),
];
let Some(state) = state else {
return jobs;
};
for binding in &state.job_bindings {
let runtime_link = latest_epiphany_runtime_link_for_binding(state, binding.id.as_str());
let replacement = if let Some(existing) = jobs.iter().find(|job| job.id == binding.id) {
overlay_epiphany_job_binding(existing.clone(), binding, runtime_link)
} else {
map_epiphany_bound_job(binding, runtime_link)
};
if let Some(existing) = jobs.iter_mut().find(|job| job.id == binding.id) {
*existing = replacement;
} else {
jobs.push(replacement);
}
}
jobs
derive_jobs(EpiphanyJobsInput {
state,
retrieval_override,
})
.into_iter()
.map(map_core_epiphany_job_view)
.collect()
}
fn map_epiphany_bound_job(
binding: &EpiphanyJobBinding,
runtime_link: Option<&EpiphanyRuntimeLink>,
) -> ThreadEpiphanyJob {
overlay_epiphany_job_binding(
ThreadEpiphanyJob {
id: binding.id.clone(),
kind: map_core_epiphany_job_kind(binding.kind),
scope: binding.scope.clone(),
owner_role: binding.owner_role.clone(),
launcher_job_id: None,
authority_scope: binding.authority_scope.clone(),
backend_job_id: runtime_link.map(|link| link.runtime_job_id.clone()),
status: if binding.blocking_reason.is_some() {
ThreadEpiphanyJobStatus::Blocked
} else {
ThreadEpiphanyJobStatus::Idle
},
items_processed: None,
items_total: None,
progress_note: None,
last_checkpoint_at_unix_seconds: None,
blocking_reason: None,
active_thread_ids: Vec::new(),
linked_subgoal_ids: binding.linked_subgoal_ids.clone(),
linked_graph_node_ids: binding.linked_graph_node_ids.clone(),
},
binding,
runtime_link,
)
}
fn overlay_epiphany_job_binding(
mut job: ThreadEpiphanyJob,
binding: &EpiphanyJobBinding,
runtime_link: Option<&EpiphanyRuntimeLink>,
) -> ThreadEpiphanyJob {
job.kind = map_core_epiphany_job_kind(binding.kind);
job.scope = binding.scope.clone();
job.owner_role = binding.owner_role.clone();
job.launcher_job_id = None;
job.authority_scope = binding.authority_scope.clone();
job.backend_job_id = runtime_link.map(|link| link.runtime_job_id.clone());
if !binding.linked_subgoal_ids.is_empty() {
job.linked_subgoal_ids = binding.linked_subgoal_ids.clone();
fn map_core_epiphany_job_view(job: EpiphanyJobView) -> ThreadEpiphanyJob {
ThreadEpiphanyJob {
id: job.id,
kind: map_core_epiphany_job_kind(job.kind),
scope: job.scope,
owner_role: job.owner_role,
launcher_job_id: None,
authority_scope: job.authority_scope,
backend_job_id: job.runtime_job_id,
status: map_core_epiphany_job_status(job.status),
items_processed: job.items_processed,
items_total: job.items_total,
progress_note: job.progress_note,
last_checkpoint_at_unix_seconds: job.last_checkpoint_at_unix_seconds,
blocking_reason: job.blocking_reason,
active_thread_ids: job.active_thread_ids,
linked_subgoal_ids: job.linked_subgoal_ids,
linked_graph_node_ids: job.linked_graph_node_ids,
}
if !binding.linked_graph_node_ids.is_empty() {
job.linked_graph_node_ids = binding.linked_graph_node_ids.clone();
}
if let Some(blocking_reason) = binding.blocking_reason.clone() {
job.blocking_reason = Some(blocking_reason);
}
if binding.blocking_reason.is_some() {
job.status = ThreadEpiphanyJobStatus::Blocked;
return job;
}
if runtime_link.is_some() {
job.status = ThreadEpiphanyJobStatus::Pending;
job.blocking_reason = None;
job.progress_note =
Some("Queued for Epiphany heartbeat activation through runtime_links.".to_string());
return job;
}
job
}
fn map_core_epiphany_job_kind(kind: CoreEpiphanyJobKind) -> ThreadEpiphanyJobKind {
@ -16532,187 +16469,17 @@ fn map_core_epiphany_job_kind(kind: CoreEpiphanyJobKind) -> ThreadEpiphanyJobKin
}
}
fn map_epiphany_index_job(
state: Option<&EpiphanyThreadState>,
retrieval_override: Option<&EpiphanyRetrievalState>,
) -> ThreadEpiphanyJob {
let retrieval = state
.and_then(|state| state.retrieval.as_ref())
.or(retrieval_override);
let linked_subgoal_ids = epiphany_active_subgoal_ids(state);
let linked_graph_node_ids = epiphany_active_graph_node_ids(state);
let Some(retrieval) = retrieval else {
return ThreadEpiphanyJob {
id: "retrieval-index".to_string(),
kind: ThreadEpiphanyJobKind::Indexing,
scope: "workspace".to_string(),
owner_role: "epiphany-core".to_string(),
launcher_job_id: None,
authority_scope: None,
backend_job_id: None,
status: ThreadEpiphanyJobStatus::Unavailable,
items_processed: None,
items_total: None,
progress_note: None,
last_checkpoint_at_unix_seconds: None,
blocking_reason: Some("Retrieval state is unavailable for this thread.".to_string()),
active_thread_ids: Vec::new(),
linked_subgoal_ids,
linked_graph_node_ids,
};
};
let dirty_path_count = retrieval.dirty_paths.len();
let progress_note = match retrieval.status {
EpiphanyRetrievalStatus::Ready if dirty_path_count == 0 => {
"Retrieval catalog is ready.".to_string()
}
EpiphanyRetrievalStatus::Ready => {
format!("Retrieval catalog is ready with {dirty_path_count} dirty path(s) noted.")
}
EpiphanyRetrievalStatus::Stale => {
format!("Retrieval catalog is stale; {dirty_path_count} dirty path(s) need refresh.")
}
EpiphanyRetrievalStatus::Indexing => "Retrieval catalog is indexing.".to_string(),
EpiphanyRetrievalStatus::Unavailable => "Retrieval catalog is unavailable.".to_string(),
};
ThreadEpiphanyJob {
id: "retrieval-index".to_string(),
kind: ThreadEpiphanyJobKind::Indexing,
scope: retrieval.workspace_root.display().to_string(),
owner_role: "epiphany-core".to_string(),
launcher_job_id: None,
authority_scope: None,
backend_job_id: None,
status: epiphany_job_status_from_retrieval_status(retrieval.status),
items_processed: retrieval.indexed_file_count,
items_total: None,
progress_note: Some(progress_note),
last_checkpoint_at_unix_seconds: retrieval.last_indexed_at_unix_seconds,
blocking_reason: (retrieval.status == EpiphanyRetrievalStatus::Unavailable).then(|| {
"Indexing requires a readable workspace and configured retrieval backend.".to_string()
}),
active_thread_ids: Vec::new(),
linked_subgoal_ids,
linked_graph_node_ids,
}
}
fn epiphany_job_status_from_retrieval_status(
status: EpiphanyRetrievalStatus,
) -> ThreadEpiphanyJobStatus {
fn map_core_epiphany_job_status(status: CoreEpiphanyJobStatus) -> ThreadEpiphanyJobStatus {
match status {
EpiphanyRetrievalStatus::Ready => ThreadEpiphanyJobStatus::Idle,
EpiphanyRetrievalStatus::Stale => ThreadEpiphanyJobStatus::Needed,
EpiphanyRetrievalStatus::Indexing => ThreadEpiphanyJobStatus::Running,
EpiphanyRetrievalStatus::Unavailable => ThreadEpiphanyJobStatus::Unavailable,
}
}
fn map_epiphany_remap_job(state: Option<&EpiphanyThreadState>) -> ThreadEpiphanyJob {
let Some(state) = state else {
return epiphany_blocked_state_job(
"graph-remap",
ThreadEpiphanyJobKind::Remap,
"architecture/dataflow graphs",
"Epiphany state is missing, so there is no graph to remap.",
);
};
let frontier = state.graph_frontier.as_ref();
let dirty_path_count = frontier
.map(|frontier| frontier.dirty_paths.len())
.unwrap_or_default();
let open_count = frontier
.map(|frontier| frontier.open_question_ids.len() + frontier.open_gap_ids.len())
.unwrap_or_default();
let graph_freshness = state
.churn
.as_ref()
.and_then(|churn| churn.graph_freshness.as_deref());
let freshness_needs_work = graph_freshness
.is_some_and(|freshness| !matches!(freshness, "fresh" | "ready" | "current" | "ok"));
let needs_work = dirty_path_count > 0 || open_count > 0 || freshness_needs_work;
let progress_note = if needs_work {
format!(
"Graph frontier has {dirty_path_count} dirty path(s) and {open_count} open question/gap id(s)."
)
} else {
"Graph frontier has no reflected remap pressure.".to_string()
};
ThreadEpiphanyJob {
id: "graph-remap".to_string(),
kind: ThreadEpiphanyJobKind::Remap,
scope: "architecture/dataflow graphs".to_string(),
owner_role: "epiphany-core".to_string(),
launcher_job_id: None,
authority_scope: None,
backend_job_id: None,
status: if needs_work {
ThreadEpiphanyJobStatus::Needed
} else {
ThreadEpiphanyJobStatus::Idle
},
items_processed: None,
items_total: None,
progress_note: Some(progress_note),
last_checkpoint_at_unix_seconds: None,
blocking_reason: None,
active_thread_ids: Vec::new(),
linked_subgoal_ids: epiphany_active_subgoal_ids(Some(state)),
linked_graph_node_ids: epiphany_active_graph_node_ids(Some(state)),
}
}
fn map_epiphany_verification_job(state: Option<&EpiphanyThreadState>) -> ThreadEpiphanyJob {
let Some(state) = state else {
return epiphany_blocked_state_job(
"verification",
ThreadEpiphanyJobKind::Verification,
"invariants/evidence",
"Epiphany state is missing, so there are no invariants to verify.",
);
};
let total = state.invariants.len() as u32;
let verified = state
.invariants
.iter()
.filter(|invariant| epiphany_invariant_status_is_accepting(&invariant.status))
.count() as u32;
let status = if total > 0 && verified < total {
ThreadEpiphanyJobStatus::Needed
} else {
ThreadEpiphanyJobStatus::Idle
};
let progress_note = if total == 0 {
"No invariants are recorded yet.".to_string()
} else if verified == total {
format!("All {total} invariant(s) are currently accepting.")
} else {
format!("{verified} of {total} invariant(s) are currently accepting.")
};
ThreadEpiphanyJob {
id: "verification".to_string(),
kind: ThreadEpiphanyJobKind::Verification,
scope: "invariants/evidence".to_string(),
owner_role: "epiphany-harness".to_string(),
launcher_job_id: None,
authority_scope: None,
backend_job_id: None,
status,
items_processed: Some(verified),
items_total: Some(total),
progress_note: Some(progress_note),
last_checkpoint_at_unix_seconds: None,
blocking_reason: None,
active_thread_ids: Vec::new(),
linked_subgoal_ids: epiphany_active_subgoal_ids(Some(state)),
linked_graph_node_ids: epiphany_active_graph_node_ids(Some(state)),
CoreEpiphanyJobStatus::Idle => ThreadEpiphanyJobStatus::Idle,
CoreEpiphanyJobStatus::Needed => ThreadEpiphanyJobStatus::Needed,
CoreEpiphanyJobStatus::Pending => ThreadEpiphanyJobStatus::Pending,
CoreEpiphanyJobStatus::Running => ThreadEpiphanyJobStatus::Running,
CoreEpiphanyJobStatus::Completed => ThreadEpiphanyJobStatus::Completed,
CoreEpiphanyJobStatus::Failed => ThreadEpiphanyJobStatus::Failed,
CoreEpiphanyJobStatus::Cancelled => ThreadEpiphanyJobStatus::Cancelled,
CoreEpiphanyJobStatus::Blocked => ThreadEpiphanyJobStatus::Blocked,
CoreEpiphanyJobStatus::Unavailable => ThreadEpiphanyJobStatus::Unavailable,
}
}
@ -16756,13 +16523,6 @@ fn epiphany_active_graph_node_ids(state: Option<&EpiphanyThreadState>) -> Vec<St
.unwrap_or_default()
}
fn epiphany_invariant_status_is_accepting(status: &str) -> bool {
matches!(
status,
"ok" | "ready" | "accepted" | "verified" | "pass" | "passed"
)
}
fn status_counts<'a>(
statuses: impl Iterator<Item = &'a str>,
) -> Vec<ThreadEpiphanySceneStatusCount> {