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: contain scheduled handler loading and execution failures
[._.]/ Adam Eivybc397977aa90
diff --git a/server/services/scheduledHandlers/index.js b/server/services/scheduledHandlers/index.jsindex 588d253588..39dc32c2c2 100644--- a/server/services/scheduledHandlers/index.js+++ b/server/services/scheduledHandlers/index.js@@ -68,9 +68,12 @@ const load = async (taskType) =>* broken handler can't wedge a burn family's whole plan or blank a status page.*/export async function countScheduledHandlerPending({ taskType, params, job, family } = {}) {- const mod = await load(taskType);- if (!mod) return { count: 0, detail: `unknown scheduled handler: ${taskType}` };- return mod.countPending({ params, job, family })+ // Include lazy module initialization and synchronous handler throws in the+ // same failure boundary as rejected handler promises.+ return load(taskType)+ .then((mod) => mod+ ? mod.countPending({ params, job, family })+ : { count: 0, detail: `unknown scheduled handler: ${taskType}` }).catch((err) => ({ count: 0, detail: `probe failed: ${err.message}` }));}@@ -80,8 +83,9 @@ export async function countScheduledHandlerPending({ taskType, params, job, fami* to start must not charge a quota window's cap.*/export async function runScheduledHandler({ taskType, params, job, family, context, force = false } = {}) {- const mod = await load(taskType);- if (!mod) return { dispatched: false, reason: `unknown scheduled handler: ${taskType}` };- return mod.run({ params, job, family, context, force })+ return load(taskType)+ .then((mod) => mod+ ? mod.run({ params, job, family, context, force })+ : { dispatched: false, reason: `unknown scheduled handler: ${taskType}` }).catch((err) => ({ dispatched: false, reason: `handler failed: ${err.message}` }));}diff --git a/server/services/scheduledHandlers/index.test.js b/server/services/scheduledHandlers/index.test.jsnew file mode 100644index 0000000000..e6961ad411--- /dev/null+++ b/server/services/scheduledHandlers/index.test.js@@ -0,0 +1,50 @@+import { afterEach, describe, expect, it, vi } from 'vitest';+import {+ SCHEDULED_HANDLER_MODULES,+ countScheduledHandlerPending,+ runScheduledHandler,+} from './index.js';++afterEach(() => vi.restoreAllMocks());++// This boundary owns failures from both lazy module initialization and handler+// execution; callers rely on a result to continue draining the remaining work.+describe.each([+ ['probe', countScheduledHandlerPending, 'countPending', { count: 0, detail: 'probe failed: unavailable' }],+ ['run', runScheduledHandler, 'run', { dispatched: false, reason: 'handler failed: unavailable' }],+])('scheduled handler %s', (_label, invoke, method, failure) => {+ const taskType = 'universe-bible-describe';++ it.each(['module load', 'synchronous execution', 'asynchronous execution'])('contains failure during %s', async (phase) => {+ const error = new Error('unavailable');+ const loader = vi.spyOn(SCHEDULED_HANDLER_MODULES, taskType);+ if (phase === 'module load') loader.mockRejectedValue(error);+ else loader.mockResolvedValue({+ [method]: phase === 'synchronous execution'+ ? () => { throw error; }+ : () => Promise.reject(error),+ });++ await expect(invoke({ taskType })).resolves.toEqual(failure);+ });++ it('preserves the handler result and invocation options', async () => {+ const result = method === 'run' ? { dispatched: true, summary: 'Started' } : { count: 2, context: { ids: ['entry-1'] } };+ const handler = vi.fn().mockResolvedValue(result);+ vi.spyOn(SCHEDULED_HANDLER_MODULES, taskType).mockResolvedValue({ [method]: handler });+ const options = { params: { maxEntries: 2 }, job: { model: 'example-model' }, family: { id: 'example-family' } };+ if (method === 'run') Object.assign(options, { context: { ids: ['entry-1'] }, force: true });++ await expect(invoke({ taskType, ...options })).resolves.toBe(result);+ expect(handler).toHaveBeenCalledWith(options);+ });++ it('declines inherited registry keys without loading a handler', async () => {+ const loader = vi.spyOn(SCHEDULED_HANDLER_MODULES, taskType);+ const message = 'unknown scheduled handler: constructor';+ await expect(invoke({ taskType: 'constructor' })).resolves.toEqual(+ method === 'run' ? { dispatched: false, reason: message } : { count: 0, detail: message },+ );+ expect(loader).not.toHaveBeenCalled();+ });+});