From 2590627881c4bbe0704b4d60ef22bf3d551520d3 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 12 Jul 2026 20:01:07 +0100 Subject: [PATCH] Move daemon lifecycle truth to provider --- .../src/bin/epiphany-cluster-daemon.rs | 36 +++- epiphany-core/src/bin/epiphany-verse-query.rs | 186 ++++-------------- notes/epiphany-current-algorithmic-map.md | 8 + notes/fresh-workspace-handoff.md | 4 + state/ledgers.msgpack | Bin 429692 -> 430143 bytes state/map.yaml | 2 +- 6 files changed, 77 insertions(+), 159 deletions(-) diff --git a/epiphany-core/src/bin/epiphany-cluster-daemon.rs b/epiphany-core/src/bin/epiphany-cluster-daemon.rs index 6b4bbec4..0c62f36d 100644 --- a/epiphany-core/src/bin/epiphany-cluster-daemon.rs +++ b/epiphany-core/src/bin/epiphany-cluster-daemon.rs @@ -1,10 +1,12 @@ use anyhow::Context; use anyhow::Result; use chrono::Utc; -use epiphany_core::EpiphanyCultMeshDaemonStatusEntry; +use epiphany_core::load_epiphany_cultmesh_cluster_topology; use epiphany_core::query_epiphany_local_verse_context; use epiphany_core::seed_epiphany_local_verse_context; use epiphany_core::write_epiphany_cultmesh_daemon_status; +use epiphany_core::EpiphanyCultMeshDaemonStatusEntry; +use epiphany_core::EPIPHANY_CULTMESH_DAEMON_STATUS_SCHEMA_VERSION; use serde_json::json; use std::env; use std::path::PathBuf; @@ -48,12 +50,32 @@ fn write_heartbeat(args: &Args, iteration: u64) -> Result Result<()> { ); } "poke-daemon" | "daemon-poke" => { + reject_daemon_poke_response_fields(&args)?; seed_epiphany_local_verse_context( &args.store, args.runtime_id.clone(), @@ -666,43 +667,21 @@ fn run_cli() -> Result<()> { .collect::() ) }); - let receipt_id = args - .receipt_id - .clone() - .unwrap_or_else(|| intent_id.replace("intent", "receipt")); - let resulting_status = args - .resulting_status - .clone() - .unwrap_or_else(|| daemon_status.status.clone()); - let receipt_status = args - .receipt_status - .clone() - .unwrap_or_else(|| "recorded".to_string()); - let artifact_ref = args - .artifact_ref - .clone() - .unwrap_or_else(|| format!("cultmesh://epiphany-local/daemon-poke/{intent_id}")); - let poke_result = write_daemon_poke_receipts( + let poke_result = write_daemon_poke_intent( &args, &context, daemon_status, intent_id, - receipt_id, reason, - resulting_status, - receipt_status, - artifact_ref, )?; let context = query_epiphany_local_verse_context(&args.store, args.runtime_id.clone())?; - if context.latest_daemon_poke_intent.is_none() - || context.latest_daemon_poke_receipt.is_none() - { - anyhow::bail!("local Verse query lost daemon poke intent/receipt after write"); + if context.latest_daemon_poke_intent.is_none() { + anyhow::bail!("local Verse query lost daemon poke intent after write"); } println!( "{}", serde_json::to_string_pretty(&json!({ - "status": "ok", + "status": "pending-lifecycle-owner", "store": args.store, "runtimeId": context.runtime_id, "targetDaemonId": poke_result["targetDaemonId"], @@ -712,29 +691,31 @@ fn run_cli() -> Result<()> { "receiptId": poke_result["receiptId"], "receiptStatus": poke_result["receiptStatus"], "resultingStatus": poke_result["resultingStatus"], + "responseOwner": poke_result["responseOwner"], "privateStateRequested": poke_result["privateStateRequested"], "privateStateExposed": poke_result["privateStateExposed"], }))? ); } "poke-down-daemons" | "poke-unready-daemons" | "daemon-poke-down" => { + reject_daemon_poke_response_fields(&args)?; seed_epiphany_local_verse_context( &args.store, args.runtime_id.clone(), Utc::now().to_rfc3339(), )?; let context = query_epiphany_local_verse_context(&args.store, args.runtime_id.clone())?; - let pokes = write_poke_receipts_for_non_ready_daemons(&args, &context)?; + let pokes = write_poke_intents_for_non_ready_daemons(&args, &context)?; let poke_tui_rows = pokes.iter().map(poke_result_tui_row).collect::>(); let context = query_epiphany_local_verse_context(&args.store, args.runtime_id.clone())?; println!( "{}", serde_json::to_string_pretty(&json!({ - "status": if pokes.is_empty() { "noop" } else { "ok" }, + "status": if pokes.is_empty() { "noop" } else { "pending-lifecycle-owner" }, "store": args.store, "runtimeId": context.runtime_id, "observedDaemonCount": context.daemon_statuses.len(), - "pokedDaemonCount": pokes.len(), + "requestedDaemonCount": pokes.len(), "pokes": pokes, "pokeRows": poke_tui_rows, "tuiRows": poke_tui_rows, @@ -864,77 +845,12 @@ fn run_cli() -> Result<()> { } else { let context = query_epiphany_local_verse_context(&args.store, args.runtime_id.clone())?; - write_poke_receipts_for_non_ready_daemons(&args, &context)? + write_poke_intents_for_non_ready_daemons(&args, &context)? }; let output = SwarmTriageOutput::from_report(args.store, args.runtime_id, overview, pokes); println!("{}", serde_json::to_string_pretty(&output)?); } - "daemon-status" | "set-daemon-status" => { - seed_epiphany_local_verse_context( - &args.store, - args.runtime_id.clone(), - Utc::now().to_rfc3339(), - )?; - let context = query_epiphany_local_verse_context(&args.store, args.runtime_id.clone())?; - let daemon_id = args - .daemon_id - .as_deref() - .context("daemon-status requires --daemon-id, for example epiphany-daemon-hands")?; - let current = context - .daemon_statuses - .iter() - .find(|status| status.daemon_id == daemon_id) - .with_context(|| format!("local Verse has no daemon status for {daemon_id:?}"))?; - let status = args - .daemon_status - .clone() - .or_else(|| args.resulting_status.clone()) - .unwrap_or_else(|| "ready".to_string()); - let operator_action = args - .operator_action - .clone() - .or_else(|| args.requested_action.clone()) - .unwrap_or_else(|| { - if status == "ready" { - "none".to_string() - } else { - "pokeDaemon".to_string() - } - }); - let mut next = current.clone(); - next.status = status; - next.last_heartbeat_utc = Utc::now().to_rfc3339(); - next.operator_action = operator_action; - if let Some(reason) = args.reason.clone() { - next.notes.push(format!("Status update reason: {reason}")); - } - let written = - write_epiphany_cultmesh_daemon_status(&args.store, args.runtime_id.clone(), next)?; - let context = query_epiphany_local_verse_context(&args.store, args.runtime_id.clone())?; - let projected = context - .daemon_statuses - .iter() - .find(|status| status.daemon_id == written.daemon_id) - .context("local Verse query lost daemon status after write")?; - if projected.status != written.status { - anyhow::bail!("local Verse projected a different daemon status after write"); - } - println!( - "{}", - serde_json::to_string_pretty(&json!({ - "status": "ok", - "store": args.store, - "runtimeId": context.runtime_id, - "daemonId": written.daemon_id, - "clusterId": written.cluster_id, - "daemonStatus": written.status, - "operatorAction": written.operator_action, - "lastHeartbeatUtc": written.last_heartbeat_utc, - "privateStateExposed": written.private_state_exposed, - }))? - ); - } "bifrost-publication" | "publish-body-change" => { if args.receipt_id.is_some() || args.receipt_status.is_some() @@ -2468,7 +2384,7 @@ fn run_cli() -> Result<()> { "local Verse query smoke lost Eve surface readback for globally invokable eve-connect tools" ); } - let no_op_pokes = write_poke_receipts_for_non_ready_daemons(&args, &context)?; + let no_op_pokes = write_poke_intents_for_non_ready_daemons(&args, &context)?; if !no_op_pokes.is_empty() { anyhow::bail!("local Verse query smoke poked ready daemons during no-op sweep"); } @@ -2612,7 +2528,7 @@ fn run_cli() -> Result<()> { "local Verse query smoke degraded overview lost wrapper poke command" ); } - let batch_pokes = write_poke_receipts_for_non_ready_daemons(&args, &context)?; + let batch_pokes = write_poke_intents_for_non_ready_daemons(&args, &context)?; if batch_pokes.len() != 1 { anyhow::bail!( "local Verse query smoke expected exactly one batch daemon poke, got {}", @@ -2666,7 +2582,7 @@ fn run_cli() -> Result<()> { let triage_pokes = if triage_overview.liveness_status == "ready" { Vec::new() } else { - write_poke_receipts_for_non_ready_daemons(&args, &context)? + write_poke_intents_for_non_ready_daemons(&args, &context)? }; if triage_overview.status != "attention" || triage_overview.attention_daemon_ids != vec!["epiphany-daemon-hands".to_string()] @@ -9770,16 +9686,25 @@ fn compact_tui_text(value: &str, max_chars: usize) -> String { + "..." } -fn write_daemon_poke_receipts( +fn reject_daemon_poke_response_fields(args: &Args) -> Result<()> { + if args.receipt_id.is_some() + || args.receipt_status.is_some() + || args.resulting_status.is_some() + || args.artifact_ref.is_some() + { + anyhow::bail!( + "daemon poke commands accept requester intent fields only; the lifecycle owner owns receipt id/status, resulting daemon status, and result artifacts" + ); + } + Ok(()) +} + +fn write_daemon_poke_intent( args: &Args, context: &EpiphanyLocalVerseContext, daemon_status: &EpiphanyCultMeshDaemonStatusEntry, intent_id: String, - receipt_id: String, reason: String, - resulting_status: String, - receipt_status: String, - artifact_ref: String, ) -> Result { assert_swarm_brake_allows_surface( context, @@ -9798,18 +9723,6 @@ fn write_daemon_poke_receipts( args.runtime_id.clone(), poke_intent.clone(), )?; - let poke_receipt = epiphany_cultmesh_daemon_poke_receipt_for_intent( - receipt_id, - &poke_intent, - receipt_status, - resulting_status, - artifact_ref, - ); - let written_receipt = write_epiphany_cultmesh_daemon_poke_receipt( - &args.store, - args.runtime_id.clone(), - poke_receipt, - )?; let cluster = cluster_topology_for_id(context, &written_intent.target_cluster_id)?; Ok(json!({ "targetDaemonId": written_intent.target_daemon_id, @@ -9820,15 +9733,16 @@ fn write_daemon_poke_receipts( "eveSurfaceId": cluster.eve_surface_id.clone(), "observedStatus": written_intent.observed_status, "intentId": written_intent.intent_id, - "receiptId": written_receipt.receipt_id, - "receiptStatus": written_receipt.status, - "resultingStatus": written_receipt.resulting_status, + "receiptId": null, + "receiptStatus": null, + "resultingStatus": null, + "responseOwner": "Idunn/target-daemon", "privateStateRequested": written_intent.private_state_requested, - "privateStateExposed": written_receipt.private_state_exposed, + "privateStateExposed": false, })) } -fn write_poke_receipts_for_non_ready_daemons( +fn write_poke_intents_for_non_ready_daemons( args: &Args, context: &EpiphanyLocalVerseContext, ) -> Result> { @@ -9842,35 +9756,18 @@ fn write_poke_receipts_for_non_ready_daemons( for daemon_status in statuses { let safe_daemon_id = sanitize_id(&daemon_status.daemon_id); let intent_id = format!("daemon-poke-intent-{safe_daemon_id}-{issued_at}"); - let receipt_id = format!("daemon-poke-receipt-{safe_daemon_id}-{issued_at}"); let reason = args.reason.clone().unwrap_or_else(|| { format!( "Operator requested typed lifecycle poke sweep after observing {} status {}.", daemon_status.daemon_id, daemon_status.status ) }); - let resulting_status = args - .resulting_status - .clone() - .unwrap_or_else(|| daemon_status.status.clone()); - let receipt_status = args - .receipt_status - .clone() - .unwrap_or_else(|| "recorded".to_string()); - let artifact_ref = args - .artifact_ref - .clone() - .unwrap_or_else(|| format!("cultmesh://epiphany-local/daemon-poke-sweep/{intent_id}")); - pokes.push(write_daemon_poke_receipts( + pokes.push(write_daemon_poke_intent( args, context, daemon_status, intent_id, - receipt_id, reason, - resulting_status, - receipt_status, - artifact_ref, )?); } Ok(pokes) @@ -10576,8 +10473,6 @@ struct Args { smoke_default_store: bool, agent_store: Option, daemon_id: Option, - daemon_status: Option, - operator_action: Option, capability_id: Option, requesting_agent_id: Option, brake_id: Option, @@ -10637,8 +10532,6 @@ impl Args { let mut runtime_id_overridden = false; let mut agent_store = None; let mut daemon_id = None; - let mut daemon_status = None; - let mut operator_action = None; let mut capability_id = None; let mut requesting_agent_id = None; let mut brake_id = None; @@ -10705,13 +10598,6 @@ impl Args { "--daemon-id" => { daemon_id = Some(values.next().context("missing --daemon-id value")?); } - "--daemon-status" => { - daemon_status = Some(values.next().context("missing --daemon-status value")?); - } - "--operator-action" => { - operator_action = - Some(values.next().context("missing --operator-action value")?); - } "--capability-id" => { capability_id = Some(values.next().context("missing --capability-id value")?); } @@ -10959,8 +10845,6 @@ impl Args { smoke_default_store, agent_store, daemon_id, - daemon_status, - operator_action, capability_id, requesting_agent_id, brake_id, diff --git a/notes/epiphany-current-algorithmic-map.md b/notes/epiphany-current-algorithmic-map.md index 20a494f4..d886f7b5 100644 --- a/notes/epiphany-current-algorithmic-map.md +++ b/notes/epiphany-current-algorithmic-map.md @@ -37,6 +37,14 @@ - Dependent invariant: collaboration feedback may cite only a persisted provider receipt; a consumer request is not acceptance. - Negative proof: provider receipt remains absent after request, response-shaped fields fail, and feedback without provider acceptance fails. +## Daemon lifecycle request and heartbeat paths (2026-07-12) + +- Request owner: Self/operator owns a daemon-poke intent; Idunn or the target daemon owns its receipt and resulting status. +- Poke output: pending intent with observed status and null receipt/result fields, shared by single, batch, and triage paths. +- Forbidden writers: poke callers cannot provide receipt id/status, resulting status, or artifact; the generic Verse CLI daemon-status writer no longer exists. +- Heartbeat owner: `epiphany-cluster-daemon` writes status. On its first run it derives identity/routing fields from persisted topology and authors the first heartbeat itself. +- Negative proof: a real provider heartbeat can precede a pending poke; no poke receipt appears, counterfeit `ready` result is rejected, and `set-daemon-status` is unavailable. + This is the source-grounded map of the live machine. Historical route and bridge anatomy belongs in git history and evidence ledgers, not here. diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 1c764eac..99011c62 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -16,6 +16,10 @@ The conceptual-substitution audit found observation manufacturing the body it cl `connect-eve` and wrapper mode `eve-connect` now persist only `epiphany.cultmesh.eve_connection_intent`, return `pending-provider`, name the target cluster as response owner, and leave receipt fields null. Consumer-supplied connection receipt id/status is rejected. The request path no longer projects repo-work queue data as if the provider had accepted and returned a surface. `collaboration-feedback` now requires the cited Eve connection receipt to exist in CultMesh, and the wrapper no longer invokes `connect-eve` then cites a receipt that the same command fabricated. Physical proof shows intent present, provider receipt absent, counterfeit receipt fields rejected, and feedback refused without a genuine provider receipt. +## 2026-07-12 daemon lifecycle requester/provider split + +Single poke, batch poke, and swarm triage now write only `epiphany.cultmesh.daemon_poke_intent`. They report `pending-lifecycle-owner`, leave receipt/result fields null, and reject caller-supplied receipt id/status, resulting daemon status, or artifact result. The generic `daemon-status` / `set-daemon-status` CLI writer was deleted because it let callers proclaim readiness and stamp a heartbeat. `epiphany-cluster-daemon`, the provider body, now creates its own initial status from persisted topology after bootstrap rather than depending on a seeded fake heartbeat. Physical proof: provider heartbeat `degraded`, poke intent observes `degraded`, provider receipt absent, caller-supplied `ready` result rejected, and generic status writer unavailable. + This is the re-entry rite for `E:\Projects\EpiphanyAgent`: the waking chant for the local machine-spirit before it touches the forge. diff --git a/state/ledgers.msgpack b/state/ledgers.msgpack index 5c454daa42a1d2fac0b53f6d83343acf1c4efb19..410bf10b9b66e5bb0a379ddd3bcdf5562a6cb20f 100644 GIT binary patch delta 425 zcmYLEy-or_5cW_{8?6ilT8uGT@plv&ZS@VXvRm#3Ze-a#cjq8f78Zt>XrYA0!bdQ% zFjjWHiZ4Oo5JZ#x_9wI7-}Jfk`BHi<1{=pG^+?vm*HZYf^R^dU1;O-YT(}(<0>SKD z7OV(X-^YdU`)=#$qfu`hR_aHUsBs?6`IBfj*e*UcGffPM!k#stsg3b4)|2iigzF}m zj>a;y6vt^9lu3XcsSZMByRs=xJs3NH44o&>K!(w<2W#}O3=T8vScWDMp+9W|J1{~> zDVzPd#F!ygTBDO!jFfTBq0cp6*OX&wE19im{G^)OsJKLw^pW{KbyqH(v3^g() z&_Qvb__tccv*O&tz!9UX!l}-^To%P=EmY2_bsk6>kRjeDr6ENL(LyB|ob4@|iaguQ WYTFr3qWkb*vOWqo*D~cjCe