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
This commit is contained in:
Brooklyn Nicholson 2026-04-29 00:22:38 -05:00
parent 88a9efdb1a
commit cc5efb6fc1

View File

@ -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", []))