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(email): unblock notification reads after unavailable archive replies (#7355)
Peter Chinman47eef6146299
diff --git a/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts b/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.tsindex 477ab6da53..016120b5ae 100644--- a/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts+++ b/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts@@ -1,4 +1,8 @@-import { SaveEmailDraftDocument } from '@service-storage/graphql/generated/graphql';+import {+ SaveEmailDraftDocument,+ SetEmailThreadArchivedDocument,+ UpdateNotificationsDocument,+} from '@service-storage/graphql/generated/graphql';import {markGraphqlEmailThreadSeen,markGraphqlEmailThreadUnread,@@ -2557,6 +2561,89 @@ describe('normalizedCacheExchange', () => {expect(host.commits[0]?.transactionId).toBe('restored-1');});+ it.each([true, false])(+ 'only advances past an unavailable archived thread when its error is terminal (retryable=%s)',+ async (retryable) => {+ vi.useFakeTimers();+ try {+ host.seedQueued({+ uuid: '00000000-0000-4000-8000-000000000001',+ query: stringifyDocument(SetEmailThreadArchivedDocument),+ operationName: 'SetEmailThreadArchived',+ variables: {+ input: { threadId: 'trashed-thread', archived: true },+ },+ data: {+ setEmailThreadArchived: {+ __typename: 'GraphqlSoupEmailThread',+ id: 'trashed-thread',+ inboxVisible: false,+ },+ },+ });+ const readResult = {+ updateNotifications: [+ {+ __typename: 'GraphqlNotification',+ id: 'notification',+ state: 'SEEN',+ },+ ],+ };+ host.seedQueued({+ uuid: '00000000-0000-4000-8000-000000000002',+ query: stringifyDocument(UpdateNotificationsDocument),+ operationName: 'UpdateNotifications',+ variables: {+ input: {+ notificationIds: ['notification'],+ operation: 'MARK_SEEN',+ },+ },+ data: {+ updateNotifications: [+ { __typename: 'GraphqlNotification', id: 'notification' },+ ],+ },+ });+ const { forwarded } = harness(+ host,+ (op) =>+ 'threadId' in op.variables!.input+ ? {+ data: undefined,+ error: new CombinedError({+ graphQLErrors: [+ {+ message: 'updated email thread is unavailable',+ extensions: retryable+ ? { code: 'INTERNAL', retryable: true }+ : { code: 'NOT_FOUND' },+ },+ ],+ }),+ }+ : { data: readResult },+ { shouldRetryMutation: shouldRetryGraphqlMutation }+ );+ await vi.advanceTimersByTimeAsync(10);+ if (retryable) {+ expect(forwarded).toHaveLength(1);+ expect(host.defers).toHaveLength(1);+ expect(host.commits).toHaveLength(0);+ } else {+ expect(forwarded).toHaveLength(2);+ expect(host.rollbacks).toEqual(['restored-1']);+ expect(host.commits).toMatchObject([+ { transactionId: 'restored-2', data: readResult },+ ]);+ }+ } finally {+ vi.useRealTimers();+ }+ }+ );+it.each(['terminal','superseded',diff --git a/crates/graphql_email/src/mutation.rs b/crates/graphql_email/src/mutation.rsindex 8e6a192678..efb928b963 100644--- a/crates/graphql_email/src/mutation.rs+++ b/crates/graphql_email/src/mutation.rs@@ -470,13 +470,17 @@ async fn reload_thread<O: EmailThreadMutationOutput>(user_id: MacroUserIdStr<'static>,thread_id: Uuid,) -> async_graphql::Result<O::Thread> {- async {- O::load_email_thread(ctx, user_id, thread_id)- .await?- .ok_or_else(|| async_graphql::Error::new("updated email thread is unavailable"))- }- .await- .map_err(retryable_email_error)+ O::load_email_thread(ctx, user_id, thread_id)+ .await+ .map_err(retryable_email_error)?+ .ok_or_else(|| {+ // The primary-backed lookup completed, but its All Mail projection+ // can omit a trashed thread even after the write committed. Repeating+ // that write cannot recover the reply and blocks every later queued+ // mutation, including unrelated notification reads.+ async_graphql::Error::new("updated email thread is unavailable")+ .extend_with(|_, extensions| extensions.set("code", "NOT_FOUND"))+ })}/// GraphQL email mutations.diff --git a/crates/graphql_email/src/mutation/test.rs b/crates/graphql_email/src/mutation/test.rsindex dde2a13256..55fe7d5fd9 100644--- a/crates/graphql_email/src/mutation/test.rs+++ b/crates/graphql_email/src/mutation/test.rs@@ -59,6 +59,7 @@ struct CapturingEmailMutationService {delete_reports_missing: std::sync::atomic::AtomicBool,attachment_load_fails: bool,thread_load_fails: bool,+ thread_load_missing: bool,attachments: Vec<MessageAttachment>,attachments_draft: Vec<AttachmentDraft>,attachments_forwarded: Vec<AttachmentForwarded>,@@ -292,12 +293,13 @@ impl EmailThreadMutationOutput for TestEmailThreadOutput {) -> Pin<Box<dyn Future<Output = async_graphql::Result<Option<Self::Thread>>> + Send + 'ctx>>{Box::pin(async move {- if ctx- .data::<Arc<CapturingEmailMutationService>>()?- .thread_load_fails- {+ let service = ctx.data::<Arc<CapturingEmailMutationService>>()?;+ if service.thread_load_fails {return Err(async_graphql::Error::new("thread loading failed"));}+ if service.thread_load_missing {+ return Ok(None);+ }Ok(Some(TestEmailThread {id: ID(thread_id.to_string()),is_read: true,diff --git a/crates/graphql_email/src/mutation/test/archive.rs b/crates/graphql_email/src/mutation/test/archive.rsindex ae6eaf7e1a..68280cbd04 100644--- a/crates/graphql_email/src/mutation/test/archive.rs+++ b/crates/graphql_email/src/mutation/test/archive.rs@@ -1,5 +1,44 @@use super::*;+#[tokio::test]+async fn missing_post_write_thread_does_not_block_the_mutation_queue_with_retries() {+ let thread_id = Uuid::from_u128(42);+ let mutations = [+ format!(+ "setEmailThreadArchived(input: {{threadId: \"{thread_id}\", archived: true}}) {{id}}"+ ),+ format!("markEmailThreadSeen(input: {{threadId: \"{thread_id}\"}}) {{id}}"),+ format!("markEmailThreadUnread(input: {{threadId: \"{thread_id}\"}}) {{id}}"),+ format!(+ "updateEmailThreadLabel(input: {{threadId: \"{thread_id}\", labelId: \"{}\", value: true}}) {{id}}",+ Uuid::from_u128(43)+ ),+ ];+ for mutation in mutations {+ // All Mail omits a trashed thread even though its state write succeeded.+ let service = Arc::new(CapturingEmailMutationService {+ thread_load_missing: true,+ ..Default::default()+ });+ let response = schema(service.clone())+ .execute(format!("mutation {{ {mutation} }}"))+ .await;+ assert_eq!(service.calls.lock().unwrap().len(), 1, "{mutation}");+ assert_eq!(response.errors.len(), 1, "{mutation}");+ let error = &response.errors[0];+ assert_eq!(error.message, "updated email thread is unavailable");+ let extensions = error.extensions.as_ref().unwrap();+ assert_eq!(+ extensions.get("code"),+ Some(&async_graphql::Value::from("NOT_FOUND"))+ );+ assert_ne!(+ extensions.get("retryable"),+ Some(&async_graphql::Value::Boolean(true))+ );+ }+}+#[tokio::test]async fn archive_reply_failure_is_retryable_after_the_write_commits() {let service = Arc::new(CapturingEmailMutationService {