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

fix: log next task type selection failures instead of silently skipping apps (#11444)

[._.]/ Adam Eivy4abd9ce4095c
diff --git a/server/services/cosTaskGenerator.js b/server/services/cosTaskGenerator.js
index aef296166c..c579f667b3 100644
--- a/server/services/cosTaskGenerator.js
+++ b/server/services/cosTaskGenerator.js
@@ -1323,7 +1323,10 @@ export async function queueEligibleImprovementTasks(state, cosTaskData, {
const nextTypeResult = cronTasks.length === 0
? await getNextTaskType(app.id, {
perpetualOnly: onCooldown, continuingTaskType, dueTasks
- }).catch(() => null)
+ }).catch(err => {
+ emitLog('error', `Failed to select next improvement task type for ${app.name}: ${err.message}`, { appId: app.id });
+ return null;
+ })
: null;
const nextTypes = cronTasks.length > 0
? cronTasks.map(task => task.taskType)
diff --git a/server/services/cosTaskGenerator.nextTypeError.test.js b/server/services/cosTaskGenerator.nextTypeError.test.js
new file mode 100644
index 0000000000..a2899ddd95
--- /dev/null
+++ b/server/services/cosTaskGenerator.nextTypeError.test.js
@@ -0,0 +1,85 @@
+/**
+ * Improvement-queue selection failures are logged, not swallowed (#11444).
+ *
+ * `queueEligibleImprovementTasks` asks `getNextTaskType` for each app. A
+ * rejection there used to be `.catch(() => null)`, which skipped the app with
+ * no trace. These cases pin that the failure is logged with the app id and the
+ * error message, and that the per-app loop keeps going for the other apps.
+ *
+ * Isolated file so the taskSchedule double can't leak into the shared
+ * cosTaskGenerator suite.
+ */
+
+import { describe, it, expect, beforeEach, vi } from 'vitest';
+
+const emitLog = vi.fn();
+vi.mock('./cosEvents.js', async (importActual) => ({
+ ...(await importActual()),
+ cosEvents: { emit: vi.fn(), on: vi.fn() },
+ emitLog: (...args) => emitLog(...args),
+}));
+
+const getNextTaskType = vi.fn();
+vi.mock('./taskSchedule.js', async (importActual) => ({
+ ...(await importActual()),
+ getDueTasks: vi.fn(async () => []),
+ getNextTaskType: (...args) => getNextTaskType(...args),
+ recordExecution: vi.fn(async () => {}),
+}));
+
+const APPS = [
+ { id: 'app-broken', name: 'Broken App' },
+ { id: 'app-ok', name: 'Healthy App' },
+];
+vi.mock('./apps.js', async (importActual) => ({
+ ...(await importActual()),
+ getActiveApps: vi.fn(async () => APPS),
+}));
+
+vi.mock('./appActivity.js', async (importActual) => ({
+ ...(await importActual()),
+ loadAppActivity: vi.fn(async () => ({ apps: {} })),
+}));
+
+vi.mock('./cosState.js', async (importActual) => ({
+ ...(await importActual()),
+ isImprovementEnabled: vi.fn(() => true),
+}));
+
+const { queueEligibleImprovementTasks } = await import('./cosTaskGenerator.js');
+
+const state = { config: {} };
+const cosTaskData = { tasks: [] };
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ getNextTaskType.mockImplementation(async (appId) => {
+ if (appId === 'app-broken') throw new Error('schedule descriptor is malformed');
+ return { taskType: 'security' };
+ });
+});
+
+describe('queueEligibleImprovementTasks next-type selection failures', () => {
+ it('logs the app id and error message when getNextTaskType rejects, and keeps evaluating other apps', async () => {
+ // Injected preparer: returning no task keeps the test off the spawn/persist path.
+ const prepareTask = vi.fn(async () => ({ task: null }));
+ const persistTask = vi.fn();
+
+ await expect(queueEligibleImprovementTasks(state, cosTaskData, {
+ prepareTask, persistTask,
+ })).resolves.toBeUndefined();
+
+ expect(emitLog).toHaveBeenCalledWith(
+ 'error',
+ expect.stringContaining('schedule descriptor is malformed'),
+ { appId: 'app-broken' }
+ );
+ expect(emitLog.mock.calls.find(([level]) => level === 'error')[1]).toContain('Broken App');
+
+ // The failed app produced no task, but the loop still reached the healthy app.
+ expect(prepareTask).toHaveBeenCalledTimes(1);
+ expect(prepareTask.mock.calls[0][0]).toBe('security');
+ expect(prepareTask.mock.calls[0][1]).toMatchObject({ id: 'app-ok' });
+ expect(persistTask).not.toHaveBeenCalled();
+ });
+});