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

+45
View File
@@ -87,6 +87,51 @@ def test_tree_endpoint(tmp_path):
server.close()
def test_tree_endpoint_carries_skill_status(tmp_path):
scheduler = build_scheduler(tmp_path)
def predict(ctx, request):
return Prediction(text="", decisions=[])
def act(ctx, request, prediction):
return ActionResult(action_log="ok", new_state=request.text)
scheduler.tree["tracking"] = [
Skill(name="ready", category="tracking", description="r", predict=predict, act=act),
Skill(name="stub", category="tracking", description="s"),
]
stub = next(s for s in scheduler.tree["tracking"] if s.name == "stub")
stub.writing = True
server = Server(scheduler)
try:
status, payload = server.get("/api/tree")
assert status == 200
by_name = {s["name"]: s["status"] for s in payload["categories"]["tracking"]}
assert by_name["ready"] == "ready"
assert by_name["stub"] == "writing"
finally:
server.close()
def test_restart_without_codegen_returns_error_json(tmp_path):
scheduler = build_scheduler(tmp_path)
scheduler.tree["tracking"] = [
Skill(name="track_live", category="tracking", description="Follow a package.")
]
server = Server(scheduler)
try:
status, payload = server.post("/api/restart", {"category": "tracking", "skill": "track_live"})
assert status == 200
assert payload["status"] == "error"
assert "codegen" in payload["detail"]
status, payload = server.post("/api/restart", {"category": "tracking", "skill": "missing"})
assert payload["status"] == "error"
assert "no skill" in payload["detail"]
finally:
server.close()
def test_trace_endpoint_empty(tmp_path):
server = Server(build_scheduler(tmp_path))
try: