Bind decision audit to sealed semantic roles

This commit is contained in:
Meta Vens 2026-08-22 12:44:53 +02:00
commit 785213ec29
2 changed files with 57 additions and 7 deletions

View file

@ -493,6 +493,15 @@ enum CommandKind {
Status,
}
fn validate_command_turn_bound(command: CommandKind, max_steps: u64) -> Result<()> {
if matches!(command, CommandKind::Serve) && max_steps != 1 {
return Err(anyhow!(
"resident serve requires --max-steps 1 because each state-driven continuation owns exactly one coordinator step"
));
}
Ok(())
}
struct Args {
command: CommandKind,
state_store: PathBuf,
@ -589,6 +598,7 @@ impl Args {
.cloned()
.ok_or_else(|| anyhow!("missing --release-witness-sha256"))?,
};
validate_command_turn_bound(command, policy.max_steps)?;
let pressure = objective.map(|objective| ResidentSelfPressure {
schema_version: epiphany_core::RESIDENT_SELF_PRESSURE_SCHEMA_VERSION.into(),
pressure_id: value
@ -781,6 +791,14 @@ fn resident_self_brake_engaged(
mod brake_tests {
use super::*;
#[test]
fn resident_serve_refuses_a_multi_step_coordinator_policy_at_startup() {
assert!(validate_command_turn_bound(CommandKind::Serve, 4).is_err());
assert!(validate_command_turn_bound(CommandKind::Serve, 1).is_ok());
assert!(validate_command_turn_bound(CommandKind::Once, 4).is_ok());
assert!(validate_command_turn_bound(CommandKind::Status, 4).is_ok());
}
#[test]
fn resident_body_preflight_refuses_missing_git_before_serve() {
assert!(require_resident_git("epiphany-deliberately-missing-git").is_err());

View file

@ -895,14 +895,13 @@ fn validate_decision_terminal_records(
records: &EpiphanyDecisionTerminalRecords,
) -> Result<()> {
let context_id = context.context_id.as_str();
if records
.role_worker_results
let terminal_role_id = role_terminal_semantic_role(basis)?;
if records.role_worker_results.iter().any(|record| {
record.job_id != basis.pass_id || terminal_role_id.as_deref() != Some(&record.role_id)
}) || records
.reorient_worker_results
.iter()
.any(|record| record.job_id != basis.pass_id || record.role_id != basis.organ_id)
|| records
.reorient_worker_results
.iter()
.any(|record| record.job_id != basis.pass_id)
.any(|record| record.job_id != basis.pass_id)
|| records
.runtime_job_results
.iter()
@ -995,6 +994,15 @@ fn validate_decision_terminal_records(
Ok(())
}
fn role_terminal_semantic_role(basis: &EpiphanyReasoningBasis) -> Result<Option<String>> {
Ok(match basis.projection()? {
EpiphanyReasoningProjection::RolePass(projection) => {
Some(projection.authority.role_id)
}
_ => None,
})
}
pub fn worker_reasoning_basis(
store_path: &Path,
launch: &EpiphanyRuntimeWorkerLaunchRequest,
@ -1989,6 +1997,30 @@ mod tests {
Ok(())
}
#[test]
fn role_terminal_identity_uses_the_sealed_semantic_role_not_the_runtime_owner_label()
-> Result<()> {
let canonical = basis()?;
let projection = canonical.projection()?;
let owner_labeled = EpiphanyReasoningBasis::new(
&canonical.pass_id,
crate::EPIPHANY_MODELING_OWNER_ROLE,
&canonical.projection_policy_id,
canonical.source_documents.clone(),
projection,
)?;
assert_eq!(
role_terminal_semantic_role(&owner_labeled)?.as_deref(),
Some("Modeling")
);
assert_ne!(
role_terminal_semantic_role(&owner_labeled)?.as_deref(),
Some(crate::EPIPHANY_MODELING_OWNER_ROLE)
);
Ok(())
}
#[test]
fn decision_context_binds_exact_provider_and_tool_bytes() -> Result<()> {
let reasoning_basis = basis()?;