From 4b676908bd0109110080408e4dbc481076e49154 Mon Sep 17 00:00:00 2001 From: npub16v54tttfqacx9ycvc3k0ut0npj564ahcuajzy6qjvh57ntmsf4uq4806j2 Date: Wed, 10 Jun 2026 13:38:36 -0400 Subject: [PATCH] fix(acp): death notice threading, error variant, and DRY extraction Death notices referenced the thread root with NIP-10 marker "reply" instead of "root", causing incorrect threading in clients. Tag-parse errors incorrectly mapped to RelayError::AuthFailed. - Change e-tag marker from "reply" to "root" in build_death_notice - Add RelayError::EventBuild variant for tag-parse failures - Add publish_death_notice() method on HarnessRelay to consolidate the build+publish+warn pattern used by both timeout and transport error paths - Replace inline match blocks in handle_prompt_result with method call Co-authored-by: Will Pfleger Signed-off-by: Will Pfleger --- crates/sprout-acp/src/lib.rs | 24 +++--------------------- crates/sprout-acp/src/relay.rs | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/crates/sprout-acp/src/lib.rs b/crates/sprout-acp/src/lib.rs index 019773f0d..aabd2233e 100644 --- a/crates/sprout-acp/src/lib.rs +++ b/crates/sprout-acp/src/lib.rs @@ -2096,16 +2096,7 @@ fn handle_prompt_result( // Post a visible death notice to the channel so humans know why // the agent went silent. if let Some(ch) = channel_id { - match relay.build_death_notice(ch, death_message, thread_root.as_deref()) { - Ok(event) => { - if let Err(e) = relay.try_publish_event(event) { - tracing::warn!("failed to publish death notice: {e}"); - } - } - Err(e) => { - tracing::warn!("failed to build death notice: {e}"); - } - } + relay.publish_death_notice(ch, death_message, thread_root.as_deref()); } let index = result.agent.index; let slot_history = &mut crash_history[index]; @@ -2166,20 +2157,11 @@ fn handle_prompt_result( // Post a visible death notice for transport errors too. if let Some(ch) = channel_id { - match relay.build_death_notice( + relay.publish_death_notice( ch, "Agent connection lost (transport error)", thread_root.as_deref(), - ) { - Ok(event) => { - if let Err(e) = relay.try_publish_event(event) { - tracing::warn!("failed to publish death notice: {e}"); - } - } - Err(e) => { - tracing::warn!("failed to build death notice: {e}"); - } - } + ); } let index = result.agent.index; diff --git a/crates/sprout-acp/src/relay.rs b/crates/sprout-acp/src/relay.rs index 738957618..505ae0e81 100644 --- a/crates/sprout-acp/src/relay.rs +++ b/crates/sprout-acp/src/relay.rs @@ -320,6 +320,9 @@ pub enum RelayError { #[error("Unexpected message: {0}")] UnexpectedMessage(String), + + #[error("Event build error: {0}")] + EventBuild(String), } impl From for RelayError { @@ -760,11 +763,11 @@ impl HarnessRelay { use sprout_core::kind::KIND_STREAM_MESSAGE; let h_tag = Tag::parse(["h", &channel_id.to_string()]) - .map_err(|e| RelayError::AuthFailed(e.to_string()))?; + .map_err(|e| RelayError::EventBuild(e.to_string()))?; let mut tags = vec![h_tag]; if let Some(root_id) = thread_root { - let e_tag = Tag::parse(["e", root_id, "", "reply"]) - .map_err(|e| RelayError::AuthFailed(e.to_string()))?; + let e_tag = Tag::parse(["e", root_id, "", "root"]) + .map_err(|e| RelayError::EventBuild(e.to_string()))?; tags.push(e_tag); } let event = EventBuilder::new(Kind::Custom(KIND_STREAM_MESSAGE as u16), message) @@ -773,6 +776,19 @@ impl HarnessRelay { Ok(event) } + /// Build and publish a death notice, logging any failure rather than + /// propagating it. Used by both the timeout and transport-error paths. + pub fn publish_death_notice(&self, channel_id: Uuid, message: &str, thread_root: Option<&str>) { + match self.build_death_notice(channel_id, message, thread_root) { + Ok(event) => { + if let Err(e) = self.try_publish_event(event) { + warn!("failed to publish death notice: {e}"); + } + } + Err(e) => warn!("failed to build death notice: {e}"), + } + } + /// Set the startup watermark timestamp (Finding #22). /// /// Call this once after `connect()` with the Unix timestamp captured just