On a large Gmail mailbox the email-summary poller's SINCE scan often finds nothing (INTERNALDATE/date-header quirks), so it falls back to SEARCH ALL. That returns one enormous UID line; the socket read can time out mid-response, and the exception was swallowed — leaving the unread '* SEARCH 325188 …' bytes on the socket. The next command (the downstream re-select) then read those leftover bytes and failed with 'EXAMINE => unexpected response: b'325188 …''. Extract the fallback into _latest_inbox_fallback_uids(conn, reconnect): on a failed SEARCH ALL it logs out the poisoned connection and reconnects, returning the fresh connection for downstream use. Reconnecting is correct by construction — a new connection cannot carry the old one's leftover bytes — so the re-select always runs on a clean socket. The same SEARCH ALL + reuse pattern also exists in mcp_servers/email_server.py and routes/email_routes.py; left for a separate change to keep this surgical. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2.6 KiB
2.6 KiB