Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

refactor(events): share one ellipsis-preserving clip; correct a stale test comment\n\nTwo more review findings.\n\nThe notification arms truncated with a bare chars().take(..) while\nDomainEvent::log_detail had a clip() that appends an ellipsis, so a clipped\ntransport error read as if it ended where it was cut, and the three limits had\nalready drifted apart. Hoists clip_to_chars next to DomainEvent and uses it for\nthe two MCP arms.\n\nThe SubagentFailed arm is deliberately NOT converted. It predates this PR, the\nfinding named only the MCP arms, and subagent_failed_truncates_long_error_to_100_chars\nasserts <= 100 chars — the ellipsis makes it 101. Loosening that assertion to\naccommodate an out-of-scope change would be backwards, so the arm keeps its\nexisting truncation and the test is untouched.\n\nAlso corrects a test doc comment that referenced is_for_this_workspace, a\nfunction that never existed; the readers are store_target / should_announce.\n\nVerified: cargo fmt clean; 196 lib tests pass across core::events,\ndesktop::notifications and config::schema::load, 0 failed.\n

M3gA-Mind919e3b7f9476
diff --git a/src/core/events.rs b/src/core/events.rs
index 22456f2c99..f20ae94734 100644
--- a/src/core/events.rs
+++ b/src/core/events.rs
@@ -1363,6 +1363,22 @@ pub enum DomainEvent {
ThreadGoalCleared { thread_id: String },
}
+/// Truncate to `max` characters, appending `…` when anything was dropped.
+///
+/// Counted in `char`s, so a multi-byte error cannot be split mid-character.
+/// The ellipsis is the point: without it a clipped provider error reads as if
+/// it ended where it was cut, and a reader cannot tell a complete message from
+/// a truncated one. Shared so the Event Log summary and the notification
+/// bodies cannot drift into three different truncation rules — they had.
+#[must_use]
+pub fn clip_to_chars(text: &str, max: usize) -> String {
+ let mut out: String = text.chars().take(max).collect();
+ if text.chars().nth(max).is_some() {
+ out.push('…');
+ }
+ out
+}
+
impl DomainEvent {
/// Returns the domain name for routing and filtering.
pub fn domain(&self) -> &'static str {
@@ -1721,13 +1737,7 @@ impl DomainEvent {
/// `char`s, so a multi-byte error cannot be split mid-character.
const MAX_DETAIL_CHARS: usize = 160;
- fn clip(text: &str) -> String {
- let mut out: String = text.chars().take(MAX_DETAIL_CHARS).collect();
- if text.chars().nth(MAX_DETAIL_CHARS).is_some() {
- out.push('…');
- }
- out
- }
+ let clip = |text: &str| clip_to_chars(text, MAX_DETAIL_CHARS);
match self {
Self::McpServerProbeTimedOut {
diff --git a/src/openhuman/desktop/notifications/bus.rs b/src/openhuman/desktop/notifications/bus.rs
index 1bede92c21..15f4d44a10 100644
--- a/src/openhuman/desktop/notifications/bus.rs
+++ b/src/openhuman/desktop/notifications/bus.rs
@@ -364,7 +364,7 @@ pub fn event_to_notification(event: &DomainEvent) -> Option<CoreNotificationEven
body: format!(
"{qualified_name} stopped answering, so its tools are unavailable until it \
reconnects. It retries automatically. {}",
- error.chars().take(120).collect::<String>()
+ crate::core::events::clip_to_chars(error, 120)
),
deep_link: Some("/connections?tab=mcp".into()),
timestamp_ms: ts,
@@ -400,7 +400,7 @@ pub fn event_to_notification(event: &DomainEvent) -> Option<CoreNotificationEven
body: format!(
"{qualified_name} will not be retried: {}. Install the missing runtime, then \
disable and re-enable the server.",
- error.chars().take(160).collect::<String>()
+ crate::core::events::clip_to_chars(error, 160)
),
deep_link: Some("/connections?tab=mcp".into()),
timestamp_ms: ts,
diff --git a/src/openhuman/desktop/notifications/bus_tests_2_tests.rs b/src/openhuman/desktop/notifications/bus_tests_2_tests.rs
index 01c6bec5ab..7abac03bfb 100644
--- a/src/openhuman/desktop/notifications/bus_tests_2_tests.rs
+++ b/src/openhuman/desktop/notifications/bus_tests_2_tests.rs
@@ -175,7 +175,8 @@ fn notification_triaged_unrouted_escalate_is_silent() {
// ── MCP reconnect supervisor (#5931) ────────────────────────────────────────
/// The workspace an MCP supervisor event is attributed to. The pure
-/// translator ignores it — the bridge's `is_for_this_workspace` is what reads
+/// translator ignores it — the bridge's `store_target` / `should_announce`
+/// are what read
/// it — so these cases all use the same one.
fn mcp_workspace() -> std::path::PathBuf {
std::path::PathBuf::from("/tmp/openhuman-ws")