Repository navigation
fix(email): stop mail search settling for the wrong messages - #4159
Conversation
Skill audit
✅ All audited skills cleared the tier they claim. Per-finding detail is withheld here on purpose. Read it in the Security > Code scanning tab, or download the |
Request changesGood fix for a real failure: mail search used to stop the moment any query came back, so two plausible-but-unrelated hits ended the hunt and the model answered confidently from the wrong thread. Turning the ladder into a bounded sweep, collapsing chatty threads to one hit, and labelling anything the query never matched as unverified all address that directly — and the PR is honest that it is a partial fix. Two things to settle before merge:
Real-world evidenceStrong, and it supports the verdict: A query that matches as sent still costs one round trip and is never hedged: A paraphrase that matches nothing recovers the real message and refuses to call it a match: Thread collapse also verified (5 distinct threads at 🔍 Technical details🟡 A failing sweep rung discards exact results (
|
Live Gmail re-run — Q3 fixed, the thread comes back and the model names it correctlyRan the three #4134 recollection questions against the real mailbox on the leased Acer Swift at Question 3 now works. This is the one that failed 2 of 2 runs on
That is the open question the PR flagged — whether the model would do anything useful with the Per-thread dedupe works. No confident wrong answer in any run. Where the agent missed, it said so and asked for a keyword rather than presenting wrong mail as the answer — a materially different outcome from the original defect. One thing I could not settle, flagged rather than dismissed. In one Q1 run of three, the model emitted a ~350-word keyword-stuffed query; every rung missed until the single-term rung The eval checkbox stays unticked — that gate is blocked on a judge credential, tracked separately. 🔍 Technical detailsEnvironment
Q3 — PASS (reproduced, executed) The exact hits are unchanged from the old failure; the fix is that the sweep no longer stops there. Note the mechanism that made this work is Q1 — PASS 2/3 (reproduced, executed) Discriminator at 1-in-3 here versus 0-in-3 there. Competing causes, neither excluded: ordinary sampling variance, or the new docstring's "search the rare nouns, not the paraphrase" framing inducing keyword expansion. n=3 per side cannot separate them. Run 1's answer was an honest miss, not a false match:
Q2 — PASS (reproduced, executed) Dedupe — PASS (reproduced, executed) Two smaller observations
|
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
Five tests, all failing at 7c3bc60, for the half of mail recollection one conversation spends every result slot, and a result set the tool cannot vouch for comes back looking like a confident match.
Ask the flagship for a message you half-remember and it could hand you a confident wrong answer. Search stopped the moment a query returned anything, so two or three plausible-but-unrelated hits ended the hunt and the model answered from them. It now keeps gathering candidates from broader queries, returns one hit per conversation instead of letting one chatty thread spend every slot, and marks any result the query itself never matched as unverified — with an instruction to re-query in the sender's vocabulary or ask the user, rather than answer from a guess. The ladder is no longer a fallback chain that any non-empty rung ends; it is a bounded recall sweep. An exact hit still wins and keeps `messages` to itself, so a query that works today is unaffected; looser hits arrive separately under `alternatives`.
Overlapping rungs return the same message repeatedly, which inflated the per-thread match count into a claim the mailbox never made.
Stacked on the phishing safeguard, whose screen ran on the single result list that existed before broadening created a second one. Alternatives are returned to the model, so they are screened too, and `suspicious_count` counts both sets. The interaction is worse than a missing flag. The unverified note tells the model to search again "with the words the sender would have written" — so a lure surfacing in a broadened rung would have chosen the terms of the next search, and its results would come back as ordinary mail. The note now excludes flagged hits as a vocabulary source whenever anything in the set is flagged, and the triage skill says the same in the step that governs untrusted content.
…didates The docstring told the model that hits which did not match its query carry `unverified: true`. The flag was payload-level and set only when nothing matched at all, so the fallback path — an exact hit plus alternatives — had no marker on the very hits that needed one. The model reads the docstring, not the code, so the contract had to become true rather than quieter: every hit found by a broader rung now carries it. Alternatives also ride along on every broadened search, so they are trimmed to what identifies and screens a thread: 748 -> 522 bytes each, 30% off a full 25-candidate set. The count is deliberately unchanged — the live run that fixed the failing question picked its answer out of 25 candidates from a late rung, and a count cap would risk discarding exactly the hit this change exists to surface.
A backend error on a broadened rung (expired token, rate limit) used to propagate past already-found exact hits and fail the whole search, throwing away a result the query itself had already matched. The sweep now degrades to reporting sweep_incomplete instead, and only re-raises when there is nothing exact to fall back on. Flagged in review on this PR; fixing it here rather than merging around it.
b525166 to
8f20e0b
Compare
…dget The rebase onto main exposed a real lint gate: the added exact_match / unverified / alternatives explanation pushed the schema description to 912 chars against the 500-char budget enforced by util/lint.py --tool-descriptions, which the PR's own test plan had believed passing. Condensed to the same facts without the rationale.
Ask the flagship for a message you only half-remember and it could hand you a confident wrong answer. Search stopped the moment a query returned anything, so two or three plausible-but-unrelated hits ended the hunt and the model answered from them — worse than a miss, because nothing says it went wrong. It now keeps gathering candidates from broader queries, returns one hit per conversation instead of letting a single chatty thread spend every result slot, and labels every hit its own query never matched as a candidate rather than an answer.
Verified live on a real 1137-message mailbox. The recollection question that failed both runs this morning — "sign off on a contract schedule before the end of the week", target
Re: Fieldstone MSA — counter-signature needed before Friday— now passes. The exact query still returns the same three unrelated hits; the difference is that the sweep no longer stops there, a broader rung surfaces the right thread underalternatives, and the model picks it and quotes real body content. Per-thread dedupe confirmed in the same run: a query that used to spend all five slots on one conversation now returns five distinct threads. No confident wrong answer in any run — where it missed, it said so and asked for a keyword. Transcript.🔒 SECURITY CONCERN — this PR closes a hole that exists only where it meets #4155, and neither PR's reviewer could have seen it. @kovtcharov-amd
Broadened search results are mail the user's own words never matched, so #4155's phishing screen had to be extended to cover them — that part is straightforward. The real problem is the instruction: telling the model to search again "with the words the sender would have written" points it at attacker-written text as a source of search terms whenever a lure lands in that set. The lure does not merely get restated; it chooses the next query, and those results come back into the conversation as ordinary mail. Flagged hits are now excluded as a vocabulary source whenever anything in the result set is flagged, in both the tool result and the triage skill. Two tests cover it, one of them on a mixed set — a guard that only fires when every hit is flagged would pass a lure-only test and fail the realistic shape.
What this still does not fix. A query sharing no word at all with its target is not guaranteed to find it — the live pass worked because a broader rung happened to match, not because the tool can bridge "contract schedule" to "counter-signature". Deterministically closing that gap needs semantic retrieval, which belongs in its own issue. Part of #4156; not closing it.
Test plan
pytest tests/unit/agents/tools/ -q— 199 passed (includes fix(email): stop the flagship repeating a phishing lure's instructions #4155's suite). Six tests were proven failing against7c3bc609before the fix; the two interaction tests can only pass with both PRs, since each asserts fields from both.pytest tests/unit/agents/ -q— 1305 passed, 50 skippedpython util/lint.py --all— exit 0; Black, isort, Pylint, Flake8, Bandit all PASS. The WARN lines are the repo's pre-existing mypy and workflow-ancestor advisories, none in the touched files.054c0c2a. A re-verification on the post-merge head is queued separately, since the code under test has moved since that run.search_email's docstring and the inbox-triage skill both changed, which is an LLM-affecting surface, so CLAUDE.md asks for agaia eval agentrun. The judge needs Claude credentials the test fleet cannot get — enterprise Claude has nosetup-tokenpath and the box cannot reach the gateway — so this gate is unobtainable here rather than waiting on someone. fix(email): stop the flagship repeating a phishing lure's instructions #4155 merged on the same basis.🔍 Technical details
Mechanism. The broadening ladder stops being a fallback chain that any non-empty rung terminates and becomes a bounded recall sweep, keyed on distinct conversations rather than on "did anything come back":
messagesto themselves — a query that works today is unaffected, and looser hits arrive separately underalternatives. This is the path the live pass took:exact_match: trueplus a populatedalternatives, with the model choosing a candidate over the exact hits.thread_id(already in both backends' provider-neutral shape) with a small additive over-fetch. A message re-found by a later rung is counted once.unverified: trueandmatched_query. When nothing matched the query, the payload repeats the flag and adds a note telling the model to verify, re-query in the sender's vocabulary, or ask the user — never to answer from the set. That is the no-silent-fallback half: the tool says what it cannot vouch for instead of degrading quietly into a confident answer.Why the alternatives count is not capped. They cost ~522 bytes each after trimming and there can be 25, which is real. But the live run picked its answer out of 25 candidates contributed by a late rung, so a count cap risks discarding exactly the hit this change exists to surface — trading a measured pass for an unmeasured saving. Trimming the per-candidate object was the part that carries no such risk. A count cap is the obvious next lever once there are enough live runs to measure one against.
Rejected:
Acceptance criteria not met as written. AC #2 asks for a multi-rung
attemptsarray when "the first rung returns a small, low-relevance set". When rung 0 returns hits,attemptsdoes grow past one entry — the sweep still runs and fillsalternatives— but those hits stay out ofmessages. Promoting them would inject lower-precision results ahead of a case that passes live today, and the tool has no honest way to tell a small correct set from a small wrong one.