Share resident singleton locks across containers

This commit is contained in:
Meta Vens 2026-08-09 10:33:52 +01:00
commit c930f50529
3 changed files with 47 additions and 7 deletions

View file

@ -10,6 +10,7 @@ use cultcache_rs::{
SingleFileMessagePackBackingStore,
};
use serde::Serialize;
#[cfg(windows)]
use sha2::{Digest, Sha256};
#[cfg(windows)]
use std::ffi::OsStr;
@ -38,6 +39,15 @@ pub struct ResidentProcessSingletonGuard {
file: File,
}
#[cfg(unix)]
fn resident_process_singleton_lock_path(role: &str, store: &Path) -> Result<PathBuf> {
let file_name = store
.file_name()
.ok_or_else(|| anyhow!("resident singleton store has no file name"))?
.to_string_lossy();
Ok(store.with_file_name(format!("{file_name}.{role}.process.lock")))
}
impl Drop for ResidentProcessSingletonGuard {
fn drop(&mut self) {
#[cfg(windows)]
@ -60,12 +70,12 @@ pub fn acquire_resident_process_singleton(
bail!("unsupported resident singleton role: {role}");
}
let store = canonical_or_absolute(store.as_ref());
let identity = format!(
"{:x}",
Sha256::digest(format!("{role}|{}", store.to_string_lossy().to_lowercase()).as_bytes())
);
#[cfg(windows)]
{
let identity = format!(
"{:x}",
Sha256::digest(format!("{role}|{}", store.to_string_lossy().to_lowercase()).as_bytes())
);
let name = OsStr::new(&format!("Global\\EpiphanyResident-{role}-{identity}"))
.encode_wide()
.chain(std::iter::once(0))
@ -88,7 +98,7 @@ pub fn acquire_resident_process_singleton(
}
#[cfg(unix)]
{
let path = std::env::temp_dir().join(format!("epiphany-resident-{role}-{identity}.lock"));
let path = resident_process_singleton_lock_path(role, &store)?;
let file = File::options()
.create(true)
.read(true)
@ -733,6 +743,21 @@ mod tests {
Ok(())
}
#[cfg(unix)]
#[test]
fn unix_resident_singleton_lock_is_shared_beside_the_mounted_store() -> Result<()> {
let store = Path::new("/state/resident.cc");
assert_eq!(
resident_process_singleton_lock_path("resident-self", store)?,
PathBuf::from("/state/resident.cc.resident-self.process.lock")
);
assert_eq!(
resident_process_singleton_lock_path("heartbeat", store)?,
PathBuf::from("/state/resident.cc.heartbeat.process.lock")
);
Ok(())
}
#[test]
fn resident_readiness_reads_the_canonical_brake_store_truth() -> Result<()> {
let temp = tempfile::tempdir()?;

View file

@ -1,5 +1,20 @@
# Fresh workspace handoff
## Warm package acceptance and resident-owner lock — 2026-08-09
Construction-owned Cargo home is accepted. Exact `9f369528` migration release
`sha256-154af0ef9a729f7f46876f99add6828d7e5503f3ecc949ac791f00f26017beca`
with witness `sha256-9b670a4acca14480840da3f09fd83ff5c97829b19f81bd6037c59c9146548cec`
took 15m04s once. The identical warm replay took 10.17s wall, Cargo 1.38s,
and passed independent 24-binary inspection without warnings or collisions.
Do not describe the resident store as globally single-writer. Heartbeat and
authenticated operator admission own separate typed CAS entries. The proven
fault is that Unix `resident-self` singleton locks use container-private temp
directories. Current source places role-specific process locks beside the
mounted store, preserving Heartbeat's distinct role lock. Windows focused
tests pass; package once and prove two-container exclusion on Linux.
## Corrected shutdown replay and Cargo-home ownership — 2026-08-09
Exact `b8138a6b` release `sha256-f3e0966333b86181bf13893a45f7636d0c6ff13720fbf535b29cca485c3fd58d`

View file

@ -35,7 +35,7 @@ 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. Exact b8138a6b active-child SIGTERM and restart are proven on copied Linux physiology: exact coordinator termination, zero resident exit, truthful braked projection, restart to sleeping, and second idle zero exit. Concurrent external writes to the live resident store can be overwritten by its in-memory owner and remain an open authority seam. Exact b8138a6b packaging took 19m26s because routine release construction still has cold-cache corrosion; source now makes build_cache_root own Cargo home instead of relying on a throwaway container home, and awaits exact benchmark. Retention, long-duration plateau, log ownership, and stable Starfire firewall ownership remain open. Yggdrasil is the small public crossing body, never the release forge.
summary: Epiphany is a supervised engineering alpha on Starfire, not deployment-ready. Exact b8138a6b active-child SIGTERM and restart are proven on copied Linux physiology. Exact 9f369528 makes build_cache_root own Cargo home: the one-time migration package took 15m04s, then an independently inspected identical 24-binary warm replay took 10.17s wall with Cargo at 1.38s. Runtime inspection narrowed the live-store seam: typed CAS entry writers remain legitimate, but Unix resident singleton locks live in container-private temp directories and permit two resident owners for one mounted store. Current source moves those locks beside the mounted store and awaits exact Linux packaging and cross-container exclusion proof. Retention, long-duration plateau, log ownership, and stable Starfire firewall ownership remain open. Yggdrasil is the small public crossing body, never the release forge.
latest_phase: Commit 76afdaf0 moved release construction, filesystem verification, and witness inspection out of monolithic epiphany-core into epiphany-release-construction; core retains only CultMesh publication, load, and authentication. The bootstrap dependency graph excludes epiphany-core, all 19 construction tests pass, and the full core test harness compiles. Exact Linux bootstrap fell from 7m57s to 30.24s cold and 4.40s warm. Exact source 76afdaf0 then produced warning-free 24-binary release sha256-30caab9ef1ea89f9a885d87832b1e312a35288ec3f895bd5b0e83f7f7a6a1aec with witness sha256-89c2ad604254faec3e1e01f753b5dff38a402f43d009074ba4b47b1ec46fdecf. Independent inspection accepted the 12m16s cold build and the identical 10.16s warm replay with Cargo at 0.82s. The packaged full publisher accepted the narrow constructor's witness and changed c005 local-verse.cc from SHA-256 b160c610988753278afbad7f5bad436193144a92e9fd506982099ad58d213909 to 83ed430f5bf0c33996d7c4ee7bf0fa6c9f5f80bc8db94621395ea560852cae81 without body activation.
operational_state:
local_worktree: release_construction_receipts_pending_commit
@ -69,7 +69,7 @@ current_status:
yggdrasil_epiphany_service_contract: repaired_in_gamecult_ops_812b427_not_installed
resident_physiology: authenticated_9b8df0b4_c005_bound_to_eyes_tools_nervous_system_with_217dd_and_bd96305e_helpers_running
unresolved_authority: SIGTERM is not observed by epiphany-swarm; serve owns an unconditional loop and blocking sleep, so Docker stops end in exit 137 even while idle. Repository Body observation still performs two authenticated full-tree Git index/manifest passes. Execute-mode workers require a persistent process body. Keyed storage has not earned live migration. One Discord consequence remains blocked by the absent Yggdrasil credential. Resident stdout/stderr logs remain an unbounded supervisor-owned surface.
next_action: Commit and benchmark construction-owned Cargo home with one cold migration and one warm replay. Then map and repair the live resident-store single-writer/command-ingress seam before retention and endurance.
next_action: Commit the mounted-store singleton lock, build it once through the proven warm package graph, and prove a second resident owner in another container is refused while Heartbeat retains its separate typed-entry authority. Then continue retention and endurance.
active_subgoals:
- Prove Persona, Self, Eyes, Modeling, Imagination, Hands, Soul, Mind, Continuity, and nervous-system behavior individually.