Add typed Epiphany acceptance receipts
This commit is contained in:
parent
1406971f46
commit
247c6950c6
5 changed files with 412 additions and 5 deletions
|
|
@ -57,6 +57,7 @@ use codex_protocol::protocol::AgentStatus as CoreAgentStatus;
|
|||
use codex_protocol::protocol::AskForApproval as CoreAskForApproval;
|
||||
use codex_protocol::protocol::CodexErrorInfo as CoreCodexErrorInfo;
|
||||
use codex_protocol::protocol::CreditsSnapshot as CoreCreditsSnapshot;
|
||||
use codex_protocol::protocol::EpiphanyAcceptanceReceipt as CoreEpiphanyAcceptanceReceipt;
|
||||
use codex_protocol::protocol::EpiphanyChurnState as CoreEpiphanyChurnState;
|
||||
use codex_protocol::protocol::EpiphanyCodeRef as CoreEpiphanyCodeRef;
|
||||
use codex_protocol::protocol::EpiphanyEvidenceRecord as CoreEpiphanyEvidenceRecord;
|
||||
|
|
@ -4317,6 +4318,7 @@ pub struct ThreadEpiphanyRoleAcceptResponse {
|
|||
pub epiphany_state: CoreEpiphanyThreadState,
|
||||
pub role_id: ThreadEpiphanyRoleId,
|
||||
pub binding_id: String,
|
||||
pub accepted_receipt_id: String,
|
||||
pub accepted_observation_id: String,
|
||||
pub accepted_evidence_id: String,
|
||||
pub applied_patch: ThreadEpiphanyUpdatePatch,
|
||||
|
|
@ -5109,6 +5111,7 @@ pub struct ThreadEpiphanyReorientAcceptResponse {
|
|||
pub changed_fields: Vec<ThreadEpiphanyStateUpdatedField>,
|
||||
pub epiphany_state: CoreEpiphanyThreadState,
|
||||
pub binding_id: String,
|
||||
pub accepted_receipt_id: String,
|
||||
pub accepted_observation_id: String,
|
||||
pub accepted_evidence_id: String,
|
||||
pub finding: ThreadEpiphanyReorientFinding,
|
||||
|
|
@ -5421,6 +5424,8 @@ pub struct ThreadEpiphanyUpdatePatch {
|
|||
#[ts(optional = nullable)]
|
||||
pub job_bindings: Option<Vec<CoreEpiphanyJobBinding>>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub acceptance_receipts: Vec<CoreEpiphanyAcceptanceReceipt>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub observations: Vec<CoreEpiphanyObservation>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub evidence: Vec<CoreEpiphanyEvidenceRecord>,
|
||||
|
|
@ -5481,6 +5486,7 @@ pub enum ThreadEpiphanyStateUpdatedField {
|
|||
Scratch,
|
||||
InvestigationCheckpoint,
|
||||
JobBindings,
|
||||
AcceptanceReceipts,
|
||||
Observations,
|
||||
Evidence,
|
||||
Churn,
|
||||
|
|
|
|||
|
|
@ -450,6 +450,7 @@ use codex_protocol::protocol::ConversationAudioParams;
|
|||
use codex_protocol::protocol::ConversationStartParams;
|
||||
use codex_protocol::protocol::ConversationStartTransport;
|
||||
use codex_protocol::protocol::ConversationTextParams;
|
||||
use codex_protocol::protocol::EpiphanyAcceptanceReceipt;
|
||||
use codex_protocol::protocol::EpiphanyCodeRef;
|
||||
use codex_protocol::protocol::EpiphanyEvidenceRecord;
|
||||
use codex_protocol::protocol::EpiphanyInvestigationCheckpoint;
|
||||
|
|
@ -5133,6 +5134,29 @@ impl CodexMessageProcessor {
|
|||
}
|
||||
};
|
||||
let accepted_prefix = epiphany_role_label(role_id);
|
||||
let runtime_result_id = match role_finding_runtime_result_id(&finding) {
|
||||
Some(result_id) => result_id,
|
||||
None => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
"cannot accept role finding without a runtimeResultId".to_string(),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let runtime_job_id = match role_finding_runtime_job_id(&finding) {
|
||||
Some(job_id) => job_id,
|
||||
None => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
"cannot accept role finding without a runtimeJobId".to_string(),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let accepted_receipt_id = format!("accept-{accepted_prefix}-{runtime_result_id}");
|
||||
let accepted_evidence_id = format!("ev-{accepted_prefix}-{}", Uuid::new_v4());
|
||||
let accepted_observation_id = format!("obs-{accepted_prefix}-{}", Uuid::new_v4());
|
||||
let code_refs = role_finding_code_refs(&finding);
|
||||
|
|
@ -5153,6 +5177,19 @@ impl CodexMessageProcessor {
|
|||
};
|
||||
patch.evidence.push(evidence);
|
||||
patch.observations.push(observation);
|
||||
patch.acceptance_receipts.push(EpiphanyAcceptanceReceipt {
|
||||
id: accepted_receipt_id.clone(),
|
||||
result_id: runtime_result_id,
|
||||
job_id: runtime_job_id,
|
||||
binding_id: binding_id.clone(),
|
||||
surface: "roleAccept".to_string(),
|
||||
role_id: accepted_prefix.to_string(),
|
||||
status: "accepted".to_string(),
|
||||
accepted_at: Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true),
|
||||
accepted_observation_id: Some(accepted_observation_id.clone()),
|
||||
accepted_evidence_id: Some(accepted_evidence_id.clone()),
|
||||
summary: finding.summary.clone(),
|
||||
});
|
||||
let changed_fields = epiphany_update_patch_changed_fields(&patch);
|
||||
let applied_patch = patch.clone();
|
||||
|
||||
|
|
@ -5169,6 +5206,7 @@ impl CodexMessageProcessor {
|
|||
scratch: patch.scratch,
|
||||
investigation_checkpoint: patch.investigation_checkpoint,
|
||||
job_bindings: patch.job_bindings,
|
||||
acceptance_receipts: patch.acceptance_receipts,
|
||||
observations: patch.observations,
|
||||
evidence: patch.evidence,
|
||||
churn: patch.churn,
|
||||
|
|
@ -5203,6 +5241,7 @@ impl CodexMessageProcessor {
|
|||
epiphany_state: epiphany_state.clone(),
|
||||
role_id,
|
||||
binding_id: binding_id.clone(),
|
||||
accepted_receipt_id,
|
||||
accepted_observation_id,
|
||||
accepted_evidence_id,
|
||||
applied_patch,
|
||||
|
|
@ -6044,6 +6083,29 @@ impl CodexMessageProcessor {
|
|||
|
||||
let accepted_evidence_id = format!("ev-reorient-{}", Uuid::new_v4());
|
||||
let accepted_observation_id = format!("obs-reorient-{}", Uuid::new_v4());
|
||||
let runtime_result_id = match reorient_finding_runtime_result_id(&finding) {
|
||||
Some(result_id) => result_id,
|
||||
None => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
"cannot accept reorientation finding without a runtimeResultId".to_string(),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let runtime_job_id = match reorient_finding_runtime_job_id(&finding) {
|
||||
Some(job_id) => job_id,
|
||||
None => {
|
||||
self.send_invalid_request_error(
|
||||
request_id,
|
||||
"cannot accept reorientation finding without a runtimeJobId".to_string(),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
let accepted_receipt_id = format!("accept-reorient-{runtime_result_id}");
|
||||
let code_refs = reorient_finding_code_refs(&finding);
|
||||
let evidence = EpiphanyEvidenceRecord {
|
||||
id: accepted_evidence_id.clone(),
|
||||
|
|
@ -6076,6 +6138,7 @@ impl CodexMessageProcessor {
|
|||
};
|
||||
|
||||
let mut changed_fields = vec![
|
||||
ThreadEpiphanyStateUpdatedField::AcceptanceReceipts,
|
||||
ThreadEpiphanyStateUpdatedField::Observations,
|
||||
ThreadEpiphanyStateUpdatedField::Evidence,
|
||||
];
|
||||
|
|
@ -6091,6 +6154,19 @@ impl CodexMessageProcessor {
|
|||
expected_revision,
|
||||
scratch,
|
||||
investigation_checkpoint,
|
||||
acceptance_receipts: vec![EpiphanyAcceptanceReceipt {
|
||||
id: accepted_receipt_id.clone(),
|
||||
result_id: runtime_result_id,
|
||||
job_id: runtime_job_id,
|
||||
binding_id: binding_id.clone(),
|
||||
surface: "reorientAccept".to_string(),
|
||||
role_id: "reorientation".to_string(),
|
||||
status: "accepted".to_string(),
|
||||
accepted_at: Utc::now().to_rfc3339_opts(SecondsFormat::Secs, true),
|
||||
accepted_observation_id: Some(accepted_observation_id.clone()),
|
||||
accepted_evidence_id: Some(accepted_evidence_id.clone()),
|
||||
summary: finding.summary.clone(),
|
||||
}],
|
||||
observations: vec![observation],
|
||||
evidence: vec![evidence],
|
||||
..Default::default()
|
||||
|
|
@ -6122,6 +6198,7 @@ impl CodexMessageProcessor {
|
|||
changed_fields: changed_fields.clone(),
|
||||
epiphany_state: epiphany_state.clone(),
|
||||
binding_id: binding_id.clone(),
|
||||
accepted_receipt_id,
|
||||
accepted_observation_id,
|
||||
accepted_evidence_id,
|
||||
finding,
|
||||
|
|
@ -6489,6 +6566,7 @@ impl CodexMessageProcessor {
|
|||
scratch: patch.scratch,
|
||||
investigation_checkpoint: patch.investigation_checkpoint,
|
||||
job_bindings: patch.job_bindings,
|
||||
acceptance_receipts: patch.acceptance_receipts,
|
||||
observations: patch.observations,
|
||||
evidence,
|
||||
churn: patch.churn,
|
||||
|
|
@ -6579,6 +6657,7 @@ impl CodexMessageProcessor {
|
|||
scratch: patch.scratch,
|
||||
investigation_checkpoint: patch.investigation_checkpoint,
|
||||
job_bindings: patch.job_bindings,
|
||||
acceptance_receipts: patch.acceptance_receipts,
|
||||
observations: patch.observations,
|
||||
evidence: patch.evidence,
|
||||
churn: patch.churn,
|
||||
|
|
@ -14045,6 +14124,22 @@ fn json_string_field(value: &serde_json::Value, key: &str) -> Option<String> {
|
|||
.map(str::to_string)
|
||||
}
|
||||
|
||||
fn role_finding_runtime_result_id(finding: &ThreadEpiphanyRoleFinding) -> Option<String> {
|
||||
json_string_field(&finding.raw_result, "runtimeResultId")
|
||||
}
|
||||
|
||||
fn role_finding_runtime_job_id(finding: &ThreadEpiphanyRoleFinding) -> Option<String> {
|
||||
json_string_field(&finding.raw_result, "runtimeJobId")
|
||||
}
|
||||
|
||||
fn reorient_finding_runtime_result_id(finding: &ThreadEpiphanyReorientFinding) -> Option<String> {
|
||||
json_string_field(&finding.raw_result, "runtimeResultId")
|
||||
}
|
||||
|
||||
fn reorient_finding_runtime_job_id(finding: &ThreadEpiphanyReorientFinding) -> Option<String> {
|
||||
json_string_field(&finding.raw_result, "runtimeJobId")
|
||||
}
|
||||
|
||||
fn json_string_array_field(value: &serde_json::Value, key: &str) -> Vec<String> {
|
||||
value
|
||||
.get(key)
|
||||
|
|
@ -14955,6 +15050,16 @@ fn epiphany_reorient_finding_already_accepted(
|
|||
state: &EpiphanyThreadState,
|
||||
finding: &ThreadEpiphanyReorientFinding,
|
||||
) -> bool {
|
||||
if let Some(result_id) = reorient_finding_runtime_result_id(finding)
|
||||
&& state.acceptance_receipts.iter().any(|receipt| {
|
||||
receipt.result_id == result_id
|
||||
&& receipt.status == "accepted"
|
||||
&& receipt.surface == "reorientAccept"
|
||||
})
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
let accepted_summary = reorient_finding_summary(finding);
|
||||
state.recent_evidence.iter().any(|evidence| {
|
||||
evidence.kind == "reorient_result"
|
||||
|
|
@ -14974,9 +15079,13 @@ fn epiphany_role_finding_accepted_evidence_id(
|
|||
state: &EpiphanyThreadState,
|
||||
finding: &ThreadEpiphanyRoleFinding,
|
||||
) -> Option<String> {
|
||||
epiphany_role_finding_accepted_index(state, finding)
|
||||
.and_then(|index| state.recent_evidence.get(index))
|
||||
.map(|evidence| evidence.id.clone())
|
||||
epiphany_role_finding_acceptance_receipt(state, finding)
|
||||
.and_then(|receipt| receipt.accepted_evidence_id.clone())
|
||||
.or_else(|| {
|
||||
epiphany_role_finding_accepted_index(state, finding)
|
||||
.and_then(|index| state.recent_evidence.get(index))
|
||||
.map(|evidence| evidence.id.clone())
|
||||
})
|
||||
}
|
||||
|
||||
fn epiphany_verification_finding_covers_current_modeling(
|
||||
|
|
@ -15017,13 +15126,13 @@ fn role_finding_accepted_after(
|
|||
let Some(later) = later else {
|
||||
return false;
|
||||
};
|
||||
let Some(later_index) = epiphany_role_finding_accepted_index(state, later) else {
|
||||
let Some(later_index) = epiphany_role_finding_accepted_order_index(state, later) else {
|
||||
return false;
|
||||
};
|
||||
let Some(earlier) = earlier else {
|
||||
return true;
|
||||
};
|
||||
let Some(earlier_index) = epiphany_role_finding_accepted_index(state, earlier) else {
|
||||
let Some(earlier_index) = epiphany_role_finding_accepted_order_index(state, earlier) else {
|
||||
return true;
|
||||
};
|
||||
later_index < earlier_index
|
||||
|
|
@ -15063,6 +15172,59 @@ fn epiphany_role_finding_cites_implementation_evidence(
|
|||
fn epiphany_role_finding_accepted_index(
|
||||
state: &EpiphanyThreadState,
|
||||
finding: &ThreadEpiphanyRoleFinding,
|
||||
) -> Option<usize> {
|
||||
if let Some(receipt) = epiphany_role_finding_acceptance_receipt(state, finding) {
|
||||
return receipt
|
||||
.accepted_evidence_id
|
||||
.as_ref()
|
||||
.and_then(|id| {
|
||||
state
|
||||
.recent_evidence
|
||||
.iter()
|
||||
.position(|evidence| evidence.id == *id)
|
||||
})
|
||||
.or(Some(0));
|
||||
}
|
||||
epiphany_role_finding_summary_accepted_index(state, finding)
|
||||
}
|
||||
|
||||
fn epiphany_role_finding_accepted_order_index(
|
||||
state: &EpiphanyThreadState,
|
||||
finding: &ThreadEpiphanyRoleFinding,
|
||||
) -> Option<usize> {
|
||||
epiphany_role_finding_acceptance_receipt_index(state, finding)
|
||||
.or_else(|| epiphany_role_finding_summary_accepted_index(state, finding))
|
||||
}
|
||||
|
||||
fn epiphany_role_finding_acceptance_receipt<'a>(
|
||||
state: &'a EpiphanyThreadState,
|
||||
finding: &ThreadEpiphanyRoleFinding,
|
||||
) -> Option<&'a EpiphanyAcceptanceReceipt> {
|
||||
let result_id = role_finding_runtime_result_id(finding)?;
|
||||
state.acceptance_receipts.iter().find(|receipt| {
|
||||
receipt.result_id == result_id
|
||||
&& receipt.status == "accepted"
|
||||
&& receipt.surface == "roleAccept"
|
||||
&& receipt.role_id == epiphany_role_label(finding.role_id)
|
||||
})
|
||||
}
|
||||
|
||||
fn epiphany_role_finding_acceptance_receipt_index(
|
||||
state: &EpiphanyThreadState,
|
||||
finding: &ThreadEpiphanyRoleFinding,
|
||||
) -> Option<usize> {
|
||||
let result_id = role_finding_runtime_result_id(finding)?;
|
||||
state.acceptance_receipts.iter().position(|receipt| {
|
||||
receipt.result_id == result_id
|
||||
&& receipt.status == "accepted"
|
||||
&& receipt.surface == "roleAccept"
|
||||
&& receipt.role_id == epiphany_role_label(finding.role_id)
|
||||
})
|
||||
}
|
||||
|
||||
fn epiphany_role_finding_summary_accepted_index(
|
||||
state: &EpiphanyThreadState,
|
||||
finding: &ThreadEpiphanyRoleFinding,
|
||||
) -> Option<usize> {
|
||||
let accepted_kind = match finding.role_id {
|
||||
ThreadEpiphanyRoleId::Imagination => "planning_synthesis",
|
||||
|
|
@ -15555,6 +15717,11 @@ fn imagination_role_accept_patch_errors(patch: &ThreadEpiphanyUpdatePatch) -> Ve
|
|||
"job binding changes are not allowed through imagination role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if !patch.acceptance_receipts.is_empty() {
|
||||
errors.push(
|
||||
"acceptance receipt changes are owned by roleAccept, not worker statePatch".to_string(),
|
||||
);
|
||||
}
|
||||
if patch.churn.is_some() || patch.mode.is_some() {
|
||||
errors.push(
|
||||
"churn or mode changes are not allowed through imagination role acceptance".to_string(),
|
||||
|
|
@ -15612,6 +15779,11 @@ fn modeling_role_accept_patch_errors(patch: &ThreadEpiphanyUpdatePatch) -> Vec<S
|
|||
"job binding changes are not allowed through modeling role acceptance".to_string(),
|
||||
);
|
||||
}
|
||||
if !patch.acceptance_receipts.is_empty() {
|
||||
errors.push(
|
||||
"acceptance receipt changes are owned by roleAccept, not worker statePatch".to_string(),
|
||||
);
|
||||
}
|
||||
if patch.planning.is_some() {
|
||||
errors
|
||||
.push("planning changes are not allowed through modeling role acceptance".to_string());
|
||||
|
|
@ -17814,6 +17986,7 @@ fn thread_epiphany_patch_has_state_replacements(patch: &ThreadEpiphanyUpdatePatc
|
|||
|| patch.scratch.is_some()
|
||||
|| patch.investigation_checkpoint.is_some()
|
||||
|| patch.job_bindings.is_some()
|
||||
|| !patch.acceptance_receipts.is_empty()
|
||||
|| patch.churn.is_some()
|
||||
|| patch.mode.is_some()
|
||||
|| patch.planning.is_some()
|
||||
|
|
@ -17919,6 +18092,9 @@ fn epiphany_update_patch_changed_fields(
|
|||
if patch.job_bindings.is_some() {
|
||||
fields.push(ThreadEpiphanyStateUpdatedField::JobBindings);
|
||||
}
|
||||
if !patch.acceptance_receipts.is_empty() {
|
||||
fields.push(ThreadEpiphanyStateUpdatedField::AcceptanceReceipts);
|
||||
}
|
||||
if !patch.observations.is_empty() {
|
||||
fields.push(ThreadEpiphanyStateUpdatedField::Observations);
|
||||
}
|
||||
|
|
@ -21738,6 +21914,58 @@ mod tests {
|
|||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn role_finding_acceptance_prefers_runtime_result_receipt() {
|
||||
let modeling = map_epiphany_role_finding(
|
||||
ThreadEpiphanyRoleId::Modeling,
|
||||
serde_json::json!({
|
||||
"roleId": "modeling",
|
||||
"verdict": "checkpoint-ready",
|
||||
"summary": "Runtime receipt owns identity.",
|
||||
"nextSafeMove": "Verify from the receipt.",
|
||||
"runtimeResultId": "runtime-result-1",
|
||||
"runtimeJobId": "runtime-job-1",
|
||||
"statePatch": {
|
||||
"scratch": {
|
||||
"summary": "Receipt-backed model.",
|
||||
"next_probe": "Verify."
|
||||
}
|
||||
}
|
||||
}),
|
||||
None,
|
||||
None,
|
||||
);
|
||||
let state = EpiphanyThreadState {
|
||||
acceptance_receipts: vec![EpiphanyAcceptanceReceipt {
|
||||
id: "accept-modeling-runtime-result-1".to_string(),
|
||||
result_id: "runtime-result-1".to_string(),
|
||||
job_id: "runtime-job-1".to_string(),
|
||||
binding_id: "modeling".to_string(),
|
||||
surface: "roleAccept".to_string(),
|
||||
role_id: "modeling".to_string(),
|
||||
status: "accepted".to_string(),
|
||||
accepted_at: "2026-05-12T00:00:00Z".to_string(),
|
||||
accepted_observation_id: Some("obs-modeling".to_string()),
|
||||
accepted_evidence_id: Some("ev-modeling".to_string()),
|
||||
summary: Some("Summary text can drift without owning identity.".to_string()),
|
||||
}],
|
||||
recent_evidence: vec![EpiphanyEvidenceRecord {
|
||||
id: "ev-modeling".to_string(),
|
||||
kind: "modeling_result".to_string(),
|
||||
status: "accepted".to_string(),
|
||||
summary: "Different summary; receipt should still match.".to_string(),
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert!(epiphany_role_finding_already_accepted(&state, &modeling));
|
||||
assert_eq!(
|
||||
epiphany_role_finding_accepted_evidence_id(&state, &modeling).as_deref(),
|
||||
Some("ev-modeling")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verification_coverage_accepts_modeling_source_evidence_ids() {
|
||||
let modeling = map_epiphany_role_finding(
|
||||
|
|
|
|||
148
vendor/codex/codex-rs/core/src/codex_thread.rs
vendored
148
vendor/codex/codex-rs/core/src/codex_thread.rs
vendored
|
|
@ -25,6 +25,7 @@ use codex_protocol::models::ResponseInputItem;
|
|||
use codex_protocol::models::ResponseItem;
|
||||
use codex_protocol::openai_models::ReasoningEffort;
|
||||
use codex_protocol::protocol::AskForApproval;
|
||||
use codex_protocol::protocol::EpiphanyAcceptanceReceipt;
|
||||
use codex_protocol::protocol::EpiphanyChurnState;
|
||||
use codex_protocol::protocol::EpiphanyEvidenceRecord;
|
||||
use codex_protocol::protocol::EpiphanyGraphCheckpoint;
|
||||
|
|
@ -125,6 +126,7 @@ pub struct EpiphanyStateUpdate {
|
|||
pub scratch: Option<EpiphanyScratchPad>,
|
||||
pub investigation_checkpoint: Option<EpiphanyInvestigationCheckpoint>,
|
||||
pub job_bindings: Option<Vec<EpiphanyJobBinding>>,
|
||||
pub acceptance_receipts: Vec<EpiphanyAcceptanceReceipt>,
|
||||
pub observations: Vec<EpiphanyObservation>,
|
||||
pub evidence: Vec<EpiphanyEvidenceRecord>,
|
||||
pub churn: Option<EpiphanyChurnState>,
|
||||
|
|
@ -183,6 +185,7 @@ impl EpiphanyStateUpdate {
|
|||
&& self.scratch.is_none()
|
||||
&& self.investigation_checkpoint.is_none()
|
||||
&& self.job_bindings.is_none()
|
||||
&& self.acceptance_receipts.is_empty()
|
||||
&& self.observations.is_empty()
|
||||
&& self.evidence.is_empty()
|
||||
&& self.churn.is_none()
|
||||
|
|
@ -1040,6 +1043,13 @@ fn epiphany_state_update_validation_errors(
|
|||
if let Some(job_bindings) = update.job_bindings.as_ref() {
|
||||
errors.extend(validate_epiphany_job_bindings(job_bindings));
|
||||
}
|
||||
if !update.acceptance_receipts.is_empty() {
|
||||
errors.extend(validate_epiphany_acceptance_receipts(
|
||||
&state.acceptance_receipts,
|
||||
&update.acceptance_receipts,
|
||||
&known_evidence_ids,
|
||||
));
|
||||
}
|
||||
if let Some(planning) = update.planning.as_ref() {
|
||||
errors.extend(validate_epiphany_planning_state(planning));
|
||||
}
|
||||
|
|
@ -1048,6 +1058,67 @@ fn epiphany_state_update_validation_errors(
|
|||
errors
|
||||
}
|
||||
|
||||
fn validate_epiphany_acceptance_receipts(
|
||||
existing: &[EpiphanyAcceptanceReceipt],
|
||||
receipts: &[EpiphanyAcceptanceReceipt],
|
||||
known_evidence_ids: &HashSet<&str>,
|
||||
) -> Vec<String> {
|
||||
let mut errors = Vec::new();
|
||||
let mut seen_ids = existing
|
||||
.iter()
|
||||
.map(|receipt| receipt.id.as_str())
|
||||
.collect::<HashSet<_>>();
|
||||
let mut seen_result_ids = existing
|
||||
.iter()
|
||||
.map(|receipt| receipt.result_id.as_str())
|
||||
.collect::<HashSet<_>>();
|
||||
|
||||
for receipt in receipts {
|
||||
require_nonempty_update(&receipt.id, "acceptance_receipt.id", &mut errors);
|
||||
require_nonempty_update(
|
||||
&receipt.result_id,
|
||||
"acceptance_receipt.result_id",
|
||||
&mut errors,
|
||||
);
|
||||
require_nonempty_update(&receipt.job_id, "acceptance_receipt.job_id", &mut errors);
|
||||
require_nonempty_update(
|
||||
&receipt.binding_id,
|
||||
"acceptance_receipt.binding_id",
|
||||
&mut errors,
|
||||
);
|
||||
require_nonempty_update(&receipt.surface, "acceptance_receipt.surface", &mut errors);
|
||||
require_nonempty_update(&receipt.role_id, "acceptance_receipt.role_id", &mut errors);
|
||||
require_nonempty_update(&receipt.status, "acceptance_receipt.status", &mut errors);
|
||||
require_nonempty_update(
|
||||
&receipt.accepted_at,
|
||||
"acceptance_receipt.accepted_at",
|
||||
&mut errors,
|
||||
);
|
||||
if !seen_ids.insert(receipt.id.as_str()) {
|
||||
errors.push(format!(
|
||||
"acceptance receipt id {:?} is duplicated",
|
||||
receipt.id
|
||||
));
|
||||
}
|
||||
if !seen_result_ids.insert(receipt.result_id.as_str()) {
|
||||
errors.push(format!(
|
||||
"runtime result {:?} already has an acceptance receipt",
|
||||
receipt.result_id
|
||||
));
|
||||
}
|
||||
if let Some(evidence_id) = receipt.accepted_evidence_id.as_deref()
|
||||
&& !known_evidence_ids.contains(evidence_id)
|
||||
{
|
||||
errors.push(format!(
|
||||
"acceptance receipt {:?} cites missing evidence id {:?}",
|
||||
receipt.id, evidence_id
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
errors
|
||||
}
|
||||
|
||||
fn validate_epiphany_job_bindings(job_bindings: &[EpiphanyJobBinding]) -> Vec<String> {
|
||||
let mut errors = Vec::new();
|
||||
let mut seen_ids = HashSet::<&str>::new();
|
||||
|
|
@ -1335,6 +1406,7 @@ fn apply_epiphany_state_update(
|
|||
if let Some(job_bindings) = update.job_bindings {
|
||||
state.job_bindings = job_bindings;
|
||||
}
|
||||
prepend_recent(&mut state.acceptance_receipts, update.acceptance_receipts);
|
||||
if let Some(churn) = update.churn {
|
||||
state.churn = Some(churn);
|
||||
}
|
||||
|
|
@ -1408,6 +1480,26 @@ mod epiphany_update_tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn acceptance_receipt(
|
||||
id: &str,
|
||||
result_id: &str,
|
||||
evidence_id: &str,
|
||||
) -> EpiphanyAcceptanceReceipt {
|
||||
EpiphanyAcceptanceReceipt {
|
||||
id: id.to_string(),
|
||||
result_id: result_id.to_string(),
|
||||
job_id: "runtime-job-1".to_string(),
|
||||
binding_id: "modeling".to_string(),
|
||||
surface: "roleAccept".to_string(),
|
||||
role_id: "modeling".to_string(),
|
||||
status: "accepted".to_string(),
|
||||
accepted_at: "2026-05-12T00:00:00Z".to_string(),
|
||||
accepted_observation_id: Some("obs-modeling".to_string()),
|
||||
accepted_evidence_id: Some(evidence_id.to_string()),
|
||||
summary: Some("Accepted modeling result.".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apply_epiphany_state_update_replaces_typed_fields_and_prepends_evidence() {
|
||||
let mut state = EpiphanyThreadState {
|
||||
|
|
@ -1508,6 +1600,29 @@ mod epiphany_update_tests {
|
|||
assert_eq!(state.last_updated_turn_id.as_deref(), Some("turn-jobs"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn apply_epiphany_state_update_prepends_acceptance_receipts() {
|
||||
let mut state = EpiphanyThreadState {
|
||||
revision: 2,
|
||||
recent_evidence: vec![evidence("ev-new")],
|
||||
acceptance_receipts: vec![acceptance_receipt("accept-old", "result-old", "ev-old")],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
apply_epiphany_state_update(
|
||||
&mut state,
|
||||
EpiphanyStateUpdate {
|
||||
acceptance_receipts: vec![acceptance_receipt("accept-new", "result-new", "ev-new")],
|
||||
..Default::default()
|
||||
},
|
||||
Some("turn-accept".to_string()),
|
||||
);
|
||||
|
||||
assert_eq!(state.revision, 3);
|
||||
assert_eq!(state.acceptance_receipts[0].id, "accept-new");
|
||||
assert_eq!(state.acceptance_receipts[1].id, "accept-old");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_epiphany_state_update_accepts_planning_state() {
|
||||
let update = EpiphanyStateUpdate {
|
||||
|
|
@ -1742,6 +1857,39 @@ mod epiphany_update_tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_epiphany_state_update_rejects_duplicate_acceptance_result() {
|
||||
let state = EpiphanyThreadState {
|
||||
acceptance_receipts: vec![acceptance_receipt(
|
||||
"accept-existing",
|
||||
"result-existing",
|
||||
"ev-existing",
|
||||
)],
|
||||
recent_evidence: vec![evidence("ev-existing"), evidence("ev-new")],
|
||||
..Default::default()
|
||||
};
|
||||
let update = EpiphanyStateUpdate {
|
||||
acceptance_receipts: vec![
|
||||
acceptance_receipt("accept-new", "result-existing", "ev-new"),
|
||||
acceptance_receipt("accept-new", "result-new", "ev-new"),
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let errors = epiphany_state_update_validation_errors(&state, &update);
|
||||
|
||||
assert!(
|
||||
errors
|
||||
.iter()
|
||||
.any(|error| error.contains("runtime result \"result-existing\" already has"))
|
||||
);
|
||||
assert!(
|
||||
errors
|
||||
.iter()
|
||||
.any(|error| error.contains("acceptance receipt id \"accept-new\" is duplicated"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn validate_epiphany_state_update_rejects_structurally_invalid_replacements() {
|
||||
let state = EpiphanyThreadState {
|
||||
|
|
|
|||
|
|
@ -338,6 +338,7 @@ fn sample_epiphany_state_for_prompt() -> EpiphanyThreadState {
|
|||
}),
|
||||
investigation_checkpoint: None,
|
||||
job_bindings: Vec::new(),
|
||||
acceptance_receipts: Vec::new(),
|
||||
scratch: Some(EpiphanyScratchPad {
|
||||
summary: Some("Inject the state as a developer fragment, not as a user message.".to_string()),
|
||||
hypothesis: Some("Keeping the block bounded will help resume without making prompt sludge.".to_string()),
|
||||
|
|
|
|||
24
vendor/codex/codex-rs/protocol/src/protocol.rs
vendored
24
vendor/codex/codex-rs/protocol/src/protocol.rs
vendored
|
|
@ -3024,6 +3024,9 @@ pub struct EpiphanyThreadState {
|
|||
#[ts(type = "Array<EpiphanyJobBinding>")]
|
||||
pub job_bindings: Vec<EpiphanyJobBinding>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
#[ts(type = "Array<EpiphanyAcceptanceReceipt>")]
|
||||
pub acceptance_receipts: Vec<EpiphanyAcceptanceReceipt>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
#[ts(type = "Array<EpiphanyObservation>")]
|
||||
pub observations: Vec<EpiphanyObservation>,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
|
|
@ -3043,6 +3046,27 @@ pub struct EpiphanyThreadState {
|
|||
pub last_updated_turn_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, TS, Default)]
|
||||
pub struct EpiphanyAcceptanceReceipt {
|
||||
pub id: String,
|
||||
pub result_id: String,
|
||||
pub job_id: String,
|
||||
pub binding_id: String,
|
||||
pub surface: String,
|
||||
pub role_id: String,
|
||||
pub status: String,
|
||||
pub accepted_at: String,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
pub accepted_observation_id: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
pub accepted_evidence_id: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
#[ts(type = "string | null")]
|
||||
pub summary: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema, TS, Default)]
|
||||
pub struct EpiphanySubgoal {
|
||||
pub id: String,
|
||||
|
|
|
|||
Reference in a new issue