From cc5efb6fc16fc620dd2f4f47d0fd244da06f3739 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Wed, 29 Apr 2026 00:22:38 -0500 Subject: [PATCH] fix(tui): keep non-agent session RPCs lazy Respond to Copilot's lazy-start review: session metadata/history/usage do not need a constructed AIAgent, so keep them on the no-wait session path. This preserves the deferred startup model and avoids blocking simple session RPCs on agent initialization. Tests: - python -m py_compile tui_gateway/server.py tui_gateway/entry.py - cd ui-tui && npm run type-check && npm run build - scripts/run_tests.sh tests/tui_gateway/test_protocol.py::test_sess_found tests/tools/test_code_execution_modes.py tests/tools/test_code_execution.py - cd ui-tui && npm test -- --run src/__tests__/useSessionLifecycle.test.ts src/__tests__/useConfigSync.test.ts --- tui_gateway/server.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tui_gateway/server.py b/tui_gateway/server.py index ad07ce97..ca0ecfe7 100644 --- a/tui_gateway/server.py +++ b/tui_gateway/server.py @@ -1736,7 +1736,9 @@ def _(rid, params: dict) -> dict: if session is not None: _start_agent_build(sid, session) - threading.Timer(0.05, _deferred_build).start() + build_timer = threading.Timer(0.05, _deferred_build) + build_timer.daemon = True + build_timer.start() return _ok( rid, @@ -1889,7 +1891,7 @@ def _(rid, params: dict) -> dict: @method("session.title") def _(rid, params: dict) -> dict: - session, err = _sess(params, rid) + session, err = _sess_nowait(params, rid) if err: return err db = _get_db() @@ -1952,13 +1954,16 @@ def _(rid, params: dict) -> dict: @method("session.usage") def _(rid, params: dict) -> dict: - session, err = _sess(params, rid) - return err or _ok(rid, _get_usage(session["agent"])) + session, err = _sess_nowait(params, rid) + if err: + return err + agent = session.get("agent") + return _ok(rid, _get_usage(agent) if agent is not None else {"calls": 0, "input": 0, "output": 0, "total": 0}) @method("session.history") def _(rid, params: dict) -> dict: - session, err = _sess(params, rid) + session, err = _sess_nowait(params, rid) if err: return err history = list(session.get("history", []))