scheduler: surface failed authoring to the front end
A skill-body write or a draft authoring call that fails only printed to stdout. On the voice gateway that goes to the journal, so the user heard "authoring a new skill in the background; the request will re-run when it is ready" and then nothing — the creation had failed silently. Buffer a user-facing notice on the scheduler outbox (the same path a post-authoring re-run uses), keyed by the originating run id, so a front end's drain_outbox() routes it to the chat. Add _brief_error to collapse and bound the exception text for speech. Tests assert the notice is routable with the right run id for both the draft_failed and skill_write_failed paths.
This commit is contained in:
1 parent
b15a9e1b45
commit
b953475bf7
2 files changed
+57
-1
No files matched your search
@@ -656,6 +656,29 @@ class Scheduler:
|
||||
self._outbox.clear()
|
||||
return replies
|
||||
|
||||
def _notify_outbox(self, run_id: str, text: str) -> None:
|
||||
"""Buffer a user-facing notice for the front end that owns `run_id`.
|
||||
|
||||
Background paths that fail (a skill body write, a draft authoring call)
|
||||
run off the gate with no front end to return to, so the caller only sees
|
||||
the scheduler's own stdout. Pushing a `SchedulerReply` here lets a front
|
||||
end's `drain_outbox()` route it to the originating chat — a voice user
|
||||
hears that creation failed instead of silence. `status="error"` maps to
|
||||
a `notice` on the gateway (never rewritten by `result_only`/`humanize`).
|
||||
"""
|
||||
with self._lock:
|
||||
self._outbox.append(
|
||||
SchedulerReply(status="error", text=text, run_id=run_id)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _brief_error(exc: Exception, limit: int = 160) -> str:
|
||||
"""One collapsed, length-bounded line from an exception for speech."""
|
||||
text = " ".join(str(exc).split())
|
||||
if len(text) <= limit:
|
||||
return text
|
||||
return text[: limit - 3].rstrip() + "..."
|
||||
|
||||
def _run_queue_locked(self) -> list[SchedulerReply]:
|
||||
results = []
|
||||
while self.current is None and len(self.queue) > 0:
|
||||
@@ -1572,6 +1595,13 @@ class Scheduler:
|
||||
category=job.category,
|
||||
message=str(exc),
|
||||
)
|
||||
self._notify_outbox(
|
||||
job.request.id,
|
||||
(
|
||||
f"I couldn't create a new {job.kind} for that request — "
|
||||
f"{self._brief_error(exc)}. Please try again."
|
||||
),
|
||||
)
|
||||
print(
|
||||
f"[llm] {job.kind} authoring for {target} FAILED: {exc}. "
|
||||
"The request was not re-dispatched."
|
||||
@@ -2187,6 +2217,14 @@ class Scheduler:
|
||||
skill=job.draft.name,
|
||||
message=str(exc),
|
||||
)
|
||||
self._notify_outbox(
|
||||
job.request.id,
|
||||
(
|
||||
f"I couldn't finish creating {job.category}.{job.draft.name} — "
|
||||
f"{self._brief_error(exc)}. It's saved as an empty stub; ask me "
|
||||
"to retry it."
|
||||
),
|
||||
)
|
||||
print(
|
||||
f"[codegen] body write for {job.category}.{job.draft.name} FAILED: {exc}. "
|
||||
f"The leaf is a stub — restart it with `restart {job.category} {job.draft.name}`."
|
||||
|
||||
+19
-1
@@ -1401,7 +1401,8 @@ def test_dispatch_create_category_queues_draft_and_is_not_fatal(tmp_path):
|
||||
trace=trace,
|
||||
)
|
||||
scheduler.tree = {}
|
||||
result = scheduler._dispatch(Request("anything"))
|
||||
request = Request("anything")
|
||||
result = scheduler._dispatch(request)
|
||||
assert result.kind == "create_category"
|
||||
assert scheduler.fatal is None
|
||||
deadline = time.monotonic() + 5
|
||||
@@ -1412,6 +1413,13 @@ def test_dispatch_create_category_queues_draft_and_is_not_fatal(tmp_path):
|
||||
assert any(e["kind"] == "draft_failed" for e in trace.read())
|
||||
assert scheduler.fatal is None
|
||||
|
||||
# The failure is buffered for the front end that owns the request (the
|
||||
# voice gateway speaks it instead of leaving the user in silence).
|
||||
notices = scheduler.drain_outbox()
|
||||
assert notices, "a failed draft must be routable to the chat"
|
||||
assert notices[0].run_id == request.id
|
||||
assert "couldn't create a new category" in notices[0].text
|
||||
|
||||
|
||||
def _answer_approval_when_posted(scheduler, approved, timeout=5.0):
|
||||
"""Approve/deny the first pending creation proposal, as a front end would."""
|
||||
@@ -1753,6 +1761,16 @@ def test_async_skill_write_fails_gracefully_on_bad_contract(tmp_path):
|
||||
assert failed is not None, "worker must surface the failure"
|
||||
assert not leaf.writing
|
||||
assert leaf.is_noop(), "leaf must stay a restartable stub"
|
||||
|
||||
# The failure is buffered for the front end that owns the request, so a
|
||||
# voice user hears it instead of the scheduler's stdout-only print.
|
||||
deadline = time.monotonic() + 5
|
||||
while time.monotonic() < deadline and not scheduler._outbox:
|
||||
time.sleep(0.02)
|
||||
notices = scheduler.drain_outbox()
|
||||
assert notices, "a failed body write must be routable to the chat"
|
||||
assert notices[0].run_id == request.id
|
||||
assert "couldn't finish creating" in notices[0].text
|
||||
finally:
|
||||
httpd.shutdown()
|
||||
httpd.server_close()
|
||||
|
||||
Reference in new issue
Block a user