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 Layered Intelligence sitting pending forever when pinned to an API-only provider
[._.]/ Adam Eivyf1f2d0468c8a
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 9b45065c80..613b9424eb 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -1,5 +1,9 @@# Unreleased+## Fixes++- **Layered Intelligence no longer silently wedges when pinned to an API-only provider.** After LI became an agent-backed scheduled task (#2322), its reasoning run needs a CLI/TUI coding provider (one with a file-writing harness to emit the `.agent-done` sentinel). Installs that carried an HTTP `api` provider (ollama / LM Studio) through migration 184 hit a dead end: every dispatch failed provider resolution *before* an agent registered, so nothing updated the task's status and it sat pending forever — silently blocking the app's whole improvement slot. Now the LI `buildTaskInput` hook detects an api-only provider up front and **skips** with an actionable reason (surfaced on the Intelligence tab: *"pick a CLI/TUI provider — e.g. the Claude Ollama sample"*), and, as a general safety net, any agent task that fails provider resolution with a **permanent** config error is **blocked** with a `provider-config` reason instead of re-failing on every dispatch.+## Features- **PortOS now installs a service worker for offline app-shell loading and low-bandwidth caching** — the modern replacement for the long-deprecated AppCache manifest. After the first online visit, the built app shell (`index.html`) and the content-hashed JS/CSS chunks are cached, so the UI loads instantly on repeat visits, keeps rendering when the server is briefly unreachable (flaky Tailnet links), and stops re-pulling megabytes of vendor JS on every navigation over a slow connection. Google Fonts and static public assets (icons, textures, manifest) are cached too. Real-time and large/dynamic routes — `/api/*`, `/socket.io/*`, and `/data/*` media — are **never** cached, so live data and streamed assets always hit the network (HTTP Range preserved for `/data`). Navigations stay network-first so a fresh build is always picked up when online, and the existing build-id / stale-chunk-reload machinery still handles "the server rebuilt while a tab was open." The worker registers only in a production **secure context** (HTTPS, or `localhost`) — it is a progressive enhancement that silently no-ops over a plain-HTTP Tailnet hostname and in the Vite dev server (where it also tears down any stale worker). Implemented as a hand-rolled worker (`client/public/sw.js`) with no new dependency; registration lives in `client/src/lib/registerServiceWorker.js`. The PWA manifest gained explicit `id`/`scope` for a deterministic installed-app identity.diff --git a/client/src/utils/layeredIntelligenceReasons.js b/client/src/utils/layeredIntelligenceReasons.jsindex f0f3481e0d..d04c953a53 100644--- a/client/src/utils/layeredIntelligenceReasons.js+++ b/client/src/utils/layeredIntelligenceReasons.js@@ -4,7 +4,8 @@// layeredIntelligenceHooks.js — `no-provider`, `unparseable-response`,// `no-proposal`, `scope-suppressed`, `file-failed`, `duplicate`,// `semantic-duplicate`, `tracker-read-failed`, `blocking-read-failed`,-// `jira-not-configured`, `blocking-open`, plus the synthesized `llm-error:<msg>`+// `jira-not-configured`, `provider-not-agent-capable`, `blocking-open`, plus the+// synthesized `llm-error:<msg>`// prefix) and consumed by BOTH the on-demand toast (useOnDemandTaskToast) and the// durable "Last run" status line (LayeredIntelligenceTab). Keeping the token→prose// map here — not forked per component — means a new server reason has exactly ONE@@ -27,7 +28,8 @@ const LI_REASON_LABELS = {'semantic-duplicate': 'the proposal closely matched an existing issue','tracker-read-failed': "couldn't read the issue tracker — it'll retry next run",'blocking-read-failed': "couldn't read blocking issues — it'll retry next run",- 'jira-not-configured': "Jira isn't fully configured for this app"+ 'jira-not-configured': "Jira isn't fully configured for this app",+ 'provider-not-agent-capable': 'the selected provider is an API-only model with no coding harness — pick a CLI/TUI provider (e.g. the Claude Ollama sample) for the reasoning agent'};const LLM_ERROR_PREFIX = 'llm-error:';diff --git a/client/src/utils/layeredIntelligenceReasons.test.js b/client/src/utils/layeredIntelligenceReasons.test.jsindex df440d347a..825833469f 100644--- a/client/src/utils/layeredIntelligenceReasons.test.js+++ b/client/src/utils/layeredIntelligenceReasons.test.js@@ -7,6 +7,11 @@ describe('formatLiReason', () => {expect(formatLiReason({ action: 'no-op', reason: 'no-provider' })).toMatch(/no AI provider/i);});+ it('glosses an api-only provider pinned to the reasoning agent', () => {+ expect(formatLiReason({ action: 'skipped', reason: 'provider-not-agent-capable' }))+ .toMatch(/API-only model with no coding harness — pick a CLI\/TUI provider/i);+ });+it('strips the llm-error prefix into a provider-error sentence', () => {expect(formatLiReason({ action: 'no-op', reason: 'llm-error: provider timeout' })).toBe('the AI provider errored — provider timeout');diff --git a/server/services/agentLifecycle.js b/server/services/agentLifecycle.jsindex 4170337294..30393d33a2 100644--- a/server/services/agentLifecycle.js+++ b/server/services/agentLifecycle.js@@ -294,6 +294,26 @@ export async function spawnAgentForTask(task) {const resolution = await resolveAgentProviderAndModel(task);if (!resolution.ok) {await cleanupOnError(resolution.error);+ // A PERMANENT provider-config failure (e.g. an `api`-only provider pinned+ // to an agent task, which has no file-writing harness) fails identically on+ // every re-dispatch. Leaving the task pending makes it silently re-fail+ // forever AND wedge its app's single improvement slot. Block it with an+ // actionable reason so it stops re-dispatching and surfaces in the UI —+ // `...buildRelease()` keeps the federation claim cleared (cleanupOnError+ // released it in persistence; the in-memory metadata spread would otherwise+ // re-introduce it). Transient failures stay non-permanent and still retry.+ if (resolution.permanent) {+ await updateTask(task.id, {+ status: 'blocked',+ metadata: {+ ...task.metadata,+ ...buildRelease(),+ blockedReason: resolution.error,+ blockedCategory: 'provider-config',+ blockedAt: new Date().toISOString()+ }+ }, task.taskType || 'user').catch(() => {});+ }cosEvents.emit('agent:error', {taskId: task.id,error: resolution.error,diff --git a/server/services/agentLifecycle.test.js b/server/services/agentLifecycle.test.jsindex 8acaebdb15..a0557aed7b 100644--- a/server/services/agentLifecycle.test.js+++ b/server/services/agentLifecycle.test.js@@ -380,6 +380,24 @@ describe('agentLifecycle source — app-review marker release (issue #989)', ()});});+// ─── spawnAgentForTask — permanent provider-config failure blocks the task ───+//+// A resolution failure marked `permanent` (an api-only provider pinned to an+// agent task, which has no file-writing harness) fails identically on every+// re-dispatch. Without a block, the task stays pending and silently re-fails+// forever — the layered-intelligence "sits pending, never picked up" bug. Pin+// that the permanent branch flips the task to blocked so it stops re-dispatching.+describe('agentLifecycle source — permanent provider-config failure blocks the task', () => {+ it('the resolution-failure path blocks a permanent failure with a provider-config reason', () => {+ const idx = AGENT_LIFECYCLE_SRC.indexOf('const resolution = await resolveAgentProviderAndModel(task)');+ expect(idx, 'resolution call must exist').toBeGreaterThan(-1);+ const body = AGENT_LIFECYCLE_SRC.slice(idx, idx + 1200);+ expect(body, 'gates the block on resolution.permanent').toMatch(/if\s*\(resolution\.permanent\)/);+ expect(body, 'flips the task to blocked').toMatch(/status:\s*'blocked'/);+ expect(body, 'tags the block category').toMatch(/blockedCategory:\s*'provider-config'/);+ });+});+// ─── spawnAgentForTask — cleanupOnError ────────────────────────────────────//// `spawnAgentForTask` has ~400 LOC of async work betweendiff --git a/server/services/agentProviderResolution.js b/server/services/agentProviderResolution.jsindex 6351c523bb..104a919931 100644--- a/server/services/agentProviderResolution.js+++ b/server/services/agentProviderResolution.js@@ -100,6 +100,10 @@ export async function resolveAgentProviderAndModel(task) {if (provider.type === 'api') {return {ok: false,+ // PERMANENT config error: this resolves the same way on every re-dispatch+ // (an api provider is never gaining a harness), so the caller must retire+ // the task rather than leave it pending to silently re-fail forever.+ permanent: true,error: `Provider "${provider.id}" is an HTTP API provider with no file-writing harness — CoS agent tasks need a CLI/TUI coding provider (claude, codex, or the "Claude Ollama" Claude-on-Ollama sample).`,providerId: provider.id};diff --git a/server/services/agentProviderResolution.test.js b/server/services/agentProviderResolution.test.jsindex 2e8e51678d..d814ab4793 100644--- a/server/services/agentProviderResolution.test.js+++ b/server/services/agentProviderResolution.test.js@@ -161,6 +161,9 @@ describe('resolveAgentProviderAndModel', () => {expect(r.ok).toBe(false);expect(r.providerId).toBe('ollama');expect(r.error).toContain('no file-writing harness');+ // Marked permanent so the spawn caller retires the task instead of leaving+ // it pending to silently re-fail on every re-dispatch.+ expect(r.permanent).toBe(true);// Guard fires before model selection — never spawns.expect(selectModelForTask).not.toHaveBeenCalled();});@@ -178,6 +181,7 @@ describe('resolveAgentProviderAndModel', () => {expect(r.ok).toBe(false);expect(r.providerId).toBe('lmstudio');expect(r.error).toContain('no file-writing harness');+ expect(r.permanent).toBe(true);});it('falls back to the provider tier default when the selected model is not in the provider model list', async () => {diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.js b/server/services/autonomousJobs/layeredIntelligenceHooks.jsindex 138f6dd3ce..9ef99b2777 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.js@@ -163,6 +163,20 @@ export async function buildTaskInput({ app } = {}) {return { skip: { reason } }}+ // The reasoning agent needs a file-writing CLI/TUI harness to emit its+ // `.agent-done` sentinel — an HTTP `api` provider (ollama / lmstudio / kimi)+ // has none, so an agent-backed run pinned to one fails provider resolution and+ // the task sits pending forever (pre-#2322 LI called the API path directly, so+ // installs routinely carried an api provider through migration 184). Skip with+ // an actionable reason instead of generating a doomed task. `providerId` is the+ // per-app override overlaid in resolveLiContext (the documented home for LI's+ // provider); a null/absent one inherits the default coding agent and is fine.+ if (config.providerId) {+ const { getProviderById } = await import('../providers.js')+ const provider = await getProviderById(config.providerId).catch(() => null)+ if (provider?.type === 'api') return skip('skipped', 'provider-not-agent-capable')+ }+// A jira-tracked app with no usable instance/project can't file — skip before// burning an agent on a result we couldn't land.if (filer === 'jira' && !jira) return skip('skipped', 'jira-not-configured')diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js b/server/services/autonomousJobs/layeredIntelligenceHooks.test.jsindex 3c60bc4436..c9a2114395 100644--- a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.test.js@@ -16,6 +16,13 @@ vi.mock('../../lib/fileUtils.js', () => ({tryReadFile: vi.fn().mockResolvedValue(null)}));+// The provider-type guard in buildTaskInput looks the pinned provider up to+// reject an api-only (harnessless) provider. Default to a CLI provider so the+// happy path passes; the dedicated test overrides it to an api provider.+vi.mock('../providers.js', () => ({+ getProviderById: vi.fn(async (id) => ({ id, type: 'cli' }))+}));+vi.mock('../layeredIntelligence.js', () => ({getEffectiveConfig: vi.fn(() => ({ providerId: 'ollama', model: 'qwen', allowedScopes: ['app-improvement'], sources: {} })),buildPrompt: vi.fn(() => 'REASONING PROMPT'),@@ -47,12 +54,14 @@ import { buildTaskInput, processTaskOutput } from './layeredIntelligenceHooks.jsimport * as li from '../layeredIntelligence.js';import * as apps from '../apps.js';import { resolveAppWorkTracker } from '../../lib/workTracker.js';+import { getProviderById } from '../providers.js';const APP = { id: 'app-1', name: 'App One', repoPath: '/repo', taskTypeOverrides: {} };beforeEach(() => {vi.clearAllMocks();resolveAppWorkTracker.mockResolvedValue({ resolved: 'github', forge: 'gh' });+ getProviderById.mockImplementation(async (id) => ({ id, type: 'cli' }));li.getEffectiveConfig.mockReturnValue({ providerId: 'ollama', model: 'qwen', allowedScopes: ['app-improvement'], sources: {} });li.filerForTracker.mockImplementation((r) => (r === 'github' || r === 'gitlab') ? 'forge' : (r === 'jira' ? 'jira' : 'plan'));li.trackerSupportsPause.mockImplementation((r) => r !== 'plan');@@ -79,6 +88,23 @@ describe('buildTaskInput', () => {expect(await buildTaskInput({ app: APP })).toEqual({ skip: { reason: 'blocking-read-failed' } });});+ it('skips when the pinned provider is an api-only (harnessless) provider', async () => {+ getProviderById.mockResolvedValue({ id: 'ollama', type: 'api' });+ const res = await buildTaskInput({ app: APP });+ expect(res).toEqual({ skip: { reason: 'provider-not-agent-capable' } });+ // Short-circuits before any tracker/source I/O — nothing doomed is built.+ expect(li.gatherSources).not.toHaveBeenCalled();+ expect(li.listBlockingIssues).not.toHaveBeenCalled();+ });++ it('proceeds when no provider is pinned (inherits the default coding agent)', async () => {+ li.getEffectiveConfig.mockReturnValue({ providerId: null, model: null, allowedScopes: ['app-improvement'], sources: {} });+ const res = await buildTaskInput({ app: APP });+ expect(res.skip).toBeUndefined();+ expect(getProviderById).not.toHaveBeenCalled();+ expect(res.prompt).toContain('REASONING PROMPT');+ });+it('skips a jira-tracked app with no usable jira config', async () => {resolveAppWorkTracker.mockResolvedValue({ resolved: 'jira', forge: null });const res = await buildTaskInput({ app: { ...APP, jira: { enabled: false } } });