async skill-body authoring: single-slot codegen worker, restart, re-dispatch

create_skill now authors the stub synchronously and returns immediately;
the runnable body is written by a single-slot background worker (the gate
stays free for new input). On success the body is materialized and
hot-merged, the leaf's writing flag clears, and the original request is
re-queued at its scored weight and re-runs navigation onto the new leaf.
On failure the leaf stays a restartable stub and the user is notified.

- scheduler: _dispatch_skill launches the async write instead of blocking;
  _run_skill guards writing/stub leaves (no silent no-op); restart_skill
  re-kicks a write for an empty not-in-progress leaf (reuses the stored
  request_text); RLock guards tree/queue/current across worker and main
  thread; awaiting_skill_body meta guard stops a re-dispatched request
  from authoring a second skill.
- skills: Skill.writing + status/is_noop via module-level no-op sentinels;
  registry entries persist the originating request_text.
- engine: call/generate serialized with a Lock so the worker's degeneration
  checks never race main-thread navigation/scoring on one llama.cpp context.
- cli: restart <category> <skill> command; REPL drains the queue after input.
- dashboard: POST /api/restart; /api/tree carries per-skill status; tree
  rows + skill_write_failed flow nodes get restart buttons; reads snapshotted.
- tests: async end-to-end (real CodegenClient vs fake SSE endpoint), restart,
  loop guard, status derivation, dashboard endpoint/status; integration chain
  test rewritten to poll for async completion + assessed.
This commit is contained in:
Denton Social committed 2026-09-25 03:08:33 -05:00
1 parent db35cb66dc
commit 87438c881a
11 files changed
+818 -204

No files matched your search

+44 -19
View File
@@ -93,35 +93,48 @@ def build_dream_report(scheduler: Scheduler) -> dict:
def build_status(scheduler: Scheduler) -> dict:
current = (
{"skill": scheduler.current.skill, "request_id": scheduler.current.request.id}
if scheduler.current
else None
)
pending = (
{"skill": scheduler.pending.skill.name, "question": scheduler.pending.question}
if scheduler.pending
else None
)
queue = [
{"id": request.id, "weight": weight, "text": request.text[:80]}
for weight, request in scheduler.queue.items()
]
with scheduler._lock:
current = (
{"skill": scheduler.current.skill, "request_id": scheduler.current.request.id}
if scheduler.current
else None
)
pending = (
{"skill": scheduler.pending.skill.name, "question": scheduler.pending.question}
if scheduler.pending
else None
)
queue = [
{"id": request.id, "weight": weight, "text": request.text[:80]}
for weight, request in scheduler.queue.items()
]
tau = scheduler.tau
queue_max = scheduler.queue.max_size
return {
"current": current,
"pending": pending,
"queue": queue,
"tau": scheduler.tau,
"queue_max": scheduler.queue.max_size,
"tau": tau,
"queue_max": queue_max,
}
def build_tree_payload(scheduler: Scheduler) -> dict:
tree = scheduler.tree
with scheduler._lock:
snapshot = {
category: list(skills) for category, skills in scheduler.tree.items()
}
return {
"categories": {
category: [{"name": skill.name, "description": skill.description} for skill in skills]
for category, skills in sorted(tree.items())
category: [
{
"name": skill.name,
"description": skill.description,
"status": skill.status,
}
for skill in skills
]
for category, skills in sorted(snapshot.items())
}
}
@@ -233,6 +246,18 @@ class DashboardHandler(BaseHTTPRequestHandler):
return
self._send(200, {"status": status, "detail": detail})
return
if path == "/api/restart":
with self.lock:
try:
body = self._read_json()
status, detail = self.scheduler.restart_skill(
str(body.get("category", "")), str(body.get("skill", ""))
)
except Exception as exc:
self._send_error(500, str(exc))
return
self._send(200, {"status": status, "detail": detail})
return
self._send_error(404, "no such endpoint")
def log_message(self, format, *args):