huskies: merge 1211 story Deterministic crash notification when the agent PTY dies mid-turn

This commit is contained in:
Huskies Agent
2026-07-18 11:00:28 +00:00
parent 153333d055
commit 71f3fa09c4
8 changed files with 315 additions and 6 deletions
@@ -221,6 +221,50 @@ pub fn format_agent_completed_notification(
(plain, html)
}
/// Format an agent-crashed notification message (story 1211).
///
/// Sent when an agent's PTY child process dies before completing its
/// current turn (no `"result"` event observed) — a crash, kill, or
/// watchdog termination rather than a clean finish. Includes the exit
/// code and the last line emitted by the child when available.
/// Returns `(plain_text, html)` suitable for `ChatTransport::send_message`.
pub fn format_agent_crashed_notification(
item_id: &str,
story_name: &str,
agent_name: &str,
exit_code: Option<u32>,
last_error_line: Option<&str>,
) -> (String, String) {
let number = extract_item_number(item_id).unwrap_or(item_id);
let effective_name = if story_name.is_empty() {
None
} else {
Some(story_name)
};
let name_plain = effective_name.map(|n| format!("{n} ")).unwrap_or_default();
let name_html = effective_name
.map(|n| format!("<em>{n}</em> "))
.unwrap_or_default();
let exit_code_display = exit_code
.map(|c| c.to_string())
.unwrap_or_else(|| "unknown".to_string());
let mut plain = format!(
"\u{1f480} #{number} {name_plain}\u{2014} {agent_name} crashed mid-turn \
(exit code: {exit_code_display})"
);
let mut html = format!(
"\u{1f480} <strong>#{number}</strong> {name_html}\u{2014} {agent_name} crashed mid-turn \
(exit code: {exit_code_display})"
);
if let Some(line) = last_error_line {
plain.push_str(&format!("\nLast line: {line}"));
html.push_str(&format!("<br>Last line: <code>{line}</code>"));
}
(plain, html)
}
/// Emoji used to badge a work item's kind in creation notifications.
fn item_type_emoji(item_type: &str) -> &'static str {
match item_type {