Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(search): index channel messages with Macro-bot user mentions (#4410)
gbirman842725b496fe
diff --git a/.github/workspace-dep-closures.json b/.github/workspace-dep-closures.jsonindex a84c5e3dca..3bd1bb3b22 100644--- a/.github/workspace-dep-closures.json+++ b/.github/workspace-dep-closures.json@@ -2925,8 +2925,6 @@"workspace-hack"],"mention_utils": [- "cowlike",- "macro_user_id","mention_utils","workspace-hack"],diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 3f831e2660..c0b5248d1c 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -7951,7 +7951,6 @@ name = "mention_utils"version = "0.1.0"dependencies = ["cool_asserts",- "macro_user_id","nom 8.0.0","serde","serde_json",diff --git a/rust/cloud-storage/mention_utils/Cargo.toml b/rust/cloud-storage/mention_utils/Cargo.tomlindex d7afe2b1d3..bce66d1887 100644--- a/rust/cloud-storage/mention_utils/Cargo.toml+++ b/rust/cloud-storage/mention_utils/Cargo.toml@@ -5,7 +5,6 @@ publish = falseversion = "0.1.0"[dependencies]-macro_user_id = { path = "../macro_user_id" }nom = { workspace = true }serde = { workspace = true }serde_json = { workspace = true }diff --git a/rust/cloud-storage/mention_utils/src/parse.rs b/rust/cloud-storage/mention_utils/src/parse.rsindex e7c9ba6594..11a98d9d78 100644--- a/rust/cloud-storage/mention_utils/src/parse.rs+++ b/rust/cloud-storage/mention_utils/src/parse.rs@@ -1,5 +1,3 @@-use macro_user_id::email::ReadEmailParts;-use macro_user_id::user_id::BorrowedUserIdStr;use nom::{Finish, IResult, Parser,branch::alt,@@ -58,7 +56,7 @@ pub trait XmlTaggedParsed<'de>: Deserialize<'de> {#[non_exhaustive]pub struct ParsedUserMention<'a> {#[serde(borrow)]- pub user_id: BorrowedUserIdStr<'a>,+ pub user_id: Cow<'a, str>,#[serde(borrow)]pub email: Cow<'a, str>,}@@ -321,7 +319,7 @@ impl XmlFormatter for PlainTextFormatter {}fn format_user(user: &ParsedUserMention<'_>, f: &mut Formatter<'_>) -> std::fmt::Result {- write!(f, "{}", user.user_id.0.email_part().email_str())+ write!(f, "{}", user.email)}fn format_contact(diff --git a/rust/cloud-storage/mention_utils/src/tests.rs b/rust/cloud-storage/mention_utils/src/tests.rsindex 9be20e1fa0..f63286b0e8 100644--- a/rust/cloud-storage/mention_utils/src/tests.rs+++ b/rust/cloud-storage/mention_utils/src/tests.rs@@ -1,8 +1,9 @@use cool_asserts::assert_matches;use crate::parse::{- ParsedContactMention, ParsedDateMention, ParsedDocumentMention, ParsedGroupMention, ParsedLink,- ParsedUserMention, ParsedXmlText, TextSegment, XmlTag,+ NullXmlFormatter, ParsedContactMention, ParsedDateMention, ParsedDocumentMention,+ ParsedGroupMention, ParsedLink, ParsedUserMention, ParsedXmlText, PlainTextFormatter,+ TextSegment, XmlFormatter, XmlTag,};// =============================================================================@@ -79,7 +80,7 @@ fn parse_single_user_mention() {assert_matches!(out.0, [TextSegment::Xml(XmlTag::User(ParsedUserMention { user_id, email }))] => {- assert_eq!(user_id.0.as_ref(), "macro|[email protected]");+ assert_eq!(user_id.as_ref(), "macro|[email protected]");assert_eq!(email.as_ref(), "[email protected]");});}@@ -94,9 +95,9 @@ fn parse_multiple_user_mentions() {TextSegment::Plain(" and "),TextSegment::Xml(XmlTag::User(ParsedUserMention { user_id: uid2, email: email2 })),] => {- assert_eq!(uid1.0.as_ref(), "macro|[email protected]");+ assert_eq!(uid1.as_ref(), "macro|[email protected]");assert_eq!(email1.as_ref(), "[email protected]");- assert_eq!(uid2.0.as_ref(), "macro|[email protected]");+ assert_eq!(uid2.as_ref(), "macro|[email protected]");assert_eq!(email2.as_ref(), "[email protected]");});}@@ -116,6 +117,59 @@ fn parse_user_mention_invalid_json() {assert!(result.is_err());}+// =============================================================================+// Bot mention tests+// =============================================================================++#[test]+fn parse_bare_uuid_bot_mention() {+ let input = r#"<m-user-mention>{"userId":"00000000-0000-0000-0000-00000000a1a1","email":"Macro"}</m-user-mention> there will come a day when I shall liberate you"#;+ let out = ParsedXmlText::parse(input).unwrap();+ assert_matches!(out.0, [+ TextSegment::Xml(XmlTag::User(ParsedUserMention { user_id, email })),+ TextSegment::Plain(" there will come a day when I shall liberate you"),+ ] => {+ assert_eq!(user_id.as_ref(), "00000000-0000-0000-0000-00000000a1a1");+ assert_eq!(email.as_ref(), "Macro");+ });+}++#[test]+fn parse_prefixed_bot_mention() {+ let input = r#"<m-user-mention>{"userId":"bot|00000000-0000-0000-0000-00000000a1a1","email":"Macro"}</m-user-mention>"#;+ let out = ParsedXmlText::parse(input).unwrap();+ assert_matches!(out.0, [+ TextSegment::Xml(XmlTag::User(ParsedUserMention { user_id, email })),+ ] => {+ assert_eq!(user_id.as_ref(), "bot|00000000-0000-0000-0000-00000000a1a1");+ assert_eq!(email.as_ref(), "Macro");+ });+}++#[test]+fn bot_mention_renders_display_name() {+ let input = r#"hi <m-user-mention>{"userId":"00000000-0000-0000-0000-00000000a1a1","email":"Macro"}</m-user-mention> ok"#;+ let parsed = ParsedXmlText::parse(input).unwrap();+ let rendered = PlainTextFormatter::format_xml_text(parsed).0;+ assert_eq!(rendered, "hi Macro ok");+}++#[test]+fn bot_mention_null_formatter_strips_mention() {+ let input = r#"hi <m-user-mention>{"userId":"00000000-0000-0000-0000-00000000a1a1","email":"Macro"}</m-user-mention> ok"#;+ let parsed = ParsedXmlText::parse(input).unwrap();+ let rendered = NullXmlFormatter::format_xml_text(parsed).0;+ assert_eq!(rendered, "hi ok");+}++#[test]+fn user_mention_renders_email() {+ let input = r#"<m-user-mention>{"userId":"macro|[email protected]","email":"[email protected]"}</m-user-mention>"#;+ let parsed = ParsedXmlText::parse(input).unwrap();+ let rendered = PlainTextFormatter::format_xml_text(parsed).0;+ assert_eq!(rendered, "[email protected]");+}+// =============================================================================// Contact mention tests// =============================================================================diff --git a/rust/cloud-storage/search_processing_service/src/process/channel.rs b/rust/cloud-storage/search_processing_service/src/process/channel.rsindex 958ab77f7c..68c0222858 100644--- a/rust/cloud-storage/search_processing_service/src/process/channel.rs+++ b/rust/cloud-storage/search_processing_service/src/process/channel.rs@@ -33,9 +33,14 @@ pub async fn process_channel_message_update(return Ok(());}- let parsed = ParsedXmlText::parse(&channel_message_info.channel_message.content)?;-- let transformed_content = PlainTextFormatter::format_xml_text(parsed);+ let raw_content = &channel_message_info.channel_message.content;+ let transformed_content = match ParsedXmlText::parse(raw_content) {+ Ok(parsed) => PlainTextFormatter::format_xml_text(parsed).0,+ Err(e) => {+ tracing::error!(error = ?e, %channel_id, %message_id, "failed to parse channel message content, indexing raw content");+ raw_content.clone()+ }+ };let upsert_channel_message_args = UpsertChannelMessageArgs {channel_id: channel_message_info.channel_id.to_string(),@@ -49,7 +54,7 @@ pub async fn process_channel_message_update(.to_string(),sender_id: channel_message_info.channel_message.sender_id,mentions: channel_message_info.channel_message.mentions,- content: transformed_content.0.trim().to_string(),+ content: transformed_content.trim().to_string(),created_at_seconds: EpochSeconds::new(channel_message_info.channel_message.created_at.timestamp(),)?,