Repository navigation
fix(ui): never re-run a failed chat turn behind the user's back - #5338
Conversation
|
Verdict: Approve with suggestions When a model error hit mid-turn, the Agent UI used to reload the model and quietly run the whole query again, so any tool the turn had already run (a file write, a shell command, a sent email) ran a second time. This PR removes that replay from both the streamed and non-streamed chat paths. The turn now ends with an error that tells the user whether sending it again will help. That is the right trade: a visible failure beats silently doing a side effect twice, and it fits the project's fail-loudly rule. Nothing blocks the merge. I traced the recovery path: both chat paths still run the model pre-flight at the start of every turn, so "send your message again" really does reload an evicted or too-small model first. The new tests reproduce the double run and pin it to a single run on both paths. One thing to fix in the PR description. The technical notes say the "model not loaded" message was left alone, but the diff rewrites it. Update that bullet so reviewers aren't confused. The behaviour change is expected: a turn that used to recover silently from an eviction now fails once and asks the user to resend. Watch Real-world evidenceN/A: no evidence bundle was produced for this run. The change sits on the Agent UI error path, and real model eviction needs live inference, so it's deferred to the strix-halo lane. The verdict rests on static review and the PR's unit tests. pytest isn't installed on this runner, so I couldn't re-run them here. 🔍 Technical detailsIssues
Verified
Strengths
|
When a turn hit a retryable model error (the model was evicted, a network blip), the Agent UI reloaded the model and ran the whole query again. Any tool the turn had already run (a file write, a shell command, a sent email) ran a second time, and the user only saw "Model reloaded, retrying...". The turn now ends with the error, which says whether sending it again can help, and the user chooses to resend. The next turn's pre-flight reloads an evicted model. Applies to both the streamed and non-streamed paths.
Without the hidden retry, an overflow caused by a model loaded at too small a window told the user to start a fresh task, though sending the message again works: the next turn's pre-flight reloads it at the right size. That case now says so, and comments that described the removed retry are corrected.
Nothing reloads the model when a turn finds it unloaded any more; the next turn's pre-flight does. The message now says so.
The new no-retry test marked its one sync test as asyncio, which the auto mode already covers. An older overflow test still described the chat layer replaying the turn as current behaviour.
ca2baf2 to
52fa734
Compare
Before: two Agent UI chats on different models swapped models on every turn, and starting a turn unloaded models that other apps sharing Lemonade were answering with. When GAIA couldn't get the model (lease timeout, not enough memory, server not answering), it showed a warning and answered anyway, so Lemonade loaded the model itself and skipped the free-memory check. Settings → Load and the auto-title went straight to Lemonade with no lease or lock, so either could evict a model mid-answer, and a title could load a second model. After: GAIA only ever unloads models it loaded itself, and only to make room. A turn that can't get its model fails and says why. Titles run on the side slot and never load anything. Load asks before interrupting a chat that's answering. - **Shared server, shared rules.** Settings → Load, the post-download auto-load and titles take the same lease and lock a chat turn does, in the same order. - **Stop is honoured before a load.** A turn stopped while waiting for the model slot or another chat's load ends there: no load, no query. The wait for another chat's load is shown. - **A restart still knows GAIA's own models.** Chat models already on GAIA's own Lemonade at startup count as its own, so they can be unloaded to make room; on a server you run, nothing is. Reproduced by `tests/unit/chat/ui/test_model_slot_discipline.py`; each case fails on main and passes here, including a whole turn stopped during the pre-flight. Overlaps amd#5241 and amd#5275 (both edit `_chat_helpers.py`; different functions). Builds on the amd#4772 discussion without fixing amd#4772 itself: the title still uses the model it's given, but it can no longer load it. **Merging with amd#5328:** whichever of the two lands second also carries, as agreed with that PR's author: - `except LeaseWaitCancelled` (quiet) in `_preflight_load`, ahead of its catch-all; - the chat title's wait for the model wrapped in `lease_wait_limit(30)`, with the 504 logged at info and the title skipped that turn, plus a test that it gives up. - keep this PR's own raises of `InsufficientMemoryError` and `ModelInUseError` ahead of that clause. **Merging with amd#5337:** the two PRs conflict in one hunk of `_chat_helpers.py` next to `model_load_lock`. Both sides only add code there, so keep both. I ran a trial merge of the two locally: the UI suite and amd#5337's non-streamed timeout test passed 8 times out of 8. That test was racy with amd#5336's stop check, and amd#5337 now fixes it. ## Test plan - [x] `pytest tests/unit/chat/ui tests/unit/test_chat_preflight.py tests/unit/test_model_server_info.py tests/unit/test_users_lemonade_untouched.py tests/unit/test_ui_warmup.py tests/unit/test_broker_wiring.py`: all pass - [x] `npx vitest run` in `src/gaia/apps/webui`: all pass, new `api.loadModel.test.ts` - [x] `python util/lint.py --black --isort --pylint --flake8` - [ ] Live: two chats on two models that both fit, and confirm neither is unloaded between turns <details> <summary>🔍 Technical details</summary> - `_maybe_load_expected_model` no longer unloads other resident chat models. On `InsufficientMemoryError` it unloads only models in `_models_loaded_here` (pre-flight and Settings loads record there, with names normalized), says so in a status event, and loads once more. Otherwise it raises. - Exceptions now raised instead of a warning status: `BrokerUnavailableError` (with the model and what to check), `InsufficientMemoryError` (unchanged text), and `RuntimeError` for anything else, including a non-200 `/health`. The streaming and non-streamed paths both show the reason. The non-streamed path used to substitute "make sure Lemonade is running" for every unclassified error. - `_maybe_load_expected_model` wraps `_preflight_load`: any exception raised while the turn's Stop flag or its own cancel event is set is read as the Stop. That covers turns that pass those in, which the streamed turn does. A non-streamed turn's Stop reaches the wait only through amd#5328's `interactive_turn(cancel=...)`, so there only the `except LeaseWaitCancelled` clause above keeps it quiet. amd#5328's `test_stop_during_a_queued_preflight_stays_quiet_on_the_non_streaming_path` guards that. - A failed Settings or post-download load shows in `/api/system/status` `probe_warnings` until a load succeeds. - `model_load_lock` is taken with `_take_model_load_lock` (polls, shows status, returns on Stop) after the lease. `_load_through_the_slot` in `routers/system.py` uses the same lease-then-lock order. - Title: `LemonadeClient.chat_completions` under one background-priority `model_lease` spanning the residency check and the call; `id_slot=SIDE_SLOT` when the model has two slots; `auto_download=False`. - Ownership: the UI keeps a record of the models it loaded (`<GAIA home>/ui/loaded_models.json`, written whole under a lock): pre-flight and Settings loads, and any load its own agents make (a `LemonadeClient` load listener). Models Lemonade no longer has loaded drop out of it. A same-name copy at too small a window is reloaded only if the UI loaded it or it is an auto-load (Lemonade's 4096 default or the supervisor's profile window); otherwise `ModelInUseError` says another app has it. - `/api/system/load-model` gains `force`. Without it the endpoint returns 409 while any run is active. `loadModelAskingFirst` turns that into a `confirm()` in Settings. The API schema and types are regenerated. - Updated tests that pinned the old behaviour: unload-before-load (amd#1382's double-load case is now covered by the free-memory check), swallowed pre-flight failures, and raw-HTTP titles. - Not changed here: the retry-on-error path that re-runs the whole query is amd#5338. - LLM-affecting? Error surfacing only; prompts and tools are unchanged. Categories to watch on the next RC: `rag_quality`, `gaia_core`. </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]>
# Conflicts: # src/gaia/ui/_chat_helpers.py
…de/ui-composer-context-retry-779e65 main no longer re-runs a failed turn, so the follow-up inbox's re-offer for that re-run (requeue_taken) has no caller and goes, with its test.
Brings in main's removal of the in-turn retry (amd#5338), so the panel's retried-turn handling is dropped with it.
Before: when an Agent UI turn hit a retryable model error (the model got evicted, a network blip), GAIA reloaded the model and ran the whole query again. Every tool the turn had already run (a file write, a shell command, a sent email) ran a second time, and all the user saw was "Model reloaded — retrying...". After: the turn ends with the error, which says whether sending it again can help, and the user decides. The next turn's pre-flight reloads an evicted model.
Reproduced by
tests/unit/chat/ui/test_no_hidden_retry.py: on main the tool runs twice, here once. Covers both the streamed and the non-streamed paths.Overlaps #5241 and #5275 (they also edit
_chat_helpers.py, in different functions) and #5336 (its pre-flight docstring touches the same note; whichever lands second keeps one sentence).Test plan
pytest tests/unit/chat/ui tests/unit/test_chat_preflight.py tests/unit/test_ctx_overflow_device_profile_2884.py tests/unit/test_lemonade_error_classification.py: all passpython util/lint.py --black --isort --pylint --flake8 --test-lanes🔍 Technical details
except → _maybe_load_expected_model → process_queryreplay in_run_agent(streamed) and_query(non-streamed). Errors still go through_classify_chat_exception, so the user sees the classifieduser_message.agents/base), which is outside the UI backend. Failing visibly is the safe half; resuming can follow there.LemonadeModelNotLoadedError.user_messagenow says the model was unloaded and to send the message again, since nothing reloads it mid-turn any more.gaia_coreandrag_qualityon the next RC. A turn that used to recover silently from an eviction now fails once.