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 <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
npub16v54tttfqacx9ycvc3k0ut0npj564ahcuajzy6qjvh57ntmsf4uq4806j2
2026-06-10 13:38:36 -04:00
co-authored by Will Pfleger
parent 7b666057e6
commit 4b676908bd
2 changed files with 22 additions and 24 deletions
+3 -21
View File
@@ -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;
+19 -3
View File
@@ -320,6 +320,9 @@ pub enum RelayError {
#[error("Unexpected message: {0}")]
UnexpectedMessage(String),
#[error("Event build error: {0}")]
EventBuild(String),
}
impl From<nostr::event::builder::Error> 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