Move MVP operator reads onto Epiphany view

This commit is contained in:
Meta Vens 2026-05-12 04:50:51 +01:00
commit 7b1e79a765
15 changed files with 1138 additions and 78 deletions

View file

@ -266,9 +266,14 @@ use codex_app_server_protocol::ThreadEpiphanyStateUpdatedSource;
use codex_app_server_protocol::ThreadEpiphanyUpdateParams;
use codex_app_server_protocol::ThreadEpiphanyUpdatePatch;
use codex_app_server_protocol::ThreadEpiphanyUpdateResponse;
use codex_app_server_protocol::ThreadEpiphanyViewCoordinator;
use codex_app_server_protocol::ThreadEpiphanyViewCrrc;
use codex_app_server_protocol::ThreadEpiphanyViewLens;
use codex_app_server_protocol::ThreadEpiphanyViewParams;
use codex_app_server_protocol::ThreadEpiphanyViewPlanning;
use codex_app_server_protocol::ThreadEpiphanyViewReorient;
use codex_app_server_protocol::ThreadEpiphanyViewResponse;
use codex_app_server_protocol::ThreadEpiphanyViewRoles;
use codex_app_server_protocol::ThreadForkParams;
use codex_app_server_protocol::ThreadForkResponse;
use codex_app_server_protocol::ThreadIncrementElicitationParams;
@ -4307,7 +4312,12 @@ impl CodexMessageProcessor {
vec![
ThreadEpiphanyViewLens::Scene,
ThreadEpiphanyViewLens::Jobs,
ThreadEpiphanyViewLens::Roles,
ThreadEpiphanyViewLens::Planning,
ThreadEpiphanyViewLens::Pressure,
ThreadEpiphanyViewLens::Reorient,
ThreadEpiphanyViewLens::Crrc,
ThreadEpiphanyViewLens::Coordinator,
]
} else {
lenses
@ -4336,7 +4346,17 @@ impl CodexMessageProcessor {
}
};
let retrieval_override = if lenses.contains(&ThreadEpiphanyViewLens::Jobs)
let needs_jobs = lenses.contains(&ThreadEpiphanyViewLens::Jobs)
|| lenses.contains(&ThreadEpiphanyViewLens::Roles)
|| lenses.contains(&ThreadEpiphanyViewLens::Crrc)
|| lenses.contains(&ThreadEpiphanyViewLens::Coordinator);
let needs_reorientation_inputs = lenses.contains(&ThreadEpiphanyViewLens::Roles)
|| lenses.contains(&ThreadEpiphanyViewLens::Reorient)
|| lenses.contains(&ThreadEpiphanyViewLens::Crrc)
|| lenses.contains(&ThreadEpiphanyViewLens::Coordinator);
let needs_pressure =
lenses.contains(&ThreadEpiphanyViewLens::Pressure) || needs_reorientation_inputs;
let retrieval_override = if (needs_jobs || needs_reorientation_inputs)
&& thread
.epiphany_state
.as_ref()
@ -4351,9 +4371,288 @@ impl CodexMessageProcessor {
} else {
None
};
let token_usage_info = if lenses.contains(&ThreadEpiphanyViewLens::Pressure) {
let watcher_snapshot = if needs_reorientation_inputs {
if let Some(loaded_thread) = loaded_thread.as_ref() {
let config_snapshot = loaded_thread.config_snapshot().await;
self.epiphany_invalidation_manager
.ensure_thread_watch(&thread_id, &config_snapshot.cwd)
.await;
Some(
self.epiphany_invalidation_manager
.snapshot(&thread_id)
.await,
)
} else {
None
}
} else {
None
};
let token_usage_info = if needs_pressure {
if let Some(loaded_thread) = loaded_thread.as_ref() {
loaded_thread.token_usage_info().await
} else {
match thread.path.as_deref() {
Some(path) => latest_token_usage_info_from_rollout_path(path).await,
None => None,
}
}
} else {
None
};
let pressure = needs_pressure.then(|| map_epiphany_pressure(token_usage_info.as_ref()));
let freshness = needs_reorientation_inputs.then(|| {
map_epiphany_freshness(
thread.epiphany_state.as_ref(),
retrieval_override.as_ref(),
watcher_snapshot.as_ref(),
)
});
let (state_revision, reorient_state_status, reorient_decision) =
if let (Some((state_revision, retrieval, graph, watcher)), Some(pressure)) =
(freshness.as_ref(), pressure.as_ref())
{
let (state_status, decision) = map_epiphany_reorient(
thread.epiphany_state.as_ref(),
pressure,
retrieval,
graph,
watcher,
);
(*state_revision, state_status, Some(decision))
} else {
(None, ThreadEpiphanyReorientStateStatus::Missing, None)
};
let jobs = if needs_jobs {
map_epiphany_jobs(thread.epiphany_state.as_ref(), retrieval_override.as_ref())
} else {
Vec::new()
};
let runtime_store_path = if lenses.contains(&ThreadEpiphanyViewLens::Roles)
|| lenses.contains(&ThreadEpiphanyViewLens::Crrc)
|| lenses.contains(&ThreadEpiphanyViewLens::Coordinator)
{
if let Some(loaded_thread) = loaded_thread.as_ref() {
Some(loaded_thread.epiphany_runtime_spine_store_path().await)
} else {
None
}
} else {
None
};
let reorient_job = jobs
.iter()
.find(|job| job.id == EPIPHANY_REORIENT_LAUNCH_BINDING_ID)
.cloned();
let (reorient_result_status, reorient_finding, reorient_result_note) = if runtime_store_path
.is_some()
|| lenses.contains(&ThreadEpiphanyViewLens::Crrc)
|| lenses.contains(&ThreadEpiphanyViewLens::Coordinator)
{
load_epiphany_reorient_result_snapshot(
thread.epiphany_state.as_ref(),
runtime_store_path.as_deref(),
EPIPHANY_REORIENT_LAUNCH_BINDING_ID,
)
.await
} else {
(
ThreadEpiphanyReorientResultStatus::MissingState,
None,
"Reorient result was not requested.".to_string(),
)
};
let checkpoint_present = thread
.epiphany_state
.as_ref()
.and_then(|state| state.investigation_checkpoint.as_ref())
.is_some();
let reorient_finding_accepted = reorient_finding.as_ref().is_some_and(|finding| {
thread
.epiphany_state
.as_ref()
.is_some_and(|state| epiphany_reorient_finding_already_accepted(state, finding))
});
let recommendation = if let (Some(pressure), Some(decision)) =
(pressure.as_ref(), reorient_decision.as_ref())
{
Some(map_epiphany_crrc_recommendation(
loaded,
reorient_state_status,
pressure,
decision,
reorient_result_status,
checkpoint_present,
reorient_finding.is_some(),
reorient_finding_accepted,
))
} else {
None
};
let roles = if let (Some(pressure), Some(decision), Some(recommendation)) = (
pressure.as_ref(),
reorient_decision.as_ref(),
recommendation.as_ref(),
) {
Some(map_epiphany_roles(
thread.epiphany_state.as_ref(),
&jobs,
decision,
pressure,
recommendation,
reorient_result_status,
reorient_job.as_ref(),
))
} else {
None
};
let coordinator_response = if lenses.contains(&ThreadEpiphanyViewLens::Coordinator) {
if let (Some(pressure), Some(recommendation), Some(roles)) =
(pressure.as_ref(), recommendation.as_ref(), roles.clone())
{
let (modeling_result_status, modeling_finding, _) =
if let Some(state) = thread.epiphany_state.as_ref() {
load_epiphany_role_result_snapshot(
state,
runtime_store_path.as_deref(),
ThreadEpiphanyRoleId::Modeling,
EPIPHANY_MODELING_ROLE_BINDING_ID,
)
.await
} else {
(
ThreadEpiphanyRoleResultStatus::MissingState,
None,
"No authoritative Epiphany state exists for this thread.".to_string(),
)
};
let modeling_result_accepted = modeling_finding.as_ref().is_some_and(|finding| {
thread
.epiphany_state
.as_ref()
.is_some_and(|state| epiphany_role_finding_already_accepted(state, finding))
});
let modeling_result_reviewable = modeling_finding
.as_ref()
.is_some_and(epiphany_modeling_finding_has_reviewable_state_patch);
let (verification_result_status, verification_finding, _) =
if let Some(state) = thread.epiphany_state.as_ref() {
load_epiphany_role_result_snapshot(
state,
runtime_store_path.as_deref(),
ThreadEpiphanyRoleId::Verification,
EPIPHANY_VERIFICATION_ROLE_BINDING_ID,
)
.await
} else {
(
ThreadEpiphanyRoleResultStatus::MissingState,
None,
"No authoritative Epiphany state exists for this thread.".to_string(),
)
};
let verification_result_accepted =
verification_finding.as_ref().is_some_and(|finding| {
thread.epiphany_state.as_ref().is_some_and(|state| {
epiphany_role_finding_already_accepted(state, finding)
})
});
let verification_result_covers_current_modeling =
thread.epiphany_state.as_ref().is_none_or(|state| {
epiphany_verification_finding_covers_current_modeling(
state,
modeling_result_accepted,
modeling_finding.as_ref(),
verification_finding.as_ref(),
)
});
let modeling_result_accepted_after_verification =
thread.epiphany_state.as_ref().is_some_and(|state| {
role_finding_accepted_after(
state,
modeling_finding.as_ref(),
verification_finding.as_ref(),
)
});
let implementation_evidence_after_verification =
thread.epiphany_state.as_ref().is_some_and(|state| {
implementation_evidence_after_role_finding(
state,
verification_finding.as_ref(),
)
});
let verification_result_cites_implementation_evidence =
thread.epiphany_state.as_ref().is_some_and(|state| {
epiphany_role_finding_cites_implementation_evidence(
state,
verification_finding.as_ref(),
)
});
let verification_result_allows_implementation = verification_result_accepted
&& verification_finding
.as_ref()
.is_some_and(epiphany_verification_finding_allows_implementation);
let verification_result_needs_evidence = verification_result_accepted
&& verification_finding
.as_ref()
.is_some_and(epiphany_verification_finding_needs_evidence);
let source_signals = ThreadEpiphanyCoordinatorSignals {
pressure_level: pressure.level,
should_prepare_compaction: pressure.should_prepare_compaction,
reorient_action: reorient_decision
.as_ref()
.map(|decision| decision.action)
.unwrap_or(ThreadEpiphanyReorientAction::Resume),
crrc_action: recommendation.action,
modeling_result_status,
verification_result_status,
reorient_result_status,
};
let coordinator = map_epiphany_coordinator(
reorient_state_status,
checkpoint_present,
pressure,
recommendation,
&roles,
&source_signals,
modeling_result_accepted,
modeling_result_reviewable,
modeling_result_accepted_after_verification,
implementation_evidence_after_verification,
verification_result_cites_implementation_evidence,
verification_result_covers_current_modeling,
verification_result_accepted,
verification_result_allows_implementation,
verification_result_needs_evidence,
reorient_finding_accepted,
);
let note = render_epiphany_coordinator_note(
recommendation.action,
pressure.level,
modeling_result_status,
verification_result_status,
reorient_result_status,
coordinator.action,
);
Some(ThreadEpiphanyViewCoordinator {
thread_id: thread_id.clone(),
source: if loaded {
ThreadEpiphanyRolesSource::Live
} else {
ThreadEpiphanyRolesSource::Stored
},
state_status: reorient_state_status,
state_revision,
action: coordinator.action,
target_role: coordinator.target_role,
recommended_scene_action: coordinator.recommended_scene_action,
requires_review: coordinator.requires_review,
can_auto_run: coordinator.can_auto_run,
reason: coordinator.reason,
source_signals,
roles,
note,
})
} else {
None
}
@ -4362,18 +4661,113 @@ impl CodexMessageProcessor {
};
let response = ThreadEpiphanyViewResponse {
thread_id,
thread_id: thread_id.clone(),
scene: lenses
.contains(&ThreadEpiphanyViewLens::Scene)
.then(|| map_epiphany_scene(thread.epiphany_state.as_ref(), loaded)),
jobs: if lenses.contains(&ThreadEpiphanyViewLens::Jobs) {
map_epiphany_jobs(thread.epiphany_state.as_ref(), retrieval_override.as_ref())
jobs.clone()
} else {
Vec::new()
},
roles: lenses.contains(&ThreadEpiphanyViewLens::Roles).then(|| {
let roles = roles.clone().unwrap_or_default();
ThreadEpiphanyViewRoles {
thread_id: thread_id.clone(),
source: if loaded {
ThreadEpiphanyRolesSource::Live
} else {
ThreadEpiphanyRolesSource::Stored
},
state_status: reorient_state_status,
state_revision,
note: render_epiphany_roles_note(
&roles,
reorient_state_status,
recommendation
.as_ref()
.map(|recommendation| recommendation.action)
.unwrap_or(ThreadEpiphanyCrrcAction::Continue),
),
roles,
}
}),
planning: lenses.contains(&ThreadEpiphanyViewLens::Planning).then(|| {
let (state_status, state_revision, planning, summary) =
map_epiphany_planning(thread.epiphany_state.as_ref());
ThreadEpiphanyViewPlanning {
thread_id: thread_id.clone(),
source: if loaded {
ThreadEpiphanyContextSource::Live
} else {
ThreadEpiphanyContextSource::Stored
},
state_status,
state_revision,
planning,
summary,
}
}),
pressure: lenses
.contains(&ThreadEpiphanyViewLens::Pressure)
.then(|| map_epiphany_pressure(token_usage_info.as_ref())),
.then(|| pressure.clone())
.flatten(),
reorient: lenses
.contains(&ThreadEpiphanyViewLens::Reorient)
.then(|| {
reorient_decision
.clone()
.map(|decision| ThreadEpiphanyViewReorient {
thread_id: thread_id.clone(),
source: if loaded {
ThreadEpiphanyReorientSource::Live
} else {
ThreadEpiphanyReorientSource::Stored
},
state_status: reorient_state_status,
state_revision,
decision,
})
})
.flatten(),
crrc: lenses
.contains(&ThreadEpiphanyViewLens::Crrc)
.then(|| {
let pressure = pressure.clone()?;
let decision = reorient_decision.clone()?;
let recommendation = recommendation.clone()?;
let available_actions = epiphany_scene_available_actions(
loaded,
thread.epiphany_state.is_some(),
checkpoint_present,
reorient_job.is_some(),
);
let note = format!(
"{} Result status: {:?}. {}",
recommendation.reason, reorient_result_status, reorient_result_note
);
Some(ThreadEpiphanyViewCrrc {
thread_id: thread_id.clone(),
source: if loaded {
ThreadEpiphanyReorientSource::Live
} else {
ThreadEpiphanyReorientSource::Stored
},
state_status: reorient_state_status,
state_revision,
pressure,
decision,
recommendation,
reorient_binding_id: EPIPHANY_REORIENT_LAUNCH_BINDING_ID.to_string(),
reorient_result_status,
reorient_job: reorient_job.clone(),
reorient_finding: reorient_finding.clone(),
available_actions,
note,
})
})
.flatten(),
coordinator: coordinator_response,
lenses,
};
self.outgoing.send_response(request_id, response).await;