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

surface provider-resolution errors when force-spawning a pending CoS task

[._.]/ Adam Eivyd27ffeff7235
diff --git a/server/services/cos.js b/server/services/cos.js
index 6420fa3297..d80b9f0135 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -73,6 +73,7 @@ const RECENT_COMPLETION_GRACE_MS = 60_000;
// Internal imports for functions used in this module
import { pruneOldAgentArchives, archiveStaleAgents as _archiveStaleAgents, loadAgentIndex } from './cosAgents.js';
+import { resolveAgentProviderAndModel } from './agentProviderResolution.js';
// Task generation + evaluation engine (extracted to cosTaskGenerator.js).
// `evaluateTasks` and the generators emit `task:ready`; the spawn-side
@@ -473,6 +474,18 @@ export async function forceSpawnTask(taskId) {
return { error: `No available agent slots (${runningAgents}/${state.config.maxConcurrentAgents})` };
}
+ // Pre-validate provider/model resolution before emitting `task:ready`. The
+ // actual spawn runs asynchronously in a `task:ready` listener, so a
+ // resolution failure there (e.g. a task pinned to an `api`-type provider with
+ // no file-writing harness) would bail silently and leave the task `pending`
+ // — while this call had already returned `{ success: true }` and the UI
+ // toasted "Spawning". Resolving here surfaces the real, actionable error
+ // (which provider to use) synchronously instead of lying to the user.
+ const resolution = await resolveAgentProviderAndModel(task);
+ if (!resolution.ok) {
+ return { error: resolution.error };
+ }
+
cosEvents.emit('task:ready', { ...task, taskType: task.taskType || 'internal' });
return { success: true, taskId };
}
diff --git a/server/services/cos.test.js b/server/services/cos.test.js
index c872bd3e7a..3127f3f251 100644
--- a/server/services/cos.test.js
+++ b/server/services/cos.test.js
@@ -1083,6 +1083,35 @@ describe('cos.js source — priority + capacity invariants', () => {
});
});
+describe('forceSpawnTask — pre-validate provider before task:ready', () => {
+ // The play button on a pending task calls forceSpawnTask, which emits
+ // `task:ready`; the actual spawn happens asynchronously in a listener. If
+ // provider/model resolution fails there (e.g. the task is pinned to an
+ // `api`-type provider with no file-writing harness), the spawn bails
+ // silently and the task stays `pending` — but the HTTP call had already
+ // returned `{ success: true }` and the UI toasted "Spawning". Pin that
+ // forceSpawnTask resolves the provider FIRST and returns the resolution
+ // error (so the route surfaces a truthful 400) instead of emitting
+ // `task:ready` on a doomed spawn.
+ const forceFn = extractFnBody(COS_SRC, COS_SRC.indexOf('export async function forceSpawnTask'));
+
+ it('calls resolveAgentProviderAndModel and returns its error', () => {
+ expect(forceFn, 'forceSpawnTask must pre-resolve the provider/model')
+ .toMatch(/resolveAgentProviderAndModel\(\s*task\s*\)/);
+ expect(forceFn, 'forceSpawnTask must return the resolution error on failure')
+ .toMatch(/if\s*\(\s*!\s*resolution\.ok\s*\)\s*\{\s*return\s*\{\s*error:\s*resolution\.error\s*\}/);
+ });
+
+ it('bails on a failed resolution BEFORE emitting task:ready', () => {
+ const resolveIdx = forceFn.indexOf('resolveAgentProviderAndModel');
+ const readyIdx = forceFn.indexOf("cosEvents.emit('task:ready'");
+ expect(resolveIdx, 'resolution must happen in forceSpawnTask').toBeGreaterThan(-1);
+ expect(readyIdx, 'forceSpawnTask must still emit task:ready on success').toBeGreaterThan(-1);
+ expect(resolveIdx, 'provider resolution must precede the task:ready emit')
+ .toBeLessThan(readyIdx);
+ });
+});
+
describe('addTask — first-line dedup', () => {
it('returns the first non-empty trimmed line', () => {
expect(firstLine('hello\nworld')).toBe('hello');