Derive Resident Self routing from current Mind work

This commit is contained in:
Meta Vens 2026-08-22 15:51:10 +02:00
commit 470d4cb5b4
8 changed files with 612 additions and 812 deletions

View file

@ -16,7 +16,6 @@ fn main() -> Result<()> {
let args = arguments()?;
let feedback_store = path(&args, "--persona-feedback-store")?;
let runtime_store = path(&args, "--runtime-store")?;
let resident_store = path(&args, "--resident-store")?;
let forbidden = [
"--mind-store",
"--release-store",
@ -47,8 +46,7 @@ fn main() -> Result<()> {
}
bind_runtime_repository_domain(&runtime_store, "GameCult/Epiphany", "2026-07-18T00:00:00Z")?;
let inserted = ingest_resident_self_domain_pressure(
&resident_store,
let materialized = materialize_resident_self_domain_obligations(
&runtime_store,
&feedback_store,
"epiphany-yggdrasil",
@ -56,8 +54,8 @@ fn main() -> Result<()> {
runtime_store.parent().unwrap().to_str().unwrap(),
1_752_796_800_000,
)?;
if inserted < admitted.len() {
bail!("resident Self did not ingest every admitted feedback item");
if materialized < admitted.len() {
bail!("resident Self did not materialize every admitted feedback obligation");
}
for feedback in admitted {
let request = commit_imagination_consideration_request(

View file

@ -8,12 +8,12 @@ use epiphany_core::{
authenticate_resident_self_policy, bind_runtime_repository_domain,
bridge_admitted_persona_feedback_to_heartbeat, capture_process_instance,
coordinator_run_receipts, derive_resident_cognition_readiness, enqueue_resident_self_pressure,
import_bifrost_persona_feedback_deliveries,
ingest_resident_self_coordinator_continuation_pressure, ingest_resident_self_domain_pressure,
import_bifrost_persona_feedback_deliveries, ingest_resident_self_current_work_pressure,
live_resident_self_typed_request_ids, load_epiphany_cultmesh_swarm_brake,
load_resident_self_state, observe_process_instance, pending_resident_self_acks,
prepare_resident_self_launch, publish_resident_provider_readiness, reap_exited_child_process,
resident_cognitive_runtime_id, resident_prepared_launch_thread_id, resident_self_child_claim,
load_resident_self_state, materialize_resident_self_domain_obligations,
observe_process_instance, pending_resident_self_acks, prepare_resident_self_launch,
publish_resident_provider_readiness, reap_exited_child_process, resident_cognitive_runtime_id,
resident_prepared_launch_thread_id, resident_self_child_claim,
resident_self_local_provider_status, retain_completed_runtime_sessions,
retain_coordinator_run_receipts, retain_failed_runtime_worker_attempts,
retain_fulfilled_runtime_worker_attempts, retain_resident_self_lifecycles,
@ -331,8 +331,7 @@ fn cycle(
&args.feedback_target_repository,
&Utc::now().to_rfc3339(),
)?;
ingest_resident_self_domain_pressure(
&args.state_store,
materialize_resident_self_domain_obligations(
&args.policy.runtime_store,
&args.persona_feedback_store,
&cognitive_runtime_id,
@ -340,7 +339,7 @@ fn cycle(
&args.policy.workspace.display().to_string(),
now,
)?;
ingest_resident_self_coordinator_continuation_pressure(
ingest_resident_self_current_work_pressure(
&args.state_store,
&args.policy.runtime_store,
now,

View file

@ -33,6 +33,15 @@ pub struct EpiphanyCurrentWorkProjection {
pub hands_frontier_ready: bool,
}
impl EpiphanyCurrentWorkProjection {
pub fn projection_digest(&self) -> Result<String> {
Ok(format!(
"sha256:{:x}",
Sha256::digest(rmp_serde::to_vec_named(self)?)
))
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum EpiphanyAgentPassContinuationAction {
@ -3355,18 +3364,50 @@ mod tests {
current_work.mind_projection_digest,
crate::assemble_mind_view(&store)?.projection_digest
);
assert_eq!(crate::repository_body_read_counters(), (0, 0));
assert_current_work_reentry_is_read_only(&store, &current_work)?;
let resident_pressure = crate::resident_self_body_modeling_pressure(&store, 1)?
.expect("unresolved Body work must create Resident Self pressure");
let mut distinct_launch = current_work.clone();
distinct_launch
.body_modeling
.as_mut()
.expect("fixture has Body Modeling work")
.work_id
.push_str("-distinct-request");
assert_eq!(
resident_pressure.provenance_ref,
distinct_launch.body_modeling_action,
current_work.body_modeling_action
);
assert_ne!(
distinct_launch.projection_digest()?,
current_work.projection_digest()?,
"distinct exact work cannot alias merely because its route action matches"
);
let resident_store = temp.path().join("resident-self.cc");
assert!(crate::ingest_resident_self_current_work_pressure(
&resident_store,
&store,
1,
)?);
let current_work_grant = crate::heartbeat_issue_resident_self_grant(
&resident_store,
"current-work-schedule",
"current-work-action",
2,
)?
.expect("the exact current-work projection should receive one grant");
assert_eq!(
current_work_grant.pressure_kind,
crate::RESIDENT_SELF_CURRENT_WORK_PRESSURE_KIND
);
assert_eq!(
current_work_grant.provenance_ref,
format!(
"{}{}",
crate::RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX,
projected_work.work_id
"{}{}{}",
crate::RESIDENT_SELF_CURRENT_WORK_PROVENANCE_PREFIX,
current_work.projection_digest()?,
"/launchModeling"
)
);
assert_eq!(crate::repository_body_read_counters(), (0, 0));
assert_current_work_reentry_is_read_only(&store, &current_work)?;
let scheduled = launch_current_body_modeling_work(
&store,
EpiphanyBodyModelingLaunchOptions {
@ -3382,8 +3423,41 @@ mod tests {
scheduled_work.body_modeling_action,
Some(EpiphanyAgentPassContinuationAction::Wait)
);
let resident_policy = crate::ResidentSelfPolicy {
workspace: temp.path().join("workspace"),
coordinator_bin: temp.path().join("epiphany-mvp-coordinator"),
model_runtime_bin: temp.path().join("epiphany-model-runtime"),
tool_adapter_bin: temp.path().join("epiphany-tool-mcp-runtime"),
runtime_store: store.clone(),
local_verse_store: temp.path().join("local-verse.cc"),
agent_memory_store: temp.path().join("mind.cc"),
artifact_root: temp.path().join("artifacts"),
codex_home: temp.path().join("codex-home"),
mcp_config: temp.path().join("mcp.toml"),
model_provider: "openrouter".into(),
model: "stealth/ox-alpha".into(),
provider_credential_path: None,
max_steps: 4,
turn_timeout_seconds: 600,
cooldown_seconds: 10,
idle_sleep_seconds: 2,
failure_backoff_seconds: 30,
release_commit: "release-commit".into(),
release_manifest_digest: "sha256:release-manifest".into(),
release_store: temp.path().join("release.cc"),
release_runtime_id: "runtime".into(),
release_id: "release-id".into(),
release_witness_sha256: "sha256:release-witness".into(),
};
assert!(
crate::prepare_resident_self_launch(&resident_store, &resident_policy, 3)?.is_none(),
"a grant derived from the prior Mind projection must not launch"
);
assert!(crate::pending_resident_self_grant(&resident_store)?.is_none());
let supersession_acks = crate::pending_resident_self_acks(&resident_store)?;
assert_eq!(supersession_acks.len(), 1);
assert_eq!(supersession_acks[0].terminal_status, "superseded");
assert_current_work_reentry_is_read_only(&store, &scheduled_work)?;
assert!(crate::resident_self_body_modeling_pressure(&store, 2)?.is_none());
let mut scheduled_cache = crate::runtime_spine_cache(&store)?;
scheduled_cache.pull_all_backing_stores()?;
assert!(
@ -3494,35 +3568,10 @@ mod tests {
project_current_work(&store)?.body_modeling_action,
Some(EpiphanyAgentPassContinuationAction::Review)
);
let continuation = crate::EpiphanyCoordinatorRunReceipt {
schema_version: crate::COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION.into(),
receipt_id: "body-continuation".into(),
session_id: crate::EPIPHANY_RUNTIME_ROOT_SESSION_ID.into(),
thread_id: "transport-thread".into(),
mode: "execute".into(),
status: "planned".into(),
final_action: "waitForModelingResult".into(),
final_reason: None,
step_count: 1,
created_at: "2026-08-17T00:00:04Z".into(),
model_provider: None,
runtime_store: store.display().to_string(),
artifact_refs: Vec::new(),
sealed_artifact_refs: Vec::new(),
metadata: Default::default(),
resident_grant_id: None,
resident_launch_digest: None,
resident_policy_digest: None,
resident_argv_digest: None,
resident_objective_digest: None,
resident_release_commit: None,
resident_release_manifest_digest: None,
resident_executable_digest: None,
final_runtime_job_id: Some(result.job_id.clone()),
};
assert_eq!(
crate::resident_self::resident_self_safe_continuation_action(&store, &continuation)?,
Some("reviewModelingResult".into())
crate::resident_self::resident_self_current_work_action(&store)?
.map(|(_, action)| action),
Some("reviewModelingResult".into()),
);
let receipt = accept_body_modeling_result(&store, &result.job_id, "2026-08-17T00:00:05Z")?;
assert_eq!(
@ -3534,10 +3583,7 @@ mod tests {
let completed_work = project_current_work(&store)?;
assert!(completed_work.body_modeling.is_none());
assert!(completed_work.body_modeling_action.is_none());
assert!(
crate::resident_self::resident_self_safe_continuation_action(&store, &continuation)?
.is_none()
);
assert!(crate::resident_self::resident_self_current_work_action(&store)?.is_none());
assert_eq!(crate::repository_body_read_counters(), (0, 0));
assert_current_work_reentry_is_read_only(&store, &completed_work)?;

View file

@ -1181,6 +1181,7 @@ pub use surfaces::epiphany_view_needs_reorientation_inputs;
pub use surfaces::epiphany_view_needs_runtime_store;
pub use surfaces::interpret_runtime_reorient_worker_result;
pub use surfaces::interpret_runtime_role_worker_result;
pub use surfaces::recommend_coordinator_action;
pub use surfaces::recommend_crrc_action;
pub use surfaces::render_role_board_note;
pub use surfaces::review_role_self_patch_document;

View file

@ -14,15 +14,13 @@ pub const RESIDENT_SELF_RUNTIME_RECEIPT_SCHEMA_VERSION: &str =
pub const RESIDENT_SELF_PRESSURE_SCHEMA_VERSION: &str = "epiphany.resident_self.pressure.v0";
pub const RESIDENT_SELF_COORDINATOR_CONTINUATION_PRESSURE_KIND: &str =
"coordinator-internal-continuation";
pub const RESIDENT_SELF_CURRENT_WORK_PRESSURE_KIND: &str = "current-work";
pub const RESIDENT_SELF_ATLAS_MODELING_PRESSURE_KIND: &str = "atlas-impact-modeling";
pub const RESIDENT_SELF_ATLAS_SOUL_PRESSURE_KIND: &str = "atlas-impact-soul";
pub const RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND: &str = "body-modeling";
pub const RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX: &str = "cultcache://body-modeling-work/";
pub const RESIDENT_SELF_ATLAS_IMPACT_PROVENANCE_PREFIX: &str = "cultcache://atlas-impact-proposal/";
pub const RESIDENT_SELF_ATLAS_NO_HANDS_AUTHORITY_CLAUSE: &str =
"This wake grants no Hands authority.";
const RESIDENT_SELF_COORDINATOR_CONTINUATION_PROVENANCE_PREFIX: &str =
"cultcache://coordinator-run-receipt/";
pub const RESIDENT_SELF_CURRENT_WORK_PROVENANCE_PREFIX: &str = "cultcache://current-work/";
pub const RESIDENT_SELF_GRANT_SCHEMA_VERSION: &str = "epiphany.resident_self.heartbeat_grant.v1";
pub const RESIDENT_SELF_ACK_SCHEMA_VERSION: &str = "epiphany.resident_self.terminal_ack.v0";
pub const RESIDENT_SELF_CHILD_CLAIM_SCHEMA_VERSION: &str = "epiphany.resident_self.child_claim.v0";
@ -68,10 +66,11 @@ impl ResidentSelfPressure {
| "imagination-proposal"
| "repo-frontier-proposal-modeling"
| "repo-frontier-verdict-modeling"
| RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND
| "body-modeling"
| RESIDENT_SELF_ATLAS_MODELING_PRESSURE_KIND
| RESIDENT_SELF_ATLAS_SOUL_PRESSURE_KIND
| RESIDENT_SELF_COORDINATOR_CONTINUATION_PRESSURE_KIND
| RESIDENT_SELF_CURRENT_WORK_PRESSURE_KIND
)
|| self.pressure_id.trim().is_empty()
|| self.provenance_ref.trim().is_empty()
@ -107,15 +106,22 @@ impl ResidentSelfPressure {
));
}
}
if self.kind == RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND {
let work_id = self
if self.kind == RESIDENT_SELF_CURRENT_WORK_PRESSURE_KIND {
let (projection_digest, action) = self
.provenance_ref
.strip_prefix(RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX)
.filter(|value| !value.trim().is_empty())
.ok_or_else(|| anyhow!("Body Modeling pressure lost its exact work identity"))?;
if self.pressure_id != format!("body-modeling-{work_id}") {
.strip_prefix(RESIDENT_SELF_CURRENT_WORK_PROVENANCE_PREFIX)
.and_then(|value| value.split_once('/'))
.filter(|(projection_digest, action)| {
projection_digest.starts_with("sha256:")
&& !projection_digest.trim().is_empty()
&& !action.trim().is_empty()
})
.ok_or_else(|| anyhow!("current-work pressure lost its exact projection/action"))?;
if self.pressure_id != format!("current-work-{projection_digest}-{action}")
|| self.objective != resident_self_current_work_objective(action)
{
return Err(anyhow!(
"Body Modeling pressure identity does not match its work"
"current-work pressure must be derived from one exact Mind projection and action"
));
}
}
@ -717,16 +723,13 @@ pub fn resident_cognitive_runtime_id(runtime_store: &Path) -> Result<String> {
fn resident_self_atlas_required_action(pressure_kind: &str) -> Option<&'static str> {
match pressure_kind {
RESIDENT_SELF_ATLAS_MODELING_PRESSURE_KIND | RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND => {
Some("launchModeling")
}
RESIDENT_SELF_ATLAS_MODELING_PRESSURE_KIND => Some("launchModeling"),
RESIDENT_SELF_ATLAS_SOUL_PRESSURE_KIND => Some("launchVerification"),
_ => None,
}
}
fn resident_coordinator_binding_for_grant(
resident_store: &Path,
policy: &ResidentSelfPolicy,
grant: &ResidentSelfHeartbeatGrant,
) -> Result<Option<ResidentCoordinatorBinding>> {
@ -744,49 +747,38 @@ fn resident_coordinator_binding_for_grant(
}));
}
if grant.pressure_kind == RESIDENT_SELF_COORDINATOR_CONTINUATION_PRESSURE_KIND {
let receipt_id = grant
// Historical receipt-shaped pressure is audit/display state only. It
// can never recover behavioral authority in a current binary.
return Ok(None);
}
if grant.pressure_kind == RESIDENT_SELF_CURRENT_WORK_PRESSURE_KIND {
let (projection_digest, required_action) = grant
.provenance_ref
.strip_prefix(RESIDENT_SELF_COORDINATOR_CONTINUATION_PROVENANCE_PREFIX)
.filter(|value| !value.trim().is_empty())
.ok_or_else(|| anyhow!("coordinator continuation lost exact receipt provenance"))?;
let receipt = cache
.get::<crate::EpiphanyCoordinatorRunReceipt>(receipt_id)?
.ok_or_else(|| anyhow!("coordinator continuation receipt is missing"))?;
let required_action = if matches!(
receipt.status.as_str(),
"planned" | "needsReview" | "completed"
) {
resident_self_safe_continuation_action(&policy.runtime_store, &receipt)?
} else {
resident_self_failed_receipt_typed_continuation_action(
resident_store,
&policy.runtime_store,
&receipt,
)?
};
let Some(required_action) = required_action else {
.strip_prefix(RESIDENT_SELF_CURRENT_WORK_PROVENANCE_PREFIX)
.and_then(|value| value.split_once('/'))
.ok_or_else(|| anyhow!("current-work grant lost exact projection/action"))?;
let Some((current_projection_digest, current_action)) =
resident_self_current_work_action(&policy.runtime_store)?
else {
return Ok(None);
};
if projection_digest != current_projection_digest || required_action != current_action {
return Ok(None);
}
let thread_id = resident_coordinator_thread_id(&runtime_identity.runtime_id)?;
return Ok(Some(ResidentCoordinatorBinding {
runtime_id: runtime_identity.runtime_id,
thread_id: receipt.thread_id,
thread_id,
typed_request: None,
required_action: Some(required_action),
required_action: Some(current_action),
}));
}
let (prefix, request_flag) = match grant.pressure_kind.as_str() {
"imagination-consideration" => (
"cultcache://imagination-consideration/",
"--imagination-consideration-request-id",
),
"admitted-model-direction-consideration" => (
"cultcache://admitted-model-direction-consideration/",
"--admitted-model-direction-consideration-request-id",
),
"repo-frontier-proposal-modeling" => (
"cultcache://repo-frontier-proposal-modeling/",
"--proposal-modeling-request-id",
),
match grant.pressure_kind.as_str() {
"imagination-consideration"
| "admitted-model-direction-consideration"
| "repo-frontier-proposal-modeling"
| "repo-frontier-verdict-modeling"
| "body-modeling" => return Ok(None),
_ => {
return Ok(Some(ResidentCoordinatorBinding {
thread_id: resident_coordinator_thread_id(&runtime_identity.runtime_id)?,
@ -795,46 +787,7 @@ fn resident_coordinator_binding_for_grant(
required_action: None,
}));
}
};
let request_id = grant
.provenance_ref
.strip_prefix(prefix)
.filter(|value| !value.trim().is_empty())
.ok_or_else(|| anyhow!("consideration grant lost exact request provenance"))?;
let (runtime_id, thread_id) = match grant.pressure_kind.as_str() {
"imagination-consideration" => {
let request = cache
.get::<crate::ImaginationConsiderationRequest>(request_id)?
.ok_or_else(|| anyhow!("Imagination consideration request is missing"))?;
(request.runtime_id, request.thread_id)
}
"admitted-model-direction-consideration" => {
let request = cache
.get::<crate::AdmittedModelDirectionConsiderationRequest>(request_id)?
.ok_or_else(|| anyhow!("model direction consideration request is missing"))?;
(request.runtime_id, request.thread_id)
}
_ => {
let request = cache
.get::<crate::RepoFrontierProposalModelingRequest>(request_id)?
.ok_or_else(|| anyhow!("proposal Modeling request is missing"))?;
(request.runtime_id, request.thread_id)
}
};
if runtime_id != runtime_identity.runtime_id || thread_id.trim().is_empty() {
return Err(anyhow!(
"resident typed request {request_id} kind {} belongs to runtime {runtime_id} with thread-present={}, but mounted runtime store belongs to {}",
grant.pressure_kind,
!thread_id.trim().is_empty(),
runtime_identity.runtime_id,
));
}
Ok(Some(ResidentCoordinatorBinding {
runtime_id: runtime_identity.runtime_id,
thread_id,
typed_request: Some((request_flag.into(), request_id.into())),
required_action: None,
}))
}
fn prepared_coordinator_thread_id(argv: &[String]) -> Result<String> {
@ -1182,8 +1135,7 @@ fn enqueue_resident_self_pressure_idempotent(
Ok(true)
}
pub fn ingest_resident_self_domain_pressure(
resident_store: &Path,
pub fn materialize_resident_self_domain_obligations(
runtime_store: &Path,
persona_feedback_store: &Path,
runtime_id: &str,
@ -1191,49 +1143,14 @@ pub fn ingest_resident_self_domain_pressure(
workspace: &str,
now_millis: u64,
) -> Result<usize> {
let mut inserted = 0;
let mut materialized = 0;
let requested_at = chrono::DateTime::<chrono::Utc>::from_timestamp_millis(now_millis as i64)
.ok_or_else(|| anyhow!("resident consideration timestamp is out of range"))?
.to_rfc3339();
if let Some(pressure) = resident_self_body_modeling_pressure(runtime_store, now_millis)? {
inserted += usize::from(enqueue_resident_self_pressure_idempotent(
resident_store,
&pressure,
)?);
}
if let Some(request) =
if let Some(_request) =
crate::commit_admitted_model_direction_consideration_request(runtime_store, &requested_at)?
{
inserted += usize::from(enqueue_resident_self_pressure_idempotent(resident_store, &ResidentSelfPressure {
schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id: format!("admitted-model-direction-consideration-{}", request.request_id),
kind: "admitted-model-direction-consideration".into(),
provenance_ref: format!("cultcache://admitted-model-direction-consideration/{}", request.request_id),
objective: "Launch the exact typed admitted model direction consideration request; proposal only.".into(),
created_at_millis: now_millis, status: "pending".into(), consumed_by_grant_id: None, private_state_exposed: false,
})?);
}
if let Some(work) = crate::project_current_work(runtime_store)?
.frontier_verdict_modeling
.filter(|work| work.action == crate::EpiphanyAgentPassContinuationAction::Launch)
{
inserted += usize::from(enqueue_resident_self_pressure_idempotent(
resident_store,
&ResidentSelfPressure {
schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id: format!("repo-frontier-verdict-modeling-{}", work.request.request_id),
kind: "repo-frontier-verdict-modeling".into(),
provenance_ref: format!(
"cultcache://repo-frontier-verdict-modeling/{}",
work.request.request_id
),
objective: "Launch the exact Soul-verdict-bound Modeling obligation; no unrelated Mind mutation or external consequence.".into(),
created_at_millis: now_millis,
status: "pending".into(),
consumed_by_grant_id: None,
private_state_exposed: false,
},
)?);
materialized += 1;
}
crate::promote_autonomous_direction_options_for_modeling(
runtime_store,
@ -1241,37 +1158,10 @@ pub fn ingest_resident_self_domain_pressure(
workspace,
&requested_at,
)?;
// Autonomous promotion may select several Imagination options at once.
// Runtime request order is the single scheduler: expose pressure only for
// its current head, then let that request's exact launch binding reveal
// the next one on a later ingestion cycle.
if let Some(selection) = crate::project_current_work(runtime_store)?
.proposal_modeling
.filter(|work| work.action == crate::EpiphanyAgentPassContinuationAction::Launch)
.map(|work| work.request)
{
inserted += usize::from(enqueue_resident_self_pressure_idempotent(
resident_store,
&ResidentSelfPressure {
schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id: format!("repo-frontier-proposal-modeling-{}", selection.request_id),
kind: "repo-frontier-proposal-modeling".into(),
provenance_ref: format!(
"cultcache://repo-frontier-proposal-modeling/{}",
selection.request_id
),
objective: "Launch the exact autonomous proposal Modeling review; do not admit, adopt, act, release, or deploy.".into(),
created_at_millis: now_millis,
status: "pending".into(),
consumed_by_grant_id: None,
private_state_exposed: false,
},
)?);
}
for feedback in
crate::bridged_persona_feedback_ready_for_cognition(persona_feedback_store, runtime_id)?
{
let Some(request) = crate::commit_imagination_consideration_request(
let Some(_request) = crate::commit_imagination_consideration_request(
runtime_store,
persona_feedback_store,
&feedback.feedback_id,
@ -1283,236 +1173,61 @@ pub fn ingest_resident_self_domain_pressure(
else {
continue;
};
inserted += usize::from(enqueue_resident_self_pressure_idempotent(
resident_store,
&ResidentSelfPressure {
schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id: format!("imagination-consideration-{}", request.request_id),
kind: "imagination-consideration".into(),
provenance_ref: format!("cultcache://imagination-consideration/{}", request.request_id),
objective: "Launch the exact typed Imagination consideration request; do not adopt, act, release, or deploy.".into(),
created_at_millis: now_millis,
status: "pending".into(),
consumed_by_grant_id: None,
private_state_exposed: false,
},
)?);
materialized += 1;
}
Ok(inserted)
Ok(materialized)
}
pub fn resident_self_body_modeling_pressure(
runtime_store: &Path,
now_millis: u64,
) -> Result<Option<ResidentSelfPressure>> {
Ok(crate::project_current_work(runtime_store)?
.body_modeling
.map(|work| ResidentSelfPressure {
schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id: format!("body-modeling-{}", work.work_id),
kind: RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND.into(),
provenance_ref: format!(
"{RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX}{}",
work.work_id
),
objective: "Launch the exact unresolved repository Body Modeling obligation; no Hands, Persona, deployment, or external consequence.".into(),
created_at_millis: now_millis,
status: "pending".into(),
consumed_by_grant_id: None,
private_state_exposed: false,
}))
fn resident_self_current_work_objective(action: &str) -> String {
format!(
"Continue exact current Mind work action {action}; no receipt, event, role lane, or timestamp owns this route."
)
}
pub(crate) fn resident_self_safe_continuation_action(
pub(crate) fn resident_self_current_work_action(
runtime_store: &Path,
receipt: &crate::EpiphanyCoordinatorRunReceipt,
) -> Result<Option<String>> {
if matches!(
receipt.final_action.as_str(),
"launchResearch" | "waitForResearchResult" | "reviewResearchResult"
) {
return Ok(
crate::runtime_repo_frontier_research_lifecycle(runtime_store)?
.continuation_action()
.map(|action| action.as_str().to_string()),
);
}
if matches!(
receipt.final_action.as_str(),
"launchModeling" | "waitForModelingResult" | "reviewModelingResult"
) {
if let Some(job_id) = receipt.final_runtime_job_id.as_deref() {
if let Some(action) =
crate::body_modeling_continuation_action_for_job(runtime_store, job_id)?
{
return Ok(match action {
crate::EpiphanyAgentPassContinuationAction::Launch => {
Some("launchModeling".to_string())
}
crate::EpiphanyAgentPassContinuationAction::Wait => None,
crate::EpiphanyAgentPassContinuationAction::Review => {
Some("reviewModelingResult".to_string())
}
});
}
if let Some(action) =
crate::proposal_modeling_continuation_action_for_job(runtime_store, job_id)?
{
return Ok(match action {
crate::EpiphanyAgentPassContinuationAction::Launch => {
Some("launchModeling".to_string())
}
crate::EpiphanyAgentPassContinuationAction::Wait => None,
crate::EpiphanyAgentPassContinuationAction::Review => {
Some("reviewModelingResult".to_string())
}
});
}
if let Some(action) =
crate::frontier_verdict_modeling_continuation_action_for_job(runtime_store, job_id)?
{
return Ok(match action {
crate::EpiphanyAgentPassContinuationAction::Launch => {
Some("launchModeling".to_string())
}
crate::EpiphanyAgentPassContinuationAction::Wait => None,
crate::EpiphanyAgentPassContinuationAction::Review => {
Some("reviewModelingResult".to_string())
}
});
}
}
}
if matches!(
receipt.final_action.as_str(),
"launchVerification" | "waitForVerificationResult" | "reviewVerificationResult"
) {
return Ok(crate::project_current_work(runtime_store)?
.verification
.map(|work| match work.action {
crate::EpiphanyAgentPassContinuationAction::Launch => {
"launchVerification".to_string()
}
crate::EpiphanyAgentPassContinuationAction::Wait => {
"waitForVerificationResult".to_string()
}
crate::EpiphanyAgentPassContinuationAction::Review => {
"reviewVerificationResult".to_string()
}
}));
}
let direct = matches!(
receipt.final_action.as_str(),
"startFrontierPlanning"
| "launchImagination"
| "requestMindPlanReview"
| "launchMindPlanReview"
| "commitFrontierPlanDecision"
);
if direct {
return Ok(Some(receipt.final_action.clone()));
}
let action = match receipt.final_action.as_str() {
"waitForImaginationResult" => {
match crate::runtime_repo_frontier_planning_lifecycle(runtime_store)?.stage {
crate::RepoFrontierPlanningLifecycleStage::ImaginationResultReady => {
Some("requestMindPlanReview")
}
_ => None,
}
}
"waitForMindPlanResult" => {
match crate::runtime_repo_frontier_planning_lifecycle(runtime_store)?.stage {
crate::RepoFrontierPlanningLifecycleStage::MindResultReady => {
Some("commitFrontierPlanDecision")
}
_ => None,
}
}
_ => None,
};
Ok(action.map(str::to_string))
}
fn resident_self_failed_receipt_typed_continuation_action(
resident_store: &Path,
runtime_store: &Path,
receipt: &crate::EpiphanyCoordinatorRunReceipt,
) -> Result<Option<String>> {
if matches!(
receipt.status.as_str(),
"planned" | "needsReview" | "completed"
) {
return Ok(None);
}
let Some(grant_id) = receipt.resident_grant_id.as_deref() else {
return Ok(None);
};
let resident = state_cache(resident_store)?;
let Some(grant) = resident.get::<ResidentSelfHeartbeatGrant>(grant_id)? else {
return Ok(None);
};
if grant.consumed_at_millis.is_none()
|| grant.terminal_at_millis.is_none()
|| grant.private_state_exposed
{
return Ok(None);
}
let Some(request) = resident_self_typed_request_ref(&grant)? else {
return Ok(None);
};
) -> Result<Option<(String, String)>> {
let current_work = crate::project_current_work(runtime_store)?;
let projection_digest = current_work.projection_digest()?;
let decision = crate::recommend_coordinator_action(crate::EpiphanyCoordinatorInput {
mind_present: true,
should_prepare_compaction: false,
recommendation: crate::EpiphanyCoordinatorCrrcRecommendation {
action: crate::EpiphanyCrrcAction::Continue,
recommended_scene_action: None,
},
current_work,
});
if !matches!(
request,
crate::RuntimeTypedRequestRef::ProposalModeling(_)
| crate::RuntimeTypedRequestRef::FrontierVerdictModeling(_)
decision.action,
crate::EpiphanyCoordinatorAction::LaunchReorientWorker
| crate::EpiphanyCoordinatorAction::ReviewReorientResult
| crate::EpiphanyCoordinatorAction::LaunchResearch
| crate::EpiphanyCoordinatorAction::ReviewResearchResult
| crate::EpiphanyCoordinatorAction::LaunchModeling
| crate::EpiphanyCoordinatorAction::ReviewModelingResult
| crate::EpiphanyCoordinatorAction::LaunchVerification
| crate::EpiphanyCoordinatorAction::ReviewVerificationResult
| crate::EpiphanyCoordinatorAction::StartFrontierPlanning
| crate::EpiphanyCoordinatorAction::LaunchImagination
| crate::EpiphanyCoordinatorAction::RequestMindPlanReview
| crate::EpiphanyCoordinatorAction::LaunchMindPlanReview
| crate::EpiphanyCoordinatorAction::CommitFrontierPlanDecision
| crate::EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure
| crate::EpiphanyCoordinatorAction::LaunchImaginationConsideration
| crate::EpiphanyCoordinatorAction::LaunchAdmittedModelDirectionConsideration
) {
return Ok(None);
}
let acknowledgements = resident
.get_all::<ResidentSelfTerminalAck>()?
.into_iter()
.filter(|ack| ack.grant_id == grant.grant_id)
.collect::<Vec<_>>();
if acknowledgements.len() != 1 {
return Err(anyhow!(
"failed coordinator receipt typed continuation requires one exact terminal acknowledgement"
));
}
let acknowledgement = &acknowledgements[0];
if acknowledgement.coordinator_receipt_id != receipt.receipt_id
|| receipt.resident_launch_digest.as_deref() != Some(acknowledgement.launch_digest.as_str())
{
return Err(anyhow!(
"failed coordinator receipt typed continuation lost its exact resident binding"
));
}
let Some(evidence) = crate::runtime_typed_request_fulfillment(runtime_store, request)? else {
return Ok(None);
};
let action = match request {
crate::RuntimeTypedRequestRef::ProposalModeling(_) => {
crate::proposal_modeling_continuation_action_for_job(runtime_store, &evidence.job_id)?
}
crate::RuntimeTypedRequestRef::FrontierVerdictModeling(_) => {
crate::frontier_verdict_modeling_continuation_action_for_job(
runtime_store,
&evidence.job_id,
)?
}
_ => None,
};
Ok(match action {
Some(crate::EpiphanyAgentPassContinuationAction::Review) => {
Some("reviewModelingResult".to_string())
}
Some(crate::EpiphanyAgentPassContinuationAction::Launch) => {
Some("launchModeling".to_string())
}
Some(crate::EpiphanyAgentPassContinuationAction::Wait) | None => None,
})
let action = serde_json::to_value(decision.action)?
.as_str()
.filter(|value| !value.trim().is_empty())
.ok_or_else(|| anyhow!("current-work coordinator action did not serialize to a name"))?
.to_string();
Ok(Some((projection_digest, action)))
}
pub fn ingest_resident_self_coordinator_continuation_pressure(
pub fn ingest_resident_self_current_work_pressure(
resident_store: &Path,
runtime_store: &Path,
now_millis: u64,
@ -1523,44 +1238,21 @@ pub fn ingest_resident_self_coordinator_continuation_pressure(
if state.active_turn.is_some() || state.prepared_launch.is_some() {
return Ok(false);
}
let Some(receipt_id) = state.last_coordinator_receipt_id else {
let Some((projection_digest, action)) = resident_self_current_work_action(runtime_store)?
else {
return Ok(false);
};
let mut runtime = crate::runtime_spine_cache(runtime_store)?;
runtime.pull_all_backing_stores()?;
let Some(receipt) = runtime.get::<crate::EpiphanyCoordinatorRunReceipt>(&receipt_id)? else {
return Err(anyhow!(
"resident continuation lost its last exact coordinator receipt"
));
};
let action = if matches!(
receipt.status.as_str(),
"planned" | "needsReview" | "completed"
) {
resident_self_safe_continuation_action(runtime_store, &receipt)?
} else {
resident_self_failed_receipt_typed_continuation_action(
resident_store,
runtime_store,
&receipt,
)?
};
let Some(action) = action else {
return Ok(false);
};
let pressure_id = format!("resident-self-continuation-{receipt_id}-{action}");
let pressure_id = format!("current-work-{projection_digest}-{action}");
enqueue_resident_self_pressure_idempotent(
resident_store,
&ResidentSelfPressure {
schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id,
kind: RESIDENT_SELF_COORDINATOR_CONTINUATION_PRESSURE_KIND.into(),
kind: RESIDENT_SELF_CURRENT_WORK_PRESSURE_KIND.into(),
provenance_ref: format!(
"{RESIDENT_SELF_COORDINATOR_CONTINUATION_PROVENANCE_PREFIX}{receipt_id}"
),
objective: format!(
"Continue exact internal cognition action {action}; no Hands, Persona, deployment, or external consequence."
"{RESIDENT_SELF_CURRENT_WORK_PROVENANCE_PREFIX}{projection_digest}/{action}"
),
objective: resident_self_current_work_objective(&action),
created_at_millis: now_millis,
status: "pending".into(),
consumed_by_grant_id: None,
@ -2397,24 +2089,21 @@ pub fn resident_self_policy_digest(policy: &ResidentSelfPolicy) -> String {
])
}
fn supersede_unlaunched_resident_self_continuation(
fn supersede_unlaunched_resident_self_derived_grant(
path: &Path,
grant: &ResidentSelfHeartbeatGrant,
now_millis: u64,
) -> Result<ResidentSelfTerminalAck> {
if grant.pressure_kind != RESIDENT_SELF_COORDINATOR_CONTINUATION_PRESSURE_KIND
|| grant.consumed_at_millis.is_some()
if matches!(
grant.pressure_kind.as_str(),
"operator-objective" | "persona-feedback"
) || grant.consumed_at_millis.is_some()
|| grant.terminal_at_millis.is_some()
{
return Err(anyhow!(
"only an exact unlaunched coordinator continuation grant may be superseded"
"only an exact unlaunched derived grant may be superseded"
));
}
let receipt_id = grant
.provenance_ref
.strip_prefix(RESIDENT_SELF_COORDINATOR_CONTINUATION_PROVENANCE_PREFIX)
.filter(|value| !value.trim().is_empty())
.ok_or_else(|| anyhow!("superseded continuation lost receipt provenance"))?;
let cache = state_cache(path)?;
let mut state = cache
.get::<ResidentSelfState>(RESIDENT_SELF_STATE_KEY)?
@ -2443,7 +2132,7 @@ fn supersede_unlaunched_resident_self_continuation(
let launch_digest = digest_parts([
"resident-self-unlaunched-superseded",
grant.grant_id.as_str(),
receipt_id,
grant.provenance_ref.as_str(),
]);
let ack = ResidentSelfTerminalAck {
schema_version: RESIDENT_SELF_ACK_SCHEMA_VERSION.into(),
@ -2452,7 +2141,7 @@ fn supersede_unlaunched_resident_self_continuation(
heartbeat_schedule_id: grant.heartbeat_schedule_id.clone(),
heartbeat_action_id: grant.heartbeat_action_id.clone(),
launch_digest,
coordinator_receipt_id: receipt_id.into(),
coordinator_receipt_id: format!("resident-self-superseded-input-{}", grant.grant_id),
terminal_status: "superseded".into(),
completed_at_millis: now_millis,
consumed_by_heartbeat_at_millis: None,
@ -2495,7 +2184,7 @@ fn supersede_unlaunched_resident_self_continuation(
&[expected_state, expected_pressure, expected_grant],
vec![state_entry, pressure_entry, grant_entry, ack_entry],
)? {
return Err(anyhow!("resident Self lost superseded-continuation CAS"));
return Err(anyhow!("resident Self lost derived-grant supersession CAS"));
}
Ok(ack)
}
@ -2519,8 +2208,8 @@ pub fn prepare_resident_self_launch(
let Some(mut grant) = pending_resident_self_grant(path)? else {
return Ok(None);
};
let Some(binding) = resident_coordinator_binding_for_grant(path, policy, &grant)? else {
supersede_unlaunched_resident_self_continuation(path, &grant, now_millis)?;
let Some(binding) = resident_coordinator_binding_for_grant(policy, &grant)? else {
supersede_unlaunched_resident_self_derived_grant(path, &grant, now_millis)?;
return Ok(None);
};
let wake = ResidentSelfWake::Explicit {
@ -3316,6 +3005,35 @@ pub fn load_resident_self_state(path: &Path) -> Result<ResidentSelfState> {
mod coordinator_launch_contract_tests {
use super::*;
fn test_policy(root: &Path, runtime_store: PathBuf) -> ResidentSelfPolicy {
ResidentSelfPolicy {
workspace: root.join("workspace"),
coordinator_bin: root.join("epiphany-mvp-coordinator"),
model_runtime_bin: root.join("epiphany-model-runtime"),
tool_adapter_bin: root.join("epiphany-tool-mcp-runtime"),
runtime_store,
local_verse_store: root.join("local-verse.cc"),
agent_memory_store: root.join("mind.cc"),
artifact_root: root.join("artifacts"),
codex_home: root.join("codex-home"),
mcp_config: root.join("mcp.toml"),
model_provider: "openrouter".into(),
model: "stealth/ox-alpha".into(),
provider_credential_path: None,
max_steps: 4,
turn_timeout_seconds: 600,
cooldown_seconds: 10,
idle_sleep_seconds: 2,
failure_backoff_seconds: 30,
release_commit: "release-commit".into(),
release_manifest_digest: "sha256:release-manifest".into(),
release_store: root.join("release.cc"),
release_runtime_id: "epiphany-runtime".into(),
release_id: "release-id".into(),
release_witness_sha256: "sha256:release-witness".into(),
}
}
#[test]
fn coordinator_argv_uses_only_coordinator_owned_state_inputs() {
let policy = ResidentSelfPolicy {
@ -3362,6 +3080,50 @@ mod coordinator_launch_contract_tests {
]
}));
}
#[test]
fn historical_coordinator_receipt_pressure_has_no_launch_authority() -> Result<()> {
let temp = tempfile::tempdir()?;
let runtime_store = temp.path().join("runtime.cc");
crate::initialize_runtime_spine(
&runtime_store,
crate::RuntimeSpineInitOptions {
runtime_id: "epiphany-runtime".into(),
display_name: "Epiphany".into(),
created_at: "2026-08-22T00:00:00Z".into(),
},
)?;
let policy = test_policy(temp.path(), runtime_store);
let grant = ResidentSelfHeartbeatGrant {
schema_version: RESIDENT_SELF_GRANT_SCHEMA_VERSION.into(),
grant_id: "legacy-receipt-grant".into(),
pressure_id: "legacy-receipt-pressure".into(),
pressure_kind: RESIDENT_SELF_COORDINATOR_CONTINUATION_PRESSURE_KIND.into(),
provenance_ref: "cultcache://coordinator-receipt/old-receipt".into(),
objective: "Replay the old receipt action".into(),
heartbeat_schedule_id: "schedule".into(),
heartbeat_action_id: "action".into(),
issued_at_millis: 1,
consumed_at_millis: None,
private_state_exposed: false,
terminal_at_millis: None,
terminal_status: None,
};
assert!(resident_coordinator_binding_for_grant(&policy, &grant)?.is_none());
Ok(())
}
#[test]
fn domain_materialization_has_no_scheduler_pressure_writer() {
let source = include_str!("resident_self.rs");
let body = source
.split("pub fn materialize_resident_self_domain_obligations")
.nth(1)
.and_then(|tail| tail.split("fn resident_self_current_work_objective").next())
.expect("domain materialization function must remain inspectable");
assert!(!body.contains("ResidentSelfPressure"));
assert!(!body.contains("enqueue_resident_self_pressure"));
}
}
#[cfg(test)]
@ -3512,26 +3274,6 @@ mod atlas_pressure_tests {
Ok(())
}
#[test]
fn body_modeling_pressure_is_keyed_by_exact_work() -> Result<()> {
let pressure = ResidentSelfPressure {
schema_version: RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id: "body-modeling-body-work-1".into(),
kind: RESIDENT_SELF_BODY_MODELING_PRESSURE_KIND.into(),
provenance_ref: format!("{RESIDENT_SELF_BODY_MODELING_PROVENANCE_PREFIX}body-work-1"),
objective: "Launch exact Body work".into(),
created_at_millis: 1,
status: "pending".into(),
consumed_by_grant_id: None,
private_state_exposed: false,
};
pressure.validate()?;
let mut hostile = pressure;
hostile.pressure_id = "body-modeling-body-work-2".into();
assert!(hostile.validate().is_err());
Ok(())
}
#[test]
fn atlas_pressure_cannot_wake_an_active_or_prepared_coordinator() -> Result<()> {
let active_store = test_store("active");

View file

@ -1,10 +1,7 @@
use epiphany_core::{
EpiphanyAgentPassContinuationAction, EpiphanyCoordinatorAction,
EpiphanyCoordinatorAutomationAction, EpiphanyCoordinatorCrrcRecommendation,
EpiphanyCoordinatorDecision, EpiphanyCoordinatorInput, EpiphanyCoordinatorRoleId,
EpiphanyCoordinatorAction, EpiphanyCoordinatorAutomationAction, EpiphanyCoordinatorDecision,
EpiphanyCoordinatorSceneAction, EpiphanyCoordinatorSourceSignals, EpiphanyCoordinatorStatus,
EpiphanyCoordinatorStatusInput, EpiphanyCrrcAction, EpiphanyCrrcSceneAction,
RepoFrontierPlanningLifecycleStage, RepoFrontierResearchContinuationAction,
EpiphanyCoordinatorStatusInput, EpiphanyCrrcSceneAction,
};
pub fn crrc_scene_action_to_coordinator_scene_action(
@ -29,18 +26,19 @@ pub fn derive_coordinator_status(
crrc_action: input.recommendation.action,
reorient_result_status: input.reorient_result_status,
};
let decision = recommend_coordinator_action(EpiphanyCoordinatorInput {
mind_present: input.mind_present,
should_prepare_compaction: input.pressure.should_prepare_compaction,
recommendation: EpiphanyCoordinatorCrrcRecommendation {
action: input.recommendation.action,
recommended_scene_action: input
.recommendation
.recommended_scene_action
.map(crrc_scene_action_to_coordinator_scene_action),
},
current_work: input.current_work,
});
let decision =
epiphany_core::recommend_coordinator_action(epiphany_core::EpiphanyCoordinatorInput {
mind_present: input.mind_present,
should_prepare_compaction: input.pressure.should_prepare_compaction,
recommendation: epiphany_core::EpiphanyCoordinatorCrrcRecommendation {
action: input.recommendation.action,
recommended_scene_action: input
.recommendation
.recommended_scene_action
.map(crrc_scene_action_to_coordinator_scene_action),
},
current_work: input.current_work,
});
EpiphanyCoordinatorStatus {
decision,
source_signals,
@ -48,293 +46,6 @@ pub fn derive_coordinator_status(
}
}
pub fn recommend_coordinator_action(
input: EpiphanyCoordinatorInput,
) -> EpiphanyCoordinatorDecision {
if !input.mind_present {
return decision(
EpiphanyCoordinatorAction::PrepareCheckpoint,
None,
Some(EpiphanyCoordinatorSceneAction::Update),
false,
false,
"Canonical keyed Mind is missing; admit an explicit operator objective before coordination continues.",
);
}
if let Some(work) = input.current_work.reorientation.as_ref() {
return continuation_decision(
work.action,
EpiphanyCoordinatorAction::LaunchReorientWorker,
EpiphanyCoordinatorAction::WaitForReorientWorker,
EpiphanyCoordinatorAction::ReviewReorientResult,
EpiphanyCoordinatorRoleId::Reorientation,
"continuity",
);
}
if input.should_prepare_compaction {
return decision(
EpiphanyCoordinatorAction::CompactRehydrateReorient,
Some(EpiphanyCoordinatorRoleId::Reorientation),
Some(EpiphanyCoordinatorSceneAction::Reorient),
false,
true,
"Context pressure requires a new continuity obligation over the current keyed Mind.",
);
}
if input.recommendation.action == EpiphanyCrrcAction::RegatherManually {
return decision(
EpiphanyCoordinatorAction::RegatherManually,
Some(EpiphanyCoordinatorRoleId::Research),
Some(EpiphanyCoordinatorSceneAction::Reorient),
true,
false,
"The accepted continuity decision requires explicit operator regather.",
);
}
if let Some(result) = planning_decision(input.current_work.frontier_planning_stage) {
return result;
}
if let Some(work) = input.current_work.proposal_modeling.as_ref() {
return modeling_decision(work.action, "proposal Modeling");
}
if let Some(action) = input.current_work.body_modeling_action {
return modeling_decision(action, "Body Modeling");
}
if let Some(work) = input.current_work.frontier_verdict_modeling.as_ref() {
return modeling_decision(work.action, "frontier-verdict Modeling");
}
if let Some(work) = input.current_work.verification.as_ref() {
return continuation_decision(
work.action,
EpiphanyCoordinatorAction::LaunchVerification,
EpiphanyCoordinatorAction::ReviewVerificationResult,
EpiphanyCoordinatorAction::ReviewVerificationResult,
EpiphanyCoordinatorRoleId::Verification,
"Verification",
);
}
if let Some(action) = input.current_work.research_continuation_action {
return match action {
RepoFrontierResearchContinuationAction::LaunchResearch => decision(
EpiphanyCoordinatorAction::LaunchResearch,
Some(EpiphanyCoordinatorRoleId::Research),
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
false,
true,
"The exact external-evidence obligation requires an Eyes attempt.",
),
RepoFrontierResearchContinuationAction::ReviewResearchResult => decision(
EpiphanyCoordinatorAction::ReviewResearchResult,
Some(EpiphanyCoordinatorRoleId::Research),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
true,
false,
"The exact Eyes result awaits Mind admission.",
),
};
}
if let Some(work) = input.current_work.imagination_considerations.first() {
return continuation_decision(
work.action,
EpiphanyCoordinatorAction::LaunchImaginationConsideration,
EpiphanyCoordinatorAction::WaitForImaginationConsideration,
EpiphanyCoordinatorAction::WaitForImaginationConsideration,
EpiphanyCoordinatorRoleId::Imagination,
"Persona-feedback Imagination consideration",
);
}
if let Some(work) = input
.current_work
.admitted_model_direction_consideration
.as_ref()
{
return continuation_decision(
work.action,
EpiphanyCoordinatorAction::LaunchAdmittedModelDirectionConsideration,
EpiphanyCoordinatorAction::WaitForAdmittedModelDirectionConsideration,
EpiphanyCoordinatorAction::WaitForAdmittedModelDirectionConsideration,
EpiphanyCoordinatorRoleId::Imagination,
"admitted-model direction consideration",
);
}
if input.current_work.hands_frontier_ready {
return decision(
EpiphanyCoordinatorAction::ContinueImplementation,
Some(EpiphanyCoordinatorRoleId::Implementation),
None,
false,
false,
"Mind has an exact actionable Hands frontier route.",
);
}
decision(
EpiphanyCoordinatorAction::AwaitFrontierProposal,
Some(EpiphanyCoordinatorRoleId::Imagination),
None,
false,
false,
"No unresolved typed work obligation exists; await a new Body, evidence, proposal, or continuity mutation.",
)
}
fn decision(
action: EpiphanyCoordinatorAction,
target_role: Option<EpiphanyCoordinatorRoleId>,
recommended_scene_action: Option<EpiphanyCoordinatorSceneAction>,
requires_review: bool,
can_auto_run: bool,
reason: &str,
) -> EpiphanyCoordinatorDecision {
EpiphanyCoordinatorDecision {
action,
target_role,
recommended_scene_action,
requires_review,
can_auto_run,
reason: reason.to_string(),
}
}
fn modeling_decision(
action: EpiphanyAgentPassContinuationAction,
label: &str,
) -> EpiphanyCoordinatorDecision {
continuation_decision(
action,
EpiphanyCoordinatorAction::LaunchModeling,
EpiphanyCoordinatorAction::WaitForModelingResult,
EpiphanyCoordinatorAction::ReviewModelingResult,
EpiphanyCoordinatorRoleId::Modeling,
label,
)
}
fn continuation_decision(
action: EpiphanyAgentPassContinuationAction,
launch: EpiphanyCoordinatorAction,
wait: EpiphanyCoordinatorAction,
review: EpiphanyCoordinatorAction,
role: EpiphanyCoordinatorRoleId,
label: &str,
) -> EpiphanyCoordinatorDecision {
match action {
EpiphanyAgentPassContinuationAction::Launch => decision(
launch,
Some(role),
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
false,
true,
&format!("The exact {label} obligation has no live attempt."),
),
EpiphanyAgentPassContinuationAction::Wait => decision(
wait,
Some(role),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
false,
false,
&format!("The exact {label} attempt is still live."),
),
EpiphanyAgentPassContinuationAction::Review => decision(
review,
Some(role),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
true,
false,
&format!("The exact {label} result awaits its family admission owner."),
),
}
}
fn planning_decision(
stage: RepoFrontierPlanningLifecycleStage,
) -> Option<EpiphanyCoordinatorDecision> {
let value = match stage {
RepoFrontierPlanningLifecycleStage::Ready => decision(
EpiphanyCoordinatorAction::StartFrontierPlanning,
Some(EpiphanyCoordinatorRoleId::Imagination),
None,
false,
true,
"An exact frontier planning obligation is ready to become a typed request.",
),
RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady => decision(
EpiphanyCoordinatorAction::LaunchImagination,
Some(EpiphanyCoordinatorRoleId::Imagination),
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
false,
true,
"The exact frontier planning request awaits Imagination.",
),
RepoFrontierPlanningLifecycleStage::ImaginationRunning => decision(
EpiphanyCoordinatorAction::WaitForImaginationResult,
Some(EpiphanyCoordinatorRoleId::Imagination),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
false,
false,
"The exact frontier Imagination attempt is still live.",
),
RepoFrontierPlanningLifecycleStage::ImaginationFailed => decision(
EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure,
Some(EpiphanyCoordinatorRoleId::Imagination),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
true,
false,
"The exact frontier Imagination attempt failed.",
),
RepoFrontierPlanningLifecycleStage::ImaginationResultReady => decision(
EpiphanyCoordinatorAction::RequestMindPlanReview,
None,
None,
false,
true,
"The exact Imagination candidate awaits a typed Mind request.",
),
RepoFrontierPlanningLifecycleStage::MindLaunchReady => decision(
EpiphanyCoordinatorAction::LaunchMindPlanReview,
None,
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
false,
true,
"The exact Mind plan request has no live attempt.",
),
RepoFrontierPlanningLifecycleStage::MindRunning => decision(
EpiphanyCoordinatorAction::WaitForMindPlanResult,
None,
Some(EpiphanyCoordinatorSceneAction::RoleResult),
false,
false,
"The exact Mind plan attempt is still live.",
),
RepoFrontierPlanningLifecycleStage::MindFailed => decision(
EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure,
None,
Some(EpiphanyCoordinatorSceneAction::RoleResult),
true,
false,
"The exact Mind plan attempt failed.",
),
RepoFrontierPlanningLifecycleStage::MindResultReady => decision(
EpiphanyCoordinatorAction::CommitFrontierPlanDecision,
None,
None,
false,
true,
"The exact Mind judgment awaits atomic plan admission.",
),
RepoFrontierPlanningLifecycleStage::Unavailable
| RepoFrontierPlanningLifecycleStage::Terminal => return None,
};
Some(value)
}
pub fn coordinator_automation_action(
decision: &EpiphanyCoordinatorDecision,
) -> EpiphanyCoordinatorAutomationAction {
@ -355,6 +66,11 @@ pub fn coordinator_automation_action(
#[cfg(test)]
mod tests {
use super::*;
use epiphany_core::{
EpiphanyAgentPassContinuationAction, EpiphanyCoordinatorCrrcRecommendation,
EpiphanyCoordinatorInput, EpiphanyCrrcAction, RepoFrontierPlanningLifecycleStage,
RepoFrontierResearchContinuationAction, recommend_coordinator_action,
};
fn current_work() -> epiphany_core::EpiphanyCurrentWorkProjection {
epiphany_core::EpiphanyCurrentWorkProjection {
@ -413,19 +129,4 @@ mod tests {
EpiphanyCoordinatorAction::LaunchResearch
);
}
#[test]
fn source_has_no_aggregate_or_latest_lane_routing() {
let source = include_str!("coordinator.rs");
let production = source.split("#[cfg(test)]").next().unwrap_or(source);
for forbidden in [
"EpiphanyThreadState",
"accepted_after",
"latest_result",
"finding_signals",
"state_revision",
] {
assert!(!production.contains(forbidden));
}
}
}

View file

@ -0,0 +1,311 @@
use crate::{
EpiphanyAgentPassContinuationAction, EpiphanyCoordinatorAction, EpiphanyCoordinatorDecision,
EpiphanyCoordinatorInput, EpiphanyCoordinatorRoleId, EpiphanyCoordinatorSceneAction,
EpiphanyCrrcAction, RepoFrontierPlanningLifecycleStage, RepoFrontierResearchContinuationAction,
};
pub fn recommend_coordinator_action(
input: EpiphanyCoordinatorInput,
) -> EpiphanyCoordinatorDecision {
if !input.mind_present {
return decision(
EpiphanyCoordinatorAction::PrepareCheckpoint,
None,
Some(EpiphanyCoordinatorSceneAction::Update),
false,
false,
"Canonical keyed Mind is missing; admit an explicit operator objective before coordination continues.",
);
}
if let Some(work) = input.current_work.reorientation.as_ref() {
return continuation_decision(
work.action,
EpiphanyCoordinatorAction::LaunchReorientWorker,
EpiphanyCoordinatorAction::WaitForReorientWorker,
EpiphanyCoordinatorAction::ReviewReorientResult,
EpiphanyCoordinatorRoleId::Reorientation,
"continuity",
);
}
if input.should_prepare_compaction {
return decision(
EpiphanyCoordinatorAction::CompactRehydrateReorient,
Some(EpiphanyCoordinatorRoleId::Reorientation),
Some(EpiphanyCoordinatorSceneAction::Reorient),
false,
true,
"Context pressure requires a new continuity obligation over the current keyed Mind.",
);
}
if input.recommendation.action == EpiphanyCrrcAction::RegatherManually {
return decision(
EpiphanyCoordinatorAction::RegatherManually,
Some(EpiphanyCoordinatorRoleId::Research),
Some(EpiphanyCoordinatorSceneAction::Reorient),
true,
false,
"The accepted continuity decision requires explicit operator regather.",
);
}
if let Some(result) = planning_decision(input.current_work.frontier_planning_stage) {
return result;
}
if let Some(work) = input.current_work.proposal_modeling.as_ref() {
return modeling_decision(work.action, "proposal Modeling");
}
if let Some(action) = input.current_work.body_modeling_action {
return modeling_decision(action, "Body Modeling");
}
if let Some(work) = input.current_work.frontier_verdict_modeling.as_ref() {
return modeling_decision(work.action, "frontier-verdict Modeling");
}
if let Some(work) = input.current_work.verification.as_ref() {
return continuation_decision(
work.action,
EpiphanyCoordinatorAction::LaunchVerification,
EpiphanyCoordinatorAction::ReviewVerificationResult,
EpiphanyCoordinatorAction::ReviewVerificationResult,
EpiphanyCoordinatorRoleId::Verification,
"Verification",
);
}
if let Some(action) = input.current_work.research_continuation_action {
return match action {
RepoFrontierResearchContinuationAction::LaunchResearch => decision(
EpiphanyCoordinatorAction::LaunchResearch,
Some(EpiphanyCoordinatorRoleId::Research),
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
false,
true,
"The exact external-evidence obligation requires an Eyes attempt.",
),
RepoFrontierResearchContinuationAction::ReviewResearchResult => decision(
EpiphanyCoordinatorAction::ReviewResearchResult,
Some(EpiphanyCoordinatorRoleId::Research),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
true,
false,
"The exact Eyes result awaits Mind admission.",
),
};
}
if let Some(work) = input.current_work.imagination_considerations.first() {
return continuation_decision(
work.action,
EpiphanyCoordinatorAction::LaunchImaginationConsideration,
EpiphanyCoordinatorAction::WaitForImaginationConsideration,
EpiphanyCoordinatorAction::WaitForImaginationConsideration,
EpiphanyCoordinatorRoleId::Imagination,
"Persona-feedback Imagination consideration",
);
}
if let Some(work) = input
.current_work
.admitted_model_direction_consideration
.as_ref()
{
return continuation_decision(
work.action,
EpiphanyCoordinatorAction::LaunchAdmittedModelDirectionConsideration,
EpiphanyCoordinatorAction::WaitForAdmittedModelDirectionConsideration,
EpiphanyCoordinatorAction::WaitForAdmittedModelDirectionConsideration,
EpiphanyCoordinatorRoleId::Imagination,
"admitted-model direction consideration",
);
}
if input.current_work.hands_frontier_ready {
return decision(
EpiphanyCoordinatorAction::ContinueImplementation,
Some(EpiphanyCoordinatorRoleId::Implementation),
None,
false,
false,
"Mind has an exact actionable Hands frontier route.",
);
}
decision(
EpiphanyCoordinatorAction::AwaitFrontierProposal,
Some(EpiphanyCoordinatorRoleId::Imagination),
None,
false,
false,
"No unresolved typed work obligation exists; await a new Body, evidence, proposal, or continuity mutation.",
)
}
fn decision(
action: EpiphanyCoordinatorAction,
target_role: Option<EpiphanyCoordinatorRoleId>,
recommended_scene_action: Option<EpiphanyCoordinatorSceneAction>,
requires_review: bool,
can_auto_run: bool,
reason: &str,
) -> EpiphanyCoordinatorDecision {
EpiphanyCoordinatorDecision {
action,
target_role,
recommended_scene_action,
requires_review,
can_auto_run,
reason: reason.to_string(),
}
}
fn modeling_decision(
action: EpiphanyAgentPassContinuationAction,
label: &str,
) -> EpiphanyCoordinatorDecision {
continuation_decision(
action,
EpiphanyCoordinatorAction::LaunchModeling,
EpiphanyCoordinatorAction::WaitForModelingResult,
EpiphanyCoordinatorAction::ReviewModelingResult,
EpiphanyCoordinatorRoleId::Modeling,
label,
)
}
fn continuation_decision(
action: EpiphanyAgentPassContinuationAction,
launch: EpiphanyCoordinatorAction,
wait: EpiphanyCoordinatorAction,
review: EpiphanyCoordinatorAction,
role: EpiphanyCoordinatorRoleId,
label: &str,
) -> EpiphanyCoordinatorDecision {
match action {
EpiphanyAgentPassContinuationAction::Launch => decision(
launch,
Some(role),
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
false,
true,
&format!("The exact {label} obligation has no live attempt."),
),
EpiphanyAgentPassContinuationAction::Wait => decision(
wait,
Some(role),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
false,
false,
&format!("The exact {label} attempt is still live."),
),
EpiphanyAgentPassContinuationAction::Review => decision(
review,
Some(role),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
true,
false,
&format!("The exact {label} result awaits its family admission owner."),
),
}
}
fn planning_decision(
stage: RepoFrontierPlanningLifecycleStage,
) -> Option<EpiphanyCoordinatorDecision> {
let value = match stage {
RepoFrontierPlanningLifecycleStage::Ready => decision(
EpiphanyCoordinatorAction::StartFrontierPlanning,
Some(EpiphanyCoordinatorRoleId::Imagination),
None,
false,
true,
"An exact frontier planning obligation is ready to become a typed request.",
),
RepoFrontierPlanningLifecycleStage::ImaginationLaunchReady => decision(
EpiphanyCoordinatorAction::LaunchImagination,
Some(EpiphanyCoordinatorRoleId::Imagination),
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
false,
true,
"The exact frontier planning request awaits Imagination.",
),
RepoFrontierPlanningLifecycleStage::ImaginationRunning => decision(
EpiphanyCoordinatorAction::WaitForImaginationResult,
Some(EpiphanyCoordinatorRoleId::Imagination),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
false,
false,
"The exact frontier Imagination attempt is still live.",
),
RepoFrontierPlanningLifecycleStage::ImaginationFailed => decision(
EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure,
Some(EpiphanyCoordinatorRoleId::Imagination),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
true,
false,
"The exact frontier Imagination attempt failed.",
),
RepoFrontierPlanningLifecycleStage::ImaginationResultReady => decision(
EpiphanyCoordinatorAction::RequestMindPlanReview,
None,
None,
false,
true,
"The exact Imagination candidate awaits a typed Mind request.",
),
RepoFrontierPlanningLifecycleStage::MindLaunchReady => decision(
EpiphanyCoordinatorAction::LaunchMindPlanReview,
None,
Some(EpiphanyCoordinatorSceneAction::RoleLaunch),
false,
true,
"The exact Mind plan request has no live attempt.",
),
RepoFrontierPlanningLifecycleStage::MindRunning => decision(
EpiphanyCoordinatorAction::WaitForMindPlanResult,
None,
Some(EpiphanyCoordinatorSceneAction::RoleResult),
false,
false,
"The exact Mind plan attempt is still live.",
),
RepoFrontierPlanningLifecycleStage::MindFailed => decision(
EpiphanyCoordinatorAction::ReviewFrontierPlanningFailure,
None,
Some(EpiphanyCoordinatorSceneAction::RoleResult),
true,
false,
"The exact Mind plan attempt failed.",
),
RepoFrontierPlanningLifecycleStage::MindResultReady => decision(
EpiphanyCoordinatorAction::CommitFrontierPlanDecision,
None,
None,
false,
true,
"The exact Mind judgment awaits atomic plan admission.",
),
RepoFrontierPlanningLifecycleStage::Unavailable
| RepoFrontierPlanningLifecycleStage::Terminal => return None,
};
Some(value)
}
#[cfg(test)]
mod authority_tests {
#[test]
fn source_has_no_aggregate_or_latest_lane_routing() {
let source = include_str!("coordinator_decision.rs");
let production = source.split("#[cfg(test)]").next().unwrap_or(source);
for forbidden in [
"EpiphanyThreadState",
"accepted_after",
"latest_result",
"finding_signals",
"state_revision",
"coordinator_run_receipt",
] {
assert!(!production.contains(forbidden));
}
}
}

View file

@ -1,4 +1,5 @@
mod coordinator_contract;
mod coordinator_decision;
mod crrc;
mod jobs;
mod planning;
@ -12,6 +13,7 @@ mod view;
mod worker_launch;
pub use coordinator_contract::*;
pub use coordinator_decision::recommend_coordinator_action;
pub use crrc::EpiphanyCrrcAction;
pub use crrc::EpiphanyCrrcInput;
pub use crrc::EpiphanyCrrcRecommendation;