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.

Revert "fix(channels): bot-authored messages don't trigger mention notifications in document_cognition_service" (#5128)

Will Hutchinson8de3c1e13512
diff --git a/crates/channels/src/domain/service.rs b/crates/channels/src/domain/service.rs
index 1829425f1e..b9818a91df 100644
--- a/crates/channels/src/domain/service.rs
+++ b/crates/channels/src/domain/service.rs
@@ -14,9 +14,9 @@ use crate::domain::{
WithChannelId,
},
ports::{
- ChannelAttachmentsPage, ChannelContactsDispatcher, ChannelEventDispatcher,
- ChannelMentionExtractor, ChannelMessagesErr, ChannelMessagesQueryResult,
- ChannelMutationErr, ChannelReferenceSharePermissions, ChannelRepo, ChannelService,
+ ChannelAttachmentsPage, ChannelEventDispatcher, ChannelMentionExtractor,
+ ChannelMessagesErr, ChannelMessagesQueryResult, ChannelMutationErr,
+ ChannelReferenceSharePermissions, ChannelRepo, ChannelService,
},
};
use bot_id::BotIdStr;
@@ -72,22 +72,6 @@ impl ChannelReferenceSharePermissions for NoopChannelReferenceSharePermissions {
}
}
-/// No-op contacts dispatcher used by hosts that don't have a contacts ingress
-/// client wired (e.g. hosts that only need channel notifications/realtime).
-#[derive(Debug, Clone, Copy, Default)]
-pub struct NoopChannelContactsDispatcher;
-
-impl ChannelContactsDispatcher for NoopChannelContactsDispatcher {
- type Err = anyhow::Error;
-
- async fn enqueue_contacts(
- &self,
- _users: HashSet<MacroUserIdStr<'static>>,
- ) -> Result<(), Self::Err> {
- Ok(())
- }
-}
-
/// No-op mention extractor used by contexts that don't derive mentions from
/// message content.
#[derive(Debug, Clone, Copy, Default)]
diff --git a/crates/channels/src/domain/side_effects/test.rs b/crates/channels/src/domain/side_effects/test.rs
index 9a0b9e066b..79344c0884 100644
--- a/crates/channels/src/domain/side_effects/test.rs
+++ b/crates/channels/src/domain/side_effects/test.rs
@@ -894,89 +894,6 @@ async fn document_mentions_notify_participants_except_sender() {
assert!(!document_recipients.contains(&sender));
}
-#[tokio::test]
-async fn bot_message_with_user_mention_sends_mention_notification() {
- // Regression test for a bug where AI/agent-posted channel messages that
- // @-mentioned a user did not notify the mentioned user: some hosts wired
- // `ChannelServiceImpl` with a no-op `ChannelEventDispatcher`, so
- // `ChannelEvent::MessagePosted` was never handed to this side-effect
- // service and `handle_message_posted` (below) never ran. This test
- // exercises the notification-derivation logic this service owns, using a
- // bot sender to confirm it dispatches a mention notification exactly like
- // it does for a human sender (mirrors
- // `document_mentions_notify_participants_except_sender` above).
- let channel_id = Uuid::new_v4();
- let message_id = Uuid::new_v4();
- let mentioned = user("[email protected]");
- let other = user("[email protected]");
- let notifications = FakeNotifications::default();
- let service = ChannelSideEffectService::new(
- FakeContext::default(),
- FakeRealtime::default(),
- notifications.clone(),
- FakeSearch::default(),
- FakeContacts::default(),
- );
- let now = Utc::now();
-
- service
- .handle(ChannelEvent::MessagePosted {
- channel_id,
- metadata: ChannelMetadata {
- channel_type: ChannelType::Private,
- channel_name: "Project".to_string(),
- },
- participants: vec![
- ChannelParticipant {
- channel_id,
- user_id: mentioned.as_ref().to_string(),
- role: ParticipantRole::Member,
- joined_at: now,
- left_at: None,
- },
- ChannelParticipant {
- channel_id,
- user_id: other.as_ref().to_string(),
- role: ParticipantRole::Member,
- joined_at: now,
- left_at: None,
- },
- ],
- message: MutatedMessage {
- id: message_id,
- channel_id,
- thread_id: None,
- sender_id: Sender::new_from_bot(BotId::new_from_uuid(Uuid::new_v4())),
- triggered_by: None,
- content: "hello @mentioned".to_string(),
- created_at: now,
- updated_at: now,
- edited_at: None,
- deleted_at: None,
- },
- mentions: vec![SimpleMention {
- entity_type: "user".to_string(),
- entity_id: mentioned.as_ref().to_string(),
- }],
- has_attachments: false,
- attachments: Vec::new(),
- nonce: None,
- notification_policy: PostMessageNotificationPolicy::Default,
- })
- .await;
-
- let notification_effects = notifications.effects.lock().unwrap();
- let mention_recipients = notification_effects
- .iter()
- .find_map(|effect| match effect {
- ChannelNotificationEffect::UserMention { recipient_ids, .. } => Some(recipient_ids),
- _ => None,
- })
- .expect("expected a user mention notification to be enqueued");
- assert!(mention_recipients.contains(&mentioned));
- assert!(!mention_recipients.contains(&other));
-}
-
#[test]
fn contact_sync_is_derived_from_private_channel_created() {
let event = ChannelEvent::ChannelCreated {
diff --git a/services/document_cognition_service/src/main.rs b/services/document_cognition_service/src/main.rs
index 8a55efcc97..188c453df0 100644
--- a/services/document_cognition_service/src/main.rs
+++ b/services/document_cognition_service/src/main.rs
@@ -7,17 +7,7 @@ use call::inbound::toolset::CallToolContext;
use call::outbound::pg_call_repo::PgCallRepo;
use call::outbound::s3_recording_storage::S3RecordingStorage;
use channels::{
- domain::{
- list_service::ChannelListServiceImpl,
- service::NoopChannelContactsDispatcher,
- side_effects::{ChannelSideEffectService, SpawnedChannelEventDispatcher},
- },
- outbound::{
- connection_gateway_realtime::ConnectionGatewayChannelRealtimePublisher,
- notification_sender::NotificationChannelSender, pg_channels_repo::PgChannelsRepo,
- pg_side_effect_context::PgChannelSideEffectContext,
- sqs_search_indexer::SqsChannelSearchIndexer,
- },
+ domain::list_service::ChannelListServiceImpl, outbound::pg_channels_repo::PgChannelsRepo,
};
use config::{Config, Environment};
use document_storage_service_client::DocumentStorageServiceClient;
@@ -431,29 +421,8 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("initialized chat tool context");
- // Wire channel message posting to real side effects (notifications,
- // realtime, search indexing) so AI/agent flows that post channel messages
- // through this host (e.g. document cognition tools) notify mentioned
- // users the same way the in-app Macro AI channel bot does. Contact-graph
- // sync is intentionally a no-op here: this host doesn't have a contacts
- // ingress client wired.
- let channel_gateway_client = Arc::new(connection_gateway_client::ConnectionGatewayClient::new(
- internal_api_key.clone(),
- ConnectionGatewayUrl::new()?.to_string(),
- ));
- let channel_side_effects = ChannelSideEffectService::new(
- PgChannelSideEffectContext::new(db.clone()),
- ConnectionGatewayChannelRealtimePublisher::new(channel_gateway_client),
- NotificationChannelSender::new(notification_ingress_service.clone()),
- SqsChannelSearchIndexer::new(Arc::new(sqs_client.clone())),
- NoopChannelContactsDispatcher,
- )
- .with_macro_event_broker(macro_event_broker.clone());
- let channel_tool_context = ai_tools::build_channel_tool_context_with_dispatcher(
- db.clone(),
- Arc::new(SpawnedChannelEventDispatcher::new(channel_side_effects)),
- lexical_client.clone(),
- );
+ let channel_tool_context =
+ ai_tools::build_channel_tool_context(db.clone(), lexical_client.clone());
let recorder = ai_usage::pg_recorder(db.clone());
// The import pipeline: staged/imported external items, gather jobs over