Skip to content

fix(chat): stop blaming Lemonade when the model just answered empty - #5552

Merged
kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:kalin/empty-answer-cause
Oct 23, 2026
Merged

kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:kalin/empty-answer-cause

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

When a chat reply came back with no answer and no tool steps, the Agent UI always told the user to make sure Lemonade Server was running, even when Lemonade was up and the model had simply returned nothing (seen live with Qwen3.5 4B and Gemma 4 E4B on a working server). Now GAIA checks Lemonade's health before saying why. If the server is down, the message says so and how to start it on this machine. If the model isn't loaded, it says that. If everything is fine, it says the model returned an empty answer and suggests sending again or switching models.

Stacked on #5543. Merge that first; this PR then shows only its own commit.

Error classification changed, so watch the error_recovery eval category on the next RC.

Test plan

  • python -m pytest tests/unit/chat/ui/test_chat_helpers.py tests/unit/chat/ui/test_empty_answer_tail.py: covers server down, unhealthy (HTTP 503), up without the model, up with the model loaded, user. id matching, cloud model, and eval-on-Claude (no probe)
  • python util/lint.py --black --isort --flake8
  • With Lemonade running, get an empty reply (Qwen3.5 4B, short prompt): the bubble says "The model returned an empty answer…" and doesn't mention Lemonade
  • Stop Lemonade and send a message: the error names the server URL and gives this machine's start hint, not lemonade-server serve
🔍 Technical details
  • _empty_answer_backend_problem (async) reads /health through LemonadeManager.get_base_url() with auth headers. It runs only when the turn has no steps and wasn't cancelled.
  • Server down or unhealthy → error SSE, as before. Server fine → failed done event with _EMPTY_MODEL_ANSWER_MSG, the same path as the tools-but-no-answer case.
  • The agent's own model_id is preferred over the session model for the loaded check. Cloud models skip that check.
  • Updated the matching troubleshooting copy in docs/guides/agent-ui.mdx.

After Stop, the next message got the stopped answer anyway: the model saw the
stopped request with a blank reply, took it as still pending, and answered it
before the new question. A stopped turn now reads to the model as withdrawn,
and so does a turn cut off when GAIA closed.

- History for in-process agents, relayed sidecars and Retry with... comes
  from model_context_messages, which replaces a "Cancelled." or cut-off
  reply with a short note saying it was stopped and not to continue it.
- A turn stopped mid-answer records what it showed plus that note.
- The footer of a stopped or cut-off bubble says "Stopped after 16 s" /
  "Interrupted after 16 s" instead of "Answered in 16 s".
A turn that ran tools and then wrote no answer ended on an empty bubble with
no explanation, and the chat list showed it as done. Empty content is now kept
only when a render card answered the turn; otherwise the turn ends failed with
"GAIA ran its tools but didn't write an answer. Send your message again, or
try another model." and keeps its tool steps.
A turn with no answer and no tool steps always told the user to make sure
Lemonade Server was running, even when it was up and the model simply
returned nothing (seen with Qwen3.5 4B and Gemma 4 E4B on a healthy server).

The tail now asks Lemonade's /health first. Down or unhealthy: say so with
the host's own start hint. Up but the model isn't loaded: say that. Up with
the model loaded: report an empty model answer and suggest resending or
switching models. Eval runs on Claude skip the probe.
@github-actions github-actions Bot added documentation Documentation changes tests Test changes labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

When a reply comes back empty, the Agent UI no longer tells the user to check that Lemonade is running. It now asks Lemonade's health endpoint and names the real cause: server down (with this machine's start hint), model not loaded, or the model simply returned nothing. The diff also includes the stacked #5543 work: stopped or cut-off replies are marked as withdrawn for the model, and their footer reads "Stopped after…" rather than "Answered in…". The logic is sound and well tested. Nothing blocks the merge.

Worth a look before merging:

  • The new health check rewrites a probe the codebase already has. The two treat edge cases differently: an auth error (HTTP 401) here comes out as "failed its health check", followed by instructions to start a server that is already running.
  • A reply stopped partway through is marked as withdrawn for agents running inside GAIA. Sidecar agents get the raw partial text with no marker, so they may still continue the stopped request.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on static review and the PR's unit tests. The two manual Test-plan items (an empty reply with Lemonade up, and a message sent with Lemonade stopped) are unchecked, and the Agent UI before→after screenshot is still pending the strix-halo lane.

🔍 Technical details

