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

address review (codex): permanent when directly-resolved provider is api; preflight global LI provider

[._.]/ Adam Eivyddc030cf3bff
diff --git a/server/services/agentProviderResolution.js b/server/services/agentProviderResolution.js
index 0bc3cfdd6e..1d35f8fbc3 100644
--- a/server/services/agentProviderResolution.js
+++ b/server/services/agentProviderResolution.js
@@ -51,17 +51,21 @@ export async function resolveAgentProviderAndModel(task) {
return { ok: false, error: 'No active AI provider configured' };
}
+ // Type of the DIRECTLY-resolved (pinned/active) provider, captured before any
+ // fallback swap below. It gates the "permanent" flag on the api-type rejection:
+ // an api provider is permanent (a config error that re-fails identically
+ // forever) ONLY when the task was directly resolved onto an api provider — i.e.
+ // the pinned/active provider is itself api. A fallback that lands on an api
+ // provider is instead judged by THIS type: a CLI primary that's momentarily
+ // unavailable (directType 'cli') may recover, so its api fallback is transient
+ // and stays retryable; but an api primary whose fallback is also api (directType
+ // 'api') can never gain a harness, so it stays permanent (no infinite retry).
+ const directProviderType = provider.type;
// Check provider availability (usage limits, rate limits, etc.)
// Set when we fall back below to a provider with a configured "Fallback
// Model" pin — it overrides the usual per-task model selection so the
// user's chosen fallback provider+model pair is honored on agent runs.
let fallbackModelPin = null;
- // Whether `provider` below is a FALLBACK selection (the directly-resolved
- // pinned/active provider was unavailable) rather than the provider the task
- // actually asked for. It gates the "permanent" flag on the api-type rejection:
- // a fallback-selected api provider is a TRANSIENT condition (the primary CLI
- // provider may recover), so the task must stay retryable, not be blocked.
- let usedFallback = false;
const providerAvailable = isProviderAvailable(provider.id);
if (!providerAvailable) {
const status = getProviderStatus(provider.id);
@@ -89,7 +93,6 @@ export async function resolveAgentProviderAndModel(task) {
});
provider = fallbackResult.provider;
fallbackModelPin = fallbackResult.model || null;
- usedFallback = true;
} else {
const errorMsg = `Provider ${provider.id} unavailable (${status.message}) and no fallback available`;
return { ok: false, error: errorMsg, providerId: provider.id, providerStatus: status };
@@ -107,14 +110,13 @@ export async function resolveAgentProviderAndModel(task) {
if (provider.type === 'api') {
return {
ok: false,
- // PERMANENT config error ONLY when this api provider was the directly-
- // resolved (pinned or active) one — it resolves identically on every
- // re-dispatch (an api provider never gains a harness), so the caller must
- // retire the task rather than leave it silently re-failing forever. A
- // fallback-selected api provider is instead TRANSIENT: the primary CLI
- // provider that was momentarily unavailable may recover, so the task must
- // stay retryable rather than be blocked (a blocked task is never retried).
- permanent: !usedFallback,
+ // PERMANENT config error when the DIRECTLY-resolved (pinned/active) provider
+ // was itself api — no CLI/TUI harness is reachable for this task no matter
+ // how many times it re-dispatches, so the caller must retire it rather than
+ // leave it silently re-failing forever. An api provider reached by falling
+ // back from a CLI primary (directProviderType 'cli') is instead TRANSIENT:
+ // the primary may recover, so the task stays retryable.
+ permanent: directProviderType === 'api',
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.js
index 687ba54584..09a841814d 100644
--- a/server/services/agentProviderResolution.test.js
+++ b/server/services/agentProviderResolution.test.js
@@ -168,7 +168,7 @@ describe('resolveAgentProviderAndModel', () => {
expect(selectModelForTask).not.toHaveBeenCalled();
});
- it('rejects an api-type provider even when reached via the fallback chain', async () => {
+ it('rejects an api fallback from a CLI primary but keeps it retryable (transient)', async () => {
const primary = { id: 'p1', type: 'cli' };
const apiFallback = { id: 'lmstudio', type: 'api', models: ['m'] };
getActiveProvider.mockResolvedValue(primary);
@@ -181,11 +181,28 @@ describe('resolveAgentProviderAndModel', () => {
expect(r.ok).toBe(false);
expect(r.providerId).toBe('lmstudio');
expect(r.error).toContain('no file-writing harness');
- // NOT permanent: the primary CLI provider was only momentarily unavailable
- // and may recover, so the task must stay retryable rather than be blocked.
+ // NOT permanent: the directly-resolved primary was a CLI provider that was only
+ // momentarily unavailable and may recover, so the task must stay retryable.
expect(r.permanent).toBe(false);
});
+ it('marks an api fallback from an api primary PERMANENT (no CLI path can ever resolve)', async () => {
+ const apiPrimary = { id: 'ollama', type: 'api', models: ['q'] };
+ const apiFallback = { id: 'lmstudio', type: 'api', models: ['m'] };
+ getActiveProvider.mockResolvedValue(apiPrimary);
+ isProviderAvailable.mockReturnValue(false);
+ getProviderStatus.mockReturnValue({ message: 'down', reason: 'x' });
+ getAllProviders.mockResolvedValue({ providers: [apiPrimary, apiFallback] });
+ getFallbackProvider.mockResolvedValue({ provider: apiFallback, model: 'm', source: 'provider' });
+
+ const r = await resolveAgentProviderAndModel(TASK);
+ expect(r.ok).toBe(false);
+ expect(r.providerId).toBe('lmstudio');
+ // Both primary and fallback are api — no harness is reachable no matter how
+ // often it retries, so it must be retired, not left pending forever.
+ 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 () => {
const provider = { id: 'p1', type: 'cli', models: ['only-this'], heavyModel: 'heavy-x' };
getActiveProvider.mockResolvedValue(provider);
diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.js b/server/services/autonomousJobs/layeredIntelligenceHooks.js
index 9ef99b2777..f4d67d334b 100644
--- a/server/services/autonomousJobs/layeredIntelligenceHooks.js
+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.js
@@ -167,13 +167,25 @@ export async function buildTaskInput({ app } = {}) {
// `.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) {
+ // installs routinely carried an api provider through migration 184). Preflight
+ // the EFFECTIVE agent provider — the per-app override (config.providerId, the
+ // documented home for LI's provider) OR, when unset, the global schedule pin the
+ // generator applies (interval.providerId) — and skip with an actionable reason
+ // instead of generating a doomed task the lifecycle path would only block. A
+ // null/absent effective provider inherits the default coding agent and is fine;
+ // a spawn-time api resolution (e.g. an api ACTIVE provider) still falls to the
+ // lifecycle block. A pinned api provider is skipped even if it's momentarily
+ // unavailable with a CLI fallback — guiding the user to a real CLI/TUI provider
+ // beats silently running LI on a provider they didn't choose.
+ let effectiveProviderId = config.providerId || null
+ if (!effectiveProviderId) {
+ const { loadSchedule } = await import('../taskSchedule.js')
+ const schedule = await loadSchedule().catch(() => null)
+ effectiveProviderId = schedule?.tasks?.['layered-intelligence']?.providerId || null
+ }
+ if (effectiveProviderId) {
const { getProviderById } = await import('../providers.js')
- const provider = await getProviderById(config.providerId).catch(() => null)
+ const provider = await getProviderById(effectiveProviderId).catch(() => null)
if (provider?.type === 'api') return skip('skipped', 'provider-not-agent-capable')
}
diff --git a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js b/server/services/autonomousJobs/layeredIntelligenceHooks.test.js
index c9a2114395..186b4f152d 100644
--- a/server/services/autonomousJobs/layeredIntelligenceHooks.test.js
+++ b/server/services/autonomousJobs/layeredIntelligenceHooks.test.js
@@ -23,6 +23,12 @@ vi.mock('../providers.js', () => ({
getProviderById: vi.fn(async (id) => ({ id, type: 'cli' }))
}));
+// When no per-app provider is pinned, the guard falls back to the global LI
+// schedule provider. Default to no global pin so the no-provider path stays inert.
+vi.mock('../taskSchedule.js', () => ({
+ loadSchedule: vi.fn(async () => ({ tasks: { 'layered-intelligence': {} } }))
+}));
+
vi.mock('../layeredIntelligence.js', () => ({
getEffectiveConfig: vi.fn(() => ({ providerId: 'ollama', model: 'qwen', allowedScopes: ['app-improvement'], sources: {} })),
buildPrompt: vi.fn(() => 'REASONING PROMPT'),
@@ -55,6 +61,7 @@ import * as li from '../layeredIntelligence.js';
import * as apps from '../apps.js';
import { resolveAppWorkTracker } from '../../lib/workTracker.js';
import { getProviderById } from '../providers.js';
+import { loadSchedule } from '../taskSchedule.js';
const APP = { id: 'app-1', name: 'App One', repoPath: '/repo', taskTypeOverrides: {} };
@@ -62,6 +69,7 @@ beforeEach(() => {
vi.clearAllMocks();
resolveAppWorkTracker.mockResolvedValue({ resolved: 'github', forge: 'gh' });
getProviderById.mockImplementation(async (id) => ({ id, type: 'cli' }));
+ loadSchedule.mockResolvedValue({ tasks: { 'layered-intelligence': {} } });
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');
@@ -97,14 +105,24 @@ describe('buildTaskInput', () => {
expect(li.listBlockingIssues).not.toHaveBeenCalled();
});
- it('proceeds when no provider is pinned (inherits the default coding agent)', async () => {
+ it('proceeds when neither a per-app nor a global 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();
+ // Falls back to the global schedule pin (none here), so no provider lookup.
expect(getProviderById).not.toHaveBeenCalled();
expect(res.prompt).toContain('REASONING PROMPT');
});
+ it('skips on an api-only GLOBAL schedule provider when no per-app provider is pinned', async () => {
+ li.getEffectiveConfig.mockReturnValue({ providerId: null, model: null, allowedScopes: ['app-improvement'], sources: {} });
+ loadSchedule.mockResolvedValue({ tasks: { 'layered-intelligence': { providerId: 'ollama' } } });
+ getProviderById.mockResolvedValue({ id: 'ollama', type: 'api' });
+ const res = await buildTaskInput({ app: APP });
+ expect(res).toEqual({ skip: { reason: 'provider-not-agent-capable' } });
+ expect(getProviderById).toHaveBeenCalledWith('ollama');
+ });
+
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 } } });