Add Epiphany investigation checkpoints

This commit is contained in:
Meta Vens 2026-04-26 05:12:51 +01:00
commit 71ea1ed2ea
17 changed files with 578 additions and 40 deletions

View file

@ -5,6 +5,7 @@ use codex_protocol::protocol::EpiphanyGraphCheckpoint;
use codex_protocol::protocol::EpiphanyGraphFrontier;
use codex_protocol::protocol::EpiphanyGraphs;
use codex_protocol::protocol::EpiphanyInvariant;
use codex_protocol::protocol::EpiphanyInvestigationCheckpoint;
use codex_protocol::protocol::EpiphanyObservation;
use codex_protocol::protocol::EpiphanySubgoal;
use std::collections::HashSet;
@ -18,6 +19,7 @@ pub struct EpiphanyPromotionInput {
pub graphs: Option<EpiphanyGraphs>,
pub graph_frontier: Option<EpiphanyGraphFrontier>,
pub graph_checkpoint: Option<EpiphanyGraphCheckpoint>,
pub investigation_checkpoint: Option<EpiphanyInvestigationCheckpoint>,
pub churn: Option<EpiphanyChurnState>,
pub observations: Vec<EpiphanyObservation>,
pub evidence: Vec<EpiphanyEvidenceRecord>,
@ -38,6 +40,8 @@ pub struct EpiphanyStateReplacementValidationInput<'a> {
pub graphs: Option<&'a EpiphanyGraphs>,
pub graph_frontier: Option<&'a EpiphanyGraphFrontier>,
pub graph_checkpoint: Option<&'a EpiphanyGraphCheckpoint>,
pub investigation_checkpoint: Option<&'a EpiphanyInvestigationCheckpoint>,
pub available_evidence_ids: Option<&'a HashSet<&'a str>>,
pub churn: Option<&'a EpiphanyChurnState>,
}
@ -101,6 +105,8 @@ pub fn evaluate_promotion(input: EpiphanyPromotionInput) -> EpiphanyPromotionDec
graphs: input.graphs.as_ref(),
graph_frontier: input.graph_frontier.as_ref(),
graph_checkpoint: input.graph_checkpoint.as_ref(),
investigation_checkpoint: input.investigation_checkpoint.as_ref(),
available_evidence_ids: Some(&evidence_ids),
churn: input.churn.as_ref(),
},
&mut reasons,
@ -182,6 +188,9 @@ fn validate_state_replacements(
validate_checkpoint_shape(checkpoint, reasons);
}
}
if let Some(checkpoint) = input.investigation_checkpoint {
validate_investigation_checkpoint(checkpoint, input.available_evidence_ids, reasons);
}
if let Some(churn) = input.churn {
validate_churn(churn, reasons);
}
@ -450,6 +459,67 @@ fn validate_churn(churn: &EpiphanyChurnState, reasons: &mut Vec<String>) {
require_nonempty(&churn.diff_pressure, "patch.churn.diff_pressure", reasons);
}
fn validate_investigation_checkpoint(
checkpoint: &EpiphanyInvestigationCheckpoint,
available_evidence_ids: Option<&HashSet<&str>>,
reasons: &mut Vec<String>,
) {
require_nonempty(
&checkpoint.checkpoint_id,
"patch.investigation_checkpoint.checkpoint_id",
reasons,
);
require_nonempty(
&checkpoint.kind,
"patch.investigation_checkpoint.kind",
reasons,
);
require_nonempty(
&checkpoint.focus,
"patch.investigation_checkpoint.focus",
reasons,
);
if let Some(summary) = checkpoint.summary.as_deref() {
require_nonempty(summary, "patch.investigation_checkpoint.summary", reasons);
}
if let Some(next_action) = checkpoint.next_action.as_deref() {
require_nonempty(
next_action,
"patch.investigation_checkpoint.next_action",
reasons,
);
} else {
reasons.push("patch.investigation_checkpoint.next_action must not be empty".to_string());
}
if let Some(turn_id) = checkpoint.captured_at_turn_id.as_deref() {
require_nonempty(
turn_id,
"patch.investigation_checkpoint.captured_at_turn_id",
reasons,
);
}
require_unique_nonempty(
"patch.investigation_checkpoint.open_questions",
checkpoint.open_questions.iter().map(String::as_str),
reasons,
);
require_unique_nonempty(
"patch.investigation_checkpoint.evidence_ids",
checkpoint.evidence_ids.iter().map(String::as_str),
reasons,
);
if let Some(available_evidence_ids) = available_evidence_ids {
for evidence_id in &checkpoint.evidence_ids {
if !available_evidence_ids.contains(evidence_id.as_str()) {
reasons.push(format!(
"investigation checkpoint cites missing evidence id {:?}",
evidence_id
));
}
}
}
}
fn graph_node_ids(graphs: &EpiphanyGraphs) -> HashSet<&str> {
graphs
.architecture
@ -584,6 +654,7 @@ mod tests {
graphs: None,
graph_frontier: None,
graph_checkpoint: None,
investigation_checkpoint: None,
churn: None,
observations,
evidence,
@ -627,6 +698,7 @@ mod tests {
graphs: None,
graph_frontier: None,
graph_checkpoint: None,
investigation_checkpoint: None,
churn: None,
observations: vec![EpiphanyObservation {
id: "obs-1".to_string(),
@ -728,6 +800,8 @@ mod tests {
graphs: Some(&graphs),
graph_frontier: Some(&frontier),
graph_checkpoint: None,
investigation_checkpoint: None,
available_evidence_ids: None,
churn: None,
});
@ -738,6 +812,37 @@ mod tests {
);
}
#[test]
fn validate_state_replacement_patch_rejects_investigation_checkpoint_with_missing_evidence() {
let checkpoint = EpiphanyInvestigationCheckpoint {
checkpoint_id: "ix-1".to_string(),
kind: "source_gathering".to_string(),
focus: "Trace the compaction seam.".to_string(),
next_action: Some("Re-gather source before editing.".to_string()),
evidence_ids: vec!["ev-missing".to_string()],
..Default::default()
};
let available_evidence_ids = HashSet::from(["ev-present"]);
let reasons = validate_state_replacement_patch(EpiphanyStateReplacementValidationInput {
active_subgoal_id: None,
subgoals: None,
invariants: None,
graphs: None,
graph_frontier: None,
graph_checkpoint: None,
investigation_checkpoint: Some(&checkpoint),
available_evidence_ids: Some(&available_evidence_ids),
churn: None,
});
assert!(
reasons
.iter()
.any(|reason| reason.contains("missing evidence id"))
);
}
#[test]
fn evaluate_promotion_accepts_verified_map_and_churn_replacement() {
let decision = evaluate_promotion(EpiphanyPromotionInput {
@ -769,6 +874,23 @@ mod tests {
assert!(decision.accepted, "{:?}", decision.reasons);
}
#[test]
fn evaluate_promotion_accepts_investigation_checkpoint_when_backed_by_evidence() {
let decision = evaluate_promotion(EpiphanyPromotionInput {
investigation_checkpoint: Some(EpiphanyInvestigationCheckpoint {
checkpoint_id: "ix-2".to_string(),
kind: "slice_planning".to_string(),
focus: "Map the next bounded edit before compaction.".to_string(),
next_action: Some("Resume from this packet if pressure stays stable.".to_string()),
evidence_ids: vec!["ev-1".to_string()],
..Default::default()
}),
..promotion_input(true, vec![observation()], vec![evidence()], "ok")
});
assert!(decision.accepted, "{:?}", decision.reasons);
}
#[test]
fn evaluate_promotion_rejects_risky_churn_without_warning() {
let decision = evaluate_promotion(EpiphanyPromotionInput {

View file

@ -7,6 +7,8 @@ use codex_protocol::protocol::EpiphanyGraphEdge;
use codex_protocol::protocol::EpiphanyGraphFrontier;
use codex_protocol::protocol::EpiphanyGraphLink;
use codex_protocol::protocol::EpiphanyGraphNode;
use codex_protocol::protocol::EpiphanyInvestigationCheckpoint;
use codex_protocol::protocol::EpiphanyInvestigationDisposition;
use codex_protocol::protocol::EpiphanyModeState;
use codex_protocol::protocol::EpiphanyObservation;
use codex_protocol::protocol::EpiphanyScratchPad;
@ -51,6 +53,11 @@ pub fn render_epiphany_state(state: &EpiphanyThreadState) -> String {
if let Some(graphs) = render_graphs(state) {
sections.push(graphs);
}
if let Some(checkpoint) =
render_investigation_checkpoint(state.investigation_checkpoint.as_ref())
{
sections.push(checkpoint);
}
if let Some(scratch) = render_scratch(state.scratch.as_ref()) {
sections.push(scratch);
}
@ -393,6 +400,56 @@ fn render_scratch(scratch: Option<&EpiphanyScratchPad>) -> Option<String> {
}
}
fn render_investigation_checkpoint(
checkpoint: Option<&EpiphanyInvestigationCheckpoint>,
) -> Option<String> {
let checkpoint = checkpoint?;
let mut lines = vec![
format!("- Id: `{}`", checkpoint.checkpoint_id),
format!("- Kind: {}", compact_text(&checkpoint.kind)),
format!(
"- Disposition: {}",
match checkpoint.disposition {
EpiphanyInvestigationDisposition::ResumeReady => "resume_ready",
EpiphanyInvestigationDisposition::RegatherRequired => "regather_required",
}
),
format!("- Focus: {}", compact_text(&checkpoint.focus)),
];
if let Some(summary) = checkpoint.summary.as_deref() {
lines.push(format!("- Summary: {}", compact_text(summary)));
}
if let Some(next_action) = checkpoint.next_action.as_deref() {
lines.push(format!("- Next action: {}", compact_text(next_action)));
}
if let Some(turn_id) = checkpoint.captured_at_turn_id.as_deref() {
lines.push(format!("- Captured at turn: `{turn_id}`"));
}
if !checkpoint.open_questions.is_empty() {
lines.push(format!(
"- Open questions: {}",
checkpoint
.open_questions
.iter()
.map(|question| compact_text(question))
.collect::<Vec<_>>()
.join(" | ")
));
}
if !checkpoint.evidence_ids.is_empty() {
lines.push(format!(
"- Evidence ids: {}",
render_inline_ids(&checkpoint.evidence_ids)
));
}
let code_refs = render_code_refs(&checkpoint.code_refs);
if !code_refs.is_empty() {
lines.push(format!("- Code refs: {}", code_refs.join(", ")));
}
Some(format!("## Investigation Checkpoint\n{}", lines.join("\n")))
}
fn render_observations(observations: &[EpiphanyObservation]) -> Option<String> {
if observations.is_empty() {
return None;
@ -675,6 +732,8 @@ mod tests {
use codex_protocol::protocol::EpiphanyGraphFrontier;
use codex_protocol::protocol::EpiphanyGraphNode;
use codex_protocol::protocol::EpiphanyGraphs;
use codex_protocol::protocol::EpiphanyInvestigationCheckpoint;
use codex_protocol::protocol::EpiphanyInvestigationDisposition;
use codex_protocol::protocol::EpiphanyModeState;
use codex_protocol::protocol::EpiphanyThreadState;
use std::path::PathBuf;
@ -754,6 +813,27 @@ mod tests {
frontier_node_ids: vec!["arch-session".to_string()],
..Default::default()
}),
investigation_checkpoint: Some(EpiphanyInvestigationCheckpoint {
checkpoint_id: "ix-1".to_string(),
kind: "slice_planning".to_string(),
disposition: EpiphanyInvestigationDisposition::ResumeReady,
focus: "Map the state update seam before broad edits.".to_string(),
next_action: Some(
"Re-read the write path, then patch one bounded field.".to_string(),
),
open_questions: vec![
"Do scene and context both need the resume packet?".to_string(),
],
code_refs: vec![EpiphanyCodeRef {
path: PathBuf::from("core/src/codex_thread.rs"),
start_line: Some(376),
end_line: Some(424),
symbol: Some("epiphany_update_state".to_string()),
note: Some("Checkpoint writes must use the same red pen.".to_string()),
}],
evidence_ids: vec!["ev-1".to_string()],
..Default::default()
}),
churn: Some(EpiphanyChurnState {
understanding_status: "stable".to_string(),
diff_pressure: "low".to_string(),
@ -774,6 +854,9 @@ mod tests {
assert!(rendered.contains("`flow-build-context`"));
assert!(rendered.contains("Do not build the Jenga tower"));
assert!(rendered.contains("revert it before trying the next hypothesis"));
assert!(rendered.contains("## Investigation Checkpoint"));
assert!(rendered.contains("resume_ready"));
assert!(rendered.contains("Map the state update seam before broad edits."));
assert!(!rendered.contains("## Scratch"));
assert!(!rendered.contains("## Invariants"));
assert!(rendered.contains("`core/src/session/mod.rs:2433-2617`"));

View file

@ -1661,6 +1661,7 @@ mod tests {
graphs: Some(proposal.graphs),
graph_frontier: Some(proposal.graph_frontier),
graph_checkpoint: None,
investigation_checkpoint: None,
churn: Some(proposal.churn),
observations: vec![proposal.observation],
evidence: vec![proposal.evidence],