Repository navigation
fix(tui): a turn waiting for the model is not reported as broken - #5319
Conversation
|
Verdict: Approve with suggestions On a busy machine, a TUI turn waiting for the model will now show the daemon's reason for the wait instead of a bare header timeout. A queued follow-up that is still receiving updates is no longer called stalled. Both fixes are correct. The TUI's reading of the shared timeout setting matches the daemon's for every realistic value, and the new tests cover the race, the env setting, and the prompt-pending case. Nothing blocks merge. One small hardening is suggested below: an absurdly large timeout value can wrap around and quietly shrink to the 300 s default. Real-world evidenceN/A: there is no evidence bundle for this PR, and the change is a TUI timing fix with no CLI, REST, or Agent UI surface the evidence stage drives. The verdict rests on static review plus the package tests, which I re-ran on the PR head ( 🔍 Technical detailsIssues 🟢 Huge 🟢 Parity note, no change needed. Strengths
|
|
Live check passed: both fixes behave as described in the real TUI, and main shows the old behaviour side by side. How it ran: the real TUI binary (one built from main, one from this branch merged with #5318) drove the installed-binary flagship over the daemon transport, with isolated
Also pushed since the review: a huge 🔍 Technical details
|
|
Review follow-up: the TUI now waits on the budget the daemon reports, so a daemon at
Two things this PR doesn't do:
|
|
Second review round:
|
The model_queue status reached only the Agent UI's stream. The gaia agent's /query routes, which the TUI reads, ran the turn outside any turn scope: its lease was background priority, /cancel did not end a wait for the model, and the stream went silent for the whole wait, so the TUI could not tell queued from broken (amd#5319). - The /query run thread runs as an interactive turn: wait events go out on the run's stream and /query/{run_id}/cancel ends the wait. - One event builder (broker_client.queue_status_event) for both streams. - The canonical translator keeps the `queue` object on a model_queue status. - Contract spec §4.4, the agent's SKILL.md and CHANGELOG describe the phase.
|
Third review round: agreed on all three points. I've removed the queue wording rather than patching it.
|
|
Round-3 nit: the |
On a shared machine a turn can wait minutes for the model slot. The TUI cut that wait short with a bare "timeout awaiting response headers", and a queued follow-up told the user to check `gaia daemon status` after 180 s even while it was still receiving updates. - The relay waits the read budget for the sidecar to start answering, then reports why it did not. The TUI's header timeout is now that budget plus 30 s, separate from the idle-read timeout, so the relay's reason reaches the user. - The read budget follows GAIA_AGENT_TOOL_TIMEOUT the way src/gaia/daemon/timeouts.py does, so the TUI and the relay give up together; an invalid value fails every send with the setting named. - The queued follow-up notice fires only after 180 s with no event at all, waits while a prompt is open, and names the likely cause, a wait for the model, instead of the daemon.
… 300 s A value past ~9e9 s overflowed the duration conversion and came out as the 300 s default, quietly shorter than what the relay honours. It now clamps to a century, the same as "inf".
… when the agent reports one The TUI computed the relay's idle budget from its own shell, but the relay uses the daemon's environment. With the daemon at GAIA_AGENT_TOOL_TIMEOUT=600 and the TUI's shell unset, the TUI still cut in at 330 s. Its parser also disagreed with timeouts.py on whitespace, nan and hex. The queued-follow-up notice guessed "most likely waiting for the model" with nothing to go on, and fired seconds after the user answered a prompt. - The daemon reports its relay budget on /daemon/v1/status (agent_read_timeout_s, null for no limit, or agent_read_timeout_error), and the TUI waits on that. A daemon too old to report it falls back to this shell's setting, logged. - The fallback parser mirrors Python's float(). Both sides are checked against one table, tests/fixtures/daemon/agent_read_timeout_cases.json, generated from timeouts.py. - A status with phase "model_queue" (amd#5328) makes the notice name the queue; without one, the notice keeps the gaia daemon status step and guesses nothing. - Answering a prompt restarts the quiet clock, and the stall check is a pure function tested for the time it re-arms with.
…daemon The setting lives in the daemon's environment, so repeating the daemon's own "unset it" advice left out the step that makes the fix take effect: gaia daemon restart.
The second review showed the queue form of the stall notice was wrong both ways. amd#5328 sends its "granted" line under the same model_queue phase, so a hang after the grant read "still waiting for the model: Got the model after waiting 12s". And queue updates come every couple of seconds, so three minutes of silence after one means the updates stopped, not that the turn is still queued. Nothing sends these events to the TUI yet either. The notice now always keeps the gaia daemon status step. Queue updates, like any event, reset the quiet clock, so a turn that really is queued is never called stalled. The notice text is a pure helper; the tests drive real events instead of backdating the last one.
The model_queue status reached only the Agent UI's stream. The gaia agent's /query routes, which the TUI reads, ran the turn outside any turn scope: its lease was background priority, /cancel did not end a wait for the model, and the stream went silent for the whole wait, so the TUI could not tell queued from broken (amd#5319). - The /query run thread runs as an interactive turn: wait events go out on the run's stream and /query/{run_id}/cancel ends the wait. - One event builder (broker_client.queue_status_event) for both streams. - The canonical translator keeps the `queue` object on a model_queue status. - Contract spec §4.4, the agent's SKILL.md and CHANGELOG describe the phase.
f91cf39 to
5e305e5
Compare
…ws it is waiting (amd#5328) When several GAIA processes shared the model, a turn queued behind another failed after 300 s with "Check `gaia daemon logs`", even though the request ahead was legitimately running (local calls may take up to an hour). Leases were reclaimed mid-generation after 900 s. A request whose client had gone (Ctrl+C, Stop, app closed) still got the slot later and held it for nobody. The user saw nothing while waiting. Now a queued request waits for as long as the request ahead is alive. The Agent UI shows "Waiting for the model — `<who>` is using it" with its place in line and seconds waited. Stop or disconnect takes it out of the queue, and the holder keeps its lease while it renews. Independent review: a `code-reviewer` agent reviewed the diff. Its findings are fixed: Stop now cancels a queued wait, a grant that races a cancel is released on both sides, a stop during the pre-flight load stays quiet, only the holder can renew or release, and error messages don't leak lease ids. A bot review's follow-ups are fixed too: a Stop while queued is a cancelled turn, not an LLM error, and the heartbeat logs when it loses its credential. Reproduced by `tests/unit/test_daemon_broker_queue.py`. All of its 13 original tests fail on main and pass here. The two that show the user-facing symptoms with main's own API are `test_model_lease_waits_out_a_busy_holder_instead_of_failing` (504 on main) and `test_a_waiter_that_disconnects_is_never_granted_the_slot` (the dead waiter stays queued on main). Builds alongside amd#5327, which stops a busy daemon being killed. They share one identical hunk (the async credential check in `broker_routes.py`), so either can land first. amd#5287 replaces the per-model lock this PR makes reportable; whichever lands second keeps the wait reporting and cancel on the slot gate. Its shared-lease TTL margin can go once leases renew. Merge order with amd#5336: whichever lands second makes two additions. - `except LeaseWaitCancelled` in amd#5336's `_preflight_load`, ahead of its catch-all. - `lease_wait_limit(30)` around `_generate_session_title._ask`'s lease, so a title gives up rather than holding a default-pool thread behind a long queue. This PR's author does both if this lands second; amd#5336's does if that does. For the `except` clause, the guard is `test_stop_during_a_queued_preflight_stays_quiet_on_the_non_streaming_path`. It covers the turn that passes no handler and no cancel event, where only that clause keeps a stopped wait from being reported as a failed load. The handler-based variant passes either way, because amd#5336's wrapper already ignores errors once Stop is set. Merge order with amd#5339 (Agent UI indexing), same rule: whichever lands second wraps `rag.index_document(...)` in `_index_document._do_index` with `lease_wait_listener(lambda _event: _step())`. Queue updates then count as indexing progress, so an upload waiting for the embedder behind a long chat isn't stopped at amd#5339's 600 s no-progress limit. A test covers an index that waits on a lease longer than that limit. Merge order with amd#5359 (idle exit for non-default daemons), same rule. It stamps `_last_activity` in `ModelSlotBroker`, which conflicts with this PR in `broker.py` in two places, each resolved by keeping both sides. In `_grant_locked`, keep `_renewed_at` and `_last_activity`. In `_reclaim_if_stale_locked`, take this PR's version and add `self._last_activity = self._now()` before `notify_all()`. Eval categories to watch at the next RC. No prompt or tool surface changed. The agent-loop catchall gained one case: a Stop while queued for the model is a cancelled turn. Turn timing under a busy model also changed. Watch `rag_quality` and the `gaia_*` turn timings. Live run against the real daemon app (queue stream, queue route, a requester leaving, the wait cap): [output](amd#5328 (comment)). ## Test plan - [x] `python -m pytest tests/unit/test_daemon_broker_queue.py tests/unit/test_daemon_broker.py tests/unit/test_daemon_broker_routes.py tests/unit/test_broker_wiring.py tests/unit/chat/ui/test_model_queue_status.py -q` - [x] `python util/lint.py --black --isort --flake8 --pylint --test-lanes` - [ ] With a daemon running, hold the slot with a raw `POST /host/v1/models/lease`, then send an Agent UI turn. It shows the waiting line and updates it every 2 s. Press Stop, and `GET /host/v1/models/queue` shows nothing waiting. - [x] With `GAIA_MODEL_LEASE_WAIT_S=5`, the same turn fails after 5 s with where it stood in line and who held the model. <details> <summary>🔍 Technical details</summary> - **Protocol.** `POST /host/v1/models/lease` with `"stream": true` returns NDJSON: `queued` lines, then one `granted` or `error` line. Without `stream`, it is the old single JSON response with the old 300 s default, so older clients are unchanged. A new client talking to an older daemon reads its JSON reply, and never starts a heartbeat because there is no `renew_interval_s`. - **Renewal.** `"renewable": true` leases are kept by `POST …/lease/{id}/renew` every `heartbeat_ttl/4`. They are reclaimed after 60 s without a renewal, with a 4 h cap. Non-renewing leases keep the 900 s TTL. - **Cancellation.** Each wait runs on its own daemon thread (`broker_routes._Wait`), never the shared anyio pool. A disconnect or abandon sets the broker's `cancel` and calls `wake()`. A grant that races the abandon is released exactly once, under `_Wait._guard`. A streamed grant counts as delivered only after its send returns. - **Silence detection.** The client sets a 30 s socket timeout on the body only, so older daemons can still take 300 s to send headers. On the client, a cancel that arrives with the grant line releases that lease. - **Turn scope.** `broker_client.interactive_turn` sets context vars for priority, the wait listener and cancel. Plain threads (memory extraction) start without them and stay background. Threads that copy the context (tool runners, the stream watchdog) stay part of the turn. The UI cancel checks both `TurnCancel` and the SSE handler's Stop flag. - **Ownership.** Renew and release check the caller is the lease's holder. `LeaseNotHeldError` no longer echoes the active lease id. `GET /host/v1/models/queue` strips it too. - **Surfaces.** The queued state goes out as a `status` event with `phase: "model_queue"` and a `queue` object (`event` queued/granted, position, holder, seconds waited). It goes on the Agent UI's SSE stream and on the `/query` streams of the gaia agent (which the TUI reads; amd#5319 renders it) and the email agent. Both canonical translators keep `queue`, and the contract is in `agent-ui-query-sse-contract.md` §4.4. Stop in the Agent UI and `/query/{run_id}/cancel` on either sidecar end the wait. The stdio transport still only logs it. A non-streaming Agent UI turn has no stream to show it on, so queue updates only keep its idle stop from firing. - **Bounds.** A renewing lease is held at most its holder's declared hold. LemonadeClient declares the call's own timeout (the request budget when none is passed), plus the retry deadline after which no new attempt starts, plus 15 min for a load. Undeclared leases keep main's 900 s, and the ceiling is 2 h. Background waits have no ceiling, but they age: after 10 min queued they rank as interactive. Side work that must not tie up a worker thread wraps itself in `lease_wait_limit(seconds)`; the chat title gets it from whichever of this and amd#5336 lands second (above). Background work a turn starts (indexing) runs outside the turn's scope. The lease route refuses NaN or infinite `timeout` and `max_hold_s`. - **Not in this PR.** Cross-home arbitration (eval homes sharing one Lemonade through separate brokers) is designed and staged for a follow-up. </details> --------- Co-authored-by: Kalin Ovtcharov <[email protected]>
Before: on a shared machine, a TUI turn waiting for the model slot could fail with a bare "timeout awaiting response headers" before the daemon's relay sent its own explanation. The TUI used its own shell's timeout, not the daemon's, so raising
GAIA_AGENT_TOOL_TIMEOUTon the daemon didn't help. A queued follow-up also told the user to "checkgaia daemon status" after 180 s, even while it was still receiving updates or had just had a prompt answered. After: the TUI waits on the budget the daemon actually uses, so the relay's reason always reaches the user. The queued-follow-up notice appears only after 180 s of real silence and keeps the diagnostic step without guessing at a cause. Lands after v0.25.0.Reproduced by
TestRelayTimeoutReportReachesTheUserInsteadOfAHeaderTimeout,TestTheTUIUsesTheBudgetTheDaemonReports,TestQueuedSendStalledMsgIsQuietWhileTheTurnKeepsUpdatingandTestAnsweringAPromptRestartsTheQuietClock; all fail on main and pass here.Test plan
go vet ./...clean;go test -p 1 ./internal/client/ ./internal/daemon/ ./internal/event/ ./internal/ui/chat/ ./internal/ui/preflight/passespytest tests/unit/test_agent_read_timeout_table.py:timeouts.pymatches the shared table, and/daemon/v1/statusreports the budget (a number,nullfor no limit, oragent_read_timeout_error, without breaking status)TestAgentReadTimeoutMatchesThePythonTable: the Go fallback parser agrees with the same table (whitespace,+, underscores,inf,nan, hex rejected), capping only past Go's duration range🔍 Technical details
/daemon/v1/statusgainsagent_read_timeout_s(null= no limit) oragent_read_timeout_error; an unusable value fails the turn naming the setting andgaia daemon restart, since it lives in the daemon's environment. The TUI reads them in its status probe (Instance.RelayBudget). An explicitSSEOptions.ReadTimeoutwins; a daemon that predates the field falls back to this shell's setting, and the fallback is logged.HeaderTimeoutdefaults to the turn's read budget + 30 s, since the relay's httpx read timeout also covers waiting for the sidecar's headers.tests/fixtures/daemon/agent_read_timeout_cases.jsonis generated fromtimeouts.py; Python and Go both test against it.model_queuestatuses, once a sidecar forwards them) come every few seconds and, like any event, reset the quiet clock. So the notice always keeps thegaia daemon statusstep.app.py; fix(daemon): never kill a live daemon because queued leases slowed its status #5327 makes that route async, a trivial conflict.