Merge route continuity F0: typed readiness, deadlines and actuation state

The generation moves to v3 and the transaction to v4. They carry
ReadinessEvidence (the class is derived from Expected by ReadinessClass::of),
phase deadlines owned by one writer (enter_phase), RouteSupervisionState,
ContinuityBackoff, LeaseAdoptionEvidence and TerminalRecovery. The plan
moves to v3 with frozen deadline durations. A boot migration lifts every
legacy record with stored_at preserved. No decision reads the new fields
yet, so behaviour does not change at this cut.

Soul closed it after one fix batch. The first pass found every commit and
post-fence abort wedged by a deadline nothing cleared; Engine tests now
drive admissions and aborts to Complete. 204 tests. Filed forward: B3 must
give Odin its own readiness class before any route-proof admission ships,
or boot wedges; an unreadable history.cc must fail closed (B1 fix batch).
Back up control.cc before deploying: an older binary refuses a v4 store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-29 05:08:50 +02:00
commit 6e5f87676b
13 changed files with 2521 additions and 191 deletions

File diff suppressed because it is too large Load diff

View file

@ -275,6 +275,10 @@ pub struct OperatorBinding {
pub process_write_lease: Option<ProcessWriteLeaseBinding>,
pub brakes: BrakeBinding,
pub rollout: RolloutBinding,
/// Optional per-phase deadline overrides; absent fields take Idunn's defaults
/// when the plan is compiled.
#[serde(default)]
pub deadlines: Option<DeadlineBinding>,
pub placement: PlacementBinding,
#[serde(default)]
pub external_capabilities: Vec<ExternalCapabilityBinding>,
@ -709,6 +713,44 @@ pub struct RolloutBinding {
pub retain_releases: u32,
}
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct DeadlineBinding {
#[serde(default)]
pub fencing_seconds: Option<u32>,
#[serde(default)]
pub leasing_seconds: Option<u32>,
#[serde(default)]
pub awaiting_ready_seconds: Option<u32>,
#[serde(default)]
pub routing_seconds: Option<u32>,
#[serde(default)]
pub committing_seconds: Option<u32>,
}
/// Longest deadline a binding may declare: one day.
pub const MAXIMUM_DEADLINE_SECONDS: u32 = 86_400;
impl DeadlineBinding {
fn validate(&self) -> Result<()> {
for (name, seconds) in [
("fencing", self.fencing_seconds),
("leasing", self.leasing_seconds),
("awaiting-ready", self.awaiting_ready_seconds),
("routing", self.routing_seconds),
("committing", self.committing_seconds),
] {
if let Some(seconds) = seconds {
ensure!(
(1..=MAXIMUM_DEADLINE_SECONDS).contains(&seconds),
"{name} deadline must be between 1 and {MAXIMUM_DEADLINE_SECONDS} seconds"
);
}
}
Ok(())
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum RolloutStrategy {
@ -1343,6 +1385,9 @@ impl OperatorBinding {
/// The part of validation that does not depend on where the workload runs.
fn validate_shared_tail(&self) -> Result<()> {
if let Some(deadlines) = &self.deadlines {
deadlines.validate()?;
}
ensure!(
self.rollout.retain_releases >= 2,
"candidate rollout must retain at least current and prior releases"

View file

@ -12,13 +12,16 @@ use sha2::{Digest, Sha256};
use crate::control_plane::SequenceAdmittedReady;
use crate::deployment::{
CapabilityDependency, DependencyKind, ExternalCapabilityBinding, OperatorBinding,
CapabilityDependency, DeadlineBinding, DependencyKind, ExternalCapabilityBinding, OperatorBinding,
ServiceTransport, SourceSelectionPolicy, StartupOrder, StateDeclaration, TargetDeclaration,
capability_compatible,
};
pub const SOURCE_SELECTION_FACTS_SCHEMA: &str = "idunn.source_selection_facts.v1";
pub const COMPILED_DEPLOYMENT_PLAN_SCHEMA: &str = "idunn.compiled_deployment_plan.v2";
pub const COMPILED_DEPLOYMENT_PLAN_SCHEMA: &str = "idunn.compiled_deployment_plan.v3";
/// Plans sealed before phase deadlines existed. They keep their bytes, and so
/// their plan id; their deadlines are Idunn's defaults at read time.
pub const COMPILED_DEPLOYMENT_PLAN_SCHEMA_V2: &str = "idunn.compiled_deployment_plan.v2";
pub const SEALED_RELEASE_SCHEMA: &str = "idunn.sealed_release.v1";
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
@ -460,6 +463,89 @@ pub fn select_dependencies(
.collect()
}
/// Idunn's default duration for each post-fencing phase, in seconds. A binding
/// overrides any of them; the resolved values are frozen into the plan.
pub const DEFAULT_FENCING_DEADLINE_SECONDS: u32 = 120;
pub const DEFAULT_LEASING_DEADLINE_SECONDS: u32 = 120;
// Unsafe for streampixels-service (startup = "create-or-open-after-write-lease"):
// its Postgres migrations run inside AwaitingReady. B5 requires an explicit
// binding value for stateful targets instead of this default.
pub const DEFAULT_AWAITING_READY_DEADLINE_SECONDS: u32 = 300;
pub const DEFAULT_ROUTING_DEADLINE_SECONDS: u32 = 120;
pub const DEFAULT_COMMITTING_DEADLINE_SECONDS: u32 = 120;
/// The resolved per-phase deadline durations a plan carries. Nothing reads
/// them at the cut that introduced them.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct PhaseDeadlines {
pub fencing_seconds: u32,
pub leasing_seconds: u32,
pub awaiting_ready_seconds: u32,
pub routing_seconds: u32,
pub committing_seconds: u32,
}
impl PhaseDeadlines {
pub const IDUNN_DEFAULTS: Self = Self {
fencing_seconds: DEFAULT_FENCING_DEADLINE_SECONDS,
leasing_seconds: DEFAULT_LEASING_DEADLINE_SECONDS,
awaiting_ready_seconds: DEFAULT_AWAITING_READY_DEADLINE_SECONDS,
routing_seconds: DEFAULT_ROUTING_DEADLINE_SECONDS,
committing_seconds: DEFAULT_COMMITTING_DEADLINE_SECONDS,
};
/// Binding overrides over Idunn's defaults.
pub fn resolve(binding: Option<&DeadlineBinding>) -> Self {
let defaults = Self::IDUNN_DEFAULTS;
let Some(binding) = binding else {
return defaults;
};
Self {
fencing_seconds: binding.fencing_seconds.unwrap_or(defaults.fencing_seconds),
leasing_seconds: binding.leasing_seconds.unwrap_or(defaults.leasing_seconds),
awaiting_ready_seconds: binding
.awaiting_ready_seconds
.unwrap_or(defaults.awaiting_ready_seconds),
routing_seconds: binding.routing_seconds.unwrap_or(defaults.routing_seconds),
committing_seconds: binding
.committing_seconds
.unwrap_or(defaults.committing_seconds),
}
}
fn validate_against(&self, binding: &OperatorBinding) -> Result<()> {
let declared = binding.deadlines.clone().unwrap_or_default();
for (name, frozen, declared) in [
("fencing", self.fencing_seconds, declared.fencing_seconds),
("leasing", self.leasing_seconds, declared.leasing_seconds),
(
"awaiting-ready",
self.awaiting_ready_seconds,
declared.awaiting_ready_seconds,
),
("routing", self.routing_seconds, declared.routing_seconds),
(
"committing",
self.committing_seconds,
declared.committing_seconds,
),
] {
ensure!(
(1..=crate::deployment::MAXIMUM_DEADLINE_SECONDS).contains(&frozen),
"frozen {name} deadline is out of range"
);
if let Some(declared) = declared {
ensure!(
frozen == declared,
"frozen {name} deadline differs from the binding"
);
}
}
Ok(())
}
}
/// Private Idunn control-plane state. This contains host binding details and is
/// never an Odin/CultMesh projection. The shared CultNet Expected incarnation
/// is the sanitized topology projection derived only after a release validates
@ -476,12 +562,17 @@ pub struct CompiledDeploymentPlan {
pub binding_blob: Vec<u8>,
pub dependencies: Vec<DependencySelection>,
pub candidate_port: Option<u16>,
/// Present exactly on v3 plans. Skipped when absent so a v2 plan re-encodes
/// to its original bytes and keeps its plan id.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub deadlines: Option<PhaseDeadlines>,
}
impl CompiledDeploymentPlan {
pub fn validate(&self) -> Result<()> {
ensure!(
self.schema == COMPILED_DEPLOYMENT_PLAN_SCHEMA,
self.schema == COMPILED_DEPLOYMENT_PLAN_SCHEMA
|| self.schema == COMPILED_DEPLOYMENT_PLAN_SCHEMA_V2,
"unsupported deployment-plan schema"
);
require_sha256(&self.plan_id, "plan id")?;
@ -492,6 +583,11 @@ impl CompiledDeploymentPlan {
);
let (declaration, binding) = self.parsed_inputs()?;
self.source.validate_against(&binding)?;
match (&self.schema[..], &self.deadlines) {
(COMPILED_DEPLOYMENT_PLAN_SCHEMA, Some(deadlines)) => deadlines.validate_against(&binding)?,
(COMPILED_DEPLOYMENT_PLAN_SCHEMA_V2, None) => {}
_ => bail!("deployment plan deadlines differ from its schema"),
}
ensure!(
sha256_id(&self.recipe_blob) == self.source.recipe_blob_sha256,
"selected recipe blob differs from the exact plan recipe bytes"
@ -527,6 +623,12 @@ impl CompiledDeploymentPlan {
Ok(())
}
/// The deadline durations this plan runs under: frozen for v3, Idunn's
/// defaults for a v2 plan that predates them.
pub fn phase_deadlines(&self) -> PhaseDeadlines {
self.deadlines.unwrap_or(PhaseDeadlines::IDUNN_DEFAULTS)
}
pub(crate) fn parsed_inputs(&self) -> Result<(TargetDeclaration, OperatorBinding)> {
let recipe_text = std::str::from_utf8(&self.recipe_blob)
.context("stored deployment recipe is not UTF-8")?;
@ -589,6 +691,7 @@ pub(crate) fn compile_deployment_plan(
binding_blob: binding_bytes.to_vec(),
dependencies,
candidate_port,
deadlines: Some(PhaseDeadlines::resolve(binding.deadlines.as_ref())),
};
plan.plan_id = plan.recomputed_plan_id()?;
plan.validate()?;
@ -998,7 +1101,7 @@ fn sha256_id(bytes: &[u8]) -> String {
}
#[cfg(test)]
mod tests {
pub(crate) mod tests {
use super::*;
use cultnet_rs::{
GameCultProviderHealthIdentity, GameCultRuntimeCapability, IdunnRuntimeActivationLaunch,
@ -1009,7 +1112,7 @@ mod tests {
verify_runtime_authority,
};
const RECIPE: &str = r#"
pub(crate) const RECIPE: &str = r#"
schema = "gamecult.idunn.target_declaration.v1"
target = "service"
source_stamp_environment = "SERVICE_BUILD_COMMIT"
@ -1072,7 +1175,7 @@ schema = "odin.verse-topology.v1"
compatibility = "v1"
"#;
const BINDING: &str = r#"
pub(crate) const BINDING: &str = r#"
schema = "gamecult.idunn.operator_binding.v2"
target = "service"
@ -1147,7 +1250,7 @@ nodes = ["yggdrasil"]
format!("sha256-{}", char::from(byte).to_string().repeat(64))
}
fn source(recipe: &str) -> SourceSelectionFacts {
pub(crate) fn source(recipe: &str) -> SourceSelectionFacts {
SourceSelectionFacts {
schema: SOURCE_SELECTION_FACTS_SCHEMA.into(),
origin: "https://github.com/GameCult/Service.git".into(),
@ -1287,7 +1390,7 @@ nodes = ["yggdrasil"]
.unwrap()
}
fn artifact_receipt() -> ArtifactReceipt {
pub(crate) fn artifact_receipt() -> ArtifactReceipt {
ArtifactReceipt {
artifact_id: "daemon".into(),
destination: "service".into(),
@ -1297,7 +1400,7 @@ nodes = ["yggdrasil"]
}
}
fn external_input_receipt() -> ExternalInputMaterializationReceipt {
pub(crate) fn external_input_receipt() -> ExternalInputMaterializationReceipt {
ExternalInputMaterializationReceipt {
input_id: "toolchain-index".into(),
url: "https://example.invalid/toolchain-index".into(),
@ -1594,4 +1697,92 @@ nodes = ["yggdrasil"]
changed.external_inputs[0].size_bytes = 18;
assert!(changed.validate_against(&plan).is_err());
}
fn binding_with_deadlines(table: &str) -> String {
BINDING.replace("[placement]", &format!("{table}\n[placement]"))
}
fn plan_under(binding: &str) -> Result<CompiledDeploymentPlan> {
let providers = [ready_odin_provider("odin", "odin-yggdrasil", 1)];
compile_deployment_plan(
RECIPE.as_bytes(),
binding.as_bytes(),
source(RECIPE),
"service-incarnation-1",
Some(18001),
110,
&providers,
)
}
#[test]
fn a_compiled_plan_freezes_idunn_default_deadlines() {
let plan = plan();
assert_eq!(plan.schema, COMPILED_DEPLOYMENT_PLAN_SCHEMA);
assert_eq!(plan.deadlines, Some(PhaseDeadlines::IDUNN_DEFAULTS));
assert_eq!(plan.phase_deadlines(), PhaseDeadlines::IDUNN_DEFAULTS);
plan.validate().unwrap();
}
#[test]
fn a_binding_overrides_only_the_deadlines_it_names() {
let binding = binding_with_deadlines("[deadlines]\nawaiting_ready_seconds = 45\n");
let plan = plan_under(&binding).unwrap();
let frozen = plan.phase_deadlines();
assert_eq!(frozen.awaiting_ready_seconds, 45);
assert_eq!(
PhaseDeadlines {
awaiting_ready_seconds: DEFAULT_AWAITING_READY_DEADLINE_SECONDS,
..frozen
},
PhaseDeadlines::IDUNN_DEFAULTS
);
}
#[test]
fn deadline_bounds_and_unknown_phases_are_refused() {
for table in [
"[deadlines]\nrouting_seconds = 0\n",
"[deadlines]\nrouting_seconds = 86401\n",
"[deadlines]\nwarming_seconds = 5\n",
] {
assert!(
OperatorBinding::parse(&binding_with_deadlines(table)).is_err(),
"{table}"
);
}
}
#[test]
fn frozen_deadlines_must_agree_with_the_binding_and_the_plan_schema() {
let binding = binding_with_deadlines("[deadlines]\nrouting_seconds = 45\n");
let sealed = |mut plan: CompiledDeploymentPlan| {
plan.plan_id = plan.recomputed_plan_id().unwrap();
plan
};
let honest = plan_under(&binding).unwrap();
let mut drifted = honest.clone();
drifted.deadlines.as_mut().unwrap().routing_seconds = 46;
assert!(sealed(drifted).validate().is_err());
let mut absent = honest.clone();
absent.deadlines = None;
assert!(sealed(absent).validate().is_err());
let mut v2_with_deadlines = honest.clone();
v2_with_deadlines.schema = COMPILED_DEPLOYMENT_PLAN_SCHEMA_V2.into();
assert!(sealed(v2_with_deadlines).validate().is_err());
// A plan sealed before deadlines existed keeps its nine-field encoding,
// so its plan id still holds, and it runs on Idunn's defaults.
let mut v2 = plan();
v2.schema = COMPILED_DEPLOYMENT_PLAN_SCHEMA_V2.into();
v2.deadlines = None;
let v2 = sealed(v2);
v2.validate().unwrap();
assert_eq!(v2.phase_deadlines(), PhaseDeadlines::IDUNN_DEFAULTS);
assert_eq!(rmp_serde::to_vec(&v2).unwrap()[0], 0x99);
assert_eq!(rmp_serde::to_vec(&honest).unwrap()[0], 0x9a);
}
}

View file

@ -0,0 +1,24 @@
# Legacy control-record wire fixtures
Each `*.hex` file is two lines: the CultCache envelope `schema_id`, then the
record's MessagePack payload in hex. They are the exact bytes the encoder at
Idunn `9001b58` (the base of the F0 cut) wrote for records built through that
revision's own constructors: `DeploymentTransaction::new`,
`AdmittedGeneration::from_transaction`, `SealedRelease::new`,
`compile_deployment_plan`, and `rmp_serde::to_vec`. A throwaway test on a
scratch commit over `9001b58` printed them; it is not kept.
Everything in them is synthetic: identities were enrolled fresh in a temporary
directory, the Odin receipts are placeholder bytes with correct digests, and
the plan is the `deployment_plan` test recipe. No byte comes from a live store.
| File | Schema | What it is |
|---|---|---|
| `generation-with-receipts` | `idunn.admitted_generation.v2` | routed, stateless generation with Ready and latest Odin receipts |
| `generation-route-repair-started` | `idunn.admitted_generation.v2` | the same with `route_repair_started_at_unix_millis` set |
| `transaction-fencing` .. `transaction-committing` | `idunn.deployment_transaction.v3` | one continuity transaction in each post-fencing phase |
| `transaction-committing-v2` | `idunn.deployment_transaction.v2` | the Committing record in the v2 layout: the v3 tuple without key 34 (base code stops writing v2, so this one is the v3 encoding with its trailing nil slot dropped and the header count lowered) |
| `transaction-failed-after-fencing` | `idunn.deployment_transaction.v3` | terminal post-fencing failure with complete abort evidence |
`control_plane.rs` decodes these through `LegacyDeploymentTransaction` and
`LegacyAdmittedGeneration`. The fixtures die with those structs.

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long