AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).
fix(briefing): skip a sent-mail thread that fails to open in waiting-on (#607)
Rufus50127833a0d5
diff --git a/packages/core/openexecutive/briefing/waiting_on.py b/packages/core/openexecutive/briefing/waiting_on.pyindex 19fae9c2..601dcdfe 100644--- a/packages/core/openexecutive/briefing/waiting_on.py+++ b/packages/core/openexecutive/briefing/waiting_on.py@@ -89,7 +89,7 @@ async def read_waiting(now: datetime | None = None) -> list[Waiting] | None:from openexecutive.config import get_settingsfrom openexecutive.delegation.follow_ups import recipientsfrom openexecutive.delegation.ghostwriter import one_line- from openexecutive.delegation.gmail import normalize_email+ from openexecutive.delegation.gmail import GmailNotFound, normalize_emailfrom openexecutive.delegation.threads import MAX_RECIPIENTSfrom openexecutive.integrations.email_poller import sender_new_text@@ -127,13 +127,21 @@ async def read_waiting(now: datetime | None = None) -> list[Waiting] | None:async with gate:return await mailbox.get_thread(thread_id)- threads = await asyncio.gather(*(fetch(s.thread_id) for s, _, _ in candidates))+ # A thread deleted since it was listed is skipped. Any other failure+ # fails the read, so ``refresh`` keeps the last good one rather than+ # storing a list with real items missing.+ threads = await asyncio.gather(*(fetch(s.thread_id) for s, _, _ in candidates), return_exceptions=True)+ for t in threads:+ if isinstance(t, BaseException) and not isinstance(t, GmailNotFound):+ raise texcept Exception as exc:# The type only: a mailbox error can carry an address.logger.info("waiting_on: their sent mail couldn't be read (%s)", type(exc).__name__)raisewaiting: list[Waiting] = []for (sent, to, sent_at), thread in zip(candidates, threads, strict=True):+ if isinstance(thread, BaseException): # gone: any other failure raised above+ continuenewest = [m for m in thread.messages if "DRAFT" not in m.labels]if not newest or newest[-1].id != sent.id:continuediff --git a/packages/core/tests/unit/test_waiting_on.py b/packages/core/tests/unit/test_waiting_on.pyindex c4a76c36..b43768d3 100644--- a/packages/core/tests/unit/test_waiting_on.py+++ b/packages/core/tests/unit/test_waiting_on.py@@ -9,6 +9,7 @@ from typing import Anyimport pytestfrom openexecutive.briefing import waiting_on+from openexecutive.delegation.gmail import GmailNotFound, GmailRateLimitedNOW = datetime(2026, 10, 21, 20, 0, tzinfo=UTC)ME = "[email protected]"@@ -116,6 +117,49 @@ async def test_a_failing_mailbox_raises(monkeypatch: pytest.MonkeyPatch) -> Noneawait waiting_on.read_waiting(NOW)+async def test_a_thread_that_fails_to_open_is_skipped(monkeypatch: pytest.MonkeyPatch) -> None:+ class _OneGone(_Mailbox):+ async def get_thread(self, thread_id: str) -> Any:+ if thread_id == "t-gone":+ raise GmailNotFound("deleted")+ return await super().get_thread(thread_id)++ _use(+ monkeypatch,+ _OneGone(+ [+ _sent("gone", ["[email protected]"], ago=timedelta(hours=2)),+ _sent("leonard", ["[email protected]"], ago=timedelta(hours=3), subject="SVN numbers"),+ ]+ ),+ )++ found = await waiting_on.read_waiting(NOW)++ assert [w.subject for w in found or []] == ["SVN numbers"]+++async def test_one_thread_failing_otherwise_fails_the_read(monkeypatch: pytest.MonkeyPatch) -> None:+ class _OneBusy(_Mailbox):+ async def get_thread(self, thread_id: str) -> Any:+ if thread_id == "t-busy":+ raise GmailRateLimited("slow down")+ return await super().get_thread(thread_id)++ _use(+ monkeypatch,+ _OneBusy(+ [+ _sent("busy", ["[email protected]"], ago=timedelta(hours=2)),+ _sent("leonard", ["[email protected]"], ago=timedelta(hours=3)),+ ]+ ),+ )+ # A partial list would replace the last good read with items missing.+ with pytest.raises(GmailRateLimited):+ await waiting_on.read_waiting(NOW)++async def test_a_failed_refresh_keeps_the_last_good_read(monkeypatch: pytest.MonkeyPatch) -> None:good = [waiting_on.Waiting(("[email protected]",), "SVN numbers", NOW)]results: list[Any] = [good, RuntimeError("503")]