Repository navigation
Harden email IMAP polling retries - #2122
Merged
Merged
Conversation
jr551
force-pushed
the
codex/improve-imap-email-resilience
branch
from
March 17, 2026 12:06
7b50f70 to
0f76f5c
Compare
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
approved these changes
Mar 20, 2026
Re-bin
left a comment
Collaborator
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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