dashboard: drain the run queue so a multi-step chain completes
A `continue` assessment re-dispatches the next step onto the queue rather than running it inline, so a multi-step request only finishes when a front end drains `Scheduler.run_queue()` -- as the CLI and gateway already do. The dashboard ran only the first step and left the child stranded in the queue, so a compound request looked finished when it was not. - `DashboardHandler._complete` runs the returned reply through `_drain_chain` and returns the last reply (intermediate steps are hidden at `result` verbosity); `/api/submit` and `/api/answer` use it. - `/api/answer` now also returns `request_id` (`SchedulerReply.run_id`) so a front end can cross-link the resumed run. - `test_submit_completes_a_multi_step_chain` drives a deterministic two-step chain and asserts both steps ran, the reply is the final step, nothing is left in the queue, and the runs are linked.
This commit is contained in:
1 parent
9757ae893e
commit
c010cdb44e
2 files changed
+89
-4
No files matched your search
@@ -255,8 +255,11 @@ class DashboardHandler(BaseHTTPRequestHandler):
|
||||
with self.lock:
|
||||
try:
|
||||
body = self._read_json()
|
||||
reply = self.scheduler.submit_request(
|
||||
str(body.get("text", "")), source=str(body.get("source", "dashboard"))
|
||||
reply = self._complete(
|
||||
self.scheduler.submit_request(
|
||||
str(body.get("text", "")),
|
||||
source=str(body.get("source", "dashboard")),
|
||||
)
|
||||
)
|
||||
except Exception as exc:
|
||||
self._send_error(500, str(exc))
|
||||
@@ -277,11 +280,11 @@ class DashboardHandler(BaseHTTPRequestHandler):
|
||||
with self.lock:
|
||||
try:
|
||||
body = self._read_json()
|
||||
reply = self.scheduler.answer(str(body.get("text", "")))
|
||||
reply = self._complete(self.scheduler.answer(str(body.get("text", ""))))
|
||||
except Exception as exc:
|
||||
self._send_error(500, str(exc))
|
||||
return
|
||||
self._send(200, {"status": reply.status, "detail": reply.text})
|
||||
self._send(200, {"status": reply.status, "detail": reply.text, "request_id": reply.run_id})
|
||||
return
|
||||
if path == "/api/restart":
|
||||
with self.lock:
|
||||
@@ -372,6 +375,28 @@ class DashboardHandler(BaseHTTPRequestHandler):
|
||||
return
|
||||
self._send(200, {"status": status, "detail": detail})
|
||||
|
||||
def _complete(self, first):
|
||||
"""Finish a request's chain and return the reply that answers it.
|
||||
|
||||
A `continue` assessment re-dispatches the next step onto the queue
|
||||
rather than running it inline, so a multi-step request only completes
|
||||
when a front end drains `Scheduler.run_queue()` — as the CLI and
|
||||
gateway do. Without this the dashboard would run just the first step
|
||||
and strand the rest. The last reply is the final answer (intermediate
|
||||
steps are hidden at `result` verbosity).
|
||||
"""
|
||||
return [first, *self._drain_chain()][-1]
|
||||
|
||||
def _drain_chain(self) -> list:
|
||||
"""Run queued chain steps, bounded like `GatewayService.drain`."""
|
||||
replies = []
|
||||
for _ in range(100):
|
||||
batch = self.scheduler.run_queue()
|
||||
if not batch:
|
||||
break
|
||||
replies.extend(batch)
|
||||
return replies
|
||||
|
||||
def log_message(self, format, *args):
|
||||
pass
|
||||
|
||||
|
||||
Reference in new issue
Block a user