Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agent_trigger): keep attachment-only messages in agent context (#9741)

Wolf Mermelstein17e1c8970dab
diff --git a/crates/agent_trigger/src/outbound/discussion_context.rs b/crates/agent_trigger/src/outbound/discussion_context.rs
index b8eecb9657..0ee878be59 100644
--- a/crates/agent_trigger/src/outbound/discussion_context.rs
+++ b/crates/agent_trigger/src/outbound/discussion_context.rs
@@ -587,9 +587,10 @@ struct Selection<'a> {
messages_omitted: bool,
}
-/// Whether a message is live and says something.
+/// Whether a message is live and says something: text, or a shared file.
fn readable(message: &Message) -> bool {
- message.deleted_at.is_none() && !message.content.trim().is_empty()
+ let says_something = !message.content.trim().is_empty() || !message.attachments.is_empty();
+ message.deleted_at.is_none() && says_something
}
/// The prompt's discussion from its root through the prompt. Replies posted
@@ -607,7 +608,7 @@ fn prompt_thread<'a>(discussion: &'a MessageThread, prompt: &'a Message) -> Sele
break;
}
}
- if !reached_prompt && !prompt.content.trim().is_empty() {
+ if !reached_prompt && readable(prompt) {
messages.push(prompt);
}
diff --git a/crates/agent_trigger/src/outbound/discussion_context/test.rs b/crates/agent_trigger/src/outbound/discussion_context/test.rs
index f140a03890..e0b8081c1d 100644
--- a/crates/agent_trigger/src/outbound/discussion_context/test.rs
+++ b/crates/agent_trigger/src/outbound/discussion_context/test.rs
@@ -352,6 +352,86 @@ async fn a_thread_root_image_travels_on_its_context_message() {
assert!(thread.messages[1].attachments.is_empty());
}
+/// A document shared on its own starts a thread whose root has no text.
+/// The agent must still see the root and its document, here and in the
+/// channel background.
+#[tokio::test]
+async fn an_attachment_only_message_reaches_the_agent_with_its_document() {
+ let parent = channel();
+ let mut shared = posted(&parent, 30, None, "[email protected]", " \n ", 0);
+ shared.attachments = vec![MessageAttachment {
+ id: Uuid::from_u128(39),
+ entity_type: "document".to_owned(),
+ entity_id: "01a18da2-731f-7066-a182-c46cbc0db2f9".to_owned(),
+ width: None,
+ height: None,
+ created_at: at(0),
+ }];
+ let mut root = posted(&parent, 10, None, "[email protected]", "\n \n", 1);
+ root.attachments = vec![MessageAttachment {
+ id: Uuid::from_u128(19),
+ entity_type: "document".to_owned(),
+ entity_id: "0f2c1d6e-8a4b-4c3e-9f1a-2b7d5e6c8a90".to_owned(),
+ width: None,
+ height: None,
+ created_at: at(1),
+ }];
+ let prompt = posted(
+ &parent,
+ 11,
+ Some(10),
+ "@Macro summarize into a short paragraph",
+ 2,
+ );
+
+ let mut source = MockMessageReader::new();
+ let prompt_message = prompt.clone();
+ source
+ .expect_get()
+ .withf(|_, id| *id == Uuid::from_u128(11))
+ .returning(move |_, _| Ok(prompt_message.clone()));
+ let thread = discussion(root.clone(), vec![prompt.clone()], None);
+ source
+ .expect_get_thread()
+ .once()
+ .withf(|_, root| *root == Uuid::from_u128(10))
+ .return_once(move |_, _| Ok(thread));
+ let recent = vec![shared.clone(), root.clone()];
+ source
+ .expect_preceding()
+ .once()
+ .return_once(move |_, _, _| Ok(recent));
+
+ let context = context_from(source, channel_names(), Lexical::none(), &prompt).await;
+
+ assert_eq!(
+ context.thread,
+ Some(ContextThread {
+ root_id: root.id,
+ messages: vec![
+ ContextMessage {
+ content: String::new(),
+ ..entry(&root)
+ },
+ entry(&prompt),
+ ],
+ messages_omitted: false,
+ })
+ );
+ assert_eq!(
+ context.channel,
+ [ContextThread {
+ root_id: shared.id,
+ messages: vec![ContextMessage {
+ content: String::new(),
+ ..entry(&shared)
+ }],
+ messages_omitted: false,
+ }]
+ );
+}
+
/// "please fix" in thread A, posted while another thread was busier. The
/// agent must get thread A whole and be told the rest is background, not a
/// flat list whose last entry is someone else's bug.