diff --git a/epiphany-core/src/bin/epiphany-swarm.rs b/epiphany-core/src/bin/epiphany-swarm.rs index 5d351203..2eef0385 100644 --- a/epiphany-core/src/bin/epiphany-swarm.rs +++ b/epiphany-core/src/bin/epiphany-swarm.rs @@ -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()); diff --git a/epiphany-core/src/reasoning_context.rs b/epiphany-core/src/reasoning_context.rs index 45ae2444..1229aa9f 100644 --- a/epiphany-core/src/reasoning_context.rs +++ b/epiphany-core/src/reasoning_context.rs @@ -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> { + 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()?;