Repository navigation
fix(imap-trigger): process new emails after empty mailbox poll - #1093
Open
roonakyadav wants to merge 2 commits into
Open
roonakyadav wants to merge 2 commits into
roonakyadav wants to merge 2 commits into
Conversation
- Explicitly pass claim.cursor (None on first poll) to distinguish baseline from stored cursor. - Treat stored cursor with last_uid == 0 as 'nothing seen yet' rather than a baseline poll. - Prevent cursor from moving backwards within the same UIDVALIDITY when mailbox is emptied or older messages remain. - Add focused postgres resilience tests for baseline on empty mailbox followed by new emails, and mailbox emptied between polls. - Add unit tests for fetch_imap_messages cursor retention and polling edge cases. Closes heymrun#1091
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Collaborator
|
Thanks for the quick fix 🙏 Both cases from #1091 work now. Two changes before we can merge:
|
…d require explicit cursor - Store mailbox fingerprint (credential id, host, username, and folder) in trigger poll state key_id. - Establish a new baseline when a trigger node is repointed to a different mailbox to prevent replaying existing messages. - Allow legacy cursor rows saved before this change to adopt current mailbox fingerprint on their first poll without reset. - Drop default '= None' on fetch_imap_messages cursor argument and document 'cursor=None' baseline behavior in docstring. - Add tests for switching mailboxes with zero and non-zero cursors, and legacy cursor adoption. - Document mailbox switch baseline semantics in imap-trigger-node.md.
Contributor
Author
|
Updated in 0186a7f:
All frontend checks (lint, strict typecheck, and 1,281 Vitest unit tests) and backend checks (Ruff format/lint and all 9,861 backend tests) pass. |
Collaborator
|
Thanks, both are in and every mailbox switch case works now 🙏 Two small things before we merge:
|
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.
Description
Fixes #1091.
Previously,
fetch_imap_messagesinterpretedcursor.last_uid == 0as a "first poll" / baseline check and returnednext_cursor, []. Because baseline polls were coerced toImapCursor()in_poll_workflow_node, an initial poll on an empty mailbox stored a cursor withversion = 0. When subsequent emails arrived,cursor.last_uid == 0caused those emails to be treated as baseline and skipped.Additionally, when a mailbox was emptied between polls,
latest_uid = uid_list[-1] if uid_list else 0evaluated to0, moving the stored cursor backwards from the last seen UID to0. Subsequent emails were then skipped again.Changes
claim.cursor(Noneon first poll) directly to_fetch_node_messagesandfetch_imap_messages. Whencursor is None,fetch_imap_messagesrecords the baseline without downloading messages.last_uid == 0as 'nothing seen yet': An existing stored cursor withlast_uid == 0is no longer treated as a baseline, allowing new emails (uid > 0) to be fetched and executed.UIDVALIDITY, setnext_last_uid = max(cursor.last_uid, latest_uid), ensuring that an empty mailbox or one where older messages remain preserves the highest UID seen. AUIDVALIDITYchange continues to reset the cursor._mailboxintest_imap_trigger_cursor_postgres.pyto match the baseline and cursor retention semantics.test_a_baseline_on_an_empty_mailbox_runs_subsequent_new_emailsintest_imap_trigger_cursor_postgres.py.test_an_emptied_mailbox_keeps_its_cursor_and_runs_future_emailsintest_imap_trigger_cursor_postgres.py.test_poll_workflow_node_with_cursor_zero_executes_new_emailsintest_imap_trigger_service.py.test_imap_trigger_node.py.Verification
./check.sh: all checks passed (frontend lint/typecheck, backend Ruff check/format, migrations, and all 9,856 backend tests passed).