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:
gabby committed 2026-10-11 09:32:44 +00:00
1 parent 9757ae893e
commit c010cdb44e
2 files changed
+89 -4

No files matched your search

+60
View File
@@ -307,6 +307,66 @@ def test_submit_returns_request_id_matching_trace(tmp_path):
server.close()
class _ChainEngine:
"""Deterministic two-step chain: step 1 -> continue, step 2 -> done."""
def __init__(self):
self.assessments = iter(["continue", "done"])
def call(self, request):
ids = [o.id for o in request.options]
q = request.question
if "additional work to be done" in q:
selected = next(self.assessments, "done")
elif "logical next step" in q:
selected = "demo"
elif "what does this skill do" in q:
selected = "same"
elif "Is this input a request" in q:
selected = "action"
else:
selected = ids[0]
if selected not in ids:
selected = ids[0]
return DecisionResult(
request=request,
option_ids=ids,
probabilities=[1.0 if i == selected else 0.0 for i in ids],
)
def test_submit_completes_a_multi_step_chain(tmp_path):
"""A `continue` step is queued, not run inline, so a multi-step request only
finishes when a front end drains `run_queue()`. The dashboard must do that,
as the CLI and gateway do, or the child is stranded in the queue forever."""
scheduler = build_scheduler(tmp_path, engine=_ChainEngine())
counter = {"n": 0}
def act(ctx, request):
counter["n"] += 1
return ActionResult(action_log=f"step {counter['n']} done", new_state="x")
scheduler.tree["demo"] = [
Skill(name="step", category="demo", description="Do a demo step.", act=act)
]
server = Server(scheduler)
try:
status, payload = server.post("/api/submit", {"text": "do the thing"})
assert status == 200
# The reply is the final step, not the hidden intermediate.
assert payload["status"] == "ran"
assert "step 2 done" in payload["detail"]
assert counter["n"] == 2
# Nothing is left stranded in the queue.
assert list(scheduler.queue.items()) == []
# The chain ran both steps and linked them.
status, trace = server.get("/api/trace")
kinds = [e["kind"] for run in trace["runs"] for e in run["events"]]
assert "continued" in kinds
finally:
server.close()
def test_relabel_roundtrip(tmp_path):
scheduler = build_scheduler(tmp_path)
seed_decision(scheduler.log)