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
perf(agent-harness): skip the lexical mentions call for prompts with no user mention (#7540)
Wolf Mermelstein4f83c028f221
diff --git a/crates/agent_harness/src/outbound/prompt_mentions.rs b/crates/agent_harness/src/outbound/prompt_mentions.rsindex 131963ae20..0be9bee0ee 100644--- a/crates/agent_harness/src/outbound/prompt_mentions.rs+++ b/crates/agent_harness/src/outbound/prompt_mentions.rs@@ -28,6 +28,11 @@ use crate::domain::ports::PromptMentions;/// The wire name the lexical service gives a user mention.const USER_MENTION_TYPE: &str = "user";+/// The tag every user mention is written as. A prompt without it names+/// nobody, so the lexical round trip - which sits in front of dispatching the+/// prompt - is skipped.+const USER_MENTION_TAG: &str = "<m-user-mention>";+/// Extracts the user ids a markdown string mentions.pub(crate) trait MentionSource: Send + Sync + 'static {fn mentioned_user_ids(@@ -156,6 +161,9 @@ whereprompt_markdown: &'a str,) -> Pin<Box<dyn Future<Output = Result<Vec<MacroUserIdStr<'static>>>> + Send + 'a>> {Box::pin(async move {+ if !prompt_markdown.contains(USER_MENTION_TAG) {+ return Ok(Vec::new());+ }let mentioned = self.source.mentioned_user_ids(prompt_markdown).await?;let mut users: Vec<MacroUserIdStr<'static>> = Vec::new();for id in mentioned {diff --git a/crates/agent_harness/src/outbound/prompt_mentions/test.rs b/crates/agent_harness/src/outbound/prompt_mentions/test.rsindex 0716c18085..7056c56192 100644--- a/crates/agent_harness/src/outbound/prompt_mentions/test.rs+++ b/crates/agent_harness/src/outbound/prompt_mentions/test.rs@@ -98,7 +98,7 @@ async fn an_editor_shares_the_session_with_everyone_they_mention() {.share_with_mentioned(AgentSessionId::TEST_A,Some(&user("[email protected]")),- "@b @c @a @b",+ "<m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention> <m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention> <m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention> <m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention>",).await.expect("mentions resolve");@@ -127,7 +127,7 @@ async fn a_viewer_amplifies_nobody_and_only_existing_viewers_are_named() {);let users = mentions- .share_with_mentioned(AgentSessionId::TEST_A, Some(&user("[email protected]")), "@b @c")+ .share_with_mentioned(AgentSessionId::TEST_A, Some(&user("[email protected]")), "<m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention> <m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention>").await.expect("mentions resolve");@@ -147,7 +147,7 @@ async fn a_prompt_with_no_user_behind_it_shares_nothing() {);let users = mentions- .share_with_mentioned(AgentSessionId::TEST_A, None, "@owner @c")+ .share_with_mentioned(AgentSessionId::TEST_A, None, "<m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention> <m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention>").await.expect("mentions resolve");@@ -190,6 +190,29 @@ async fn a_prompt_naming_nobody_never_touches_access() {assert!(users.is_empty());}+#[tokio::test]+async fn a_prompt_without_a_user_mention_tag_never_asks_the_lexical_service() {+ struct Unreachable;+ impl MentionSource for Unreachable {+ async fn mentioned_user_ids(&self, _markdown: &str) -> Result<Vec<String>> {+ panic!("a prompt with no <m-user-mention> tag should not be parsed")+ }+ }+ let mentions =+ LexicalPromptMentions::new(Unreachable, access(vec![(owner(), AccessLevel::Owner)]));++ let users = mentions+ .share_with_mentioned(+ AgentSessionId::TEST_A,+ Some(&owner()),+ "fix the bug @a mentioned in <m-document-mention>{\"documentId\":\"d\"}</m-document-mention>",+ )+ .await+ .expect("mentions resolve");++ assert!(users.is_empty());+}+#[tokio::test]async fn ids_that_are_not_macro_users_are_skipped() {let access = access(vec![(owner(), AccessLevel::Owner)]);@@ -202,7 +225,7 @@ async fn ids_that_are_not_macro_users_are_skipped() {);let users = mentions- .share_with_mentioned(AgentSessionId::TEST_A, Some(&owner()), "@junk @a")+ .share_with_mentioned(AgentSessionId::TEST_A, Some(&owner()), "<m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention> <m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention>").await.expect("mentions resolve");@@ -217,7 +240,11 @@ async fn a_lexical_failure_is_an_error_not_an_empty_answer() {);let error = mentions- .share_with_mentioned(AgentSessionId::TEST_A, Some(&owner()), "@a")+ .share_with_mentioned(+ AgentSessionId::TEST_A,+ Some(&owner()),+ "<m-user-mention>{\"userId\":\"macro|[email protected]\"}</m-user-mention>",+ ).await.expect_err("the failure surfaces");