Make legacy coordinator repair batch atomic

This commit is contained in:
Meta Vens 2026-08-11 06:32:51 +02:00
commit aa8418734e
2 changed files with 155 additions and 99 deletions

View file

@ -2513,86 +2513,86 @@ pub fn repair_legacy_terminal_coordinator_sessions(
store_path: impl AsRef<Path>,
) -> Result<Vec<EpiphanyRuntimeSession>> {
let store_path = store_path.as_ref();
let mut repaired = Vec::new();
loop {
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
let jobs = cache.get_all::<EpiphanyRuntimeJob>()?;
let receipts = cache.get_all::<EpiphanyCoordinatorRunReceipt>()?;
let events = cache.get_all::<EpiphanyRuntimeEvent>()?;
let mut candidate = None;
for session in cache
.get_all::<EpiphanyRuntimeSession>()?
.into_iter()
.filter(|session| {
session.status == EpiphanyRuntimeSessionStatus::Active
&& session.session_id.starts_with("coordinator-")
let mut cache = runtime_spine_cache(store_path)?;
cache.pull_all_backing_stores()?;
require_identity(&cache)?;
let jobs = cache.get_all::<EpiphanyRuntimeJob>()?;
let receipts = cache.get_all::<EpiphanyCoordinatorRunReceipt>()?;
let events = cache.get_all::<EpiphanyRuntimeEvent>()?;
let mut candidates = Vec::new();
let mut sessions = cache
.get_all::<EpiphanyRuntimeSession>()?
.into_iter()
.filter(|session| {
session.status == EpiphanyRuntimeSessionStatus::Active
&& session.session_id.starts_with("coordinator-")
})
.collect::<Vec<_>>();
sessions.sort_by(|left, right| left.session_id.cmp(&right.session_id));
for session in sessions {
let session_receipts = receipts
.iter()
.filter(|receipt| receipt.session_id == session.session_id)
.collect::<Vec<_>>();
if session_receipts.is_empty() {
continue;
}
if session_receipts.len() != 1 {
return Err(anyhow!(
"legacy coordinator session {:?} has ambiguous terminal receipts",
session.session_id
));
}
let receipt = session_receipts[0];
if session
.session_id
.strip_prefix("coordinator-")
.is_none_or(|thread_id| thread_id != receipt.thread_id)
|| jobs.iter().any(|job| job.session_id == session.session_id)
{
return Err(anyhow!(
"legacy coordinator session terminal authority is inconsistent"
));
}
let session_events = events
.iter()
.filter(|event| event.session_id.as_deref() == Some(&session.session_id))
.collect::<Vec<_>>();
if session_events.is_empty()
|| session_events.iter().any(|event| {
event.event_type != "coordinator.started"
|| event.source != "epiphany-mvp-coordinator"
|| event.job_id.is_some()
})
{
let session_receipts = receipts
.iter()
.filter(|receipt| receipt.session_id == session.session_id)
.collect::<Vec<_>>();
if session_receipts.is_empty() {
continue;
}
if session_receipts.len() != 1 {
return Err(anyhow!(
"legacy coordinator session {:?} has ambiguous terminal receipts",
session.session_id
));
}
let receipt = session_receipts[0];
if session
.session_id
.strip_prefix("coordinator-")
.is_none_or(|thread_id| thread_id != receipt.thread_id)
|| jobs.iter().any(|job| job.session_id == session.session_id)
{
return Err(anyhow!(
"legacy coordinator session terminal authority is inconsistent"
));
}
let session_events = events
.iter()
.filter(|event| event.session_id.as_deref() == Some(&session.session_id))
.collect::<Vec<_>>();
if session_events.is_empty()
|| session_events.iter().any(|event| {
event.event_type != "coordinator.started"
|| event.source != "epiphany-mvp-coordinator"
|| event.job_id.is_some()
})
{
return Err(anyhow!(
"legacy coordinator session start evidence is inconsistent"
));
}
candidate = Some((session, receipt.clone()));
break;
return Err(anyhow!(
"legacy coordinator session start evidence is inconsistent"
));
}
let Some((mut session, receipt)) = candidate else {
break;
};
let snapshot = cache.snapshot_envelopes();
candidates.push((session, receipt.clone()));
}
if candidates.is_empty() {
return Ok(Vec::new());
}
let snapshot = cache.snapshot_envelopes();
let mut replacements = Vec::with_capacity(candidates.len() * 2);
let mut repaired = Vec::with_capacity(candidates.len());
for (mut session, receipt) in candidates {
let event = coordinator_completion_event(&receipt);
session.status = EpiphanyRuntimeSessionStatus::Completed;
session.updated_at = receipt.created_at.clone();
session.coordinator_note = event.summary.clone();
let replacements = vec![
cache.prepare_entry(&session.session_id, &session)?.0,
cache.prepare_entry(&event.event_id, &event)?.0,
];
if !runtime_spine_backing_store(store_path)?
.replace_and_append_if_snapshot_unchanged(&snapshot, replacements)?
{
return Err(anyhow!(
"legacy coordinator session repair lost its full snapshot fence"
));
}
replacements.push(cache.prepare_entry(&session.session_id, &session)?.0);
replacements.push(cache.prepare_entry(&event.event_id, &event)?.0);
repaired.push(session);
}
if !runtime_spine_backing_store(store_path)?
.replace_and_append_if_snapshot_unchanged(&snapshot, replacements)?
{
return Err(anyhow!(
"legacy coordinator session repair lost its full snapshot fence"
));
}
Ok(repaired)
}
@ -17994,6 +17994,55 @@ pub(crate) mod tests {
created_at: "2026-08-10T10:00:00Z".to_string(),
},
)?;
create_runtime_session(
&store,
RuntimeSpineSessionOptions {
session_id: "coordinator-thread-valid".to_string(),
objective: "Valid legacy shape preceding hostile authority.".to_string(),
created_at: "2026-08-10T10:00:00Z".to_string(),
coordinator_note: String::new(),
},
)?;
append_runtime_event(
&store,
RuntimeSpineEventOptions {
event_id: "event-coordinator-started-valid".to_string(),
occurred_at: "2026-08-10T10:00:00Z".to_string(),
event_type: "coordinator.started".to_string(),
source: "epiphany-mvp-coordinator".to_string(),
session_id: Some("coordinator-thread-valid".to_string()),
job_id: None,
summary: "Started.".to_string(),
},
)?;
put_coordinator_run_receipt(
&store,
&EpiphanyCoordinatorRunReceipt {
schema_version: COORDINATOR_RUN_RECEIPT_SCHEMA_VERSION.to_string(),
receipt_id: "valid-terminal".to_string(),
session_id: "coordinator-thread-valid".to_string(),
thread_id: "thread-valid".to_string(),
mode: "default".to_string(),
status: "completed".to_string(),
final_action: "manualRegather".to_string(),
final_reason: None,
step_count: 1,
created_at: "2026-08-10T10:00:30Z".to_string(),
model_provider: None,
runtime_store: store.display().to_string(),
artifact_refs: Vec::new(),
sealed_artifact_refs: Vec::new(),
metadata: BTreeMap::new(),
resident_grant_id: None,
resident_launch_digest: None,
resident_policy_digest: None,
resident_argv_digest: None,
resident_objective_digest: None,
resident_release_commit: None,
resident_release_manifest_digest: None,
resident_executable_digest: None,
},
)?;
create_runtime_session(
&store,
RuntimeSpineSessionOptions {
@ -18052,6 +18101,14 @@ pub(crate) mod tests {
let mut after = runtime_spine_cache(&store)?;
after.pull_all_backing_stores()?;
assert_eq!(after.snapshot_envelopes(), snapshot);
assert_eq!(
after
.get::<EpiphanyRuntimeSession>("coordinator-thread-valid")?
.expect("valid family must remain present")
.status,
EpiphanyRuntimeSessionStatus::Active,
"a later hostile family must prevent partial repair of an earlier valid family"
);
Ok(())
}

View file

@ -4,37 +4,36 @@ Disposable working memory for one bounded rite.
## Current Subgoal
Restore one owner for release incremental policy and measure the exact
24-binary construction path without weakening witness authority.
Make legacy coordinator Continuity repair atomic across the observed batch,
then use that genuine `epiphany-core` source delta to falsify release iteration
speed without weakening the 24-binary witness.
## Current mechanism
The root release-bundle manifest declares `[profile.release]
incremental = true`, but `release_build_command` force-sets
`CARGO_INCREMENTAL=0`. The construction helper therefore overrides the profile
owner and every `epiphany-core` change recompiles the broad crate and relinks the
24-binary graph. Exact `acd91e6e` took 5m02s despite an otherwise warm graph.
`repair_legacy_terminal_coordinator_sessions` previously validated and repaired
one session per loop iteration. A valid earlier family could commit before a
later ambiguous family made the call return an error. The caller therefore saw
failure after a partial batch mutation.
## Authority map
- Owner: the root release-bundle Cargo profile owns optimization and
incremental policy for the one exact Cargo graph.
- Inputs: exact source commit, frozen lockfile, target triple, toolchain
fingerprint, stable source worktree, and stable graph cache.
- Outputs: all 24 witnessed release binaries and one exact packaged-release
witness.
- Derived state: incremental objects and fingerprints are cache mechanics, not
release identity or publication authority.
- Forbidden writers: release construction may select the exact manifest,
target, feature set, Cargo home, and target directory, but may not silently
override manifest profile policy. Cache contents cannot certify a release.
- Shared paths: migration build, identical replay, and later source-changing
warm builds use the same `release_build_command` and witness inspection.
- Cut line: remove the construction-owned `CARGO_INCREMENTAL=0` override; do
not add a weaker shakedown package, second build graph, or cache-derived
trust path.
- Verification: command-shape test proves the override is absent; focused and
full construction tests pass; exact Linux migration package authenticates
24 binaries; identical replay reproduces release and witness; the next real
core-source successor must materially beat the 5m02s baseline while
retaining exact witness inspection.
- Owner: runtime Continuity owns the repair decision for the complete observed
legacy coordinator snapshot.
- Inputs: immutable runtime identity, active legacy coordinator sessions, exact
session receipts, job families, and coordinator-started events.
- Outputs: every eligible session becomes Completed and receives its
deterministic completion event in one full-snapshot CAS.
- Derived state: iteration order is deterministic presentation only; it does
not create per-family commit authority.
- Forbidden writers: the former per-session repair loop may not publish an
early family before all observed candidate families validate.
- Shared paths: runtime bind/bootstrap and explicit repair use the same batch
primitive.
- Cut line: validate and prepare the entire batch first, then make one
`replace_and_append_if_snapshot_unchanged` call. Any invalid or racing family
leaves all families unchanged.
- Verification: the full 670-test core suite passes with one intentional
ignore. The hostile test now includes a valid family before an ambiguous
family and proves the complete snapshot, including the valid Active session,
stays byte-identical. Package this exact source with the persistent Linux
cache and compare it with the 5m02s source-changing baseline.