chore(tui-gateway): inline _run_and_emit — one-off wrapper, belongs inside dispatch

This commit is contained in:
Brooklyn Nicholson 2026-04-19 07:58:33 -05:00
parent 596280a40b
commit 393175e60c

View file

@ -218,31 +218,27 @@ def handle_request(req: dict) -> dict | None:
return fn(req.get("id"), req.get("params", {})) return fn(req.get("id"), req.get("params", {}))
def _run_and_emit(req: dict) -> None:
"""Run a handler on the RPC pool and write its response directly.
Catches any unexpected exception so a misbehaving handler can't kill
the worker thread silently the caller still sees a JSON-RPC error.
"""
try:
resp = handle_request(req)
except Exception as exc:
resp = _err(req.get("id"), -32000, f"handler error: {exc}")
if resp is not None:
write_json(resp)
def dispatch(req: dict) -> dict | None: def dispatch(req: dict) -> dict | None:
"""Route an inbound RPC — long handlers to the pool, everything else inline. """Route inbound RPCs — long handlers to the pool, everything else inline.
Returns the response for sync-dispatched requests so the caller Returns a response dict when handled inline. Returns None when the
(entry.py) can write it. Returns None when the request has been handler was scheduled on the pool; the worker writes its own
scheduled on the pool; the worker writes the response itself. response via write_json when done.
""" """
if req.get("method", "") in _LONG_HANDLERS: if req.get("method") not in _LONG_HANDLERS:
_pool.submit(_run_and_emit, req) return handle_request(req)
return None
return handle_request(req) def run():
try:
resp = handle_request(req)
except Exception as exc:
resp = _err(req.get("id"), -32000, f"handler error: {exc}")
if resp is not None:
write_json(resp)
_pool.submit(run)
return None
def _wait_agent(session: dict, rid: str, timeout: float = 30.0) -> dict | None: def _wait_agent(session: dict, rid: str, timeout: float = 30.0) -> dict | None: