Repository navigation
Conversation
Encodes the acceptance criteria for the pre-scan needs_review bucket, budget-reclaim in merge_pre_scan_backends, and Gmail/Outlook coverage honesty (total_unread) ahead of the implementation.
An unconfident heuristic result (confident=False) is a placeholder guess, not a real classification -- pre_scan_inbox_impl was bucketing on category alone and never read it, so a direct question that fell through every heuristic rule to the terminal fallback was silently filed under informational (and an unconfident PROMOTIONAL guess landed in suggested archives, recommending an untrustworthy classification for archival). confident=False now always routes to a new needs_review bucket instead, regardless of the guessed category, after the existing spam/phishing safety override. Capped like the other three buckets (a real corpus is ~97% unconfident with no label signal) with the uncapped count still reported in totals, so this doesn't trade one bad UX for a worse one. merge_pre_scan_backends also stops losing a failed mailbox's scan budget: the per-backend split is now recomputed from what's actually left after each attempt, so a dead connection's share rolls forward to the surviving mailboxes instead of being lost to an even split computed before any backend was tried. total_unread/scanned/degraded fields report how much of the mailbox a scan actually covered -- Gmail's estimate is now scoped to unread mail (it previously described total inbox size), and Outlook's fabricated per-page count is replaced with an honest null rather than a lying number. The prompt and tool docstring now require the model to disclose scan coverage and never phrase a partial scan as if it covered the whole inbox.
Every model in contract.py sets extra="forbid", and the REST endpoint validates the tool's output dict against EmailPreScanResult -- adding needs_review/scanned/total_unread/degraded/mailbox_errors to the tool output without updating the contract would 500 every /v1/email/prescan call. Updates all the surfaces that share this field list: the Pydantic models (plus a new MailboxError type), the regenerated OpenAPI artifact, CONTRACT.md's prose, the hand-maintained Go TUI card struct (including its scanned() helper, which now counts needs_review toward coverage -- Go silently drops unknown JSON fields, so skipping this would make the TUI undercount and drop needs-review messages from the card entirely), and the npm TypeScript mirror. The REST prescan endpoint also stops stripping mailbox_errors from the response now that it's part of the contract. specification.html is regenerated from the introspecting spec_html.py generator (not hand-edited) to match.
The 7-message pre-scan fixture in test_pre_scan_counts.py carries two confident=False messages -- an IMPORTANT-labeled one and a bare no-match question structurally identical to the reported incident -- that both moved out of their old buckets (actionable and informational respectively) into needs_review. TestPreScanCounts.test_counts_match_fixture is updated to match; the three #1265 cheap-scan contract tests in the same file are untouched. test_briefing_job_produces_email_pre_scan_envelope's exact-set assertion picks up the same envelope fields since the scheduled briefing reuses pre_scan_inbox_impl directly. Also includes black/isort-only reformatting of the pre-existing test_pre_scan_budget_reclaim.py / test_pre_scan_coverage_disclosure.py files from the lint pass -- no assertions changed.
An IMPORTANT/STARRED message the heuristic calls NEEDS_RESPONSE-but- unconfident (rule 8: it can tell this needs a reply, just not yet whether it's urgent) was being pulled out of actionable and into needs_review alongside everything else confident=False. With actionable holding as few as 1 rendered row and needs_review capped to 5 out of what can be hundreds of candidates in arbitrary scan order, that starred message went from "the only rendered row" to one of 5 slots contested by everything else the heuristic wasn't sure about -- a worse version of the exact bug this issue exists to fix. confident=False now only overrides routing into the two LOW-SIGNAL buckets -- informational and suggested_archives, which assert "you can ignore this" from what is often a placeholder guess. It no longer pulls a message out of urgent or actionable: an unconfident guess toward a high-signal category already errs toward surfacing, which is the direction to err in. needs_review is also now ordered newest-first (human senders before automated ones on a same-timestamp tie, reusing triage_heuristics' existing automated-sender keyword list read-only rather than adding a new phrase list) instead of an arbitrary slice of backend scan order -- which N of a large uncapped bucket surface is now a stated policy. The 305-message vendor corpus has no X-Gmail-Labels, so rule 8 never fires there and its measured bucket sizes are unchanged by this fix -- the regression this closes is only visible on a real labelled mailbox, covered here by two direct fixture tests (an IMPORTANT-labeled message staying in actionable, and the ordering itself).
…imate Gmail's list_messages resultSizeEstimate -- the field total_unread was originally sourced from -- is documented by Google as approximate. On a real mailbox it reported 201 for an INBOX+UNREAD query while full pagination of the identical query found 523 real message ids: a 2.6x undercount. Reporting that as the pre-scan coverage denominator would reproduce this issue's own bug (an overstated coverage claim) inside its own fix. total_unread is now sourced from Gmail's labels().get(id="INBOX") label resource, whose messagesUnread field is an exact integer -- one call per scan, not per message, so pre-scan stays cheap. list_labels() (already used elsewhere) returns the label's MINIMAL form with no counts, so this needed a new get_label() method on the GmailBackend protocol; both LiveGmailBackend (real HTTP call) and FakeGmailBackend (computed from the in-memory message store) implement it. LiveOutlookBackend gets a structural stand-in returning None -- Graph has no equivalent honest source, same principle as its resultSizeEstimate fix, no HTTP call. Reading total_unread via getattr keeps any minimal test double that doesn't implement get_label degrading to unknown (None) rather than raising -- this is supplementary coverage metadata, never allowed to abort a pre-scan that would otherwise succeed.
Adds list_waiting_on_you, the inbound counterpart to check_followups (#1606): check_followups flags sent mail nobody answered, this flags inbound mail the user hasn't answered yet (e.g. "did you get a chance to look at this? can we meet Thursday?"). Precision is the whole difficulty here. Measured against the adversarial PROMOTIONAL corpus, a sender-shape gate is nearly useless (only 1 of 42 adversarial rows has an automated-sender keyword) and 47 of 104 PROMOTIONAL rows carry a bare "?" from a human-looking sender. Qualification therefore requires BOTH a direct-ask or meeting-time signal AND corroboration that the message is genuine correspondence (an earlier reply already in the thread, or a sender the user has emailed before) -- sender shape and recipient-count alone are deliberately not used as corroboration, since the adversarial corpus is crafted precisely to defeat those. New dependency-free leaf module tools/text_signals.py holds the direct-ask and informal-meeting-time predicates so nothing importing it (now or later) risks closing a cycle through triage_heuristics.py, which stays untouched. The existing calendar meeting heuristic is reused but gated on is_meeting_request and confidence == "high", never confidence alone, since it returns confidence="high" on its own no-signal branch too. Bulk/automated senders are excluded via the existing triage_heuristics automated-sender keyword list (no new list); threads the user already replied to are excluded; the tool is read-only. Regenerates CAPABILITY_MATRIX.md and bumps the agent's tools_count (59 -> 60) for the new tool.
…2581) hub/agents/email/python/tests/test_waiting_on_you_tools.py -- impl and tool-surface tests: direct-ask + meeting-time qualification with corroboration, the two named adversarial corpus ids that must never qualify, the PERSONAL-category gap #2584 can't close, already-replied exclusion, automated-sender exclusion, meeting-signal confidence gating, read-only guarantee, and the full 104-row corpus scored end-to-end. tests/unit/email/test_text_signals.py -- the leaf module's phrase predicates in isolation, plus an AST + source-text check that it imports nothing from gaia_agent_email. tests/unit/email/test_waiting_on_you_precision.py -- mirrors test_phishing_precision.py's corpus-driven style: locks in the panel's stated corpus measurements (104 PROMOTIONAL rows, 47 with a "?" from a non-automated sender, 42 adversarial) and asserts zero false positives over both the full corpus and the 47-row subset, scored as isolated first-contact messages (every corpus row is a thread root with no prior correspondence, so that is the correct, conservative reading of the fixture -- not an assumption imposed by the test).
Updates the npm package's README (feature list), SPEC (agent-loop-only capability section), SKILL (integration playbook's agent-loop-only bullet), and CHANGELOG (Unreleased), plus the python package's own CHANGELOG, so the new tool doesn't ship documented in only one place.
…tact (#2581) An adversarial verifier confirmed the committed-corpus zero-false-positive number was vacuous: every corpus row is an isolated thread root with no prior correspondence, so the corroboration gate never actually ran against it. When corroboration was manufactured for real, both "an earlier outbound message exists in the thread" and "the sender is a known correspondent" were content-blind -- a single injected one-liner ("Please remove me from this list.", or an unrelated "what's the pricing?" in a different thread) was enough to qualify 15 of 15 marketing messages that fire a direct-ask or meeting-time signal, including both named regression corpus ids. Three changes close this: - Corroboration now requires more than one prior exchange, or a single prior message with real substance (new text_signals.is_substantive_text, a word-count floor against one-line dismissals/inquiries) -- "a message exists" is no longer sufficient on its own. - A prior message where the user told the sender to stop contacting them (new text_signals.is_opt_out_reply) never counts as corroboration and instead suppresses that sender unconditionally -- it is evidence of wanting less contact, not more. - An independent veto: if the existing, unmodified triage_heuristics.classify_category_heuristic confidently classifies the candidate as PROMOTIONAL, it never qualifies regardless of corroboration. Corroboration proves prior contact; it must not be read as proof this specific message is personal. Re-ran the corpus measurement the way the verifier did -- corroboration synthesized both ways against the 25 PROMOTIONAL rows whose text alone fires a signal -- and both now show 0/25, down from 15/15 before this fix.
…ses (#2581) Second checkpoint fix. A further adversarial probe (6c) showed the first fix's hardening wasn't enough: one genuine, substantive prior message to a vendor in a DIFFERENT thread ("could you send pricing for the enterprise tier?") still corroborated 24 of 25 signal-firing rows via the known_correspondent path, because "has this person ever sent me a real message" is not evidence THIS message needs a reply -- sender identity was the wrong thing to corroborate on. The known_correspondent cross-thread corroboration path is removed entirely, not tightened further. "Waiting on your reply" now means: this thread has genuine back-and-forth already in it and it's the user's turn -- corroboration is scoped to a single thread's own history. A prior message to the same address in any other thread no longer corroborates anything, regardless of its content. Also normalizes the address used for opt-out suppression (casefold + strip plus-tag), so a sender can't dodge a recorded "stop contacting me" by varying the tag on an otherwise-identical mailbox. Kept, unchanged: the genuine-exchange requirement within a thread (more than one exchange, or one substantive message), the opt-out suppression itself, and the independent PROMOTIONAL-classifier veto -- none of those were implicated. Re-measured with the verifier's own three constructions plus recall: - 6a (in-thread prior outbound, opt-out-shaped): 0/25 - 6b (unrelated prior SENT thread, weak "what's the pricing?"): 0/25 - 6c (unrelated prior SENT thread, genuinely substantive vendor inquiry): 0/25 - Recall on the surviving in-thread path: both hand-authored positive scenarios (direct-ask reply, #2580 incident wording) still qualify.
…he thread total (#2581) Third checkpoint fix. The in-thread corroboration threshold (">=2 prior messages OR one substantive one") was counting every message in the thread regardless of direction. A vendor's cold intro plus a one-word "Thanks!" reply from the user is two total messages, so the count-based branch short-circuited before the substance check on that single, non-substantive outbound ever ran -- the substance requirement was built correctly but bypassed by the sender's own message volume. The threshold now counts only the user's own prior messages (prior_outbound_bodies), which is what _is_genuine_exchange already operates on -- removing the redundant, buggy thread-total branch entirely rather than patching it. Added the exact regression shape: vendor intro + one-word user reply + signal-bearing follow-up must not qualify, plus a contrast case (two genuine user replies, even short ones, still qualifies) proving this didn't overcorrect into requiring substance on every message. Re-measured: 6a/6b/6c all still 0/25; recall unchanged (2/2 hand-authored positive cases, both prior tests using the substantive default outbound body still pass). Documented two accepted, out-of-scope residual findings in the module docstring: a PROMOTIONAL message sent into a thread that has already earned genuine corroboration can still qualify (needs a message-level promotional judgement stronger than the existing label-driven heuristic; tightening corroboration further would only cost recall on real conversations), and prior messages are trusted by their backend-supplied From header with no authentication check (real spoofing defenses belong upstream, at the mail provider/backend level).
EvidenceReal-world tier on a Linux box against the live Gmail mailbox. Connection verified as genuinely authorised first ( Scanned 200 inbox messages. One qualified.
The corroboration claim was checked against the real thread, not taken from the tool's own output. The thread holds 13 messages; exactly one was genuinely sent by the user. That matches the "single substantive prior message" branch rather than the "≥2 user replies" branch, and it is the claim this detector makes — so it was verified independently rather than trusted. Notable that the subject contains no question mark and still qualified on
Scan was truncated at the 200-message ceiling, so older inbound mail was not examined. Stating that rather than presenting one hit as a whole-mailbox result. Mailbox integrity
One message arrived naturally during the run — additive and unread, consistent with ordinary incoming mail. Zero removals anywhere. Reported plainly rather than rounded to "no change". |
…dent phrasing (#2581) Cross-branch interaction, not a defect in this branch's own logic: #2583 deliberately adds "any chance to meet" to the calendar heuristic's invite phrases to close the exact gap this issue's has_meeting_time_signal was built to cover. Both changes are correct, but two tests here asserted the now-false precondition that detect_meeting_request_heuristic does NOT catch that phrasing -- true when written, false the moment a branch carries both changes. Fixed both: - hub/agents/email/python/tests/test_waiting_on_you_tools.py: dropped the precondition from test_incident_wording_qualifies_with_corroboration and kept only what the detector itself does. Added a new test (test_direct_ask_signal_catches_what_the_meeting_heuristic_still_does_not) using a phrasing with no meeting noun, invite phrase, or time token at all -- "Did you have a chance to look through the code?" -- to honestly preserve the original intent (two genuinely distinct signal paths) without depending on the other heuristic's phrase list staying static. - tests/unit/email/test_text_signals.py: removed the equivalent guard (test_existing_heuristic_does_not_catch_incident_wording) outright -- this module's own suite has no reason to assert anything about calendar_tools.py's behavior at all. Grepped both test files plus test_waiting_on_you_precision.py for any other assertion depending on detect_meeting_request_heuristic NOT matching something; these were the only two. Full email suite green (1953 passed); lint clean.
itomek-amd
left a comment
There was a problem hiding this comment.
Approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
left a comment
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
left a comment
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
left a comment
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
left a comment
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
left a comment
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
left a comment
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
left a comment
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
left a comment
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
…g-on-you # Conflicts: # hub/agents/email/python/CAPABILITY_MATRIX.md # hub/agents/email/python/gaia-agent.yaml # hub/agents/email/python/gaia_agent_email/__init__.py # hub/agents/email/python/gaia_agent_email/agent.py # hub/agents/email/python/tests/test_capability_matrix.py
|
Closing as superseded by #2604, not abandoned — every commit here is carried in that PR. This branch was stacked on #2584's, which merged as a squash, so its history diverged from Nothing is lost: the detector, the three adversarial-review fixes (dropping cross-thread corroboration, counting the user's own messages for genuine exchange, and the stale meeting-heuristic guards), the live-mailbox evidence, and the documented known limitations all ship in #2604. The precision measurement that this PR's review rested on was re-verified there — the signal-firing corpus subset moved from 25 rows to 19, traced to exactly six rows that #2589's proximity fix correctly stopped flagging, with the provenance recorded rather than the number quietly updated. Follow #2604 for the merge. |
…nto main (amd#2604) Closes amd#2581 Closes amd#2582 Recovers two pieces of the amd#2580 epic that never reached `main`. **What happened.** amd#2582's attention view was reviewed and merged as PR amd#2599 — but into `tmi/2580-attention-int`, a temporary integration branch, rather than into `main`. It reads as MERGED on the PR list, so it looked shipped; it wasn't. That branch also carried amd#2581's waiting-on-you detector, whose own PR (amd#2593) was left open and conflicting. This brings both to `main` together, updated against everything that has landed since. **Nothing here is new work.** Every line was already reviewed and passed a live-mailbox testing gate as amd#2593 and amd#2599 — including three rounds of adversarial verification on the detector's precision, and TUI captures of the populated, honest-empty and disconnected-mailbox states. This is a re-delivery of stranded work, not a fresh change. Together these complete the epic: the agent works out what needs you, and the TUI shows it on open, unprompted. ## Test plan - [ ] `python -m pytest tests/unit/agents/email/ tests/unit/email/ hub/agents/email/python/tests/ tests/test_email_openapi_conformance.py tests/unit/agents/test_email_agent.py` — 2176 passed - [ ] `python util/lint.py --all` — all blocking gates pass - [ ] `cd tui && go build ./... && go vet ./... && go test ./...` — clean - [ ] Tool count is **64**, derived by regenerating the capability matrix and independently by hand; both agree - [ ] Schema version is **2.8** with amd#2589's 2.7 content intact — verified, not assumed - [ ] `needs_review` routing and `is_meeting_request` still work *together* — `test_meeting_item_carries_flag_through_pre_scan` <details> <summary>Merge notes — what was resolved and how</summary> Twelve files conflicted. Generated artifacts (`CAPABILITY_MATRIX.md`, `openapi.email.json`, `specification.html`) were **regenerated** and then diffed against the hand-resolution to confirm agreement, rather than hand-merged. The rest were resolved to the combined state — never `--ours`/`--theirs`. Two things worth a reviewer's eye: - **`read_tools.py`** combined this branch's shared `needs_review_decision()` extraction with main's inline routing, which encoded the same rule. Git's auto-merge left a dead local and a duplicated import behind — non-conflicting but wrong — both removed. - **`contract.py` / `CONTRACT.md` / `read_tools.py`** came out byte-identical to the pre-merge tip, because this branch had already written its own `is_meeting_request` field independently before main's version landed. </details> <details> <summary>Three stale tests fixed, one of them carefully</summary> **`test_signal_firing_subset_is_25_rows` → 19.** That 25 was the denominator behind three rounds of adversarial precision work on the detector, so it was not updated on faith. The pre-amd#2589 heuristic was reconstructed as a standalone module and diffed across all 104 promotional corpus rows: **exactly 6 rows dropped, 0 newly fired.** All six matched `meeting noun 'call' with concrete time` before and `without a concrete time or invite` after — the "ACTION REQUIRED … expires 4PM" marketing template (`1677f2af`, `28226131`, `5f720d3d`, `9c0cdaf3`, `c7a9b9eb`, `d964ff4d`). None involved the direct-ask signals. This is amd#2589's proximity rule working as designed. The provenance is recorded in the module comment, and the historical 25 / 15-of-15 / 24-of-25 figures in the surrounding commentary are deliberately left intact — they document a real prior verifier run at that denominator. **`GET /v1/email/attention` had no conformance test** — added, following the existing `/briefing` and `/search` patterns, plus the 503-without-mailbox case. **`list_waiting_on_you` was missing from `EXPECTED_TOOLS`** — added. </details> <details> <summary>Known limitations, carried forward unchanged</summary> From amd#2581, documented in the module docstring rather than only in review: marketing sent *into* a thread you have genuinely corresponded in can still qualify as awaiting your reply, roughly one time in four. The thread history is real, so corroboration cannot reject it; only a message-level promotional judgement could, and the existing one is label-driven and near-inert on unlabelled mail. Tightening corroboration further costs recall on genuine correspondence. Shipped knowingly. Also unchanged: the module trusts the backend-supplied `From` header on prior messages with no authentication check. Real spoofing defences sit upstream at the provider. **Separately observed, not fixed here:** `tests/test_email_openapi_conformance.py` sits outside the `tests/unit/` network guard, so on a machine with a live Lemonade server a real embedding call succeeds and poisons a process-global cache, making 5 memory tools register in a later test. Confirmed pre-existing and environment-dependent by pointing `LEMONADE_BASE_URL` at an unreachable host — the failure vanishes. Same family as amd#2600. </details>
Closes #2581
The assistant could already tell you which mail you sent that nobody answered. It had no idea which mail you received was sitting there waiting on you — which is the direction that matters when you've been heads-down for six hours. In the #2580 incident a colleague asked a direct question and proposed a meeting time; it was classified informational and reported under "0 actionable items". This adds a read-only detector for inbound mail awaiting your response, with enough structure to say " is waiting on your reply about , sent N days ago."
The hard part was precision, and it took three rounds of adversarial review to get right. Marketing is full of question-shaped copy — "Ready to save 20%?" — so the naive version reproduces the bug it fixes. Two designs were built and discarded before this one:
What survives: the ask must sit in a thread with genuine two-way history, where genuine counts your messages rather than the thread's total. Opt-out replies suppress a sender entirely, keyed on a normalised address so a plus-tag can't dodge it.
Measured
NEEDS_RESPONSErows with genuine thread historyAll measurements are over the committed 305-row corpus and were reproduced by an independent verifier writing its own harness, not by the tests in this PR.
Test plan
python -m pytest tests/unit/agents/email/ tests/unit/email/ hub/agents/email/python/tests/— 1953 passedpython util/lint.py --all— cleantests/unit/email/test_waiting_on_you_precision.pytext_signals.pyimports nothing fromgaia_agent_email— asserted by test, so it can't reintroduce the import cycleKnown limitations — accepted, not overlooked
1. Marketing sent into an already-corroborated thread still qualifies (~1 in 4). If you genuinely negotiated with a vendor in a thread and they later send promotional content into that same thread, it can read as awaiting your reply. This is not a corroboration bug — the history is real. Rejecting it needs a message-level promotional judgement, and the existing one is label-driven and near-inert on mail without Gmail category labels (it fired on 1 of 25 in testing). Tightening corroboration further would only cost recall on genuine correspondence.
2. Prior messages are trusted via the backend-supplied
Fromheader with no authentication check, so a forged prior-outbound got through in 1 of 10 attempts. Real spoofing defences (SPF/DKIM/DMARC) sit upstream at the provider; this module adds no defence in depth of its own.Both are recorded in the module docstring and CHANGELOG so they outlive this PR.
Notes for the reviewer
text_signals.pyis a new dependency-free leaf.triage_heuristics.pyis deliberately import-free andcalendar_tools → read_tools → triage_heuristicsalready closes a cycle, so shared predicates could not live in either.triage_heuristics.pyis untouched — no classification behaviour changed, so the eval surface is unaffected.tmi/issue-2584-prescan-honesty); review that first.