Repository navigation
fix(email): reconcile chat prose against the rendered attention card - #2660
Merged
itomek-amd merged 3 commits intoJul 30, 2026
Merged
Conversation
… leaf module api_routes.py owned the process-wide attention cache directly as a module global. Move the storage (dict + lock + peek/store/reset) into a new attention_cache.py with zero gaia_agent_email imports, so the upcoming answer-grounding guard can read the same cache without pulling FastAPI into a module that is deliberately pure and dependency-light. api_routes.py keeps its public reset_attention_cache()/ATTENTION_CACHE_TTL_SECONDS names, now delegating to the new module, so existing callers are unaffected.
#2636's reported bug is the attention card (Go TUI, GET /v1/email/attention sections MEETING PROPOSALS/NEEDS REVIEW/ACTION ITEMS) rendering non-empty while the same turn's prose claims nothing needs attention. PR #2659 only guarded pre_scan_inbox contradictions -- the attention view is never a tool result (build_attention_view_impl has no @tool wrapper), so the model generating that prose has no way to see the card and cannot ground itself against it. Add a guard that reconciles the final answer against the same process-global cache the TUI's card was rendered from (server.py mounts both surfaces on one FastAPI app, and the sidecar is single-tenant, so there's exactly one card to reconcile against). It declines to correct once the cache is older than the route's own freshness window, rather than assert a since-resolved item is still open on stale data, and appends a correction naming the surface and its coverage rather than replacing the answer outright, since the false clause is typically one aside inside an otherwise-useful response.
5 tasks
itomek
marked this pull request as ready for review
July 30, 2026 14:30
itomek-amd
approved these changes
Jul 30, 2026
itomek-amd
left a comment
Collaborator
There was a problem hiding this comment.
Approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek-amd
approved these changes
Jul 30, 2026
itomek-amd
left a comment
Collaborator
There was a problem hiding this comment.
Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.
itomek
added a commit
that referenced
this pull request
Jul 30, 2026
…swer_grounding framework Merging origin/main brought in #2656's calendar-conflict grounding hook (agent.py's own _tool_names_from_conversation + a standalone process_query block) alongside #2659/#2660's answer_grounding.py framework, which already post-checks the final answer against the turn's tool trace at the same call site. Left as two separate passes, a turn could get two independent disclaimers appended to one answer. Adds find_ungrounded_calendar_conflict_claim to answer_grounding.py (reusing the module's own tools_called_this_turn plus calendar_tools.py's existing _listed_event_count_from_conversation / response_has_ungrounded_conflict_claim), wires it into ground_final_answer as another append-only rule, and deletes agent.py's duplicate _tool_names_from_conversation and its standalone hook so ground_final_answer(result) is the single grounding call in process_query. The calendar-conflict and attention-card checks are both append-only and independent, and must compose sequentially rather than either short- circuiting the other — covered by a dedicated composition test asserting both corrections can appear on the same turn.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before, the Go TUI's attention card (
GET /v1/email/attention, sections MEETING PROPOSALS / NEEDS REVIEW / ACTION ITEMS) could show real items while the same turn's chat answer said "no urgent or actionable items found" — because that view is never a tool call the model sees (build_attention_view_implhas no@toolwrapper; it exists purely to render the on-open card), so nothing grounded the model's prose against it. This completes the half of #2636 that PR #2659 could not reach — #2659 only guarded contradictions againstpre_scan_inbox's own tool result, a different, narrower scan.After: the same deterministic post-check that guards pre-scan claims now also reconciles the final answer against the process-global cache the attention card was rendered from (the TUI and the chat surface share one sidecar process). It declines to correct once that cache is older than its own 120s freshness window, so a card the user has since cleared can't get "corrected" back into looking unresolved — and it appends a correction naming the card and its coverage rather than replacing the answer outright, since the false clause is usually one aside inside an otherwise-useful response.
Test plan
PYTHON_KEYRING_BACKEND=keyring.backends.null.Keyring .venv-wt/bin/python -m pytest tests/unit/agents/email/ tests/unit/email/ hub/agents/email/python/tests/ -q— 2257 passed.venv-wt/bin/python util/lint.py --all— all quality gates PASS (mypy warnings pre-existing/non-blocking, unrelated to this change)black/isort/flake8run directly against every changedhub/file (not covered byutil/lint.py) — clean on all new/modified linesground_final_answerwiring, and the correction wording — each fix reverted alone, its test failed, then restoredCloses #2636