Skip to content

fix(email): reconcile chat prose against the rendered attention card - #2660

Merged
itomek-amd merged 3 commits into
tmi/issue-2621-grounded-prosefrom
tmi/issue-2636-cross-surface
Jul 30, 2026
Merged

itomek-amd merged 3 commits into
tmi/issue-2621-grounded-prosefrom
tmi/issue-2636-cross-surface

Conversation

@itomek

@itomek itomek commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

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_impl has no @tool wrapper; 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 against pre_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/flake8 run directly against every changed hub/ file (not covered by util/lint.py) — clean on all new/modified lines
  • Mutation-tested every guard: core detection, the TTL staleness bound, the no-cache passthrough, the ground_final_answer wiring, and the correction wording — each fix reverted alone, its test failed, then restored

Closes #2636

itomek added 3 commits July 30, 2026 02:44
… 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.
@github-actions github-actions Bot added the agent::email Email agent changes label Jul 30, 2026
@itomek itomek added the ready_for_ci Run CI workflows on draft PR without requesting review label Jul 30, 2026
@itomek
itomek marked this pull request as ready for review July 30, 2026 14:30
@itomek
itomek requested a review from kovtcharov-amd as a code owner July 30, 2026 14:30

@itomek-amd itomek-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd itomek-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving per maintainer-bottleneck arrangement while other reviewers are unavailable.

@itomek-amd
itomek-amd merged commit 98a6e50 into tmi/issue-2621-grounded-prose Jul 30, 2026
16 checks passed
@itomek-amd
itomek-amd deleted the tmi/issue-2636-cross-surface branch July 30, 2026 15:23
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent::email Email agent changes ready_for_ci Run CI workflows on draft PR without requesting review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants