Skip to content

Commit 200c362

Browse files
michaelmcneesclaude
andcommitted
fix: cap email trigger UID fetch and use teamCtx for audit events
Cap UIDs fetched per poll cycle to 200 to prevent memory exhaustion on large mailboxes. Fix audit event in fireWorkflow to use teamCtx (which carries TeamID) instead of the bare ctx. Note: go-imap v2 client.Store() already issues UID STORE automatically when passed an imap.UIDSet (via uidCmdName dispatch) — no UIDStore method exists in this API version. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 491070f commit 200c362

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

internal/server/email_trigger.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,12 +309,23 @@ func (e *EmailTriggerPoller) poll(ctx context.Context, t TriggerRecord, client *
309309
return err
310310
}
311311

312+
const maxEmailsPerPoll = 200
313+
312314
uids := searchData.AllUIDs()
313315
if len(uids) == 0 {
314316
metrics.EmailPollDuration.WithLabelValues(t.WorkflowName, folder).Observe(time.Since(start).Seconds())
315317
return nil
316318
}
317319

320+
// Cap to avoid memory exhaustion on large mailboxes.
321+
if len(uids) > maxEmailsPerPoll {
322+
e.server.Logger.Warn("email poller: truncating UID list",
323+
"trigger_id", t.ID,
324+
"total_uids", len(uids),
325+
"processing", maxEmailsPerPoll)
326+
uids = uids[:maxEmailsPerPoll]
327+
}
328+
318329
// Fetch envelope + body text for each message.
319330
var uidSet imap.UIDSet
320331
for _, uid := range uids {
@@ -409,7 +420,7 @@ func (e *EmailTriggerPoller) fireWorkflow(ctx context.Context, t TriggerRecord,
409420
"uid", uid)
410421

411422
if e.server.Auditor != nil {
412-
_ = e.server.Auditor.Emit(ctx, audit.Event{
423+
_ = e.server.Auditor.Emit(teamCtx, audit.Event{
413424
Actor: "email-poller",
414425
Action: audit.ActionEmailTriggerFired,
415426
Resource: audit.Resource{

0 commit comments

Comments
 (0)