Seal work-loop receipt failures

This commit is contained in:
Meta Vens 2026-06-13 06:17:24 +01:00
commit b83c2fb5bc
6 changed files with 117 additions and 4 deletions

View file

@ -75,6 +75,7 @@ struct RecordCommitArgs {
commit_sha: String,
branch: String,
changed_paths: Vec<String>,
validate_commit_sha: bool,
}
#[derive(Debug)]
@ -87,6 +88,7 @@ struct RecordPassArgs {
commit_sha: String,
branch: String,
changed_paths: Vec<String>,
validate_commit_sha: bool,
}
impl Args {
@ -157,6 +159,7 @@ fn parse_record_commit(tokens: impl Iterator<Item = String>) -> Result<RecordCom
commit_sha,
branch,
changed_paths,
validate_commit_sha: true,
})
}
@ -183,6 +186,7 @@ fn parse_record_pass(tokens: impl Iterator<Item = String>) -> Result<RecordPassA
commit_sha,
branch,
changed_paths,
validate_commit_sha: true,
})
}
@ -325,6 +329,11 @@ fn record_command(store: &PathBuf, args: RecordCommandArgs) -> Result<serde_json
fn record_commit(store: &PathBuf, args: RecordCommitArgs) -> Result<serde_json::Value> {
let (intent, review) = load_gate(store, &args.gate, "commit")?;
validate_paths_within_gate(&intent, &args.changed_paths)?;
let commit_sha = if args.validate_commit_sha {
resolve_git_commit_sha(&args.commit_sha)?
} else {
args.commit_sha
};
let receipt_id = args
.gate
.receipt_id
@ -333,7 +342,7 @@ fn record_commit(store: &PathBuf, args: RecordCommitArgs) -> Result<serde_json::
receipt_id,
&intent,
&review,
args.commit_sha,
commit_sha,
args.branch,
normalize_paths(args.changed_paths),
args.gate.summary,
@ -378,6 +387,7 @@ fn record_pass(store: &PathBuf, args: RecordPassArgs) -> Result<serde_json::Valu
commit_sha: args.commit_sha,
branch: args.branch,
changed_paths: args.changed_paths,
validate_commit_sha: args.validate_commit_sha,
},
)?;
Ok(json!({
@ -520,6 +530,31 @@ fn normalize_path(path: &str) -> String {
path.trim().replace('\\', "/")
}
fn resolve_git_commit_sha(commit_sha: &str) -> Result<String> {
let output = std::process::Command::new("git")
.arg("rev-parse")
.arg("--verify")
.arg(format!("{commit_sha}^{{commit}}"))
.output()
.map_err(|err| anyhow!("failed to start git rev-parse for Hands commit receipt: {err}"))?;
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();
return Err(anyhow!(
"Hands commit receipt references non-existent commit {commit_sha:?}: {stderr}"
));
}
let resolved = String::from_utf8(output.stdout)
.map_err(|err| anyhow!("git rev-parse returned non-UTF8 commit sha: {err}"))?
.trim()
.to_string();
if resolved.is_empty() {
return Err(anyhow!(
"git rev-parse returned an empty commit sha for {commit_sha:?}"
));
}
Ok(resolved)
}
fn generated_receipt_id(prefix: &str) -> String {
format!("{prefix}-{}", uuid::Uuid::new_v4())
}
@ -582,6 +617,7 @@ mod tests {
commit_sha: "abc123".to_string(),
branch: "codex/test".to_string(),
changed_paths: vec!["src/lib.rs".to_string()],
validate_commit_sha: false,
},
)?;
@ -626,6 +662,7 @@ mod tests {
commit_sha: "def456".to_string(),
branch: "codex/test".to_string(),
changed_paths: vec!["src/lib.rs".to_string()],
validate_commit_sha: false,
},
)?;
@ -663,6 +700,28 @@ mod tests {
Ok(())
}
#[test]
fn refuses_commit_receipt_for_unknown_git_sha() -> Result<()> {
let temp = tempfile::tempdir()?;
let store = temp.path().join("runtime-spine.msgpack");
seed_gate(&store, vec!["src".to_string()])?;
let result = record_commit(
&store,
RecordCommitArgs {
gate: gate_args("hands-commit-test"),
commit_sha: "0000000000000000000000000000000000000000".to_string(),
branch: "codex/test".to_string(),
changed_paths: vec!["src/lib.rs".to_string()],
validate_commit_sha: true,
},
);
assert!(result.is_err());
assert!(runtime_hands_commit_receipt(&store, "hands-commit-test")?.is_none());
Ok(())
}
#[test]
fn refuses_patch_receipt_outside_requested_paths() -> Result<()> {
let temp = tempfile::tempdir()?;

View file

@ -815,6 +815,19 @@ pub fn recommend_coordinator_action(
);
}
if input.signals.verification_result_status == EpiphanyCoordinatorRoleResultStatus::Failed
&& !input.verification_result_accepted
{
return build(
EpiphanyCoordinatorAction::ReviewVerificationResult,
Some(EpiphanyCoordinatorRoleId::Verification),
Some(EpiphanyCoordinatorSceneAction::RoleResult),
false,
false,
"The verification/review worker failed; inspect the failed Soul result before relaunching verification or continuing implementation.",
);
}
if input.verification_result_accepted && input.implementation_evidence_after_verification {
return build(
EpiphanyCoordinatorAction::LaunchVerification,
@ -1471,6 +1484,22 @@ mod tests {
EpiphanyCoordinatorAction::LaunchVerification
);
let review_failed_verification = recommend_coordinator_action(EpiphanyCoordinatorInput {
signals: EpiphanyCoordinatorSignals {
research_result_status: EpiphanyCoordinatorRoleResultStatus::MissingBinding,
modeling_result_status: EpiphanyCoordinatorRoleResultStatus::Completed,
verification_result_status: EpiphanyCoordinatorRoleResultStatus::Failed,
},
modeling_result_accepted: true,
modeling_result_reviewable: true,
..input()
});
assert_eq!(
review_failed_verification.action,
EpiphanyCoordinatorAction::ReviewVerificationResult
);
assert!(!review_failed_verification.can_auto_run);
let verification_done = EpiphanyCoordinatorSignals {
research_result_status: EpiphanyCoordinatorRoleResultStatus::MissingBinding,
modeling_result_status: EpiphanyCoordinatorRoleResultStatus::Completed,