Extract Epiphany CRRC policy into core

This commit is contained in:
Meta Vens 2026-05-12 06:56:15 +01:00
commit 8c1d0e19ee
8 changed files with 379 additions and 118 deletions

View file

@ -131,6 +131,13 @@ 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 surfaces::EpiphanyCrrcAction;
pub use surfaces::EpiphanyCrrcInput;
pub use surfaces::EpiphanyCrrcRecommendation;
pub use surfaces::EpiphanyCrrcReorientAction;
pub use surfaces::EpiphanyCrrcResultStatus;
pub use surfaces::EpiphanyCrrcSceneAction;
pub use surfaces::EpiphanyCrrcStateStatus;
pub use surfaces::EpiphanyPressure;
pub use surfaces::EpiphanyPressureBasis;
pub use surfaces::EpiphanyPressureLevel;
@ -139,3 +146,4 @@ pub use surfaces::EpiphanyViewInput;
pub use surfaces::EpiphanyViewLens;
pub use surfaces::EpiphanyViewOutput;
pub use surfaces::derive_pressure_view;
pub use surfaces::recommend_crrc_action;

View file

@ -0,0 +1,259 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EpiphanyCrrcStateStatus {
Missing,
Ready,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EpiphanyCrrcReorientAction {
Resume,
Regather,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EpiphanyCrrcResultStatus {
MissingState,
MissingBinding,
BackendUnavailable,
BackendMissing,
Pending,
Running,
Completed,
Failed,
Cancelled,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EpiphanyCrrcAction {
Continue,
PrepareCheckpoint,
LaunchReorientWorker,
WaitForReorientWorker,
ReviewReorientResult,
AcceptReorientResult,
RegatherManually,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EpiphanyCrrcSceneAction {
Update,
Reorient,
ReorientLaunch,
ReorientResult,
ReorientAccept,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EpiphanyCrrcRecommendation {
pub action: EpiphanyCrrcAction,
pub recommended_scene_action: Option<EpiphanyCrrcSceneAction>,
pub reason: String,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct EpiphanyCrrcInput {
pub loaded: bool,
pub state_status: EpiphanyCrrcStateStatus,
pub should_prepare_compaction: bool,
pub reorient_action: EpiphanyCrrcReorientAction,
pub result_status: EpiphanyCrrcResultStatus,
pub checkpoint_present: bool,
pub finding_present: bool,
pub finding_accepted: bool,
}
pub fn recommend_crrc_action(input: EpiphanyCrrcInput) -> EpiphanyCrrcRecommendation {
let build = |action: EpiphanyCrrcAction,
recommended_scene_action: Option<EpiphanyCrrcSceneAction>,
reason: &str| EpiphanyCrrcRecommendation {
action,
recommended_scene_action,
reason: reason.to_string(),
};
if input.state_status == EpiphanyCrrcStateStatus::Missing {
return build(
EpiphanyCrrcAction::RegatherManually,
None,
"No authoritative Epiphany state exists; re-gather source context before editing.",
);
}
if !input.checkpoint_present {
return build(
EpiphanyCrrcAction::PrepareCheckpoint,
Some(EpiphanyCrrcSceneAction::Update),
"Epiphany state exists, but CRRC has no durable investigation checkpoint to resume.",
);
}
match input.result_status {
EpiphanyCrrcResultStatus::Pending | EpiphanyCrrcResultStatus::Running => {
return build(
EpiphanyCrrcAction::WaitForReorientWorker,
Some(EpiphanyCrrcSceneAction::ReorientResult),
"A reorientation worker is already in flight; wait or read the bound result.",
);
}
EpiphanyCrrcResultStatus::Completed => {
if input.finding_present && !input.finding_accepted {
return build(
EpiphanyCrrcAction::AcceptReorientResult,
Some(EpiphanyCrrcSceneAction::ReorientAccept),
"A completed reorientation finding is available; review and explicitly accept it before continuing.",
);
}
if input.finding_accepted
&& input.reorient_action == EpiphanyCrrcReorientAction::Regather
{
if input.loaded {
return build(
EpiphanyCrrcAction::LaunchReorientWorker,
Some(EpiphanyCrrcSceneAction::ReorientLaunch),
"The accepted reorientation finding is stale against the current regather checkpoint; launch a fresh bounded worker before implementation continues.",
);
}
return build(
EpiphanyCrrcAction::RegatherManually,
Some(EpiphanyCrrcSceneAction::Reorient),
"The accepted reorientation finding is stale against the current regather checkpoint, but the thread is not loaded.",
);
}
if input.finding_accepted {
return build(
EpiphanyCrrcAction::Continue,
Some(EpiphanyCrrcSceneAction::Reorient),
"The reorientation finding is already accepted and the checkpoint remains resume-ready; continue the bounded task.",
);
}
if input.finding_present {
return build(
EpiphanyCrrcAction::ReviewReorientResult,
Some(EpiphanyCrrcSceneAction::ReorientResult),
"A completed reorientation finding is available, but it has not been accepted yet.",
);
}
return build(
EpiphanyCrrcAction::ReviewReorientResult,
Some(EpiphanyCrrcSceneAction::ReorientResult),
"The reorientation worker completed, but no structured finding was recorded.",
);
}
EpiphanyCrrcResultStatus::Failed | EpiphanyCrrcResultStatus::Cancelled => {
return build(
EpiphanyCrrcAction::RegatherManually,
Some(EpiphanyCrrcSceneAction::ReorientResult),
"The reorientation worker ended without a usable finding; inspect the failure before relaunching.",
);
}
EpiphanyCrrcResultStatus::MissingState => {
return build(
EpiphanyCrrcAction::RegatherManually,
None,
"No authoritative Epiphany state exists; re-gather source context before editing.",
);
}
EpiphanyCrrcResultStatus::MissingBinding
| EpiphanyCrrcResultStatus::BackendUnavailable
| EpiphanyCrrcResultStatus::BackendMissing => {}
}
if input.should_prepare_compaction
|| input.reorient_action == EpiphanyCrrcReorientAction::Regather
{
if input.loaded {
return build(
EpiphanyCrrcAction::LaunchReorientWorker,
Some(EpiphanyCrrcSceneAction::ReorientLaunch),
"The current pressure/reorientation verdict needs a bounded worker before safe continuation.",
);
}
return build(
EpiphanyCrrcAction::RegatherManually,
Some(EpiphanyCrrcSceneAction::Reorient),
"The thread is not loaded, so CRRC can only report the regather verdict.",
);
}
build(
EpiphanyCrrcAction::Continue,
Some(EpiphanyCrrcSceneAction::Reorient),
"Pressure is tolerable and the checkpoint remains resume-ready; continue the bounded task.",
)
}
#[cfg(test)]
mod tests {
use super::*;
fn input() -> EpiphanyCrrcInput {
EpiphanyCrrcInput {
loaded: true,
state_status: EpiphanyCrrcStateStatus::Ready,
should_prepare_compaction: false,
reorient_action: EpiphanyCrrcReorientAction::Resume,
result_status: EpiphanyCrrcResultStatus::MissingBinding,
checkpoint_present: true,
finding_present: false,
finding_accepted: false,
}
}
#[test]
fn continues_clean_checkpoint() {
let recommendation = recommend_crrc_action(input());
assert_eq!(recommendation.action, EpiphanyCrrcAction::Continue);
assert_eq!(
recommendation.recommended_scene_action,
Some(EpiphanyCrrcSceneAction::Reorient)
);
}
#[test]
fn launches_worker_for_regather_verdict() {
let recommendation = recommend_crrc_action(EpiphanyCrrcInput {
reorient_action: EpiphanyCrrcReorientAction::Regather,
..input()
});
assert_eq!(
recommendation.action,
EpiphanyCrrcAction::LaunchReorientWorker
);
assert_eq!(
recommendation.recommended_scene_action,
Some(EpiphanyCrrcSceneAction::ReorientLaunch)
);
}
#[test]
fn accepts_unaccepted_completed_finding() {
let recommendation = recommend_crrc_action(EpiphanyCrrcInput {
result_status: EpiphanyCrrcResultStatus::Completed,
finding_present: true,
..input()
});
assert_eq!(
recommendation.action,
EpiphanyCrrcAction::AcceptReorientResult
);
}
#[test]
fn relaunches_stale_accepted_regather() {
let recommendation = recommend_crrc_action(EpiphanyCrrcInput {
reorient_action: EpiphanyCrrcReorientAction::Regather,
result_status: EpiphanyCrrcResultStatus::Completed,
finding_present: true,
finding_accepted: true,
..input()
});
assert_eq!(
recommendation.action,
EpiphanyCrrcAction::LaunchReorientWorker
);
}
}

View file

@ -1,10 +1,19 @@
mod crrc;
mod pressure;
pub use crrc::recommend_crrc_action;
pub use crrc::EpiphanyCrrcAction;
pub use crrc::EpiphanyCrrcInput;
pub use crrc::EpiphanyCrrcRecommendation;
pub use crrc::EpiphanyCrrcReorientAction;
pub use crrc::EpiphanyCrrcResultStatus;
pub use crrc::EpiphanyCrrcSceneAction;
pub use crrc::EpiphanyCrrcStateStatus;
pub use pressure::derive_pressure_view;
pub use pressure::EpiphanyPressure;
pub use pressure::EpiphanyPressureBasis;
pub use pressure::EpiphanyPressureLevel;
pub use pressure::EpiphanyPressureStatus;
pub use pressure::derive_pressure_view;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct EpiphanyViewInput {

View file

@ -34,7 +34,7 @@ The spine exists in more than twenty-five live paths:
- context-pressure reflection: core token telemetry carries `model_auto_compact_token_limit` beside total/last usage and `model_context_window`; the `pressure` view lens reads live token usage or the latest stored rollout `TokenCount`, derives current context pressure from `last_token_usage` rather than cumulative thread spend, treats cumulative-only telemetry as unknown, and raises `shouldPrepareCompaction` at 80% of the active auto-compact/context limit without mutating Epiphany state or scheduling compaction in [protocol.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/protocol/src/protocol.rs:2237), [turn_context.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/turn_context.rs:103), [session/mod.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/core/src/session/mod.rs:2716), [common.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/common.rs:360), [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4361), [token_usage_replay.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor/token_usage_replay.rs:75), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4306), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11028).
- pre-compaction checkpoint intervention: app-server `TokenCount` handling now checks the same pressure mapper, and for loaded Epiphany threads crossing `shouldPrepareCompaction` it steers the active turn once with a bounded CRRC checkpoint directive to bank working context before compaction/reorientation. The per-turn dedupe bit and the pending compact handoff live in listener `ThreadState`; successful steering marks the active turn for a forced compact action at clean turn completion, while aborted turns clear the handoff. The intervention uses existing turn steering and turn-boundary automation rather than a new scheduler in [bespoke_event_handling.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/bespoke_event_handling.rs:1467), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:15405), and [thread_state.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/thread_state.rs:144).
- reorientation policy: the `reorient` view lens reuses the same live/stored thread view plus mapped pressure/freshness/watcher signals, and derives a bounded `resume`/`regather` verdict with checkpoint-path/frontier reasons without mutating, compacting, scheduling, notifying, or continuing work in [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4514), [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4394), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:11424).
- CRRC coordinator recommendation: the `crrc` view lens reuses the same pressure/freshness/watcher/reorientation mapping plus the fixed `reorient-worker` binding and result read-back helper, recognizes already accepted reorientation findings so an accepted result is not recommended for acceptance again, and returns one bounded recommendation such as continue, prepare checkpoint, launch worker, wait, review, accept, or regather manually without mutating, launching, accepting, compacting, notifying, scheduling, or silently continuing work in [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4661), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4546).
- CRRC coordinator recommendation: the `crrc` view lens reuses pressure/freshness/watcher/reorientation mapping plus the fixed `reorient-worker` binding and result read-back helper, recognizes already accepted reorientation findings so an accepted result is not recommended for acceptance again, and calls pure `epiphany-core` CRRC policy to return one bounded recommendation such as continue, prepare checkpoint, launch worker, wait, review, accept, or regather manually without mutating, launching, accepting, compacting, notifying, scheduling, or silently continuing work in [v2.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server-protocol/src/protocol/v2.rs:4661), [crrc.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/crrc.rs:60), and [codex_message_processor.rs](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/codex_message_processor.rs:4546).
- role ownership projection: the `roles` view lens reuses the same state/jobs/pressure/reorient/result/CRRC signals as the coordinator loop, and projects implementation, Imagination/planning, modeling/checkpoint, verification/review, and reorientation lanes with owner roles, status, linked jobs, authority scopes, and recommended scene actions without launching, scheduling, accepting, compacting, notifying, or mutating state.
- role specialist launch/read-back/acceptance: app-server declares experimental `thread/epiphany/roleLaunch`, read-only `thread/epiphany/roleResult`, and write-gated `thread/epiphany/roleAccept`. `roleLaunch` accepts fixed Imagination/planning, modeling/checkpoint, and verification/review role ids, builds bounded specialist payloads from authoritative Epiphany state, routes them through the heartbeat-backed `epiphany_launch_job` seam, opens a typed runtime-spine job receipt, and emits the normal `jobLaunch` state update for `jobBindings` only. `roleResult` resolves heartbeat bindings through typed runtime-spine job results and seals legacy `agent_jobs` bindings, projecting structured output as a reviewable finding with verdict, summary, next safe move, inspected files, frontier/evidence ids, optional `statePatch`, optional `selfPatch`, coordinator `selfPersistence` review, raw result, and errors without mutation, promotion, scheduling, or hidden continuation. `selfPatch` is a Ghostlight-shaped lane-memory request, not project truth: the coordinator accepts only role-matched, bounded, evidence-grounded memory/goal/value/private-note mutations and refuses objectives, graphs, checkpoints, scratch, planning, jobs, authority, code edits, or raw transcripts with reasons. `roleAccept` accepts completed heartbeat findings from typed runtime-spine results, accepts completed Imagination findings only when they contain a valid planning-only patch with draft Objective Draft review gates, accepts completed modeling/checkpoint findings only with a modeling-safe `statePatch`, applies accepted project patches through the existing Epiphany state validator, appends audit observation/evidence, and carries the same `selfPersistence` review. GUI/coordinator accept paths then apply accepted `selfPatch` requests to typed CultCache role dossiers in `state/agents.msgpack` through the native `epiphany-agent-memory-store` binary. Implementation stays owned by the main coding agent, verification output remains review-only, and reorientation stays on the CRRC-specific `reorientLaunch` / `reorientResult` / `reorientAccept` path.
- shared prompt memory projection and role dossiers: the prompt config now carries `[shared].persistent_memory` in [epiphany_specialists.toml](E:/Projects/EpiphanyAgent/vendor/codex/codex-rs/app-server/src/prompts/epiphany_specialists.toml:2). App-server parses that block, prepends it through `epiphany_agent_prompt_with_memory`, and therefore projects the same Ghostlight-derived memory into fixed role specialist instructions, reorientation-worker instructions, coordinator notes, and CRRC checkpoint steering. The base `<epiphany_state>` doctrine reinforces the Perfect Machine rule through [prompt.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/prompt.rs:31) and [epiphany_doctrine.md](E:/Projects/EpiphanyAgent/epiphany-core/src/prompts/epiphany_doctrine.md:1). Individual Ghostlight-shaped role dossiers now live in typed CultCache `state/agents.msgpack`, and the native `epiphany-agent-memory-store` binary validates, reviews, and applies bounded self-memory patches through the Rust store.
@ -55,6 +55,7 @@ The thick Epiphany-owned implementation is mostly outside vendored Codex now:
- deterministic observation distillation lives in [epiphany-core/src/distillation.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/distillation.rs:28).
- deterministic map/churn proposal from verified, evidence-backed observations lives in [epiphany-core/src/proposal.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/proposal.rs:115).
- verifier-backed promotion policy lives in [epiphany-core/src/promotion.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/promotion.rs:33).
- pressure and pure CRRC recommendation policy live in [pressure.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/pressure.rs:15) and [crrc.rs](E:/Projects/EpiphanyAgent/epiphany-core/src/surfaces/crrc.rs:60).
## Whole Control Flow

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 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 and pure CRRC recommendation 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.
@ -366,16 +366,15 @@ The next real move is still foundation cleanup. Start from
`notes/epiphany-architectural-teardown.md` and
`notes/epiphany-ideal-architecture-rebuild-plan.md`, not from the older outward
Phase 6 bridge/UI trail. Landed rebuild cuts: `epiphany-core/src/surfaces/`
exists, pressure view derivation and 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 cognition is quarantined, and the old
pressure/reorient/CRRC/coordinator read wrappers are deleted. The next cut is to
decide which remaining read verbs deserve to stay as true query surfaces and
which should collapse behind view lenses, then keep moving policy out of
app-server into `epiphany-core`. No Agile confetti. No new balcony on the
swaying tower.
exists, pressure view derivation/tests and pure CRRC recommendation policy/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
cognition is quarantined, and the old scene/jobs/roles/planning/pressure/reorient/
CRRC/coordinator read wrappers are deleted. The next cut is fixed-lane
coordinator or role-board policy extraction into `epiphany-core`. No Agile
confetti. No new balcony on the swaying tower.
The Phase 6 freshness slice is landed. It exposes read-only
`thread/epiphany/freshness` from live retrieval summaries plus graph

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, and promotion policy where possible.
- `epiphany-core` owns prompt rendering, rollout replay helpers, retrieval/indexing, distillation, proposal, promotion policy, pressure derivation, and the pure CRRC recommendation 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.
@ -273,4 +273,4 @@ rejected_paths:
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 policy now lives in `epiphany-core`; role/reorient acceptance writes typed `acceptance_receipts`; live duplicate-acceptance checks use runtime result receipt identity instead of summary strings; launch writes durable `runtime_links`; and role/reorient result read-back follows runtime links before falling back to legacy bindings.
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, and delete the old scene/jobs/roles/planning/pressure/reorient/CRRC/coordinator read wrappers. The next bounded cut is to keep moving policy out of app-server into `epiphany-core`, starting with the largest remaining coordinator/roles/CRRC mapping clusters. Do not resume outward Aquarium/bridge/Face/dogfood expansion until this foundation cleanup is materially farther along.
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 recommendation policy into `epiphany-core`. The next bounded cut is to extract the fixed-lane coordinator decision policy or role-board policy from app-server into `epiphany-core`. Do not resume outward Aquarium/bridge/Face/dogfood expansion until this foundation cleanup is materially farther along.

View file

@ -495,6 +495,13 @@ use codex_thread_store::ThreadStoreError;
use codex_thread_store::UpdateThreadMetadataParams as StoreUpdateThreadMetadataParams;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_pty::DEFAULT_OUTPUT_BYTES_CAP;
use epiphany_core::EpiphanyCrrcAction as CoreEpiphanyCrrcAction;
use epiphany_core::EpiphanyCrrcInput;
use epiphany_core::EpiphanyCrrcRecommendation as CoreEpiphanyCrrcRecommendation;
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::EpiphanyPressure;
use epiphany_core::EpiphanyPressureBasis as CoreEpiphanyPressureBasis;
use epiphany_core::EpiphanyPressureLevel as CoreEpiphanyPressureLevel;
@ -503,6 +510,7 @@ use epiphany_core::EpiphanyRuntimeJobResult;
use epiphany_core::EpiphanyRuntimeJobSnapshot;
use epiphany_core::EpiphanyRuntimeJobStatus;
use epiphany_core::derive_pressure_view;
use epiphany_core::recommend_crrc_action;
use epiphany_core::runtime_job_snapshot;
use std::collections::BTreeMap;
use std::collections::HashMap;
@ -14225,123 +14233,100 @@ fn map_epiphany_crrc_recommendation(
finding_present: bool,
finding_accepted: bool,
) -> ThreadEpiphanyCrrcRecommendation {
let build = |action: ThreadEpiphanyCrrcAction,
recommended_scene_action: Option<ThreadEpiphanySceneAction>,
reason: &str| ThreadEpiphanyCrrcRecommendation {
action,
recommended_scene_action,
reason: reason.to_string(),
};
map_core_crrc_recommendation(recommend_crrc_action(EpiphanyCrrcInput {
loaded,
state_status: map_core_crrc_state_status(state_status),
should_prepare_compaction: pressure.should_prepare_compaction,
reorient_action: map_core_crrc_reorient_action(decision.action),
result_status: map_core_crrc_result_status(result_status),
checkpoint_present,
finding_present,
finding_accepted,
}))
}
if state_status == ThreadEpiphanyReorientStateStatus::Missing {
return build(
ThreadEpiphanyCrrcAction::RegatherManually,
None,
"No authoritative Epiphany state exists; re-gather source context before editing.",
);
fn map_core_crrc_state_status(
status: ThreadEpiphanyReorientStateStatus,
) -> CoreEpiphanyCrrcStateStatus {
match status {
ThreadEpiphanyReorientStateStatus::Missing => CoreEpiphanyCrrcStateStatus::Missing,
ThreadEpiphanyReorientStateStatus::Ready => CoreEpiphanyCrrcStateStatus::Ready,
}
}
if !checkpoint_present {
return build(
ThreadEpiphanyCrrcAction::PrepareCheckpoint,
Some(ThreadEpiphanySceneAction::Update),
"Epiphany state exists, but CRRC has no durable investigation checkpoint to resume.",
);
fn map_core_crrc_reorient_action(
action: ThreadEpiphanyReorientAction,
) -> CoreEpiphanyCrrcReorientAction {
match action {
ThreadEpiphanyReorientAction::Resume => CoreEpiphanyCrrcReorientAction::Resume,
ThreadEpiphanyReorientAction::Regather => CoreEpiphanyCrrcReorientAction::Regather,
}
}
match result_status {
ThreadEpiphanyReorientResultStatus::Pending
| ThreadEpiphanyReorientResultStatus::Running => {
return build(
ThreadEpiphanyCrrcAction::WaitForReorientWorker,
Some(ThreadEpiphanySceneAction::ReorientResult),
"A reorientation worker is already in flight; wait or read the bound result.",
);
}
ThreadEpiphanyReorientResultStatus::Completed => {
if finding_present && !finding_accepted {
return build(
ThreadEpiphanyCrrcAction::AcceptReorientResult,
Some(ThreadEpiphanySceneAction::ReorientAccept),
"A completed reorientation finding is available; review and explicitly accept it before continuing.",
);
}
if finding_accepted && decision.action == ThreadEpiphanyReorientAction::Regather {
if loaded {
return build(
ThreadEpiphanyCrrcAction::LaunchReorientWorker,
Some(ThreadEpiphanySceneAction::ReorientLaunch),
"The accepted reorientation finding is stale against the current regather checkpoint; launch a fresh bounded worker before implementation continues.",
);
}
return build(
ThreadEpiphanyCrrcAction::RegatherManually,
Some(ThreadEpiphanySceneAction::Reorient),
"The accepted reorientation finding is stale against the current regather checkpoint, but the thread is not loaded.",
);
}
if finding_accepted {
return build(
ThreadEpiphanyCrrcAction::Continue,
Some(ThreadEpiphanySceneAction::Reorient),
"The reorientation finding is already accepted and the checkpoint remains resume-ready; continue the bounded task.",
);
}
if finding_present {
return build(
ThreadEpiphanyCrrcAction::ReviewReorientResult,
Some(ThreadEpiphanySceneAction::ReorientResult),
"A completed reorientation finding is available, but it has not been accepted yet.",
);
}
return build(
ThreadEpiphanyCrrcAction::ReviewReorientResult,
Some(ThreadEpiphanySceneAction::ReorientResult),
"The reorientation worker completed, but no structured finding was recorded.",
);
}
ThreadEpiphanyReorientResultStatus::Failed
| ThreadEpiphanyReorientResultStatus::Cancelled => {
return build(
ThreadEpiphanyCrrcAction::RegatherManually,
Some(ThreadEpiphanySceneAction::ReorientResult),
"The reorientation worker ended without a usable finding; inspect the failure before relaunching.",
);
}
fn map_core_crrc_result_status(
status: ThreadEpiphanyReorientResultStatus,
) -> CoreEpiphanyCrrcResultStatus {
match status {
ThreadEpiphanyReorientResultStatus::MissingState => {
return build(
ThreadEpiphanyCrrcAction::RegatherManually,
None,
"No authoritative Epiphany state exists; re-gather source context before editing.",
);
CoreEpiphanyCrrcResultStatus::MissingState
}
ThreadEpiphanyReorientResultStatus::MissingBinding
| ThreadEpiphanyReorientResultStatus::BackendUnavailable
| ThreadEpiphanyReorientResultStatus::BackendMissing => {}
}
if pressure.should_prepare_compaction
|| decision.action == ThreadEpiphanyReorientAction::Regather
{
if loaded {
return build(
ThreadEpiphanyCrrcAction::LaunchReorientWorker,
Some(ThreadEpiphanySceneAction::ReorientLaunch),
"The current pressure/reorientation verdict needs a bounded worker before safe continuation.",
);
ThreadEpiphanyReorientResultStatus::MissingBinding => {
CoreEpiphanyCrrcResultStatus::MissingBinding
}
return build(
ThreadEpiphanyCrrcAction::RegatherManually,
Some(ThreadEpiphanySceneAction::Reorient),
"The thread is not loaded, so CRRC can only report the regather verdict.",
);
ThreadEpiphanyReorientResultStatus::BackendUnavailable => {
CoreEpiphanyCrrcResultStatus::BackendUnavailable
}
ThreadEpiphanyReorientResultStatus::BackendMissing => {
CoreEpiphanyCrrcResultStatus::BackendMissing
}
ThreadEpiphanyReorientResultStatus::Pending => CoreEpiphanyCrrcResultStatus::Pending,
ThreadEpiphanyReorientResultStatus::Running => CoreEpiphanyCrrcResultStatus::Running,
ThreadEpiphanyReorientResultStatus::Completed => CoreEpiphanyCrrcResultStatus::Completed,
ThreadEpiphanyReorientResultStatus::Failed => CoreEpiphanyCrrcResultStatus::Failed,
ThreadEpiphanyReorientResultStatus::Cancelled => CoreEpiphanyCrrcResultStatus::Cancelled,
}
}
build(
ThreadEpiphanyCrrcAction::Continue,
Some(ThreadEpiphanySceneAction::Reorient),
"Pressure is tolerable and the checkpoint remains resume-ready; continue the bounded task.",
)
fn map_core_crrc_action(action: CoreEpiphanyCrrcAction) -> ThreadEpiphanyCrrcAction {
match action {
CoreEpiphanyCrrcAction::Continue => ThreadEpiphanyCrrcAction::Continue,
CoreEpiphanyCrrcAction::PrepareCheckpoint => ThreadEpiphanyCrrcAction::PrepareCheckpoint,
CoreEpiphanyCrrcAction::LaunchReorientWorker => {
ThreadEpiphanyCrrcAction::LaunchReorientWorker
}
CoreEpiphanyCrrcAction::WaitForReorientWorker => {
ThreadEpiphanyCrrcAction::WaitForReorientWorker
}
CoreEpiphanyCrrcAction::ReviewReorientResult => {
ThreadEpiphanyCrrcAction::ReviewReorientResult
}
CoreEpiphanyCrrcAction::AcceptReorientResult => {
ThreadEpiphanyCrrcAction::AcceptReorientResult
}
CoreEpiphanyCrrcAction::RegatherManually => ThreadEpiphanyCrrcAction::RegatherManually,
}
}
fn map_core_crrc_scene_action(action: CoreEpiphanyCrrcSceneAction) -> ThreadEpiphanySceneAction {
match action {
CoreEpiphanyCrrcSceneAction::Update => ThreadEpiphanySceneAction::Update,
CoreEpiphanyCrrcSceneAction::Reorient => ThreadEpiphanySceneAction::Reorient,
CoreEpiphanyCrrcSceneAction::ReorientLaunch => ThreadEpiphanySceneAction::ReorientLaunch,
CoreEpiphanyCrrcSceneAction::ReorientResult => ThreadEpiphanySceneAction::ReorientResult,
CoreEpiphanyCrrcSceneAction::ReorientAccept => ThreadEpiphanySceneAction::ReorientAccept,
}
}
fn map_core_crrc_recommendation(
recommendation: CoreEpiphanyCrrcRecommendation,
) -> ThreadEpiphanyCrrcRecommendation {
ThreadEpiphanyCrrcRecommendation {
action: map_core_crrc_action(recommendation.action),
recommended_scene_action: recommendation
.recommended_scene_action
.map(map_core_crrc_scene_action),
reason: recommendation.reason,
}
}
struct EpiphanyCoordinatorDecision {