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

+37 -6
View File
@@ -48,6 +48,14 @@ class ActionContext:
config: dict
def _noop_predict(ctx: ActionContext, request: Request) -> Prediction:
return Prediction(text="")
def _noop_act(ctx: ActionContext, request: Request, prediction: Prediction) -> ActionResult:
return ActionResult("", "")
@dataclass
class Skill:
name: str
@@ -55,11 +63,25 @@ class Skill:
description: str
cost_budget: float = 1.0
predict: Callable[[ActionContext, Request], Prediction] = field(
default=lambda ctx, req: Prediction(text="")
default=_noop_predict
)
act: Callable[[ActionContext, Request, Prediction], ActionResult] = field(
default=lambda ctx, req, pred: ActionResult("", "")
default=_noop_act
)
writing: bool = False
def is_noop(self) -> bool:
"""A stub leaf: authored (title + description) but no runnable body yet."""
return self.predict is _noop_predict or self.act is _noop_act
@property
def status(self) -> str:
"""Leaf readiness: `writing` (codegen in flight), `stub` (no body), `ready`."""
if self.writing:
return "writing"
if self.is_noop():
return "stub"
return "ready"
@dataclass
@@ -122,13 +144,22 @@ class CategoryRegistry:
self.path.parent.mkdir(parents=True, exist_ok=True)
self.path.write_text(json.dumps(categories, indent=2) + "\n")
def register_skill(self, category: str, name: str, description: str) -> None:
"""Add a skill leaf to a category, creating the category entry if needed."""
def register_skill(
self, category: str, name: str, description: str, request_text: str = ""
) -> None:
"""Add a skill leaf to a category, creating the category entry if needed.
`request_text` is the originating request, kept so a later restart of the
stub can re-drive codegen with the same context.
"""
categories = self.read()
entry = categories.setdefault(category, {"description": "", "skills": []})
skills = entry.setdefault("skills", [])
if not any(s.get("name") == name for s in skills):
skills.append({"name": name, "description": description})
entry_row = next((s for s in skills if s.get("name") == name), None)
if entry_row is None:
skills.append({"name": name, "description": description, "request_text": request_text})
else:
entry_row["request_text"] = request_text
self.path.parent.mkdir(parents=True, exist_ok=True)
self.path.write_text(json.dumps(categories, indent=2) + "\n")