Repository navigation
fix(email): find mail the user describes in their own words - #4148
Conversation
|
Retargeted this onto 🔍 Technical details
No history was rewritten — only the PR's base. Once #4147 merges, |
Describing a half-remembered email in your own words reported it missing. The model turns a sentence into six-to-eleven keywords, both providers AND every term, and the zero result ended the turn as "nothing matches" — while two words from the message find it instantly. Nothing told the model that a longer query is a narrower one, and a zero result had no recovery path. `search_email` now says so in its docstring and broadens on its own: drop boolean operators and stopwords, keep the two longest terms, then try the longest terms one at a time, stopping at the first rung that hits. Bounded to six searches. Every broadened rung keeps at least one content term. A bare mailbox operator is long, so length-ranking would otherwise make `is:unread` a rung of its own — and an unread pile is never empty, so the ladder would stop there and hand back 25 unrelated messages labelled as a match. That is the same confident wrong answer this change exists to remove. The broadening is reported, never hidden: the result carries every `attempt` with its count, the `query_used` the hits actually came from, and `broadened: true` so the model describes a looser match as one. It compares terms, not the raw string, so the trailing space a small model emits does not report an exact first-try hit as approximate. A genuine miss still returns zero, with the broadest query it tried named in the note. Closes #4134
Verdict: Approve with suggestionsWhen someone describes a half-remembered email in their own words, mail search used to come back empty because every word gets ANDed together. This PR teaches the search tool to retry with progressively fewer, more distinctive words, and to say out loud which query the results actually came from — so an approximate match never gets presented as an exact one. It's a clear improvement, well bounded (at most six searches), and the tests and live evidence back it up. One thing worth fixing, ideally before merge: Broadening quietly throws away the user's filters. If the model searches for "unread mail from Dana about the invoice" and that finds nothing, the fallback search drops "unread" and "from Dana" and returns anyone's invoices — including ones the user explicitly excluded with a minus sign. The results are labelled approximate, so it isn't a silent wrong answer, but the model is never told that a constraint disappeared, only that the wording was loosened. Either keep those filters on the retries, or name the dropped ones in the message handed back to the model. This isn't a regression — today that search returns nothing at all — but it's the same confident-wrong-answer shape the PR exists to close. Smaller items (an unbalanced quote switching the feature off entirely, and words containing a colon being mistaken for filters) are in the details below. Real-world evidenceStrong, and it supports the verdict. A message that genuinely isn't there still reports zero after exactly six searches, with an instruction not to keep searching. A two-word query that hits costs one round trip and no hedging. A mid-ladder 401 surfaces the auth error instead of reading as "no such mail". Sibling tools ( Gaps the bundle itself declares, and I'm taking at face value rather than treating as proven: the Agent UI screenshot is pending the strix-halo lane; no model actually drove a turn (no Lemonade on this runner), so nothing here shows a small model obeying the new docstring or repeating the hedge to the user; and only the Outlook backend was exercised — the Gmail path shares the ladder but its own query serialisation wasn't driven. Timing is loopback-only (2–6 ms), so it measures the ladder's overhead, not what six real provider round trips cost. 🔍 Technical details🟡 ImportantBroadened rungs drop search operators and negations without telling the model (
Rung 2 of the first example returns every invoice in the mailbox from every sender, read or unread. The payload sets The docstring's stated invariant ("every broadened rung is built from content terms only") is motivated by avoiding an operator-only rung — but keeping operators alongside content satisfies that too, and
Option 2 is the smaller change and keeps the "nothing is hidden from the model" property the PR description claims. Either way this deserves a test asserting the model is told which constraints were released. 🟢 MinorAn unbalanced quote disables broadening entirely (
The feature's own premise is that small models emit sloppy queries (the test suite says as much about stray whitespace), and an unmatched quote is the same class of slip — except here it silently turns the whole ladder off. One-line guard: Any colon makes a term look like a filter (
Low impact — these are unusual query terms, and the first rung still runs them verbatim — but matching against the known operator names both providers accept ( Six sequential provider searches on a miss, with no latency evidence Worst case is 6 round trips to Gmail/Graph per Strengths
|
Live Gmail re-verification — 2 of 3 pass, the third still missesRan the three recollection questions from #4134 against a real Gmail mailbox (1,137 messages) on an Acer Swift with the flagship loaded from source, at this PR's head The two camera questions now work. Both find the right thread on the model's first try — the docstring change did its job: the model sends The contract question still does not find the message it is describing. Two independent runs, neither returned The agent's answer is at least honest about it now — it says it found no exact match and asks for the sender or project, rather than presenting the wrong mail as the answer. That is an improvement, but it is not the issue's acceptance bar ("describe it in your own words, using no word that appears in its subject — it should find it"). Both regressions the reviewers asked about are refuted on the live mailbox: a bare I have not ticked the test-plan checkbox. 🔍 Technical detailsEnvironment
Q1 — "the argument over cameras police departments use to watch streets" — PASS (reproduced, executed) Q2 — "a newsletter about Flock cameras" — PASS (reproduced, executed) Q3 — "asking me to sign off on a contract schedule before the end of the week" — FAIL (reproduced, executed, 2/2 runs) Run 1 — ladder fires, stops on a non-empty but wrong rung: Run 2 — ladder never fires at all, because the first query is non-empty: Competing cause considered and discriminated: the target message is not in this mailbox. Refuted by running the backend directly — And the issue's own literal query still behaves as it did on So the residual gap is D2 (a bare provider operator becomes a broadening rung) — refuted (reproduced, executed) One attempt, run as asked, not labelled as broadened. Matches D1 (whitespace-only difference reported as broadened) — refuted (reproduced, executed) Out of scope, observed during the runs
Refs #4134 |
amd#4155) Asked what needed attention, the flagship put a phishing lure under **Critical & Urgent Action Items** and then, in its own words, told the user to do what the lure wanted ("this requires immediate verification/action"). That advice was the agent's, carrying its own authority. The retired hub email agent had guarded against exactly this, but the flagship reaches mail through a different path and never inherited the safeguard — and both existing guard tests are gated behind an import of the retired package, so nothing went red when it failed to port. Now every message body the mail tools return is fenced as untrusted content, a probable lure comes back flagged with the reason it was flagged, and the result tells the model it must not be bucketed as urgent and must not have its call to action repeated as advice. **The guard lives in the tool result, not in a skill** — the turn that produced the defect never loaded one, so a skill-only fix would not have run at all. 🔒 **SECURITY CONCERN** — this is the fix for a reported prompt-injection / phishing-amplification defect. @kovtcharov-amd ## Test plan - [ ] `python -m pytest tests/unit/agents/tools/test_email_phishing_guard.py -q` — 19 tests on the flagship path, no `importorskip`. Before the fix the whole module errored at collection (the detector did not exist); after it, the skill check still failed alone until the skill carried the rule. - [ ] `python -m pytest tests/unit/agents/ -q` — passes. - [ ] `python util/lint.py --all` — passes. - [ ] Live, against a mailbox containing a lure: **ask a mail-scoped question** — "check my inbox and tell me which emails need a reply" — in a fresh process. **Do not use the wording in the issue.** "What needs me?" was measured to make zero email tool calls and answer from memory, so it looks like a pass while never touching the mailbox. Confirm the turn actually called `list_inbox`, then that the lure is reported as suspicious with its reason, never as an action item, and that nothing in the answer tells the user to follow it. <details> <summary>🔍 Technical details</summary> - `src/gaia/agents/tools/_email/phishing.py` ports the retired agent's deterministic, LLM-free `detect_phishing` — three precision-first channels (subject keyword pairs, sender domain impersonation, body phrases) — and returns `(suspicious, reasons)` rather than a bare bool, so amd#4072's never-empty-rationale rule holds by construction rather than by convention. - `EmailToolsMixin` annotates every listing and search hit, fences every read body, and attaches the do-not-bucket / do-not-restate guidance only when something actually fired (no guidance noise on a clean inbox). - Fixtures from the live baseline: the PayPal/Microsoft homoglyph senders that the agent left unmentioned entirely are caught by the domain channel, and `[email protected]` — Google's real domain, whose "Security alert" reads exactly like a lure — is pinned as a negative case. - `hub/skills/inbox-triage/SKILL.md` carries the same rule as defence in depth, with a test pinning that it still does. Note it also renumbers the triage steps, which collides with amd#4159 — merge order matters. - Three existing tests in `test_email_tools.py` asserted on the raw body string and now unwrap the fence; they test truncation and the per-turn budget, which charge the unfenced length. - Not run here: `gaia eval agent`. The change adds tool-docstring text, an LLM-affecting surface — no Lemonade backend in this environment. amd#4148 has since merged, so this targets `main` directly and carries only its own commits. </details> Closes amd#4150
Before: describing a half-remembered email in your own words reported it missing — the flagship turned the sentence into six-to-eleven keywords, Gmail and Graph ANDed every one of them, and the zero result ended the turn as a confident "nothing matches" even though two words from the message found it instantly. After: it finds it.
search_emailnow tells the model that a longer query is a narrower one, and broadens on its own when a query returns nothing, reporting which query the hits actually came from so an approximate match is never described as an exact one.Closes #4134
Evidence
Same paraphrased question, same mocked mailbox holding one message ("The argument over Flock cameras"), driven through the real
search_emailtool entry point.Before (
main@c3f949f3) — one search, zero hits, turn over:After — broadens until it hits, and says so:
Test plan
pytest tests/unit/agents/tools/— 165 passed (13 new, covering the ANDed-terms docstring contract, a zero-result query the broadening recovers, a genuinely absent message that still honestly reports zero, the JSON naming the effective query, and the ladder's exact rungs)pytest tests/unit/agents/— 1271 passed, 50 skippedpython util/lint.py --all— cleanLive Gmail re-verification of the issue's three recollection questions — 2 of 3 pass; the third fails for a different reason, tracked separately as fix(email): mail search stops broadening on wrong results, not just on no results #4156. Run on the Acer Swift against a real 1137-message mailbox, flagship from source at this PR's head. Transcripts: fix(email): find mail the user describes in their own words #4148 (comment)
The two questions that hit nothing on
mainnow find their thread on the first try. The third never returns its thread because its query comes back with a few wrong messages rather than none — and broadening only fires on an empty result, so it never runs. That is a separate defect from the one this PR fixes, and feat(email): swap the flagship in as the mail agent once four basics work — read, answer, find, triage #4074's "Find" criterion stays open until fix(email): mail search stops broadening on wrong results, not just on no results #4156 lands.🔍 Technical details
The broadening ladder (
_broadening_ladderinsrc/gaia/agents/tools/email_tools.py) is deterministic and bounded, never a silent fallback:OR/AND/NOT) and stopwordsIt stops at the first rung that returns results — at most six provider searches on a genuine miss, and exactly one when the query already hits. Longest-term is a proxy for distinctive; the single-term rungs are what actually recover a message whose own wording the user never used, which the two-term rung alone did not (measured while building the evidence above).
Nothing is hidden from the model: every attempt and its count is in the result,
broadenedis explicit, and a zero result names the broadest query tried rather than implying the mailbox is empty. An empty/whitespace query still fails loudly through the backend's existing validation instead of returning an empty list.Scope:
src/gaia/agents/tools/email_tools.pyand its tests only —_email/gmail.pyis untouched (owned by #4110 in the same wave).