From 68c47b7ffa03b791862cf90843da83945e7292f6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 12 Jul 2026 12:49:22 +0100 Subject: [PATCH] Move heartbeat service lifecycle under Idunn --- .../src/bin/epiphany-heartbeat-store.rs | 75 ++++++++++++---- notes/epiphany-current-algorithmic-map.md | 7 ++ notes/fresh-workspace-handoff.md | 12 +++ notes/perfect-machine-audit-roadmap.md | 21 ++--- state/ledgers.msgpack | Bin 424152 -> 424533 bytes state/map.yaml | 2 +- tools/epiphany_ruminate_until.ps1 | 81 ------------------ 7 files changed, 91 insertions(+), 107 deletions(-) delete mode 100644 tools/epiphany_ruminate_until.ps1 diff --git a/epiphany-core/src/bin/epiphany-heartbeat-store.rs b/epiphany-core/src/bin/epiphany-heartbeat-store.rs index b05d6602..f05ecff7 100644 --- a/epiphany-core/src/bin/epiphany-heartbeat-store.rs +++ b/epiphany-core/src/bin/epiphany-heartbeat-store.rs @@ -2,6 +2,7 @@ use anyhow::Context; use anyhow::Result; use anyhow::anyhow; use epiphany_core::GhostlightSceneParticipantSeed; +use epiphany_core::EpiphanyCultMeshSwarmBrakeEntry; use epiphany_core::HeartbeatCompleteOptions; use epiphany_core::HeartbeatHeatUpdateOptions; use epiphany_core::HeartbeatPumpOptions; @@ -411,13 +412,38 @@ fn main() -> Result<()> { ) })?; let mut completed_iterations = 0_u64; + let mut completed_routines = 0_u64; + let mut refused_pulses = 0_u64; loop { if max_iterations > 0 && completed_iterations >= max_iterations { break; } - assert_swarm_brake_allows_heartbeat(&local_verse_store, "serve")?; let iteration = completed_iterations + 1; let iteration_dir = artifact_dir.join(format!("pulse-{iteration:06}")); + if let Some(brake) = active_swarm_brake(&local_verse_store)? { + completed_iterations = iteration; + refused_pulses += 1; + println!( + "{}", + serde_json::json!({ + "schemaVersion": "epiphany.heartbeat.serve_pulse.v0", + "status": "refused-by-swarm-brake", + "owner": "heartbeat", + "lifecycleOwner": "Idunn", + "iteration": iteration, + "artifactDir": iteration_dir, + "brakeId": brake.brake_id, + "brakeScope": brake.scope, + "reason": brake.reason, + "privateStateExposed": false + }) + ); + if max_iterations > 0 && completed_iterations >= max_iterations { + break; + } + thread::sleep(Duration::from_secs(interval_seconds)); + continue; + } let result = run_void_routine_store( &store_path, &iteration_dir, @@ -428,6 +454,7 @@ fn main() -> Result<()> { }, )?; completed_iterations = iteration; + completed_routines += 1; println!( "{}", serde_json::json!({ @@ -458,6 +485,8 @@ fn main() -> Result<()> { "artifactDir": artifact_dir, "intervalSeconds": interval_seconds, "completedIterations": completed_iterations, + "completedRoutines": completed_routines, + "refusedPulses": refused_pulses, "bounded": max_iterations > 0, "privateStateExposed": false }) @@ -488,26 +517,26 @@ fn next_value(args: &mut impl Iterator, name: &str) -> Result Result<()> { - Err(anyhow!( - "usage: epiphany-heartbeat-store init --store [--profile epiphany|ghostlight-scene] [--scene-id ] [--scene-participant ]\n epiphany-heartbeat-store tick --store --artifact-dir [--local-verse-store ] [--coordinator-action ] [--agent-store --apply-rumination] [--defer-completion]\n epiphany-heartbeat-store pump --store --artifact-dir [--local-verse-store ] [--agent-store ] [--urgency <0..1>] [--min-heartbeat-rate ] [--max-heartbeat-rate ] [--min-concurrency ] [--max-concurrency ] [--max-ticks ]\n epiphany-heartbeat-store heat --store [--local-verse-store ] [--scope global|all|agent|role|arena|participant_kind|group] [--selector ] [--multiplier ] [--id ] [--label ] [--reason ] [--expires-after ] [--clear]\n epiphany-heartbeat-store complete --store --artifact-dir --role [--action-id ]\n epiphany-heartbeat-store repair-stale --store --artifact-dir [--max-age-seconds ] [--reason ] [--now-utc ]\n epiphany-heartbeat-store queue-mention --store [--local-verse-store ] [--role Persona] --channel-id --message-id --author-id --content --visible-prompt [--author-name ] [--reply-to-message-id ] [--source-surface ]\n epiphany-heartbeat-store status --store [--artifact-dir ]\n epiphany-heartbeat-store routine --store --artifact-dir [--local-verse-store ] [--agent-store ] [--source ] [--no-dream]\n epiphany-heartbeat-store smoke [--agent-store ]" - )) + Err(anyhow!(concat!( + "usage: epiphany-heartbeat-store init --store [--profile epiphany|ghostlight-scene] [--scene-id ] [--scene-participant ]\n", + " epiphany-heartbeat-store tick --store --artifact-dir [options]\n", + " epiphany-heartbeat-store pump --store --artifact-dir [options]\n", + " epiphany-heartbeat-store heat --store [options]\n", + " epiphany-heartbeat-store complete --store --artifact-dir --role [--action-id ]\n", + " epiphany-heartbeat-store repair-stale --store --artifact-dir [options]\n", + " epiphany-heartbeat-store queue-mention --store [options]\n", + " epiphany-heartbeat-store status --store [--artifact-dir ]\n", + " epiphany-heartbeat-store routine --store --artifact-dir [options]\n", + " epiphany-heartbeat-store serve --store --artifact-dir [--local-verse-store ] [--agent-store ] [--source ] [--no-dream] [--interval-seconds ] [--max-iterations ]\n", + " epiphany-heartbeat-store smoke [--agent-store ]" + ))) } fn assert_swarm_brake_allows_heartbeat( local_verse_store: &Option, command: &str, ) -> Result<()> { - let Some(local_verse_store) = local_verse_store else { - return Ok(()); - }; - if !local_verse_store.exists() { - return Ok(()); - } - let Some(brake) = load_epiphany_cultmesh_swarm_brake(local_verse_store, "epiphany-local")? - else { - return Ok(()); - }; - if brake.status == "engaged" { + if let Some(brake) = active_swarm_brake(local_verse_store)? { anyhow::bail!( "epiphany-heartbeat-store {command} refusing to run: local Verse swarm brake engaged; scope={}; protected={}; affected={}; reason={}", brake.scope, @@ -519,6 +548,22 @@ fn assert_swarm_brake_allows_heartbeat( Ok(()) } +fn active_swarm_brake( + local_verse_store: &Option, +) -> Result> { + let Some(local_verse_store) = local_verse_store else { + return Ok(None); + }; + if !local_verse_store.exists() { + return Ok(None); + } + Ok(load_epiphany_cultmesh_swarm_brake( + local_verse_store, + "epiphany-local", + )? + .filter(|brake| brake.status == "engaged")) +} + fn parse_scene_participant(raw: &str) -> Result { let parts = raw.split('|').collect::>(); if parts.len() != 6 { diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 6e3cda7b..d902176a 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -355,6 +355,13 @@ artifact identity and success, supports bounded clean shutdown through Heartbeat owns pulse timing; the next cut is to launch this binary through Idunn and prove restart/resume, swarm-brake observability, and lifecycle readback before demoting the PowerShell rumination vigil. +That cut is now proven. An engaged brake produced two compact refused pulses +without terminating `serve`; releasing it let the same persisted store complete +a routine. Idunn then launched two pulses and a separate one-pulse restart from +that store with empty stderr and lifecycle receipts. The attached PowerShell +vigil is deleted. The remaining service boundary is durable Idunn policy and +operator readback: advertise/configure the heartbeat service through typed +daemon state so restart intent survives beyond one explicit `service-launch`. This map must change when ownership changes. Historical scars belong in git, evidence, or an explicitly archived note—not in the machine's proprioception. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 04bc7842..9baac121 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -2190,6 +2190,18 @@ completed two one-second pulses and stopped cleanly. Next launch the native serve loop through Idunn, prove persisted-state restart without duplicate pending turns, and make an engaged swarm brake observable without killing the service. +That service proof is complete. Brake/resume smoke root +`C:\Users\Meta\AppData\Local\Temp\epiphany-heartbeat-brake-4426a98f9c8e457784741fac5300d56c` +recorded two `refused-by-swarm-brake` pulses, clean closure with zero routines, +then one successful routine after release on the same store. Idunn launched +service `idunn-epiphany-heartbeat` for two routines and +`idunn-epiphany-heartbeat-restart` for a separate persisted-state restart; both +had empty stderr and compact clean closure receipts. Lifecycle receipt ids are +`daemon-service-lifecycle-receipt-idunn-epiphany-heartbeat-launch` and +`daemon-service-lifecycle-receipt-idunn-epiphany-heartbeat-restart-launch`. +The old `tools/epiphany_ruminate_until.ps1` attached loop is deleted. Next give +Idunn a durable typed heartbeat service policy/readback so restart intent and +current pulse status survive beyond an explicit operator `service-launch`. ## Immediate Re-entry Instruction diff --git a/notes/perfect-machine-audit-roadmap.md b/notes/perfect-machine-audit-roadmap.md index 2bf13903..bf4c16e4 100644 --- a/notes/perfect-machine-audit-roadmap.md +++ b/notes/perfect-machine-audit-roadmap.md @@ -92,16 +92,18 @@ The first native loop is landed as `epiphany-heartbeat-store serve`. It reuses the existing routine state owner, writes per-pulse artifact directories, emits compact sealed pulse/closure receipts, refuses a zero interval, and supports bounded clean shutdown for verification. It does not spawn or own child -lifecycle. `tools/epiphany_ruminate_until.ps1` still owns the old attached -operator vigil and must be demoted after Idunn proves the native service path. +lifecycle. The old attached PowerShell rumination vigil has been deleted; it no +longer owns timing, loop survival, or cycle status. ### Intended change -Launch the native `serve` loop through the existing Idunn service lifecycle -path. The heartbeat binary owns -pulse timing and typed heartbeat receipts. Idunn owns child survival, restart, -stdout/stderr artifacts, and lifecycle receipts. Self remains only the routing -organ consuming heartbeat pressure. +The bounded Idunn launch boundary is proven: the native loop survives brake +refusals, resumes from the same persisted store, and can be launched again by +Idunn without duplicate pending turns. The heartbeat binary owns pulse timing +and typed heartbeat receipts. Idunn owns child launch, stdout/stderr artifacts, +and lifecycle receipts. Self remains only the routing organ consuming heartbeat +pressure. The remaining step is durable Idunn restart policy and compact +operator readback for the heartbeat service, not another explicit launch smoke. ### Owner @@ -142,9 +144,8 @@ daemon is orchestration around those owners, not a second scheduler. ### Cut line -Demote `tools/epiphany_ruminate_until.ps1` to a historical/operator probe after -the native loop and Idunn launch proof exist. Do not preserve its timing, -status, or cycle-directory conventions as runtime authority. +The attached PowerShell rumination vigil is deleted. Do not preserve its +timing, status, or cycle-directory conventions as runtime authority. ### Verification diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 193bb031cc6ffc51b3c16fe1fc3343287f9f2421..b341cc058e3a06f6b87e58ccf787ff7ef597bc21 100644 GIT binary patch delta 398 zcmXv~y-LJD5H>mQID7#0x&hns#KT5gZ3Iz4E5TwenM)Rv-MBNGkjlcs2aw}x-$1bN z4SWN^);CbF*GXaVF*~#K{p@~xkKTVq&!cE<|6q4|^|mr-r!QO4Z4`aoFXD$q94Wfm zQ>-fbuZwtaST9dLtna3L)B17WJ3KIcO^T2vvg@TF4+H)v%#k(NJ>cLr%oPe<;sOZwO zVd?b5c>Rlp96K!Vn~?qPyPvm4#X L0E6Vt8)+wh#a59) delta 56 zcmccmMe@c+$qkZ>TqahArcuWj*vhwVR%R?@WPIN|m8pFy6C)6VXl5X00bPD F%K%4R62t%i diff --git a/state/map.yaml b/state/map.yaml index bdd62d20..a374b635 100644 --- a/state/map.yaml +++ b/state/map.yaml @@ -659,4 +659,4 @@ current_status: - Service lifecycle receipt history is now event-only: `load_epiphany_cultmesh_daemon_service_lifecycle_receipts` filters out the `epiphany-local/daemon-service-lifecycle-receipt/latest` mirror, while `load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt` remains the latest-state reader. Focused unit test `service_lifecycle_receipt_history_excludes_latest_mirror` proves two per-receipt writes return exactly two history records and latest points at the second. Fresh smoke `verse-query-lifecycle-history-filter-smoke` and live overview/triage `local-20260618-145632-497-efac6f0d` / `local-20260618-145632-321-867947af` prove compact swarm sights still expose service lifecycle attention plus the present elevated runbook artifact without daemon pokes or service mutation. Do not use a broad unscoped cargo test filter for this check on Windows; it fans out across bin harnesses and hit a broken pipe during this pass. - `epiphany-verse-query seed-compact` is the compact seed receipt for wrappers and read-only rites. The older `seed` command still prints the full local Verse context for explicit debugging, but compact wrapper modes now avoid full `seed`/final `query` readback after the combined overview proof exposed Windows debug stack overflow from full-context serialization pressure. last_completed_repo_swarm_cut: Huginn live-fire has crossed the first real repo Body from Persona pressure to branch-local Hands commit and Soul/Mind closure, and now has repeatable closure and redacted-public-proof mouths. On `E:\Projects\Huginn` branch `epiphany/huginn/first-awakening`, `tools/epiphany_local_run.ps1 -Mode repo-persona-intake` accepted item `huginn-inspection-readback-livefire`, Weksa/Persona intake remained sealed, and `epiphany-work derive-plan` lowered it to model-authored safe family `repo.status_section` for `README.md` only. `tools/epiphany_local_run.ps1 -Mode repo-swarm-run` advanced four bounded pulses: run-from-plan, adopt-from-plan, execute-from-plan, and close-from-execute. Huginn commit `e9b07c38fceabbdc89ea35c2156326c80c0393a2` updated only `README.md`; closure receipt `.epiphany\work\work-close-huginn-inspection-readback-livefire.json` records status `closed`, Soul verdict `passed`, Mind state commit `repo-work-close-huginn-inspection-readback-livefire-mind-commit`, safe family `repo.status_section`, path scope `README.md`, Bifrost publication gate, and `privateStateExposed=false`. Verification also ran Huginn's TypeScript compiler through concrete Node path: `C:\Program Files\nodejs\node.exe E:\Projects\Huginn\node_modules\typescript\bin\tsc -p tsconfig.json` passed. Native verifier `epiphany-repo-livefire-closure-smoke --workspace E:\Projects\Huginn --item huginn-inspection-readback-livefire --expected-path README.md --expected-family repo.status_section --expected-gate awaiting-publication --expected-blocker bifrost-publication-missing` checks closure receipt, Mind map entry, overview gate/blocker, authority seals, and `git show` changed paths, returning `status=ok`, `soulVerdict=passed`, `publicationGate=Bifrost`, and `privateStateExposed=false`. Wrapper `tools/epiphany_local_run.ps1 -Mode repo-livefire-closure -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exposes the same read-only proof through the local operator mouth; artifact `local-20260621-190156-803-2f85ba15` printed commit, path, gate, blocker, Soul verdict, Mind commit receipt, and `privateStateExposed=False` without push, merge, publication, or target mutation. New wrapper `tools/epiphany_local_run.ps1 -Mode repo-work-public-proof -Workspace E:\Projects\Huginn -RepoWorkItem huginn-inspection-readback-livefire -SkipBuild` exports the redacted proof bundle and repo-local Verse index without publishing; artifact `local-20260621-190645-345-4555b1dc` wrote `.epiphany\public\proof-bundles\repo-work-public-proof-huginn-inspection-readback-livefire.json`, proof id `repo-work-public-proof-huginn-inspection-readback-livefire`, SHA-256 `857545b199f3e37eb06c2e757e5cfc201958e46667bb1f8403fd333a22620f63`, nine artifact rows, zero publication rows, and `privateStateExposed=False`. Gjallar readback `local-20260621-190701-140-b9519ec6` sees the `REPO-WORK-PUBLIC-PROOF` row and action row from Huginn's repo-local Verse with the same SHA-256 while Bifrost publication remains missing. Launcher compact modes are now named compact operator-context modes instead of read-only modes, and `bifrost-public-proof` summaries print item, target public Verse, room, proof SHA-256, review receipts, and credit receipts so publication receipts are auditable without claiming upstream sync. - next_action: Complete the native heartbeat service boundary selected by the refreshed Perfect Machine audit. Launch `epiphany-heartbeat-store serve` through Idunn, prove its lifecycle receipt and persisted-state restart without duplicate pending turns, keep an engaged swarm brake observable instead of terminating the service, then demote the attached PowerShell rumination vigil from runtime authority. + next_action: Give Idunn durable typed ownership of the native heartbeat service beyond one explicit `service-launch`. Publish/configure the heartbeat serve command through existing daemon restart policy and operator readback surfaces, expose last pulse/brake/clean-stop state without opening routine payloads, and prove Idunn can reconcile/restart it from persisted heartbeat state without duplicate pending turns. diff --git a/tools/epiphany_ruminate_until.ps1 b/tools/epiphany_ruminate_until.ps1 deleted file mode 100644 index c0290e1a..00000000 --- a/tools/epiphany_ruminate_until.ps1 +++ /dev/null @@ -1,81 +0,0 @@ -param( - [string]$Until = "19:00", - [string]$Root = (Resolve-Path ".").Path, - [int]$IntervalSeconds = 120 -) - -$ErrorActionPreference = "Continue" -Set-Location -LiteralPath $Root - -$now = Get-Date -$target = [datetime]::ParseExact($Until, "HH:mm", $null) -$target = Get-Date -Year $now.Year -Month $now.Month -Day $now.Day -Hour $target.Hour -Minute $target.Minute -Second 0 -if ($target -le $now) { - $target = $target.AddDays(1) -} - -$runId = "perfect-machine-" + $now.ToString("yyyyMMdd-HHmmss") -$artifactDir = Join-Path $Root ".epiphany-rumination\$runId" -New-Item -ItemType Directory -Force -Path $artifactDir | Out-Null - -$logPath = Join-Path $artifactDir "rumination.log" -$statusPath = Join-Path $artifactDir "status.json" -$summaryPath = Join-Path $artifactDir "summary.md" - -$env:CARGO_TARGET_DIR = "C:\Users\Meta\.cargo-target-codex" - -function Write-Log([string]$Message) { - $line = "$(Get-Date -Format o) $Message" - Add-Content -LiteralPath $logPath -Value $line -} - -Write-Log "Starting Perfect Machine rumination until $($target.ToString("o"))." - -$cycles = 0 -$failures = 0 - -while ((Get-Date) -lt $target) { - $cycles += 1 - Write-Log "Cycle ${cycles}: heartbeat routine." - $cycleArtifactDir = Join-Path $artifactDir ("cycle-{0:D3}" -f $cycles) - New-Item -ItemType Directory -Force -Path $cycleArtifactDir | Out-Null - - & cargo run --manifest-path ".\epiphany-core\Cargo.toml" --bin epiphany-heartbeat-store -- routine --store ".\state\agent-heartbeats.msgpack" --artifact-dir $cycleArtifactDir --agent-store ".\state\agents.msgpack" --source "epiphany/perfect-machine-rumination" *> (Join-Path $cycleArtifactDir "routine.out") - if ($LASTEXITCODE -ne 0) { - $failures += 1 - Write-Log "Cycle ${cycles}: routine failed with exit code $LASTEXITCODE." - } else { - Write-Log "Cycle ${cycles}: routine completed." - } - - & cargo run --manifest-path ".\epiphany-core\Cargo.toml" --bin epiphany-heartbeat-store -- status --store ".\state\agent-heartbeats.msgpack" *> $statusPath - if ($LASTEXITCODE -ne 0) { - $failures += 1 - Write-Log "Cycle ${cycles}: status failed with exit code $LASTEXITCODE." - } - - $remaining = ($target - (Get-Date)).TotalSeconds - if ($remaining -le 0) { - break - } - Start-Sleep -Seconds ([Math]::Min($IntervalSeconds, [Math]::Max(1, [int]$remaining))) -} - -@" -# Perfect Machine Rumination - -- started: $($now.ToString("o")) -- finished: $((Get-Date).ToString("o")) -- target: $($target.ToString("o")) -- cycles: $cycles -- failures: $failures -- artifactDir: $artifactDir -- log: $logPath -- latestStatus: $statusPath - -This pass repeatedly ran the native heartbeat routine over `state/agent-heartbeats.msgpack`, -projecting memory resonance, thought lanes, appraisals, reactions, sleep, and dream -maintenance through the typed Rust/CultCache surface. -"@ | Set-Content -LiteralPath $summaryPath -Encoding UTF8 - -Write-Log "Completed Perfect Machine rumination with $cycles cycles and $failures failures."