Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: judge programmatic-I/O task outcomes by the output hook, not the exit code (#2727)

[._.]/ Adam Eivy6a88af8a7640
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 868c700297..e415a3252a 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -28,6 +28,8 @@
- [issue-2700] **Layered Intelligence runs were being recorded as failures even when they succeeded.** An LI run is a *reasoning* run: it's explicitly told not to commit or open a PR, and hands its result back through a sentinel file instead. But the shared success check only knows how to look for a code commit, and its verdict overrides the run's actual exit code — so every correct LI run was filed as a failure, dragging the loop's success rate toward 0% and skewing anything built on it (task routing, the CoS Learning card, duration estimates). Task types that hand back results programmatically rather than as a commit are now exempt from the commit check, the same way pipeline and media jobs already were. Ordinary code tasks are still held to it. Because the mis-recorded history can't be reconstructed after the fact, installs that already ran the loop get that one bucket cleared on upgrade, so it starts from an honest "no runs recorded yet" rather than a fabricated 0% — no other task type's stats are touched.
+- [issue-2727] **A Layered Intelligence run that finished cleanly but produced nothing is no longer recorded as a success.** Exempting these reasoning runs from the code-commit check (above) left them judged purely on whether the process exited cleanly — so a run that exited fine but wrote back a missing or malformed result, or whose follow-up step (filing the issue) blew up, still counted as a win and quietly inflated the loop's success rate. These runs are now judged on what they actually deliver: the result was readable and the follow-up step accepted it. A run that hands back nothing usable is recorded as the failure it is, a run that delivers is recorded as a success with no commit required, and the "nothing filed this time" outcomes (no proposal, duplicate, out of scope) still count as successes — the run did its job. Ordinary code tasks are still held to the commit check, and pipeline and media jobs are unchanged.
+
- **The Scene evaluation model dropdown no longer comes up empty when you have vision models installed.** Picking Ollama for a Creative Director project's Scene evaluation showed an empty model list (and a bare text box) even with vision-capable models pulled, because the browser decided what counts as a vision model from a hard-coded list of model-name patterns that knew `gemma-3` but not `gemma4` — so `gemma4:e4b` and `qwen3.6:35b` were filtered out as if they were text-only. Vision pickers now ask the server, which reads each model's real capabilities from the backend itself (Ollama's `/api/show`, LM Studio's `vlm` tag), and union that with the old name matching — so a newer model family shows up without waiting for the pattern list to catch up, and nothing that used to be offered disappears. The AI Assignments table's vision rows get the same fix. Also, the Scene evaluation stage now explains that it needs an API provider (Ollama / LM Studio) and can't use an agent CLI/TUI provider such as Claude Ollama TUI — pinning one there was silently ignored at run time — and a provider with no vision model installed now says so, with a link to install one, instead of showing an empty dropdown.
- The Chief of Staff status panel's Learning card no longer spills its skipped-task count outside the card on mobile. The "(3 skipped)" note used to sit beside the success rate on one line, where it was too wide to fit a narrow card and rendered past the border; it now sits on its own line under the percentage and truncates if it can't fit.
- The Brain **Graph** tab is now usable on a phone. The graph canvas sizes itself to the viewport instead of a fixed 500px (which overflowed a landscape phone entirely and left no room to scroll past a canvas that swallows drags), the controls bar stacks into readable rows instead of cramming a breadcrumb, seven type filters, and both buttons into one line, and the type filters wrap with a proper tap target. The legend — ten rows that blanketed a phone-sized graph — now shows automatically only when there's room for it and collapses behind a "Legend" toggle everywhere else, including a landscape phone (which is wide enough to look like a desktop but far too short). The hover tooltip no longer flashes under your finger advertising a double-click that touch can't do (tap the node and use the detail panel's "Explore connections" instead), and it no longer runs off the right edge in a narrow window. "Explore connections" moved out of a cramped side column onto its own full-width row, above the record text so it stays reachable on a long entry.
diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.js
index 5363e45b28..81c3ec8a17 100644
--- a/server/services/agentLifecycle.js
+++ b/server/services/agentLifecycle.js
@@ -819,30 +819,66 @@ export function releaseAgentLane({ agentId, success, duration, exitCode, executi
* and that is exactly the signal task-learning wants. `checkForTaskCommit` is
* git-repo-gated, off the event loop, and hard-timeout-bounded, so a non-repo
* workspace or a hung git degrades to "no commit" rather than stalling finalize.
+ *
+ * `hookResult` is the programmatic-I/O output-hook result (from
+ * `dispatchTaskOutputHook`), which finalizeAgent resolves BEFORE calling this so
+ * those task types can be judged by their real deliverable; `success` is the
+ * runner's exit-code verdict that hook result is weighed against. Both are
+ * absent/null for every other task shape.
*/
-export async function evaluateSuccessCriteria({ task, terminatedByUser, workspacePath }) {
+export async function evaluateSuccessCriteria({ task, terminatedByUser, workspacePath, success = false, hookResult = null }) {
if (terminatedByUser) return null;
const taskType = task?.taskType || 'user';
+ // Programmatic-I/O tasks (taskTypeHooks.js) declare their OWN criterion — the
+ // sentinel parsed and the hook accepted it — so this branch comes FIRST: it is
+ // keyed on the hook result rather than on a workspace/commit, and must not be
+ // pre-empted by the `!workspacePath` bail below (a hook that already ran and
+ // threw is a real verdict even if the worktree is gone). Their prompts
+ // explicitly FORBID committing or opening a PR (the worktree is discarded), so
+ // the `[task-<id>]` commit check would mark every correct run a failure (#2700).
+ // Judging them purely by exit code instead is also wrong: an exit-0 run whose
+ // `.agent-done` sentinel was missing/malformed, or whose hook threw, produced
+ // nothing usable and must be recorded as the failure it is (#2727).
+ if (isProgrammaticIoTaskType(task?.metadata?.analysisType)) {
+ return resolveProgrammaticIoVerdict({ success, hookResult });
+ }
// Interactive/user tasks declare no machine-checkable criterion; neither does
// a run missing the task id or workspace needed to validate.
if (taskType === 'user' || !task?.id || !workspacePath) return null;
// Pipeline/media tasks deliver artifacts, not a `[task-<id>]` commit — the
// commit criterion doesn't apply, so don't mislabel a clean artifact run as a
// validation miss (which would also pollute the correlation window). null =
- // no commit criterion declared for this task shape.
+ // no commit criterion declared for this task shape. Unlike programmatic-I/O
+ // tasks they register no output hook, so there is no deliverable signal to
+ // judge them by — they stay exit-code-judged (unchanged by #2727).
if (task?.metadata?.pipeline || task?.metadata?.mediaJob) return null;
- // Programmatic-I/O tasks (taskTypeHooks.js) are the same story one step further:
- // their deliverable is the `.agent-done` sentinel an output hook consumes, and
- // their prompts explicitly FORBID committing or opening a PR (the worktree is
- // discarded). Checking for a `[task-<id>]` commit would therefore mark every
- // correctly-executed run a failure — and because a declared verdict OVERRIDES the
- // runner's exit code in task-learning (`outcomeSuccess`), that poisons the type's
- // success rate to ~0 and, through it, anything reading that rate back. null = no
- // commit criterion declared for this task shape.
- if (isProgrammaticIoTaskType(task?.metadata?.analysisType)) return null;
return await checkForTaskCommit(task.id, workspacePath);
}
+/**
+ * The programmatic-I/O success criterion (#2727): "the sentinel parsed and the
+ * output hook accepted it". Pure.
+ *
+ * Delegates the accept/reject classification to `resolveTypeFailureSignal`, the
+ * same pure decision the #2616 type-level failure ledger uses — so the learning
+ * verdict and the ledger can never drift apart on what counts as a bad run
+ * (thrown hook, `unparseable-response`), and a new benign reason only has to be
+ * taught to one function.
+ *
+ * Sentinel discipline: a hook that never ran (type registers no
+ * `processTaskOutput`, or no task type resolved) yields NO verdict — null, not
+ * `true`. "Nothing evaluated the output" must not collapse into "the output was
+ * accepted"; null lets task-learning fall back to the exit code as before.
+ *
+ * @returns {boolean|null} true = accepted, false = rejected, null = undeclared
+ */
+export function resolveProgrammaticIoVerdict({ success, hookResult }) {
+ if (!hookResult?.ran) return null;
+ const signal = resolveTypeFailureSignal({ success, hookResult });
+ if (signal.record === 'skip') return null;
+ return signal.record === 'success';
+}
+
/**
* Shared end-of-run state writes for all three spawn paths
* (`handleAgentCompletion` runner-mode, TUI `finish`, direct-CLI `close`).
@@ -886,12 +922,38 @@ export async function finalizeAgent({
? { status: 'completed' }
: await resolveFailedTaskUpdate(task, errorAnalysis, agentId);
+ // Programmatic-I/O task types (e.g. layered-intelligence) run a deterministic
+ // post-agent step on the agent's STRUCTURED output — the parsed `.agent-done`
+ // payload — rather than only handling the completion sentinel. Read + dispatch
+ // it mode-agnostically here (the single finalize chokepoint for TUI/CLI/runner
+ // agents), gated on the task type actually registering an output hook so a
+ // normal agent pays no extra I/O. Its side effects (filing an issue, etc.) are
+ // isolated from the agent's discarded worktree — the payload is the only
+ // durable channel out. Errors are caught: a hook failure must not strand the
+ // rest of finalize. See taskTypeHooks.js + the design plan.
+ //
+ // Ordering (#2727): this runs BEFORE completeAgent because the hook result is
+ // the only signal that can judge a programmatic-I/O run (see
+ // evaluateSuccessCriteria), and completeAgent is what writes the learning
+ // verdict — so the judgement has to exist first. Safe for every other task
+ // shape: dispatchTaskOutputHook is a no-op unless the type registers a hook
+ // (isProgrammaticIoTaskType), so nothing else is reordered. The lane is already
+ // released by this point (releaseAgentLane fires earlier, in the spawn paths),
+ // and `agent:completed` — which schedules the next dequeue — still fires from
+ // completeAgent below, i.e. AFTER any handoff task the hook enqueues.
+ const hookResult = await dispatchTaskOutputHook({ agentId, task, success, workspacePath }).catch(err => {
+ emitLog('error', `processTaskOutput hook threw for ${agentId} (${task?.taskType}): ${err.message}`, { agentId, error: err.message });
+ // A thrown hook is a non-success signal for the type ledger (#2616) and a
+ // failed success criterion for task-learning (#2727).
+ return { ran: true, threw: true };
+ });
+
// Success-criteria validation (issue #2344): stamp an explicit pass/fail (or
// null-when-undeclared) verdict onto the completion result, distinct from the
// exit-code `success`, so task-learning telemetry can distinguish "ran clean
// but produced nothing" from a genuine success. Best-effort — a validation
// check failure must never block finalize (falls back to the null sentinel).
- const validationPassed = await evaluateSuccessCriteria({ task, terminatedByUser, workspacePath })
+ const validationPassed = await evaluateSuccessCriteria({ task, terminatedByUser, workspacePath, success, hookResult })
.catch(err => {
emitLog('warn', `⚠️ Success-criteria validation failed for ${agentId}: ${err.message}`, { agentId });
return null;
@@ -943,21 +1005,6 @@ export async function finalizeAgent({
}
}
- // Programmatic-I/O task types (e.g. layered-intelligence) run a deterministic
- // post-agent step on the agent's STRUCTURED output — the parsed `.agent-done`
- // payload — rather than only handling the completion sentinel. Read + dispatch
- // it mode-agnostically here (the single finalize chokepoint for TUI/CLI/runner
- // agents), gated on the task type actually registering an output hook so a
- // normal agent pays no extra I/O. Its side effects (filing an issue, etc.) are
- // isolated from the agent's discarded worktree — the payload is the only
- // durable channel out. Errors are caught: a hook failure must not strand the
- // rest of finalize. See taskTypeHooks.js + the design plan.
- const hookResult = await dispatchTaskOutputHook({ agentId, task, success, workspacePath }).catch(err => {
- emitLog('error', `processTaskOutput hook threw for ${agentId} (${task?.taskType}): ${err.message}`, { agentId, error: err.message });
- // A thrown hook is a non-success signal for the type ledger (#2616).
- return { ran: true, threw: true };
- });
-
// Type-level consecutive-failure ledger (#2616): feed the per-type
// backoff/auto-park in taskSchedule. Only SCHEDULED task types carry
// `metadata.analysisType`; user/ad-hoc tasks don't participate. The pure
diff --git a/server/services/agentLifecycle.successCriteria.test.js b/server/services/agentLifecycle.successCriteria.test.js
index 033f70004b..18d35f0077 100644
--- a/server/services/agentLifecycle.successCriteria.test.js
+++ b/server/services/agentLifecycle.successCriteria.test.js
@@ -44,7 +44,7 @@ describe('evaluateSuccessCriteria (#2344)', () => {
expect(checkForTaskCommit).not.toHaveBeenCalled();
});
- it('returns null for a programmatic-I/O task — its deliverable is the sentinel, not a commit (#2700)', async () => {
+ it('never applies the commit criterion to a programmatic-I/O task (#2700)', async () => {
// A layered-intelligence run is explicitly told NOT to commit or open a PR: it
// writes `.agent-done` and its output hook does the filing. Checking for a
// `[task-<id>]` commit would stamp validationPassed:false on every correct run —
@@ -52,9 +52,77 @@ describe('evaluateSuccessCriteria (#2344)', () => {
// that recorded successful LI runs as failures and drove the type's success rate
// to ~0.
const task = { id: 't1', taskType: 'internal', metadata: { analysisType: 'layered-intelligence', selfImprovement: true } };
- expect(await evaluateSuccessCriteria({ task, workspacePath: '/w' })).toBeNull();
+ await evaluateSuccessCriteria({ task, workspacePath: '/w', success: true, hookResult: { ran: true, outcome: { action: 'filed' } } });
expect(checkForTaskCommit).not.toHaveBeenCalled();
});
+});
+
+/**
+ * The programmatic-I/O criterion (#2727): these tasks declare their OWN success
+ * criterion — "the sentinel parsed and the output hook accepted it" — instead of
+ * declaring none and falling through to the runner's exit code, which recorded an
+ * exit-0 run that produced nothing usable as a success.
+ */
+describe('evaluateSuccessCriteria — programmatic-I/O criterion (#2727)', () => {
+ beforeEach(() => vi.clearAllMocks());
+
+ const liTask = { id: 't1', taskType: 'internal', metadata: { analysisType: 'layered-intelligence' } };
+
+ it('records an exit-0 run with a missing/malformed sentinel as a FAILURE', async () => {
+ // The hook reports `unparseable-response` when the `.agent-done` payload is
+ // absent or unparseable — the run exited clean but produced nothing usable.
+ const hookResult = { ran: true, outcome: { action: 'no-op', reason: 'unparseable-response' } };
+ expect(await evaluateSuccessCriteria({ task: liTask, workspacePath: '/w', success: true, hookResult })).toBe(false);
+ });
+
+ it('records an exit-0 run whose output hook THREW as a FAILURE', async () => {
+ expect(await evaluateSuccessCriteria({
+ task: liTask, workspacePath: '/w', success: true, hookResult: { ran: true, threw: true }
+ })).toBe(false);
+ });
+
+ it('records an exit-0 run whose hook accepted the payload as a SUCCESS — no commit required', async () => {
+ const hookResult = { ran: true, outcome: { app: 'a1', action: 'filed', reason: null } };
+ expect(await evaluateSuccessCriteria({ task: liTask, workspacePath: '/w', success: true, hookResult })).toBe(true);
+ expect(checkForTaskCommit).not.toHaveBeenCalled();
+ });
+
+ it('treats benign hook reasons (no-proposal, duplicate, scope-suppressed) as a SUCCESS', async () => {
+ // The agent did its job; the deterministic step simply had nothing to file.
+ for (const reason of ['no-proposal', 'duplicate', 'semantic-duplicate', 'scope-suppressed', 'tracker-read-failed']) {
+ expect(await evaluateSuccessCriteria({
+ task: liTask, workspacePath: '/w', success: true, hookResult: { ran: true, outcome: { action: 'no-op', reason } }
+ })).toBe(true);
+ }
+ });
+
+ it('records a non-zero exit as a FAILURE regardless of the hook outcome', async () => {
+ expect(await evaluateSuccessCriteria({
+ task: liTask, workspacePath: '/w', success: false, hookResult: { ran: true, outcome: { action: 'no-op', reason: 'agent-failed' } }
+ })).toBe(false);
+ });
+
+ it('declares NO verdict (null) when no hook ran — "not evaluated" must not become "accepted"', async () => {
+ // Sentinel discipline: a registered type whose module exports no
+ // processTaskOutput yields `{ ran: false }`. Nothing judged the output, so the
+ // verdict is undeclared and task-learning falls back to the exit code.
+ expect(await evaluateSuccessCriteria({ task: liTask, workspacePath: '/w', success: true, hookResult: { ran: false } })).toBeNull();
+ expect(await evaluateSuccessCriteria({ task: liTask, workspacePath: '/w', success: true })).toBeNull();
+ });
+
+ it('declares NO verdict for a user-terminated programmatic-I/O run', async () => {
+ expect(await evaluateSuccessCriteria({
+ task: liTask, workspacePath: '/w', success: false, terminatedByUser: true, hookResult: { ran: true, threw: true }
+ })).toBeNull();
+ });
+
+ it('judges the hook result even with no workspace to validate against', async () => {
+ // The commit criterion needs a workspace; the programmatic-I/O criterion does
+ // not — a hook that already ran is a real verdict even if the worktree is gone.
+ expect(await evaluateSuccessCriteria({
+ task: liTask, success: true, hookResult: { ran: true, threw: true }
+ })).toBe(false);
+ });
it('still applies the commit criterion to a NON-programmatic self-improvement task', async () => {
// The exemption is keyed on the taskTypeHooks registry, not on selfImprovement —
diff --git a/server/services/taskLearning/metrics.test.js b/server/services/taskLearning/metrics.test.js
index 2ef77f235d..aca0fb312f 100644
--- a/server/services/taskLearning/metrics.test.js
+++ b/server/services/taskLearning/metrics.test.js
@@ -258,6 +258,35 @@ describe('buildTaskTelemetryContext', () => {
expect(plain.outcomeSuccess).toBe(true);
});
+ it('records an exit-0 programmatic-I/O run that produced nothing usable as a failure (#2727)', () => {
+ // A layered-intelligence run whose `.agent-done` sentinel was missing/malformed
+ // (or whose output hook threw) exits 0 but delivered nothing. finalizeAgent now
+ // stamps validationPassed:false from the hook result, so the learning outcome —
+ // and the failure signature routing reads — reflect the real miss instead of
+ // reporting an inflated success rate for the type.
+ const agent = {
+ ...baseAgent,
+ metadata: { ...baseAgent.metadata, taskType: 'internal', analysisType: 'layered-intelligence' },
+ result: { success: true, duration: 3000, validationPassed: false }
+ };
+ const ctx = buildTaskTelemetryContext(agent, { taskType: 'layered-intelligence' });
+ expect(ctx.success).toBe(true);
+ expect(ctx.outcomeSuccess).toBe(false);
+ expect(ctx.failureSignature).not.toBeNull();
+ });
+
+ it('records an exit-0 programmatic-I/O run whose hook accepted the payload as a success (#2727)', () => {
+ // No commit is required for these tasks — an accepted sentinel IS the deliverable.
+ const agent = {
+ ...baseAgent,
+ metadata: { ...baseAgent.metadata, taskType: 'internal', analysisType: 'layered-intelligence' },
+ result: { success: true, duration: 3000, validationPassed: true }
+ };
+ const ctx = buildTaskTelemetryContext(agent, { taskType: 'layered-intelligence' });
+ expect(ctx.outcomeSuccess).toBe(true);
+ expect(ctx.failureSignature).toBeNull();
+ });
+
it('carries the validation verdict into the harvested failure signature sample (#2344)', () => {
const agent = {
...baseAgent,