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

+55
View File
@@ -129,6 +129,11 @@ function eventRow(evt) {
} else if (evt.kind === "skill_created") {
div.textContent = `created ${evt.skill}${evt.written ? " (body written)" : " (stub)"}`;
div.title = evt.body || evt.description || "";
} else if (evt.kind === "skill_write_failed") {
div.textContent = `body write failed: ${evt.skill}`;
div.title = evt.message || "";
} else if (evt.kind === "skill_restarted") {
div.textContent = `restarted body write: ${evt.skill}`;
} else if (evt.kind === "needs_input") {
div.textContent = "needs input";
div.title = evt.question || "";
@@ -378,6 +383,23 @@ function eventNode(evt) {
node.appendChild(p);
}
node.classList.add(evt.written ? "ok" : "stub");
} else if (evt.kind === "skill_write_failed") {
node.classList.add("stub");
const title = document.createElement("div");
title.className = "skill-title";
title.textContent = `${evt.skill} — body write failed`;
body.appendChild(title);
const msg = document.createElement("div");
msg.className = "muted";
msg.textContent = evt.message || "";
body.appendChild(msg);
const btn = document.createElement("button");
btn.className = "restart-btn";
btn.textContent = "restart";
btn.addEventListener("click", () => restartSkill(evt.category, evt.skill));
node.appendChild(btn);
} else if (evt.kind === "skill_restarted") {
body.textContent = `restarted body write for ${evt.skill}`;
} else if (evt.kind === "needs_input") {
node.classList.add("needs-input");
body.textContent = `awaiting input: ${evt.question || ""}`;
@@ -434,6 +456,38 @@ function kv(k, v) {
/* ---------------- skill tree ---------------- */
async function restartSkill(category, name) {
try {
const res = await getJSON("/api/restart", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ category, skill: name }),
});
flash(`[${res.status}] ${res.detail}`);
} catch (err) {
flash(`restart failed: ${err.message}`);
}
await refreshAll();
}
function skillStatusBadge(status, category, name) {
const span = document.createElement("span");
if (status === "writing") {
span.className = "sbadge writing";
span.textContent = "writing…";
} else if (status === "stub") {
span.className = "sbadge stub";
span.textContent = "stub";
const btn = document.createElement("button");
btn.className = "restart-btn";
btn.textContent = "restart";
btn.title = `write the body for ${category}.${name}`;
btn.addEventListener("click", () => restartSkill(category, name));
span.appendChild(btn);
}
return span;
}
function renderTree() {
const el = $("#skill-tree");
el.innerHTML = "";
@@ -455,6 +509,7 @@ function renderTree() {
desc.textContent = skill.description;
row.appendChild(nm);
row.appendChild(desc);
row.appendChild(skillStatusBadge(skill.status, cat, skill.name));
div.appendChild(row);
}
el.appendChild(div);
+18
View File
@@ -324,6 +324,24 @@ pre.json {
.skill-row { display: flex; gap: 6px; align-items: baseline; padding-left: 8px; font-size: 11px; }
.skill-row .sdesc { color: var(--muted); }
.sbadge {
margin-left: auto;
font-size: 10px;
white-space: nowrap;
display: inline-flex;
align-items: center;
gap: 4px;
}
.sbadge.writing { color: var(--warn); }
.sbadge.stub { color: var(--muted); }
.restart-btn {
padding: 1px 6px;
font-size: 10px;
border-radius: 4px;
color: var(--accent);
}
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.stat-grid .stat { background: var(--panel-2); border-radius: 4px; padding: 4px 6px; }
.stat-grid .stat .v { font-weight: 700; }