Skip to content

Harden email IMAP polling retries - #2122

Merged
Re-bin merged 3 commits into
HKUDS:mainfrom
jr551:codex/improve-imap-email-resilience
Mar 20, 2026
Merged

Re-bin merged 3 commits into
HKUDS:mainfrom
jr551:codex/improve-imap-email-resilience

Conversation

@jr551

@jr551 jr551 commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • retry one email poll cycle when an IMAP connection dies mid-request
  • skip missing mailboxes with a warning instead of surfacing a noisy polling error
  • add focused regression tests for stale-connection retry and missing-mailbox handling

Testing

  • /tmp/nanobot-official-20260316/.venv/bin/pytest /tmp/nanobot-official-20260316/tests/test_email_channel.py -q
  • /tmp/nanobot-official-20260316/.venv/bin/python -m compileall /tmp/nanobot-official-20260316/nanobot/channels/email.py

@chengyongru chengyongru added enhancement New feature or request channel labels Mar 17, 2026
@jr551
jr551 force-pushed the codex/improve-imap-email-resilience branch from 7b50f70 to 0f76f5c Compare March 17, 2026 12:06
Re-bin added 2 commits March 20, 2026 18:44
Keep messages already collected in the current poll cycle when a stale
IMAP connection dies mid-fetch, so retrying once does not drop emails
that were already parsed and marked seen. Add a regression test covering
a mid-cycle disconnect after the first message succeeds.

Made-with: Cursor

@Re-bin Re-bin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: PR #2122 — Harden email IMAP polling retries

Thanks @jr551, the direction here is good. Retrying a stale IMAP poll once and downgrading missing-mailbox failures to warnings both make the email channel much less noisy in real deployments.

I pushed a small maintainer-assist fix on top of this PR.

What was fixed

The original retry logic handled stale connections before a poll cycle completed, but it could still drop messages that had already been fetched earlier in the same cycle.

Example:

  • message 1 is fetched successfully and marked seen
  • message 2 hits a stale IMAP disconnect
  • the retry restarts the poll, but message 1 is now already seen
  • result: message 1 never reaches nanobot even though it was already fetched

The follow-up commit preserves messages already collected in the current poll cycle across the one-time retry, and avoids duplicating them after reconnect.

Tests

Added a regression test covering:

  • first message fetched successfully
  • second message triggers stale disconnect
  • retry resumes without losing the first message

Validation:

  • pytest tests/test_email_channel.py -q
  • full test suite: 544 passed

LGTM after this fix.

@Re-bin
Re-bin merged commit 5424551 into HKUDS:main Mar 20, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants