https://sonarly.com/issue/39364?type=bug
Message import jobs for Gmail can hit per-user API quota and fail the channel after 5 retries. This stops mailbox sync for affected channels until a relaunch/reset path runs.
Fix: Implemented the production fix in the Gmail import layer (right layer for the quota burst):
1) Capped Gmail message fetch concurrency
- In `GmailGetMessagesService`, replaced unbounded `Promise.all(messageIds.map(...users.messages.get...))` with `p-limit` capped execution.
- Added explicit constants:
- `GMAIL_MESSAGES_GET_CONCURRENCY = 10`
- `GMAIL_THREADS_GET_CONCURRENCY = 10`
- Applied the same cap to thread expansion (`users.threads.get`) to prevent a second unbounded fan-out path from hitting the same per-user quota envelope.
2) Added test coverage for the fix
- New spec validates that `getMessages()` never exceeds concurrency 10 while processing 30 message IDs.
Pre-fix checklist summary:
- Best-engineer/user-protection: yes, directly prevents quota burst and channel failure loop.
- Right layer: yes (Gmail driver import fan-out).
- Intentional-revert check (`git blame`): no intentional behavior reverted; unbounded fan-out came from original implementation.
- Blast radius check: limited to Gmail import fetch path and local caller behavior.
- No autogenerated files edited.
- No partial/shared-interface unsafe refactor.
Authored by Sonarly by autonomous analysis (run 44831).