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
feat(email): log which thread and why when Soup can't load its metadata (#8740)
gbirman1afbc29e9cf7
diff --git a/Cargo.lock b/Cargo.lockindex 8eaafa812d..6545f535e8 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -8997,6 +8997,7 @@ dependencies = ["serde_json","tokio","tracing",+ "tracing-subscriber","uuid","workspace-hack",]diff --git a/crates/complete_graph/src/lib.rs b/crates/complete_graph/src/lib.rsindex 8f6cea2ffe..2b4ead7cc6 100644--- a/crates/complete_graph/src/lib.rs+++ b/crates/complete_graph/src/lib.rs@@ -35,13 +35,13 @@ pub use graphql_email::{DeleteEmailDraftInput, DeleteEmailDraftPayload, EmailContentKey, EmailContentLoad,EmailContentLoader, EmailMutationService, EmailServiceEmailContentReader,EmailThreadMailProjectionLoad, EmailThreadMailProjectionLoader, EmailThreadMetadataLoad,- EmailThreadMetadataLoader, GraphqlEmailLabel, GraphqlEmailLink, GraphqlEmailLinkSettings,- GraphqlEmailMutation, GraphqlEmailProvider, GraphqlEmailQuery, GraphqlEmailSyncStatus,- MarkEmailThreadSeenInput, NoOpSoupEmailContentEdgeReader, SaveEmailDraftContactInput,- SaveEmailDraftInput, SaveEmailDraftPayload, SoupEmailContentEdgeReader, SoupEmailEdgeReader,- SoupEmailThreadMailProjectionEdgeReader, SoupEmailThreadMetadataEdgeReader,- UpdateEmailThreadLabelInput, email_content_loader, email_thread_mail_projection_loader,- email_thread_metadata_loader,+ EmailThreadMetadataLoader, EmailThreadUnavailable, GraphqlEmailLabel, GraphqlEmailLink,+ GraphqlEmailLinkSettings, GraphqlEmailMutation, GraphqlEmailProvider, GraphqlEmailQuery,+ GraphqlEmailSyncStatus, MarkEmailThreadSeenInput, NoOpSoupEmailContentEdgeReader,+ SaveEmailDraftContactInput, SaveEmailDraftInput, SaveEmailDraftPayload,+ SoupEmailContentEdgeReader, SoupEmailEdgeReader, SoupEmailThreadMailProjectionEdgeReader,+ SoupEmailThreadMetadataEdgeReader, UpdateEmailThreadLabelInput, email_content_loader,+ email_thread_mail_projection_loader, email_thread_metadata_loader,};pub use graphql_entity_mutation::{ChannelSharePolicyInput, DuplicateEntityInput, EntityMutationPayload, EntityMutationRoot,diff --git a/crates/complete_graph/src/schema/test.rs b/crates/complete_graph/src/schema/test.rsindex 380fb0a5c3..13b618e0a7 100644--- a/crates/complete_graph/src/schema/test.rs+++ b/crates/complete_graph/src/schema/test.rs@@ -1532,10 +1532,12 @@ impl TestHarness {)).data(graphql_email::email_thread_metadata_loader(user_id.clone(),+ None,self.email_content_reader.clone(),)).data(graphql_email::email_thread_mail_projection_loader(user_id,+ None,self.email_content_reader.clone(),)).data(NoOpEntityFavoriteEdgeReader)diff --git a/crates/graphql_email/Cargo.toml b/crates/graphql_email/Cargo.tomlindex 9e6235b912..90db052873 100644--- a/crates/graphql_email/Cargo.toml+++ b/crates/graphql_email/Cargo.toml@@ -18,3 +18,6 @@ tokio = { workspace = true }tracing = { workspace = true }uuid = { workspace = true }workspace-hack = { version = "0.1", path = "../workspace-hack" }++[dev-dependencies]+tracing-subscriber = { workspace = true }diff --git a/crates/graphql_email/src/lib.rs b/crates/graphql_email/src/lib.rsindex 12ca53597f..e28c9b26fb 100644--- a/crates/graphql_email/src/lib.rs+++ b/crates/graphql_email/src/lib.rs@@ -17,10 +17,10 @@ mod user_query;pub use loaders::{EmailContentKey, EmailContentLoad, EmailContentLoader, EmailContentMessage,EmailServiceEmailContentReader, EmailThreadMailProjectionLoad, EmailThreadMailProjectionLoader,- EmailThreadMetadataLoad, EmailThreadMetadataLoader, NoOpSoupEmailContentEdgeReader,- SoupEmailContentEdgeReader, SoupEmailEdgeReader, SoupEmailThreadMailProjectionEdgeReader,- SoupEmailThreadMetadataEdgeReader, email_content_loader, email_thread_mail_projection_loader,- email_thread_metadata_loader,+ EmailThreadMetadataLoad, EmailThreadMetadataLoader, EmailThreadUnavailable,+ NoOpSoupEmailContentEdgeReader, SoupEmailContentEdgeReader, SoupEmailEdgeReader,+ SoupEmailThreadMailProjectionEdgeReader, SoupEmailThreadMetadataEdgeReader,+ email_content_loader, email_thread_mail_projection_loader, email_thread_metadata_loader,};pub use mutation::{DeleteEmailDraftInput, DeleteEmailDraftPayload, EmailMutationService,diff --git a/crates/graphql_email/src/loaders.rs b/crates/graphql_email/src/loaders.rsindex e1a0b8afb8..28043724c0 100644--- a/crates/graphql_email/src/loaders.rs+++ b/crates/graphql_email/src/loaders.rs@@ -9,8 +9,9 @@ use email::domain::{ports::{EmailContentService, EmailThreadMailProjectionService, EmailThreadMetadataService},};use entity_access::domain::{models::AccessError, ports::EntityAccessService};-use futures::future::join_all;+use futures::future::{BoxFuture, join_all};use macro_user_id::user_id::MacroUserIdStr;+use tracing::Instrument;use uuid::Uuid;pub(crate) const MAX_EMAIL_CONTENT_KEYS: usize = 20;@@ -18,15 +19,29 @@ pub(crate) const MAX_EMAIL_CONTENT_MESSAGES: usize = 100;const MAX_EMAIL_THREAD_METADATA_KEYS: usize = 500;const MAX_EMAIL_THREAD_MAIL_PROJECTION_KEYS: usize = 500;+/// Why a Soup email thread's metadata or Mail projection was not returned.+#[derive(Debug, Clone, Copy, PartialEq, Eq)]+pub enum EmailThreadUnavailable {+ /// The viewer has no access to the thread.+ NoAccess,+ /// The access check found no such thread.+ ThreadNotFound,+ /// The viewer may read the thread, but the email service returned no row+ /// for it.+ NoRow,+ /// The access check failed. Details are logged, never exposed.+ AccessCheckFailed,+ /// Loading the authorized threads failed. Details are logged, never exposed.+ LoadFailed,+}+/// Canonical metadata loaded for one Soup email thread.#[derive(Debug, Clone)]pub enum EmailThreadMetadataLoad {/// The canonical thread metadata was found.Found(EmailThreadMetadata),- /// The thread was absent or inaccessible.- Missing,- /// An internal failure occurred. Details are logged, never exposed.- Failed,+ /// The metadata was not returned to this viewer.+ Unavailable(EmailThreadUnavailable),}/// Reader used by lazy Soup email-thread metadata fields.@@ -44,10 +59,8 @@ pub trait SoupEmailThreadMetadataEdgeReader: Send + Sync + 'static {pub enum EmailThreadMailProjectionLoad {/// The Mail projection data was found.Found(Arc<EmailThreadMailProjection>),- /// The thread was absent or inaccessible.- Missing,- /// An internal failure occurred. Details are logged, never exposed.- Failed,+ /// The projection was not returned to this viewer.+ Unavailable(EmailThreadUnavailable),}/// Reader used by offline Mail cache facts and canonical preview fields.@@ -230,7 +243,12 @@ impl SoupEmailThreadMetadataEdgeReader for NoOpSoupEmailContentEdgeReader {) -> HashMap<Uuid, EmailThreadMetadataLoad> {thread_ids.into_iter()- .map(|thread_id| (thread_id, EmailThreadMetadataLoad::Missing))+ .map(|thread_id| {+ (+ thread_id,+ EmailThreadMetadataLoad::Unavailable(EmailThreadUnavailable::NoRow),+ )+ }).collect()}}@@ -243,7 +261,12 @@ impl SoupEmailThreadMailProjectionEdgeReader for NoOpSoupEmailContentEdgeReader) -> HashMap<Uuid, EmailThreadMailProjectionLoad> {thread_ids.into_iter()- .map(|thread_id| (thread_id, EmailThreadMailProjectionLoad::Missing))+ .map(|thread_id| {+ (+ thread_id,+ EmailThreadMailProjectionLoad::Unavailable(EmailThreadUnavailable::NoRow),+ )+ }).collect()}}@@ -299,16 +322,28 @@ whereauthorized.push(receipt);authorized_ids.push(thread_id);}- Err(- AccessError::Unauthorized- | AccessError::UnauthorizedWithMessage(_)- | AccessError::NotFound(_),- ) => {- loads.insert(thread_id, EmailThreadMetadataLoad::Missing);+ Err(AccessError::Unauthorized | AccessError::UnauthorizedWithMessage(_)) => {+ loads.insert(+ thread_id,+ EmailThreadMetadataLoad::Unavailable(EmailThreadUnavailable::NoAccess),+ );+ }+ Err(AccessError::NotFound(_)) => {+ loads.insert(+ thread_id,+ EmailThreadMetadataLoad::Unavailable(+ EmailThreadUnavailable::ThreadNotFound,+ ),+ );}Err(error) => {tracing::error!(%thread_id, error = ?error, "email thread metadata access check failed");- loads.insert(thread_id, EmailThreadMetadataLoad::Failed);+ loads.insert(+ thread_id,+ EmailThreadMetadataLoad::Unavailable(+ EmailThreadUnavailable::AccessCheckFailed,+ ),+ );}}}@@ -325,7 +360,7 @@ whereOk(mut metadata) => {for thread_id in authorized_ids {let load = metadata.remove(&thread_id).map_or(- EmailThreadMetadataLoad::Missing,+ EmailThreadMetadataLoad::Unavailable(EmailThreadUnavailable::NoRow),EmailThreadMetadataLoad::Found,);loads.insert(thread_id, load);@@ -333,11 +368,12 @@ where}Err(error) => {tracing::error!(error = ?error, "bulk email thread metadata load failed");- loads.extend(- authorized_ids- .into_iter()- .map(|thread_id| (thread_id, EmailThreadMetadataLoad::Failed)),- );+ loads.extend(authorized_ids.into_iter().map(|thread_id| {+ (+ thread_id,+ EmailThreadMetadataLoad::Unavailable(EmailThreadUnavailable::LoadFailed),+ )+ }));}}@@ -377,16 +413,30 @@ whereauthorized.push(receipt);authorized_ids.push(thread_id);}- Err(- AccessError::Unauthorized- | AccessError::UnauthorizedWithMessage(_)- | AccessError::NotFound(_),- ) => {- loads.insert(thread_id, EmailThreadMailProjectionLoad::Missing);+ Err(AccessError::Unauthorized | AccessError::UnauthorizedWithMessage(_)) => {+ loads.insert(+ thread_id,+ EmailThreadMailProjectionLoad::Unavailable(+ EmailThreadUnavailable::NoAccess,+ ),+ );+ }+ Err(AccessError::NotFound(_)) => {+ loads.insert(+ thread_id,+ EmailThreadMailProjectionLoad::Unavailable(+ EmailThreadUnavailable::ThreadNotFound,+ ),+ );}Err(error) => {tracing::error!(%thread_id, error = ?error, "email thread Mail projection access check failed");- loads.insert(thread_id, EmailThreadMailProjectionLoad::Failed);+ loads.insert(+ thread_id,+ EmailThreadMailProjectionLoad::Unavailable(+ EmailThreadUnavailable::AccessCheckFailed,+ ),+ );}}}@@ -402,21 +452,23 @@ where{Ok(mut projections) => {for thread_id in authorized_ids {- let load = projections- .remove(&thread_id)- .map_or(EmailThreadMailProjectionLoad::Missing, |projection| {- EmailThreadMailProjectionLoad::Found(Arc::new(projection))- });+ let load = projections.remove(&thread_id).map_or(+ EmailThreadMailProjectionLoad::Unavailable(EmailThreadUnavailable::NoRow),+ |projection| EmailThreadMailProjectionLoad::Found(Arc::new(projection)),+ );loads.insert(thread_id, load);}}Err(error) => {tracing::error!(error = ?error, "bulk email thread Mail projection load failed");- loads.extend(- authorized_ids- .into_iter()- .map(|thread_id| (thread_id, EmailThreadMailProjectionLoad::Failed)),- );+ loads.extend(authorized_ids.into_iter().map(|thread_id| {+ (+ thread_id,+ EmailThreadMailProjectionLoad::Unavailable(+ EmailThreadUnavailable::LoadFailed,+ ),+ )+ }));}}@@ -613,16 +665,30 @@ where}}+/// Spawns a DataLoader batch in the span of the field that started it, so the+/// batch's logs stay in the request's trace.+fn spawn_in_current_span(batch: BoxFuture<'static, ()>) -> tokio::task::JoinHandle<()> {+ tokio::spawn(batch.in_current_span())+}+/// DataLoader for canonical metadata attached to Soup email threads.pub struct EmailThreadMetadataLoader<R> {user_id: MacroUserIdStr<'static>,+ viewer_id: Option<Uuid>,reader: R,}impl<R> EmailThreadMetadataLoader<R> {/// Create a metadata DataLoader scoped to the requesting user.- pub fn new(user_id: MacroUserIdStr<'static>, reader: R) -> Self {- Self { user_id, reader }+ ///+ /// `viewer_id` is the viewer's opaque account id (`macro_user.id`), logged+ /// instead of the email-bearing `user_id` when a thread is unavailable.+ pub fn new(user_id: MacroUserIdStr<'static>, viewer_id: Option<Uuid>, reader: R) -> Self {+ Self {+ user_id,+ viewer_id,+ reader,+ }}}@@ -634,24 +700,36 @@ wheretype Error = std::convert::Infallible;async fn load(&self, keys: &[Uuid]) -> Result<HashMap<Uuid, Self::Value>, Self::Error> {- Ok(self+ let loads = self.reader.get_email_thread_metadata(&self.user_id, keys.to_vec())- .await)+ .await;+ for (thread_id, load) in &loads {+ if let EmailThreadMetadataLoad::Unavailable(reason) = load {+ tracing::warn!(+ %thread_id,+ viewer_id = self.viewer_id.map(tracing::field::display),+ ?reason,+ "email thread metadata unavailable"+ );+ }+ }+ Ok(loads)}}/// Build a canonical email-thread metadata DataLoader scoped to the requesting user.pub fn email_thread_metadata_loader<R>(user_id: MacroUserIdStr<'static>,+ viewer_id: Option<Uuid>,reader: R,) -> DataLoader<EmailThreadMetadataLoader<R>>whereR: SoupEmailThreadMetadataEdgeReader,{let loader = DataLoader::new(- EmailThreadMetadataLoader::new(user_id, reader),- tokio::spawn,+ EmailThreadMetadataLoader::new(user_id, viewer_id, reader),+ spawn_in_current_span,).max_batch_size(MAX_EMAIL_THREAD_METADATA_KEYS);// Subscription connection data outlives one payload. Coalesce concurrent@@ -663,13 +741,21 @@ where/// DataLoader for Mail-specific cache facts and canonical previews.pub struct EmailThreadMailProjectionLoader<R> {user_id: MacroUserIdStr<'static>,+ viewer_id: Option<Uuid>,reader: R,}impl<R> EmailThreadMailProjectionLoader<R> {/// Create a Mail projection DataLoader scoped to the requesting user.- pub fn new(user_id: MacroUserIdStr<'static>, reader: R) -> Self {- Self { user_id, reader }+ ///+ /// `viewer_id` is the viewer's opaque account id (`macro_user.id`), logged+ /// instead of the email-bearing `user_id` when a thread is unavailable.+ pub fn new(user_id: MacroUserIdStr<'static>, viewer_id: Option<Uuid>, reader: R) -> Self {+ Self {+ user_id,+ viewer_id,+ reader,+ }}}@@ -681,24 +767,36 @@ wheretype Error = std::convert::Infallible;async fn load(&self, keys: &[Uuid]) -> Result<HashMap<Uuid, Self::Value>, Self::Error> {- Ok(self+ let loads = self.reader.get_email_thread_mail_projections(&self.user_id, keys.to_vec())- .await)+ .await;+ for (thread_id, load) in &loads {+ if let EmailThreadMailProjectionLoad::Unavailable(reason) = load {+ tracing::warn!(+ %thread_id,+ viewer_id = self.viewer_id.map(tracing::field::display),+ ?reason,+ "email thread Mail projection unavailable"+ );+ }+ }+ Ok(loads)}}/// Build a Mail projection DataLoader scoped to the requesting user.pub fn email_thread_mail_projection_loader<R>(user_id: MacroUserIdStr<'static>,+ viewer_id: Option<Uuid>,reader: R,) -> DataLoader<EmailThreadMailProjectionLoader<R>>whereR: SoupEmailThreadMailProjectionEdgeReader,{let loader = DataLoader::new(- EmailThreadMailProjectionLoader::new(user_id, reader),- tokio::spawn,+ EmailThreadMailProjectionLoader::new(user_id, viewer_id, reader),+ spawn_in_current_span,).max_batch_size(MAX_EMAIL_THREAD_MAIL_PROJECTION_KEYS);// Subscription connection data outlives one payload. Coalesce concurrent@@ -788,7 +886,10 @@ pub fn email_content_loader<R>(whereR: SoupEmailContentEdgeReader,{- DataLoader::new(EmailContentLoader::new(user_id, reader), tokio::spawn)+ DataLoader::new(+ EmailContentLoader::new(user_id, reader),+ spawn_in_current_span,+ )}#[cfg(test)]diff --git a/crates/graphql_email/src/loaders/test.rs b/crates/graphql_email/src/loaders/test.rsindex 8ce62fbfee..20037ccf5f 100644--- a/crates/graphql_email/src/loaders/test.rs+++ b/crates/graphql_email/src/loaders/test.rs@@ -232,6 +232,9 @@ struct RecordingContentService {page_calls: AtomicUsize,page_full_calls: AtomicUsize,pagination: Mutex<Vec<(i64, i64)>>,+ /// Return no metadata rows, as for an authorized thread the email+ /// service has no row for.+ no_metadata_rows: bool,}impl EmailThreadMetadataService for RecordingContentService {@@ -240,6 +243,9 @@ impl EmailThreadMetadataService for RecordingContentService {receipts: Vec<EntityAccessReceipt<ViewAccessLevel>>,) -> Result<HashMap<Uuid, EmailThreadMetadata>, EmailErr> {self.metadata_calls.fetch_add(1, Ordering::SeqCst);+ if self.no_metadata_rows {+ return Ok(HashMap::new());+ }Ok(receipts.into_iter().map(|receipt| {@@ -346,7 +352,7 @@ async fn batches_distinct_threads_in_one_reader_call() {async fn batches_email_thread_metadata_in_one_reader_call() {let reader = RecordingReader::default();let user_id = MacroUserIdStr::try_from_email("[email protected]").unwrap();- let loader = email_thread_metadata_loader(user_id, reader.clone());+ let loader = email_thread_metadata_loader(user_id, None, reader.clone());let first = Uuid::from_u128(1);let second = Uuid::from_u128(2);@@ -373,7 +379,7 @@ async fn batches_email_thread_metadata_in_one_reader_call() {async fn batches_email_thread_mail_projections_in_one_reader_call() {let reader = RecordingReader::default();let user_id = MacroUserIdStr::try_from_email("[email protected]").unwrap();- let loader = email_thread_mail_projection_loader(user_id, reader.clone());+ let loader = email_thread_mail_projection_loader(user_id, None, reader.clone());let first = Uuid::from_u128(1);let second = Uuid::from_u128(2);@@ -510,7 +516,9 @@ async fn unauthorized_mail_projection_keys_do_not_reach_the_email_domain() {assert_eq!(content.mail_projection_calls.load(Ordering::SeqCst), 0);assert!(matches!(loaded.get(&requested),- Some(EmailThreadMailProjectionLoad::Missing)+ Some(EmailThreadMailProjectionLoad::Unavailable(+ EmailThreadUnavailable::NoAccess+ ))));}@@ -531,10 +539,120 @@ async fn unauthorized_metadata_keys_do_not_reach_the_email_domain() {assert_eq!(content.metadata_calls.load(Ordering::SeqCst), 0);assert!(matches!(loaded.get(&requested),- Some(EmailThreadMetadataLoad::Missing)+ Some(EmailThreadMetadataLoad::Unavailable(+ EmailThreadUnavailable::NoAccess+ ))));}+#[tokio::test]+async fn authorized_threads_without_a_metadata_row_report_no_row() {+ let content = Arc::new(RecordingContentService {+ no_metadata_rows: true,+ ..Default::default()+ });+ let reader =+ EmailServiceEmailContentReader::new(content, Arc::new(TestAccessService { allow: true }));+ let user_id = MacroUserIdStr::try_from_email("[email protected]").unwrap();+ let requested = Uuid::from_u128(1);++ let loaded = reader+ .get_email_thread_metadata(&user_id, vec![requested])+ .await;++ assert!(matches!(+ loaded.get(&requested),+ Some(EmailThreadMetadataLoad::Unavailable(+ EmailThreadUnavailable::NoRow+ ))+ ));+}++#[derive(Clone, Default)]+struct CapturedLogs(Arc<Mutex<Vec<u8>>>);++impl std::io::Write for CapturedLogs {+ fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {+ self.0.lock().unwrap().extend_from_slice(bytes);+ Ok(bytes.len())+ }++ fn flush(&mut self) -> std::io::Result<()> {+ Ok(())+ }+}++impl CapturedLogs {+ fn text(&self) -> String {+ String::from_utf8(self.0.lock().unwrap().clone()).unwrap()+ }+}++#[tokio::test]+async fn unavailable_threads_are_logged_in_the_request_span_with_the_reason_and_opaque_viewer() {+ let logs = CapturedLogs::default();+ let writer = logs.clone();+ let _guard = tracing::subscriber::set_default(+ tracing_subscriber::fmt()+ .with_ansi(false)+ .with_writer(move || writer.clone())+ .finish(),+ );+ tracing::callsite::rebuild_interest_cache();+ let denying_reader = || {+ EmailServiceEmailContentReader::new(+ Arc::new(RecordingContentService::default()),+ Arc::new(TestAccessService { allow: false }),+ )+ };+ let user_id = MacroUserIdStr::try_from_email("[email protected]").unwrap();+ let viewer_id = Uuid::from_u128(77);+ let thread_id = Uuid::from_u128(1);+ let metadata_loader =+ email_thread_metadata_loader(user_id.clone(), Some(viewer_id), denying_reader());+ let projection_loader =+ email_thread_mail_projection_loader(user_id, Some(viewer_id), denying_reader());++ let (metadata, projection) = async {+ (+ metadata_loader.load_one(thread_id).await.unwrap(),+ projection_loader.load_one(thread_id).await.unwrap(),+ )+ }+ .instrument(tracing::info_span!("graphql_request"))+ .await;++ assert!(matches!(+ metadata,+ Some(EmailThreadMetadataLoad::Unavailable(+ EmailThreadUnavailable::NoAccess+ ))+ ));+ assert!(matches!(+ projection,+ Some(EmailThreadMailProjectionLoad::Unavailable(+ EmailThreadUnavailable::NoAccess+ ))+ ));+ let logs = logs.text();+ for message in [+ "email thread metadata unavailable",+ "email thread Mail projection unavailable",+ ] {+ let line = logs+ .lines()+ .find(|line| line.contains(message))+ .unwrap_or_else(|| panic!("no {message:?} warning in {logs}"));+ assert!(line.contains("WARN"), "{line}");+ // The fmt subscriber prefixes an event with the spans it fired in.+ assert!(line.contains("graphql_request:"), "{line}");+ assert!(line.contains(&format!("thread_id={thread_id}")), "{line}");+ assert!(line.contains(&format!("viewer_id={viewer_id}")), "{line}");+ assert!(line.contains("reason=NoAccess"), "{line}");+ }+ assert!(!logs.contains("[email protected]"), "{logs}");+}+#[tokio::test]async fn paginated_keys_forward_offset_and_limit_to_the_email_domain() {let content = Arc::new(RecordingContentService::default());diff --git a/crates/graphql_email/src/objects.rs b/crates/graphql_email/src/objects.rsindex 305ff7c489..465e9d34b4 100644--- a/crates/graphql_email/src/objects.rs+++ b/crates/graphql_email/src/objects.rs@@ -503,9 +503,9 @@ wherelet loader = ctx.data::<DataLoader<EmailThreadMetadataLoader<R>>>()?;match loader.load_one(thread_id).await? {Some(EmailThreadMetadataLoad::Found(metadata)) => Ok(metadata),- Some(EmailThreadMetadataLoad::Missing | EmailThreadMetadataLoad::Failed) | None => Err(- async_graphql::Error::new("email thread metadata is unavailable"),- ),+ Some(EmailThreadMetadataLoad::Unavailable(_)) | None => Err(async_graphql::Error::new(+ "email thread metadata is unavailable",+ )),}}@@ -520,10 +520,9 @@ wherelet loader = ctx.data::<DataLoader<EmailThreadMailProjectionLoader<R>>>()?;match loader.load_one(thread_id).await? {Some(EmailThreadMailProjectionLoad::Found(projection)) => Ok(projection),- Some(EmailThreadMailProjectionLoad::Missing | EmailThreadMailProjectionLoad::Failed)- | None => Err(async_graphql::Error::new(- "email thread Mail projection is unavailable",- )),+ Some(EmailThreadMailProjectionLoad::Unavailable(_)) | None => Err(+ async_graphql::Error::new("email thread Mail projection is unavailable"),+ ),}}@@ -572,7 +571,7 @@ mod tests {use uuid::Uuid;use super::*;- use crate::{SoupEmailContentEdgeReader, email_content_loader};+ use crate::{EmailThreadUnavailable, SoupEmailContentEdgeReader, email_content_loader};struct ContentQuery;@@ -632,7 +631,12 @@ mod tests {) -> HashMap<Uuid, EmailThreadMailProjectionLoad> {thread_ids.into_iter()- .map(|thread_id| (thread_id, EmailThreadMailProjectionLoad::Missing))+ .map(|thread_id| {+ (+ thread_id,+ EmailThreadMailProjectionLoad::Unavailable(EmailThreadUnavailable::NoRow),+ )+ }).collect()}}diff --git a/deny.toml b/deny.tomlindex 717a43b1b0..d901c36b79 100644--- a/deny.toml+++ b/deny.toml@@ -233,6 +233,7 @@ deny = ["documents", # Dev logging only"email", # Dev logging only"genai_telemetry", # GenAI span tests+ "graphql_email", # Unavailable-thread warning field and span tests only"graphql_entity_mutation", # Batch failure span field tests only"lambda_runtime_api_client", # External crate allowed to use tracing-subscriber"loom", # External concurrency testing dependencydiff --git a/services/document_storage_service/src/api/graphql_soup.rs b/services/document_storage_service/src/api/graphql_soup.rsindex 98596fb088..4f75eccc08 100644--- a/services/document_storage_service/src/api/graphql_soup.rs+++ b/services/document_storage_service/src/api/graphql_soup.rs@@ -17,9 +17,11 @@ use entity_registry::OwnerGrantPolicy;use entity_registry_db_utils::OwnedEntityRegistrar;use graphql_soup::email_mutation_thread_loader;use macro_authorization::{- OptionalMacroAuthorizationExtractor, UserOrInternalService, UserOrInternalServiceAuthorization,+ MacroUserAuthentication, OptionalMacroAuthorizationExtractor, UserOrInternalService,+ UserOrInternalServiceAuthorization,};use macro_user_id::user_id::MacroUserIdStr;+use uuid::Uuid;mod websocket;@@ -64,6 +66,7 @@ async fn graphql_handler(&state,acting_user.map(|user| user.macro_user_id.clone()),acting_user.and_then(|user| user.user_context.organization_id.map(i64::from)),+ acting_user.and_then(opaque_viewer_id),);state.graphql_soup_schema@@ -92,19 +95,27 @@ async fn subscription_handler(};let macro_user_id = acting_user.macro_user_id.clone();let organization_id = acting_user.user_context.organization_id.map(i64::from);+ let viewer_id = opaque_viewer_id(acting_user);let schema = state.graphql_soup_schema.clone();- let data = graphql_subscription_context_data(&state, macro_user_id, organization_id);+ let data = graphql_subscription_context_data(&state, macro_user_id, organization_id, viewer_id);upgrade.serve(schema, data)}+/// The viewer's opaque account id (`macro_user.id`, the FusionAuth user id),+/// logged in place of the email-bearing Macro user id.+fn opaque_viewer_id(user: &MacroUserAuthentication) -> Option<Uuid> {+ Uuid::parse_str(&user.user_context.fusion_user_id).ok()+}+fn graphql_subscription_context_data(state: &ApiContext,user: MacroUserIdStr<'static>,organization_id: Option<i64>,+ viewer_id: Option<Uuid>,) -> Data {let mut data = Data::default();- insert_graphql_context_data(&mut data, state, Some(user), organization_id);+ insert_graphql_context_data(&mut data, state, Some(user), organization_id, viewer_id);data}@@ -113,8 +124,15 @@ fn graphql_query_context_data(state: &ApiContext,macro_user_id: Option<MacroUserIdStr<'static>>,organization_id: Option<i64>,+ viewer_id: Option<Uuid>,) -> async_graphql::Request {- insert_graphql_context_data(&mut req.data, state, macro_user_id, organization_id);+ insert_graphql_context_data(+ &mut req.data,+ state,+ macro_user_id,+ organization_id,+ viewer_id,+ );req}@@ -123,6 +141,7 @@ fn insert_graphql_context_data(state: &ApiContext,macro_user_id: Option<MacroUserIdStr<'static>>,organization_id: Option<i64>,+ viewer_id: Option<Uuid>,) {data.insert(state.clone());@@ -206,10 +225,12 @@ fn insert_graphql_context_data());data.insert(complete_graph::email_thread_metadata_loader(macro_user_id.clone(),+ viewer_id,email_content_reader.clone(),));data.insert(complete_graph::email_thread_mail_projection_loader(macro_user_id.clone(),+ viewer_id,email_content_reader,));data.insert(complete_graph::entity_favorite_loader(