fix(tui): preserve busy and init error signaling
Finish the Copilot review cleanup for lazy prompt submission: - prompt.submit now claims session.running before returning success, preserving the existing RPC-level session busy error so the frontend can queue. - agent-init timeout/failure now emits a normal error event instead of writing a second JSON-RPC response for an already-settled request id. 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:
@@ -2433,13 +2433,19 @@ def _(rid, params: dict) -> dict:
|
|||||||
session, err = _sess_nowait(params, rid)
|
session, err = _sess_nowait(params, rid)
|
||||||
if err:
|
if err:
|
||||||
return err
|
return err
|
||||||
|
with session["history_lock"]:
|
||||||
|
if session.get("running"):
|
||||||
|
return _err(rid, 4009, "session busy")
|
||||||
|
session["running"] = True
|
||||||
|
|
||||||
_start_agent_build(sid, session)
|
_start_agent_build(sid, session)
|
||||||
|
|
||||||
def run_after_agent_ready() -> None:
|
def run_after_agent_ready() -> None:
|
||||||
err = _wait_agent(session, rid)
|
err = _wait_agent(session, rid)
|
||||||
if err:
|
if err:
|
||||||
session.get("transport", current_transport() or _stdio_transport).write(err)
|
_emit("error", sid, {"message": err.get("error", {}).get("message", "agent initialization failed")})
|
||||||
|
with session["history_lock"]:
|
||||||
|
session["running"] = False
|
||||||
return
|
return
|
||||||
_run_prompt_submit(rid, sid, session, text)
|
_run_prompt_submit(rid, sid, session, text)
|
||||||
|
|
||||||
@@ -2449,10 +2455,6 @@ def _(rid, params: dict) -> dict:
|
|||||||
|
|
||||||
def _run_prompt_submit(rid, sid: str, session: dict, text: Any) -> None:
|
def _run_prompt_submit(rid, sid: str, session: dict, text: Any) -> None:
|
||||||
with session["history_lock"]:
|
with session["history_lock"]:
|
||||||
if session.get("running"):
|
|
||||||
_emit("error", sid, {"message": "session busy"})
|
|
||||||
return
|
|
||||||
session["running"] = True
|
|
||||||
history = list(session["history"])
|
history = list(session["history"])
|
||||||
history_version = int(session.get("history_version", 0))
|
history_version = int(session.get("history_version", 0))
|
||||||
images = list(session.get("attached_images", []))
|
images = list(session.get("attached_images", []))
|
||||||
|
|||||||
Reference in New Issue
Block a user