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: stop filing investigation tasks for local-LLM playground timeouts (#5771)
Stephen Hilderbrand9ec6b52e1110
diff --git a/server/lib/aiToolkit/runner.js b/server/lib/aiToolkit/runner.jsindex 17648359ff..b52ea43867 100644--- a/server/lib/aiToolkit/runner.js+++ b/server/lib/aiToolkit/runner.js@@ -632,6 +632,13 @@ export function createRunnerService(config = {}) {metadata.success = false;metadata.error = error;metadata.errorCategory = ERROR_CATEGORIES.TIMEOUT;+ // Hosts classify a failure from `errorAnalysis`, not `errorCategory`+ // (PortOS's onRunFailed hook reads only the former), so setting the+ // category alone left every API-run timeout looking like an+ // uncategorized failure downstream — escalated for investigation+ // instead of recognized as the timeout it is. Build it from the same+ // pattern table the other failure paths use so the two can't drift.+ metadata.errorAnalysis = analyzeError(error);metadata.outputSize = Buffer.byteLength(output);await atomicWrite(metadataPath, metadata);safeSettle(() => hooks.onRunFailed?.(metadata, error, output), `Run ${runId} onRunFailed hook`);diff --git a/server/lib/aiToolkit/runner.test.js b/server/lib/aiToolkit/runner.test.jsindex 180ee6f9d1..d426908a9f 100644--- a/server/lib/aiToolkit/runner.test.js+++ b/server/lib/aiToolkit/runner.test.js@@ -624,6 +624,10 @@ describe('AI Toolkit runner service', () => {// The failure is classified as a timeout, not the AbortError's UNKNOWN/HTTP 0.expect(metadata).toMatchObject({ success: false, errorCategory: 'timeout' });expect(metadata.error).toMatch(/timed out/i);+ // Hosts read `errorAnalysis`, not `errorCategory` — with only the latter set,+ // every API timeout reached the host's failure hook as an uncategorized+ // failure and was escalated for investigation instead of read as a timeout.+ expect(metadata.errorAnalysis).toMatchObject({ hasError: true, category: 'timeout' });});it('bounds a run whose provider-readiness hook never resolves (fetch never reached)', async () => {diff --git a/server/services/localLlmPlayground.js b/server/services/localLlmPlayground.jsindex c4f38ca71b..9d9177fb7c 100644--- a/server/services/localLlmPlayground.js+++ b/server/services/localLlmPlayground.js@@ -269,9 +269,13 @@ export async function runLocalLlmTest({// investigation task (the run still has partial model output).const timedOut = timeoutController.signal.aborted;const canceled = clientSignal?.aborted === true && !timedOut;+ // Every abort that isn't the client's is this function's own deadline — the+ // same condition that names the run "Timed out", so the label and the+ // reporting decision below can never drift apart.+ const deadlineHit = !canceled && err?.name === 'AbortError';const error = canceled? 'Local LLM test canceled by client'- : err?.name === 'AbortError' ? `Timed out after ${timeoutMs}ms` : err?.message || 'Local LLM test failed';+ : deadlineHit ? `Timed out after ${timeoutMs}ms` : err?.message || 'Local LLM test failed';// A timeout/abort mid-stream still has tokens worth keeping — surface what the// model already streamed (attached to the error by streamChatCompletion) instead// of discarding it. Persist it on the failed run record too so /runs replay shows it.@@ -286,6 +290,16 @@ export async function runLocalLlmTest({success: false,error,startTime: startedAt,+ // A run cut off by THIS function's own `timeoutMs` is the playground's+ // measurement decision, not evidence the provider is broken: the model+ // was streaming (the partial text proves it), the deadline is a request+ // option the caller chose, and the caller gets the error back inline —+ // the playground pins its provider and refuses fallback, so there is no+ // recovery for the host hook to drive either. Firing `onRunFailed` here+ // only filed an investigation task for a big local model that needed+ // more than the caller allowed. Cancellation already skips the hook the+ // same way (via the `canceled` flag), for the same reason.+ reportFailure: !deadlineHit,...(canceled ? { extras: { canceled: true, completionReason: 'client-disconnect' } } : {}),}).catch(() => {});}diff --git a/server/services/localLlmPlayground.test.js b/server/services/localLlmPlayground.test.jsindex 05736c159c..105ef00483 100644--- a/server/services/localLlmPlayground.test.js+++ b/server/services/localLlmPlayground.test.js@@ -150,6 +150,28 @@ describe('runLocalLlmTest timeout/abort contract', () => {);});+ // A big local model that needs longer than the caller allowed is not a broken+ // provider: the partial text proves it was streaming, `timeoutMs` is the+ // caller's own knob, and the error comes straight back inline. Reporting it+ // through the host's provider-failure hook filed a CoS investigation task per+ // slow playground run.+ it('does not report a run cut off by its own deadline as a provider failure', async () => {+ stubStream(makeReader([sse({ content: 'Hello ' })], { abort: true }));++ await runLocalLlmTest({ backend: 'lmstudio', modelId: 'm1', prompt: 'hi', timeoutMs: 5000 });++ expect(finalizeRunRecord).toHaveBeenCalledWith(expect.objectContaining({ reportFailure: false }));+ });++ it('still reports a genuine provider failure through the host hook', async () => {+ global.fetch = vi.fn().mockRejectedValue(new Error('fetch failed: ECONNREFUSED'));++ const result = await runLocalLlmTest({ backend: 'lmstudio', modelId: 'm1', prompt: 'hi', timeoutMs: 5000 });++ expect(result.error).toContain('ECONNREFUSED');+ expect(finalizeRunRecord).toHaveBeenCalledWith(expect.objectContaining({ reportFailure: true }));+ });+it('surfaces a reasoning-only partial when no visible content streamed before the abort', async () => {stubStream(makeReader([sse({ reasoning: 'thinking hard…' })], { abort: true }));diff --git a/server/services/runner.js b/server/services/runner.jsindex cb3a97624e..5fc638f9cb 100644--- a/server/services/runner.js+++ b/server/services/runner.js@@ -147,8 +147,24 @@ export async function finalizeRunRecord({ runId, output, exitCode, success, erro// "billing", which used to turn a plain timeout into quota-exceeded and// bench a healthy provider for an hour. Other failures still analyze the// output because their provider banner is often the only useful signal.+ const analyzeError = toolkit.services.errorDetection.analyzeError;const analysisInput = exitCode === 124 ? (error || 'Process timed out') : output;- const errorAnalysis = toolkit.services.errorDetection.analyzeError(analysisInput, exitCode);+ let errorAnalysis = analyzeError(analysisInput, exitCode);+ // When that scan lands on nothing, the caller's own `error` is the better+ // evidence — and the run that proved it was a local-LLM playground timeout:+ // the host aborted its OWN deadline, finalized with exit 1 + `Timed out after+ // Nms`, and handed over the partial generation as `output`. Scanning a+ // generation that carries no failure signal returns UNKNOWN with its first+ // line lifted as the "error message", so a plain timeout reached the+ // provider-failure hook as an uncategorized Tier-4 failure titled with the+ // story's own headline. Consulted only as a fallback, so a scan that already+ // found a real category (the CLI/TUI banner case) keeps it.+ if (error && (!errorAnalysis.category || errorAnalysis.category === ERROR_CATEGORIES.UNKNOWN)) {+ const statedAnalysis = analyzeError(error, exitCode);+ if (statedAnalysis.category && statedAnalysis.category !== ERROR_CATEGORIES.UNKNOWN) {+ errorAnalysis = statedAnalysis;+ }+ }metadata.error = metadata.error || errorAnalysis.message || `Process exited with code ${exitCode}`;metadata.errorCategory = errorAnalysis.category;metadata.errorAnalysis = errorAnalysis;diff --git a/server/services/runner.test.js b/server/services/runner.test.jsindex 60bdbc2f1d..99c28bc348 100644--- a/server/services/runner.test.js+++ b/server/services/runner.test.js@@ -144,6 +144,52 @@ describe('finalizeRunRecord — authoritative timeout classification', () => {});});+ // Exit 124 is not the only authoritative statement of cause: the local-LLM+ // playground aborts its OWN wall-clock deadline and finalizes with exit 1 ++ // "Timed out after Nms", carrying the partial generation as `output`. Scanning+ // that generation matched nothing, so the run landed in UNKNOWN with the+ // story's first line lifted as its error message — and autoFixer escalated a+ // plain timeout as a Tier-4 provider failure titled with the story headline.+ it('classifies a host-deadline timeout from the stated error, not the generation it interrupted', async () => {+ setAIToolkit(fakeToolkit({ analyzeError }), { dataDir: '/tmp/test-runner' });++ const metadata = await finalizeRunRecord({+ runId: 'run-playground-timeout',+ output: '# THE FIRST PAGE OF EVERYTHING\n\nThe light turned every twelve seconds…',+ exitCode: 1,+ success: false,+ error: 'Timed out after 300000ms',+ startTime: Date.now(),+ });++ expect(metadata).toMatchObject({+ success: false,+ error: 'Timed out after 300000ms',+ errorCategory: ERROR_CATEGORIES.TIMEOUT,+ });+ expect(metadata.errorAnalysis.message).not.toContain('THE FIRST PAGE OF EVERYTHING');+ });++ // The other half of the same rule: a CLI/TUI run whose caller only knows the+ // exit code still has to be classified from the provider banner in its output.+ it('still scans the output when the caller states nothing more than the exit code', async () => {+ setAIToolkit(fakeToolkit({ analyzeError }), { dataDir: '/tmp/test-runner' });++ const metadata = await finalizeRunRecord({+ runId: 'run-cli-banner',+ output: "You've hit your usage limit. Upgrade to Pro to keep going.",+ exitCode: 1,+ success: false,+ error: 'Process exited with code 1',+ startTime: Date.now(),+ });++ expect(metadata).toMatchObject({+ errorCategory: ERROR_CATEGORIES.USAGE_LIMIT,+ errorAnalysis: expect.objectContaining({ category: ERROR_CATEGORIES.USAGE_LIMIT }),+ });+ });+it('records cancellation without scanning output or firing the provider-failure hook', async () => {const errorDetection = { analyzeError: vi.fn() };const onRunFailed = vi.fn();