Skip to content

fix(chat): a stopped reply stays stopped; tools without an answer say so - #5543

Merged
kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:kalin/stop-replay-empty-answers
Oct 23, 2026
Merged

kovtcharov-amd merged 5 commits into
amd:mainfrom
kovtcharov:kalin/stop-replay-empty-answers

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

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 turn that ran tools and then wrote nothing ended on an empty bubble marked done. Now a stopped (or cut-off) turn reads to the model as withdrawn, its footer says "Stopped after 31 s" instead of "Answered in…", and a tools-but-no-answer turn ends as failed with a message saying to send again or try another model.

Stop, then a new question: only the new question is answered

Test plan

  • pytest tests/unit/chat (incl. test_stopped_turn_history.py, test_empty_answer_tail.py): 2175 passed
  • npx vitest run in src/gaia/apps/webui: 1533 passed
  • Live: asked for a 1500-word essay, pressed Stop after 31 s, asked "What is the capital of Mongolia?"; the answer was only "Ulaanbaatar is the capital city of Mongolia.", and the stopped turn's footer reads "Stopped after 31 s"
  • Eval on the next RC: context_retention and the multi-turn gaia_* categories (the history the model sees after a stop changed)
🔍 Technical details
  • model_context_messages() builds the history for in-process agents, the sidecar relay and Retry with…; it replaces a "Cancelled." or cut-off reply with a short note that the turn was stopped and shouldn't be continued. Existing chats are fixed too, since the rewrite happens on read.
  • A turn stopped mid-answer is saved with what it showed plus that note. Only an empty answer with a render card still persists empty content.
  • Not covered: a mid-answer stop relayed to a sidecar still passes plain partial text, and the non-streaming /api/chat path doesn't use the new empty-answer outcome.

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.
@github-actions github-actions Bot added the tests Test changes label Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

Two bugs fixed. Stopping a reply and then asking something new no longer brings the stopped answer back. And a turn where the agent ran tools but wrote no answer now ends with a clear "send again or try another model" message instead of an empty bubble marked done. I found nothing that blocks merge. Every path that builds the model's history now goes through the new rewrite, and the Python and UI tests cover the two cases that matter: stop before any text and stop mid-answer.

The PR already lists the eval categories to watch on the next RC (context_retention and the multi-turn gaia_* ones). That's the right call, because this changes what the model sees after a stop.

Real-world evidence

N/A here: no evidence bundle was produced for this run. The PR description has its own live evidence: a rendered screenshot of Stop followed by a new question, where only the new question is answered, plus a written account of the 31 s stop and the "Stopped after 31 s" footer. My verdict rests on that screenshot and on reading the code. I didn't run the tests myself (pytest isn't installed on this runner), so the "tests pass" claim comes from the PR's test plan.

🔍 Technical details

Issues

🟢 The UI keeps its own copy of the cut-off notice strings (MessageBubble.tsx:418). CUT_OFF_NOTICES repeats the three constants from restart_recovery.py word for word. If someone rewords one on the Python side, the footer quietly goes back to "Answered in…" for that kind of turn. The backend matching would still work, so it's just the UI that drifts. Two options: a small Python test that greps MessageBubble.tsx for each constant, the way the repo already pins recommended_models.json; or send ended from the server on the message instead of matching text.

🟢 A real answer of exactly "Cancelled." gets read as a stop (_chat_helpers.py:1765). _withdrawn_reply treats any assistant content that is exactly Cancelled. as a stopped turn. A question like "Is the 3 pm meeting on?" answered "Cancelled." would then reach the model as withdrawn. The UI already makes the same mistake (SERVER_CANCELLED_TEXT), so this isn't new, but it now also changes what the model reads. It's rare and fine to leave. A persisted stop flag would close it if it ever shows up.

Already noted in the PR, not re-flagged: when a reply is stopped mid-answer and relayed to a sidecar, the sidecar still gets the plain partial text, and the non-streaming /api/chat path doesn't use the new failed outcome.

Strengths

  • The rewrite happens when history is read (model_context_messages), so chats saved before this change are fixed too, and the chat itself still shows the original "Cancelled." marker. get_context_messages now has a single caller, so no path that feeds the model was missed.
  • Splitting the empty-answer case on whether a render card was shown fixes the bug without breaking the echoed-card case. The streamed-turn tests in test_empty_answer_tail.py check all three outcomes (failed, card, error) end to end: SSE events, saved row and last_run_status.
  • _with_final_reply handles a recorded turn that ended on a tool call by appending the note rather than overwriting the call, and that case has its own test.

The message footer recognises a stopped or cut-off turn by matching the
server's notice text. A reworded notice on the server would quietly turn
that footer back into "Answered in…", so a test now fails when
MessageBubble.tsx stops listing any of them.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

A test now fails if the UI's copy of the stopped and cut-off reply text drifts from the server's. I left the exact-"Cancelled." case as is, and the red Linux CLI check was a Launchpad outage, not this PR.

🔍 Technical details
  • Notice drift (done): test_the_ui_matches_the_same_cut_off_text in test_stopped_turn_history.py checks that MessageBubble.tsx still lists _CANCELLED_REPLY and all three restart_recovery notices as string literals. I picked the pin over sending ended from the server: it's one small test, where the server field would change the message contract for a footer label.
  • A real answer of exactly "Cancelled." (left as is): messages have no per-message stop flag today, so closing this means a schema column plus a write on every stop path. The UI already reads that text as a stop. A one-word answer that is exactly Cancelled., with the trailing period, is rare enough that I'd add the flag only if it shows up.
  • CI: Test GAIA CLI on Linux (Full Integration) (run 39669709597) failed on apt getting 503 Service Unavailable from ppa.launchpadcontent.net for ppa:lemonade-team/stable. Every run of that workflow from 18:34 to 21:24 UTC on Oct 21 failed the same way, including main (39653922790, 39668985468, 39675364988); later runs are green. The push re-runs it.
  • Local: tsc --noEmit clean, vitest 145 files / 1533 tests pass, pytest tests/unit/chat -n 4 2179 passed, black/isort clean. Each run also showed one teardown error from a thread leaked by test_sidecar_relay_profiles that tries to spawn a daemon. It reproduces on this PR's base commit cee6a47ff without these changes, and current main passed clean, so it isn't from this PR.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 23, 2026
Merged via the queue into amd:main with commit b5a91d7 Oct 23, 2026
37 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/stop-replay-empty-answers branch October 23, 2026 12:05
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Oct 23, 2026
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 added a commit to kovtcharov/gaia that referenced this pull request Oct 23, 2026
…md#5552)

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 amd#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`

<details>
<summary>🔍 Technical details</summary>

- `_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`.
</details>

---------

Co-authored-by: Kalin Ovtcharov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants