Repository navigation
fix(gaia-agent): set up a /query turn off the event loop - #5349
Conversation
|
Verdict: Approve Starting a session or switching its model no longer freezes the other sessions on the same sidecar. The slow setup now runs on a worker thread. The PR also closes the race that moving it off the loop would have opened: another session can no longer evict this one between finding it and taking its turn. A request cancelled mid-setup still releases the session lock, or closes the agent it built. I found no blocking issues. Real-world evidenceN/A. No evidence bundle was produced for this run. This is a change to the sidecar's internal 🔍 Technical detailsIssues found No 🔴 or 🟡 issues. Things I checked that hold up:
🟢 Long waits on a stopped turn now share the general thread pool ( Strengths
|
|
Verdict: Approve with suggestions Before this change, one session starting up or switching models on the gaia agent sidecar froze every other session's stream, heartbeats included. Now that setup runs on a worker thread. I found no correctness problems. The cancellation and eviction cases are handled carefully, and each one has a test.
Real-world evidenceN/A: there is no evidence bundle for this PR. The change is limited to the sidecar's 🔍 Technical detailsIssues found 🟡 Live two-session evidence is still outstanding (PR test plan, item 2). The rubric expects real-surface proof for a user-visible change. 🟢 What I checked and found correct
Strengths
|
Starting a new session, or a /model switch that waits for a model to load, ran on the sidecar's event loop. Every other session's SSE stream stopped for that long, heartbeats included, so the TUI and the daemon relay saw an idle connection and their idle timers kept counting. Building the session's agent, building a one-shot agent and switching the model now run on worker threads; the HTTP status codes for a busy or failed session are unchanged. If the request goes away mid-setup, the abandoned call still releases what it took: the session's run lock, or the agent it built.
Review follow-ups. With setup on a worker thread, another request's get_or_create could evict a session between this request finding it and taking its run lock, and the turn then got a spurious 409 "already running a turn". The registry's new checkout() tries the lock under the same lock eviction holds, so a found session can no longer be evicted before its turn starts. Cleanup for an abandoned setup call now runs on its own thread, since closing an agent blocks. Route-level tests cover a cancelled /model switch, a cancelled one-shot build, a cancelled wait for a stopped turn, and one-shot heartbeats. Comments and the changelog no longer claim a switch loads a model.
If releasing a cancelled request's lock or agent raised on its cleanup thread, the error went only to stderr and a leaked lock left no trace in the sidecar log. It is now logged.
bc6ed19 to
3c85686
Compare
When one session started, or switched model with
/model, every other session on the same sidecar froze. No tokens or heartbeats arrived for as long as the agent build or client switch took, so the TUI and the daemon relay saw an idle connection. Session setup now runs on a worker thread, so other sessions keep streaming. A busy or failed session still returns the same 409, 503 or 500 as before.Reproduced by
hub/agents/gaia/python/tests/test_server_event_loop.py, which runs a real uvicorn sidecar and measures the heartbeat gap on one stream while another session builds, switches, or runs a one-shot. It fails on main with a 1.5 s gap and passes here.test_another_session_cannot_evict_this_one_mid_setupreproduces the spurious "already running a turn" 409 that a worker thread would otherwise open.🔍 Technical details
_off_loop()runs the blocking setup on a worker thread: the session checkout,session.switch_model, and the one-shotbuild_query_agent._SessionRegistry.checkout()takes the session's run lock under the same lock eviction holds. Another request therefore can't evict the session between finding it and taking its turn. That window appeared once setup awaited a worker./modelswitch, a cancelled one-shot build, and a cancelled wait for a stopped turn. These paths can't be cancelled on main at all, since setup there is synchronous._acquire_turnused to be. This PR replaces that function with_checkout_turn; keep this version when resolving, and keep both CHANGELOG entries. perf(llm): side work runs beside the conversation instead of queueing behind it #5287 touches other hunks.test_full_tool_bundlesandtest_manifest_tools_count_matches_real_registryalso fail on main on this dev box, where the optional browser tools aren't installed.Test plan
python -m pytest hub/agents/gaia/python/tests/test_server_event_loop.py hub/agents/gaia/python/tests/test_server_query.py hub/agents/gaia/python/tests/test_session_registry.py -q/model <other>in the other. The first keeps streaming.