runtime: cut repository body observation latency

This commit is contained in:
Meta Vens 2026-08-08 19:31:27 +01:00
commit 9d671aeef0
7 changed files with 252 additions and 22 deletions

View file

@ -272,6 +272,10 @@ path = "src/bin/epiphany-rider-bridge-smoke.rs"
name = "epiphany-runtime-spine"
path = "src/bin/epiphany-runtime-spine.rs"
[[bin]]
name = "epiphany-runtime-store-benchmark"
path = "src/bin/epiphany-runtime-store-benchmark.rs"
[[bin]]
name = "epiphany-runtime-store-migrate"
path = "src/bin/epiphany-runtime-store-migrate.rs"

View file

@ -0,0 +1,143 @@
use anyhow::{Context, Result, anyhow};
use cultcache_rs::{
CacheBackingStore, CultCacheEnvelope, RedbMessagePackBackingStore,
SingleFileMessagePackBackingStore,
};
use epiphany_core::{EpiphanyRuntimeJob, RUNTIME_JOB_TYPE};
use serde::Serialize;
use sha2::{Digest, Sha256};
use std::path::Path;
use std::time::Instant;
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
struct BenchmarkReceipt {
schema_version: &'static str,
store: String,
job_id: String,
job_created_at: String,
selection_window_milliseconds: i64,
selected_stored_ats: Vec<String>,
selected_entry_count: usize,
selected_identities: Vec<String>,
selected_envelope_set_sha256: String,
read_milliseconds: u128,
cas_milliseconds: Vec<u128>,
}
enum Store {
Snapshot(SingleFileMessagePackBackingStore),
Keyed(RedbMessagePackBackingStore),
}
impl Store {
fn open(path: &Path) -> Result<Self> {
match path.extension().and_then(|value| value.to_str()) {
Some("cc" | "msgpack") => {
Ok(Self::Snapshot(SingleFileMessagePackBackingStore::new(path)))
}
Some("redb") => Ok(Self::Keyed(RedbMessagePackBackingStore::new(path)?)),
extension => Err(anyhow!(
"unsupported benchmark store extension {extension:?}"
)),
}
}
fn pull_all(&self) -> Result<Vec<CultCacheEnvelope>> {
match self {
Self::Snapshot(store) => store.pull_all(),
Self::Keyed(store) => store.pull_all(),
}
}
fn compare_and_swap_batch(
&self,
expected: &[CultCacheEnvelope],
replacements: Vec<CultCacheEnvelope>,
) -> Result<bool> {
match self {
Self::Snapshot(store) => store.compare_and_swap_batch(expected, replacements),
Self::Keyed(store) => store.compare_and_swap_batch(expected, replacements),
}
}
}
fn main() -> Result<()> {
let mut args = std::env::args().skip(1);
let store_path = args
.next()
.ok_or_else(|| anyhow!("usage: epiphany-runtime-store-benchmark <disposable-store> <historical-job-id> [repetitions]"))?;
let job_id = args
.next()
.ok_or_else(|| anyhow!("missing historical job id"))?;
let repetitions = args
.next()
.map(|value| value.parse::<usize>())
.transpose()
.context("invalid repetitions")?
.unwrap_or(3);
if repetitions == 0 || args.next().is_some() {
return Err(anyhow!("repetitions must be positive and arguments exact"));
}
let path = Path::new(&store_path);
let store = Store::open(path)?;
let read_started = Instant::now();
let entries = store.pull_all()?;
let read_milliseconds = read_started.elapsed().as_millis();
let job = entries
.iter()
.find(|entry| entry.r#type == RUNTIME_JOB_TYPE && entry.key == job_id)
.ok_or_else(|| anyhow!("historical runtime job envelope is absent"))?;
let runtime_job: EpiphanyRuntimeJob = rmp_serde::from_slice(&job.payload)?;
let job_created_at = runtime_job.created_at;
let job_created = chrono::DateTime::parse_from_rfc3339(&job_created_at)?;
let selection_window_milliseconds = 2_000_i64;
let mut selected = entries
.into_iter()
.filter(|entry| {
chrono::DateTime::parse_from_rfc3339(&entry.stored_at)
.map(|stored| {
(stored.timestamp_millis() - job_created.timestamp_millis()).abs()
<= selection_window_milliseconds
})
.unwrap_or(false)
})
.collect::<Vec<_>>();
selected.sort_by(|left, right| (&left.r#type, &left.key).cmp(&(&right.r#type, &right.key)));
if selected.is_empty() {
return Err(anyhow!("historical job commit selected no envelopes"));
}
let selected_identities = selected
.iter()
.map(|entry| format!("{}:{}", entry.r#type, entry.key))
.collect::<Vec<_>>();
let selected_stored_ats = selected
.iter()
.map(|entry| entry.stored_at.clone())
.collect::<Vec<_>>();
let selected_envelope_set_sha256 =
format!("{:x}", Sha256::digest(rmp_serde::to_vec_named(&selected)?));
let mut cas_milliseconds = Vec::with_capacity(repetitions);
for _ in 0..repetitions {
let started = Instant::now();
if !store.compare_and_swap_batch(&selected, selected.clone())? {
return Err(anyhow!("exact historical batch CAS unexpectedly refused"));
}
cas_milliseconds.push(started.elapsed().as_millis());
}
let receipt = BenchmarkReceipt {
schema_version: "epiphany.runtime_store_benchmark_receipt.v1",
store: path.display().to_string(),
job_id,
job_created_at,
selection_window_milliseconds,
selected_stored_ats,
selected_entry_count: selected.len(),
selected_identities,
selected_envelope_set_sha256,
read_milliseconds,
cas_milliseconds,
};
println!("{}", serde_json::to_string_pretty(&receipt)?);
Ok(())
}

View file

@ -908,7 +908,14 @@ fn git_bytes(repo: &Path, envs: &[(&str, &str)], args: &[&str]) -> Result<Vec<u8
Ok(output.stdout)
}
fn raw_manifest_entries(repo: &Path, index: &[u8]) -> Result<Vec<RepositoryBodyManifestEntry>> {
let mut entries = Vec::new();
#[derive(Clone)]
struct IndexRecord {
mode: String,
oid: String,
path: String,
}
let mut records = Vec::new();
for raw in index.split(|byte| *byte == 0).filter(|raw| !raw.is_empty()) {
let tab = raw
.iter()
@ -930,22 +937,58 @@ fn raw_manifest_entries(repo: &Path, index: &[u8]) -> Result<Vec<RepositoryBodyM
if fields.next().is_some() || stage != "0" {
bail!("Git index contains an unresolved or malformed staged entry");
}
let path_buf = safe_worktree_path(repo, path)?;
let entry = match mode {
"100644" | "100755" => raw_regular_entry(&path_buf, path, mode)?,
"120000" => raw_symlink_entry(&path_buf, path, mode)?,
"160000" => RepositoryBodyManifestEntry {
path: path.into(),
git_mode: mode.into(),
kind: "gitlink_nonrecursive".into(),
raw_byte_length: 0,
raw_sha256: String::new(),
gitlink_oid: Some(oid.into()),
},
_ => bail!("unsupported Git index mode {mode:?} at {path:?}"),
};
entries.push(entry);
records.push(IndexRecord {
mode: mode.to_string(),
oid: oid.to_string(),
path: path.to_string(),
});
}
let available = std::thread::available_parallelism()
.map(usize::from)
.unwrap_or(1);
let worker_count = records.len().min((available * 4).clamp(1, 16));
let chunk_size = records.len().div_ceil(worker_count.max(1));
let mut entries = std::thread::scope(|scope| -> Result<Vec<_>> {
let mut workers = Vec::new();
for chunk in records.chunks(chunk_size.max(1)) {
workers.push(scope.spawn(move || -> Result<Vec<RepositoryBodyManifestEntry>> {
let mut local = Vec::with_capacity(chunk.len());
for record in chunk {
let path_buf = safe_worktree_path(repo, &record.path)?;
let entry = match record.mode.as_str() {
"100644" | "100755" => {
raw_regular_entry(&path_buf, &record.path, &record.mode)?
}
"120000" => raw_symlink_entry(&path_buf, &record.path, &record.mode)?,
"160000" => RepositoryBodyManifestEntry {
path: record.path.clone(),
git_mode: record.mode.clone(),
kind: "gitlink_nonrecursive".into(),
raw_byte_length: 0,
raw_sha256: String::new(),
gitlink_oid: Some(record.oid.clone()),
},
mode => bail!(
"unsupported Git index mode {mode:?} at {:?}",
record.path
),
};
local.push(entry);
}
Ok(local)
}));
}
let mut joined = Vec::with_capacity(records.len());
for worker in workers {
joined.extend(
worker
.join()
.map_err(|_| anyhow!("repository Body manifest worker panicked"))??,
);
}
Ok(joined)
})?;
entries.sort_by(|a, b| a.path.as_bytes().cmp(b.path.as_bytes()));
if entries.windows(2).any(|pair| pair[0].path == pair[1].path) {
bail!("duplicate path in repository Body manifest");

View file

@ -1671,6 +1671,25 @@ collision refusal, migration equivalence for every envelope, absence of writes
to the sealed source, crash-safe destination recovery, and a live-sized job
commit that no longer scales with total historical store bytes.
Historical transaction benchmarking after implementation corrected the causal
map. Exact surviving batches around live job `972f4e31` take roughly
0.8-1.0s through the legacy snapshot backend and 0.02-0.03s through keyed redb.
Keyed CAS is a valid secondary optimization, but it cannot explain or remove a
51.482s coordinator bucket by itself. Live migration is therefore not yet
authorized by performance evidence.
The Modeling-only pre-transaction owner is Repository Body observation. It
builds two isolated Git indexes/trees and two complete raw SHA-256 manifests,
then admits only exact equality. On the current 3,994-file Body, an authenticated
release observation took 92.30s. The isolated Git add/write-tree portion takes
about 1.62s; serial raw file reads and metadata dominate. Manifest entries are
independent after typed index parsing, so bounded parallel construction changes
only execution order. Per-file before/after metadata checks, raw hashes,
deterministic sorting, manifest-root derivation, the second full scan, and exact
equality remain owners. The measured parallel observation is 49.52s. A future
cut that reuses hashes or weakens the second scan requires a new explicit
freshness authority; it must not be smuggled in as a cache.
## Verdict-bound Modeling output authority
Live v53 exposed a missing typed boundary after Soul acceptance. The

View file

@ -150,7 +150,7 @@ probe reported `Removed 0 files` and is rejected, not evidence.
- Fresh Modeling job commit: 51.637s; coordinator total 51.865s.
- The launch wound is the whole-store transaction, not context assembly.
## Keyed runtime and packaging cut in progress
## Keyed runtime and packaging cut
The current uncommitted pass after `b070e121` introduces one runtime-spine
backend owner selected by explicit extension: `.cc`/`.msgpack` retain the
@ -178,6 +178,27 @@ Release-mode live-sized measurements are mixed but promising: legacy full read
production judgment. Do not migrate live from this proxy alone. Measure the
exact coordinator launch replacement set against the keyed v53 copy next.
That next probe changed the diagnosis. The durable
`epiphany-runtime-store-benchmark` selects typed historical transaction
envelopes by exact job identity and emits identity/digest/timing receipts on
disposable stores. The surviving launch-request batch for job `972f4e31` was
legacy 785-1,012ms versus keyed 23-32ms; its completion batch was legacy
784-1,567ms versus keyed 21-34ms. Those receipts prove keyed CAS is faster, but
also falsify the claim that snapshot CAS owned the measured 51.482s launch
bucket. Do not migrate live on that old causal story.
`commit_coordinator_job_launch` performs Modeling-only
`observe_runtime_repository_body_basis` before opening the state transaction.
That observer constructs two isolated Git trees and raw SHA-256 manifests over
3,994 files, then requires exact equality. Direct authenticated release timing
was 92.30s and created Body generation 2. The fresh-index Git phase was only
1.62s; raw file reads and metadata were the wound. Bounded parallel manifest
construction keeps the same per-file before/after metadata checks, raw hashes,
sorted root, isolated trees, and second full equality pass. All 24 observer
tests pass. Direct release observation fell to 49.52s and created generation 3.
This is material but not final; package it and measure a real launch before
claiming the original 51s path is cured.
Packaging no longer requests Cargo `--bins`, which linked every diagnostic and
smoke executable after core edits. It now requests only the authenticated
release sibling binaries, leaving the feature-gated coordinator in its existing

Binary file not shown.

View file

@ -34,9 +34,9 @@ invariants:
- Evidence and git retain history; this map retains only state that changes future decisions.
current_status:
summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Live v53 proves a complete typed Modeling-to-Imagination-to-Mind-to-Hands-to-Soul-to-Modeling circuit. Soul accepted the bounded consequence at revision 57; causal Modeling accepted result 972f4e31 at revision 59 and resolved the exact frontier without reopening or mutating other RepoModel anatomy. Self no longer derives Hands or Modeling and falls back to the legacy CRRC regather projection. The route is consumed. A keyed redb runtime backend and authenticated one-time migration are implemented locally and pass focused parity, stale-CAS, source-sealing, and coordinator transaction tests, but live migration is withheld until a coordinator-shaped benchmark proves the 51.482s commit seam. Persona consequence, retention, endurance, restart closure, and Linux/Yggdrasil cognition remain open.
summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Live v53 proves a complete typed Modeling-to-Imagination-to-Mind-to-Hands-to-Soul-to-Modeling circuit. Soul accepted the bounded consequence at revision 57; causal Modeling accepted result 972f4e31 at revision 59 and resolved the exact frontier without reopening or mutating other RepoModel anatomy. Self no longer derives Hands or Modeling and falls back to the legacy CRRC regather projection. The route is consumed. Historical-batch receipts falsified the claim that the 51.482s Modeling job-commit bucket was primarily whole-store CAS: legacy CAS is about 0.8-1.0s and keyed CAS about 0.03s, while synchronous two-pass Repository Body observation measured 92.30s. Bounded parallel raw-manifest construction preserves the same proof and measured 49.52s. Live redb migration is withheld. Persona consequence, retention, endurance, restart closure, and Linux/Yggdrasil cognition remain open.
operational_state:
local_worktree: storage_backend_and_packaging_cut_uncommitted_after_b070e121
local_worktree: clean_at_pushed_repository_body_parallel_pass
operator_wireguard: restored
yggdrasil: canonical_small_public_crossing_body
starfire: temporary_epiphany_cognition_body
@ -52,8 +52,8 @@ current_status:
bifrost_feedback_crossing: authenticated_transport_only
yggdrasil_epiphany_services: absent
resident_physiology: heartbeat_and_self_running
unresolved_authority: Modeling job commit still costs about 52 seconds against the 84 MiB runtime store. Release benchmarking shows keyed reads at 718ms versus 564ms legacy and keyed event mutation at 364ms versus 897ms legacy, but that is not yet the coordinator transaction shape. The adopted Mind decision also carries a model-supplied 2025 timestamp; coordinator commit-time timestamp ownership remains open. Persona consequence, Continuity closure, retention, endurance, and Linux cognition remain unproven.
next_action: Treat v53 as a closed circuit and do not reopen its resolved frontier through the legacy regather projection. Benchmark the exact coordinator job-commit replacement set against the migrated v53 copy; switch live only if that receipt proves the keyed backend removes the 51.482s seam without unacceptable read pressure. Then package the narrowed authenticated binary set and begin a separate native Persona consequence circuit followed by Continuity crash/restart/closure.
unresolved_authority: Modeling launch still synchronously performs an authenticated two-pass raw Repository Body observation. Parallel entry reads cut a direct release observation from 92.30s to 49.52s, but the next authenticated live launch must show whether this materially improves the original 51.482s bucket. Keyed storage is a secondary mutation optimization and has not earned live migration. The adopted Mind decision also carries a model-supplied 2025 timestamp; coordinator commit-time timestamp ownership remains open. Persona consequence, Continuity closure, retention, endurance, and Linux cognition remain unproven.
next_action: Treat v53 as a closed circuit and do not reopen its resolved frontier through the legacy regather projection. Package and authenticate the narrowed release plus parallel Repository Body observer, then measure one bounded live Modeling launch only if fresh typed pressure exists; otherwise use the direct observation receipt and proceed to a separate native Persona consequence circuit. Keep the legacy runtime store authoritative until a real live need justifies keyed migration. Follow Persona with Continuity crash/restart/closure.
active_subgoals:
- Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually.
@ -71,7 +71,7 @@ organ_readiness:
soul: proven for the current bounded route-chain consequence; exact d3bfbda0 launched Verification through typed plan-decision provenance, result f23fe2b6 was accepted at revision 57, and Self then derived Modeling before any repeated Hands authority.
mind: partial; RepoModel admission, thread-state admission, gateway review, state commit, first-valid verdict incorporation, bounded supervisor acceptance correction, and dedicated frontier-plan review requests are live. The current plan candidate awaits Mind adjudication.
continuity: partial; heartbeat and resident Self survive sequential cycles. v28 proved an ordinary bounded worker error could leave a runtime job falsely running after process death; the owner-local terminalization repair passes focused tests but still needs packaged crash/restart/closure proof.
nervous_system: partial; detached scheduling, runtime jobs, typed feedback, ordinary Windows coverage-store identity, and operator projection work. Fresh Modeling context assembly was below 250ms, but whole-store job commit cost 51.637s against a 76 MiB runtime store. Separate owner builds were rejected. Authenticated d910158f isolates Self policy behind one root-graph optional coordinator feature while core explicitly owns 74 non-coordinator binaries. Its cold stable phase took 17m38s, isolated coordinator phase 30.31s, and a real warm policy-source invalidation rebuilt only policy plus coordinator in 6.02s with all 20 stable packaged executables unchanged. Transaction cost, long-duration pressure, and resource plateau remain open. Yggdrasil is not a release forge at its current memory budget.
nervous_system: partial; detached scheduling, runtime jobs, typed feedback, ordinary Windows coverage-store identity, and operator projection work. Fresh Modeling context assembly was below 250ms. The prior 51.637s job-commit label included synchronous two-pass Repository Body observation; historical CAS receipts show snapshot persistence itself at about one second. Parallel raw-manifest construction cuts direct authenticated Body observation from 92.30s to 49.52s but still needs packaged launch confirmation. Separate owner builds were rejected. Authenticated d910158f isolates Self policy behind one root-graph optional coordinator feature while core explicitly owns 74 non-coordinator binaries. Its cold stable phase took 17m38s, isolated coordinator phase 30.31s, and a real warm policy-source invalidation rebuilt only policy plus coordinator in 6.02s with all 20 stable packaged executables unchanged. Long-duration pressure and resource plateau remain open. Yggdrasil is not a release forge at its current memory budget.
forbidden_actions:
- Do not issue a speculative deployment grant.