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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: persist auto-fix diagnostics as structured task metadata (#2328)
Adam Eivy7a58524f1ff1
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex bf7189ac66..6b70f25db4 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -14,5 +14,6 @@- **[issue-2328] Auto-fixer now has a circuit breaker so a persistently-failing resource can't flood the task queue.** The auto-fixer only deduped identical errors within a 60-second window, so a provider/model (or critical error) that failed every ~minute would queue a fresh investigation/fix task indefinitely — a runaway loop that exhausts the plan queue and never gets healed by yet another identical task. It now trips a per-resource circuit after more than 3 task-worthy failures within a rolling 1-hour window, suppressing further task creation (logged as `🔌 Auto-fix circuit OPEN …`) until the failure rate ages out and the circuit auto-closes. (Partial delivery of #2328's guardrails; the tiered fallback chain, structured failure-reason telemetry, and dashboard metrics remain.)- **[issue-2328] Auto-fixer now classifies every failure into a fallback tier and records structured per-attempt diagnostics.** A deterministic classifier maps each error category (config/env, schema/type, transient, or unknown) to one of four fallback tiers — 1 config/env, 2 schema/type, 3 constrained-agent-retry, 4 escalate — with unrecognized categories always escalating so nothing is silently swallowed. Each auto-fix attempt now builds a structured `{ triggerEvent, target, errorType, category, tier, fixStrategy, failureReason }` diagnostics object that rides on the investigation/fix task record (and its agent-facing context) and is surfaced inline in the existing single-line log (`… tier=1 (config/env) …`), so failures can be broken out by tier / category / reason. (Further #2328 slices remain: dashboard telemetry surfacing, time-to-recovery metric, full 4-tier execution wiring.)+- **[issue-2328] Auto-fix diagnostics are now persisted as structured task metadata instead of being silently dropped.** The tier/category/failure-reason diagnostics the classifier builds for every error-driven task were only ever embedded into the free-text context string and the log line — `addTask` never copied the structured object into task metadata, so it couldn't be queried or aggregated afterward. It now persists `taskData.diagnostics` as first-class `metadata.diagnostics` (round-tripping through the markdown store via the existing JSON sentinel, with a defensive non-object guard), and `createCosTaskSchema` validates it for schema parity. This is the prerequisite for the remaining #2328 telemetry slice: aggregating auto-fix outcomes by tier / failure reason / time-to-recovery and surfacing them on the dashboard.- **Layered Intelligence loop now supports every provider type.** The per-app AI-provider picker previously listed only `cli` providers, while the reasoning call went through the api-only `callProviderAISimple` — so a selected CLI provider failed at runtime with "requires an API-based provider," and API/TUI providers (Ollama, LM Studio, Claude/Codex/OpenCode TUI, etc.) never appeared at all. The reasoning call now routes through the unified `runPromptThroughProvider`, which dispatches on `provider.type`, and the picker lists all enabled `cli`/`api`/`tui` providers. CLI/TUI spawns run in the app's repo (`cwd`).- **A "Run now" of Layered Intelligence now tells you what actually happened.** Because the loop is handler-backed — it files one tracker issue rather than spawning a visible agent — a run that filed nothing gave no usable signal: the on-demand toast collapsed every non-filed outcome (reasoning model returned unparseable JSON, a duplicate/near-duplicate was suppressed, it parked on a blocking issue, no AI provider was configured, Jira wasn't set up, the tracker read failed) into a blanket "nothing to do right now," and on mobile that transient toast was easy to miss entirely. The handler now threads the real terminal reason through the on-demand feedback (so the toast reads e.g. "the reasoning model returned no usable JSON — try a non-reasoning model" or "paused on a blocking issue"), and every run persists its outcome (`lastRunAt` / action / reason / filed ref) so Edit App → Intelligence shows a durable **Last run** status line you can check any time. This is what made a reasoning-style local model (which often emits thinking text with no parseable JSON) look like a queued-but-not-running task with no explanation.diff --git a/server/lib/cosValidation.js b/server/lib/cosValidation.jsindex 1d3e7438ef..3de4c11a3e 100644--- a/server/lib/cosValidation.js+++ b/server/lib/cosValidation.js@@ -97,8 +97,24 @@ const cosTaskAttachmentSchema = z.object({mimeType: z.string().optional(),});+// Structured auto-fix diagnostics (#2328) — the record autoFixer.buildFixDiagnostics+// attaches to error-driven tasks so downstream telemetry can break auto-fix outcomes+// out by fallback tier / category / failure reason. Server-internal today (autoFixer+// calls addTask directly), but validated for schema parity now that addTask persists+// it as first-class metadata.+const cosTaskDiagnosticsSchema = z.object({+ triggerEvent: z.string().optional(),+ target: z.string().optional(),+ errorType: z.string().optional(),+ category: z.string().optional(),+ tier: z.number().optional(),+ fixStrategy: z.string().optional(),+ failureReason: z.string().optional(),+}).passthrough();+export const createCosTaskSchema = z.object({description: z.string().min(1),+ diagnostics: cosTaskDiagnosticsSchema.optional(),priority: z.string().optional(),context: z.string().optional(),model: z.string().optional(),diff --git a/server/services/cosTaskStore.js b/server/services/cosTaskStore.jsindex 4ac0fa8bd6..977b3ad04f 100644--- a/server/services/cosTaskStore.js+++ b/server/services/cosTaskStore.js@@ -270,6 +270,17 @@ export async function addTask(taskData, taskType = 'user', { raw = false, ignoreif (taskData.jiraTicketUrl) metadata.jiraTicketUrl = taskData.jiraTicketUrl;if (taskData.screenshots?.length > 0) metadata.screenshots = taskData.screenshots;if (taskData.attachments?.length > 0) metadata.attachments = taskData.attachments;+ // Structured auto-fix diagnostics (#2328): the fallback classifier builds a+ // { triggerEvent, target, errorType, category, tier, fixStrategy, failureReason }+ // record for every error-driven task, but until now addTask only ever embedded+ // it into the free-text context string and the log line — the structured object+ // was silently dropped. Persist it as first-class metadata so downstream+ // telemetry can aggregate auto-fix outcomes by tier / category / failure reason.+ // It round-trips through the markdown store via the JSON sentinel (see+ // taskParser.js escapeNewlines). A non-object (defensive) is ignored.+ if (taskData.diagnostics && typeof taskData.diagnostics === 'object') {+ metadata.diagnostics = taskData.diagnostics;+ }// Content-edit timestamp for cross-peer newest-edit-wins LWW (#1714). Stamped// at creation so a freshly-added task always carries a stamp; the merge treats// an absent stamp as oldest, so this also keeps a stamped task from losing adiff --git a/server/services/cosTaskStore.test.js b/server/services/cosTaskStore.test.jsindex a1620c8872..8e4cf74971 100644--- a/server/services/cosTaskStore.test.js+++ b/server/services/cosTaskStore.test.js@@ -161,6 +161,35 @@ describe('cosTaskStore.addTask', () => {expect(mock.events.some(e => e.name === 'tasks:changed' && e.payload.action === 'added' && e.payload.type === 'user')).toBe(true);});+ it('persists structured auto-fix diagnostics into metadata and round-trips them through markdown (#2328)', async () => {+ const diagnostics = {+ triggerEvent: 'AI_PROVIDER_EXECUTION_FAILED',+ target: 'Claude Code CLI (opus)',+ errorType: 'rate-limit',+ category: 'rate-limit',+ tier: 3,+ fixStrategy: 'constrained-agent-retry',+ failureReason: 'HTTP 429 from provider',+ };+ const created = await addTask(+ { description: 'Investigate AI provider failure', approvalRequired: true, diagnostics },+ 'internal'+ );+ // Attached to the returned task's metadata (not silently dropped).+ expect(created.metadata.diagnostics).toEqual(diagnostics);+ // Survives the markdown serialize → parse round-trip via the JSON sentinel.+ const { tasks } = await getCosTasks();+ const reloaded = tasks.find(t => t.id === created.id);+ expect(reloaded.metadata.diagnostics).toEqual(diagnostics);+ });++ it('omits diagnostics metadata when none is supplied and ignores a non-object value', async () => {+ const created = await addTask({ description: 'no diagnostics here' }, 'user');+ expect(created.metadata.diagnostics).toBeUndefined();+ const bad = await addTask({ description: 'bad diagnostics', diagnostics: 'not-an-object' }, 'user');+ expect(bad.metadata.diagnostics).toBeUndefined();+ });+it('rejects a duplicate with the same first-line description and app scope', async () => {await addTask({ description: 'dupe me', app: 'portos' }, 'user');const second = await addTask({ description: 'dupe me\nextra body', app: 'portos' }, 'user');