Repository navigation
Description
resolve_needs_you_reference (#2745, shipped in #2761) resolves "reply to 1" against a triage card cached on the agent instance. Under the daemon sidecar the agent is reconstructed on every turn, so that cache is None at the start of every query and a positional reference can never resolve. The feature is non-functional on the surface users actually drive.
#2761 merged with its real-world checkbox unticked — verification was gated by a competing session at the time. This is what that check would have caught.
Live reproduction (main @ 300163dd, Mac, Gemma-4-E4B-it-GGUF, real Gmail)
A single TUI session. The agent lists five numbered items, so "1" is a reference the user has every reason to believe in:
You: Did anyone email me proposing to meet, that I haven't replied to?
Yes, there are 5 messages currently waiting on your reply that contain a direct
ask or proposal:
1. From: <redacted> Subject: Re: Partnership intro — moving this across
2. From: <redacted> Subject: Re: Revised deck — need your numbers by Tuesday
...
Next turn, same session:
You: Which message is 1? Name the subject and sender before doing anything.
I apologize for the confusion; I do not have a recent triage card available to
reference with that number. Please ask me to "triage my inbox" or "pre-scan my
inbox" so I can show you the current list of messages...
Root cause — confirmed three ways
1. The cache is per-instance and reset in __init__:
hub/agents/email/python/gaia_agent_email/agent.py:774
self._last_needs_you_card: Optional[List[Dict[str, Any]]] = NoneIts own comment states the assumption the runtime violates — "the most recent pre_scan_inbox TOOL call this session". It is written by read_tools.py:3015 (agent._last_needs_you_card = envelope.get("needs_you", [])) and read by ref_resolve.py.
2. __init__ runs once per turn. From a single sidecar process's log (~/.gaia/agents/email/logs/sidecar-*.log), the agent.py:919 init line — five turns, five constructions:
11:17:26 11:18:35 11:20:12 11:20:47 11:21:19
So every turn begins with _last_needs_you_card is None, regardless of what the previous turn scanned.
3. Corroborating asymmetry in the same session. self._session_preferences is reset on the same line-763 path, yet a sender mute set in one turn was still in effect several turns later — because preferences persist to state.db. The card cache is memory-only, so it does not survive. Disk-backed state survives the re-init; in-memory state does not. That is the tell.
Why this is worse than a dead feature
The agent numbers things it cannot then resolve. Every listing answer renders 1., 2., 3. — a plain affordance to say "reply to 2" — and the resolver rejects it. The user is invited to use a reference the system has already discarded.
Note the failure mode is at least safe: #2761 deliberately refuses rather than guessing, so nobody replies to the wrong message. The refusal is working exactly as designed; there is simply nothing left for it to resolve against.
Two candidate fixes, materially different
- Persist the card alongside the other session state (
state.db, keyed by session), so it survives reconstruction. Matches how preferences already behave and needs no change to the sidecar lifecycle. - Stop reconstructing the agent per turn. Larger blast radius, and worth understanding on its own merits — every other piece of in-memory per-session state has the same problem, and this issue may only be the first symptom found.
Worth deciding deliberately: if per-turn reconstruction is intended, then any self._x session state in this agent is a latent version of this bug, and the fix belongs at the state layer rather than in one feature.
Acceptance criteria
- After a
pre_scan_inboxin turn N, a positional reference in turn N+1 resolves to the message that row showed - Resolution survives at least one intervening unrelated turn
- Refusal behaviour is preserved for genuinely unresolvable refs (out of range, no card yet, no
message_id) — do not trade safety for this - An audit of remaining in-memory per-session state on the agent, with a stated verdict on whether per-turn reconstruction is intended
- Verified live on the TUI, not only in-process: a test that constructs one agent and calls two tools cannot catch this
Related
- feat(email/tui): resolve "reply to 1" to the message the card actually shows #2761 / feat(email/tui): resolve positional references ("reply to 1") to the message the card actually shows #2745 — the shipped feature this makes unreachable
- Append-style answer_grounding guards never reach the live TUI (correction fires, never renders) #2789 — different mechanism, same shape: a feature that works everywhere except the surface users are on. Both argue for live-TUI verification being non-optional before a UX feature is called done.
How this was found
Live regression pass on main @ 300163dd validating merged PRs #2774/#2779/#2760/#2761/#2782.
Activity
itomek commentedon Aug 5, 2026
Correcting the fix this issue prescribes. The reproduction and the symptom stand; the root cause is one layer up, and patching
_last_needs_you_cardwould not fix it.The sidecar has two query surfaces:
agent_routes.pyPOST /query(:623)registry.get_or_create(session_id)query_routes.pyPOST /query(:503)_RunRegistry,build_session_agent()per run (:101-108)The TUI path is on the second one.
src/gaia/daemon/agent_query.py:280sends{query, run_id, context}and nosession_id, so there is no session to hold anything — anyself._xon the agent dies regardless of how it is cached. The session machinery that would fix this already exists (_SessionRegistry,/session/{id}/history,DELETE /session/{id}, per-session memory); the run-scoped surface simply never opts into it.Proposed fix, keeping the frozen #2015 contract back-compatible:
session_idtoquery_routes.QueryRequest(additive — absent behaves exactly as today).registry.get_or_create(session_id)instead of building one per run.src/gaia/daemon/agent_query.py's payload./clearmaps toDELETE /session/{id}(the endpoint already exists).This is also the enabler for #2834 — once a session survives the turn, the agent has somewhere to record the entities it surfaced, and neither the TUI nor any other host has to re-solve conversation state on its own.
feat(daemon): run_query gains an optional session_id parameter
docs(spec): document session_id in the /query request contract
docs(email): changelog entries for the session_id addition
feat(daemon): run_query gains an optional session_id parameter
docs(spec): document session_id in the /query request contract
docs(email): changelog entries for the session_id addition
fix(email): a conversation now survives its turns — session_id on /qu…