🟢 Minor

  1. Reimplements probe_backend_health, with different semantics (src/gaia/ui/_chat_helpers.py:296-346). agents/base/readiness.py:324 already probes /health and parses all_models_loaded, and it also filters inhibited models. Here, any non-200 is treated as "failed its health check" and the start hint is appended, so a 401/403 from a running server (for example a mismatched LEMONADE_API_KEY) tells the user to start it. Consider reusing the readiness helper through asyncio.to_thread, or at least limiting the start hint to 5xx and connection errors.

  2. Sidecar relay doesn't see a mid-answer stop as withdrawn (_chat_helpers.py:4316-4324, :3325). The _STOPPED_REPLY_FOR_MODEL note is written into model_messages only. The relayed sidecar's history comes from _build_history_pairs(model_context_messages(...)), which reads content. For a partial stop, content is just the partial text, so _withdrawn_reply returns None and the sidecar sees an ordinary answer. Only the "Cancelled." and cut-off-notice cases are covered for sidecars. Either mark partial stops at read time as well, or note the gap.

  3. Frontend copies the backend notice strings (MessageBubble.tsx:79-83). They match restart_recovery.py today, but nothing enforces that. A one-line comment in restart_recovery.py pointing to the TS copy, or a drift test, would keep a wording change there from silently turning the footer back to "Answered in".

Strengths

  • The health check runs only when the cause is actually ambiguous: not on cancels, not on turns with tool steps, and not under eval-on-Claude. Tests pin each of these.
  • test_empty_answer_tail.py and test_stopped_turn_history.py drive real streamed turns through the SSE producer and the DB rather than stubbing the tail. The cut-off-notice round trip (begin_turn → close_turn → model view) is tested end to end.
  • The start instruction goes through describe_start_hint(), and a test asserts that lemonade-server serve never appears.

… for sidecars

An empty answer from a Lemonade that rejects GAIA's key (401/403) now says to check LEMONADE_API_KEY instead of telling the user to start a server that is already running.

A reply stopped partway through now reads as withdrawn to a relayed sidecar too: the sidecar's history carries the stop note, including when the stopped turn itself was relayed and recorded no model messages. A test also keeps the Agent UI's copy of the cut-off notices in step with the backend.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

All three review points are addressed, and CI is green. An empty reply from a Lemonade that rejects GAIA's key now says to check the key rather than to start the server. A reply stopped partway through now reads as withdrawn to sidecar agents too.

  • Health check reuse: I kept a separate probe. probe_backend_health sends no API key and treats any HTTP answer as healthy, so a 401 would come back as "model not loaded", which is the same misdirection. 401/403 now get their own message, and the start hint stays for connection errors and other failed health checks.
  • Sidecar history: fixed on both paths. That covers a stop in an in-process turn and a stop in a relayed turn, which records no model messages.
  • Notice drift: a test now fails if MessageBubble.tsx stops matching the backend's three cut-off notices, and restart_recovery.py points at it.
🔍 Technical details
  • _empty_answer_backend_problem: 401/403 return "rejected GAIA's API key (HTTP n) … Check that LEMONADE_API_KEY matches…" with no start hint. Tested for both codes. The agent-ui guide names the case.
  • model_context_messages falls back to _marked_stopped_reply(model_messages), so _build_history_pairs carries the stop note. When the turn was stopped and has no recorded messages (a relayed turn), the stream tail records a minimal user/assistant pair with the note.
  • New tests: test_turn_stopped_mid_answer_without_a_recorded_turn_keeps_the_stop_note, a sidecar-pairs assertion on the existing mid-answer stop test, and test_the_agent_ui_footer_knows_every_cut_off_notice. _stop_turn now persists the question the way the chat route does.
  • These fixes touch the stacked fix(chat): a stopped reply stays stopped; tools without an answer say so #5543 code, so that PR's diff here grows by the same lines.
  • Local: tests/unit/chat/ui gives 2189 passed. tests/unit -k "shell or permission or confirm or setup or empty_answer" gives 2476 passed, with 3 shell tests that fail on this Windows box on main as well. Black and isort are clean.

amd#5543 landed on main as a squash, so its stacked commits conflicted. Kept
this branch's health-checked empty-answer copy and sidecar stop note, kept
main's parametrized notice drift test, and read the turn's model from
result_holder now that main dropped session_model.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
Merged via the queue into amd:main with commit 7873e78 Oct 23, 2026
32 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/empty-answer-cause branch October 23, 2026 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants