From 8d001eb33f29f45f6d00e3329f0003ca5a350eca Mon Sep 17 00:00:00 2001 From: neo773 <62795688+neo773@users.noreply.github.com> Date: Tue, 5 May 2026 18:00:57 +0530 Subject: [PATCH] fix: don't mark IMAP channel as failed on transient server errors (#20273) Map RFC 5530 codes to `TEMPORARY_ERROR` so sync retries instead of terminally flagging `FAILED_INSUFFICIENT_PERMISSIONS` when the server is briefly unavailable. prod Logs ``` 2026-05-05 03:53:42.129 authenticationFailed: true 2026-05-05 03:53:42.129 serverResponseCode: 'UNAVAILABLE', 2026-05-05 03:53:42.129 responseText: 'Account is temporarily unavailable.', 2026-05-05 03:53:42.129 2026-05-05 03:53:42.129 response: '2 NO [UNAVAILABLE] Account is temporarily unavailable.', 2026-05-05 03:53:42.129 cause: Error: Command failed 2026-05-05 03:53:42.129 code: 'INSUFFICIENT_PERMISSIONS', Caused by: Error: Command failed [Nest] 35 - 05/04/2026, 10:23:42 PM ERROR [ImapGetAllFoldersService] MessageImportDriverException: IMAP authentication error: Command failed ``` --- .../parse-imap-authentication-error.util.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util.ts b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util.ts index 6e69f337f6..65d5b9ff2d 100644 --- a/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util.ts +++ b/packages/twenty-server/src/modules/messaging/message-import-manager/drivers/imap/utils/parse-imap-authentication-error.util.ts @@ -1,3 +1,5 @@ +import { isDefined } from 'twenty-shared/utils'; + import { MessageImportDriverException, MessageImportDriverExceptionCode, @@ -5,6 +7,12 @@ import { import { type ImapFlowError } from 'src/modules/messaging/message-import-manager/drivers/imap/types/imap-error.type'; import { isImapNetworkError } from 'src/modules/messaging/message-import-manager/drivers/imap/utils/is-imap-network-error.util'; +const TRANSIENT_IMAP_RESPONSE_CODES = new Set([ + 'UNAVAILABLE', + 'INUSE', + 'SERVERBUG', +]); + export const parseImapAuthenticationError = ( error: ImapFlowError, ): MessageImportDriverException => { @@ -16,6 +24,17 @@ export const parseImapAuthenticationError = ( ); } + if ( + isDefined(error.serverResponseCode) && + TRANSIENT_IMAP_RESPONSE_CODES.has(error.serverResponseCode) + ) { + return new MessageImportDriverException( + `IMAP transient error [${error.serverResponseCode}]: ${error.responseText ?? error.message}`, + MessageImportDriverExceptionCode.TEMPORARY_ERROR, + { cause: error }, + ); + } + if (error.authenticationFailed === true) { return new MessageImportDriverException( `IMAP authentication error: ${error.message}`,