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: validate execution fields before saving CoS schedules (#9454)
[._.]/ Adam Eivy4624623a85af
diff --git a/server/lib/README.md b/server/lib/README.mdindex 7ae0e15e43..9c006136fd 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -506,6 +506,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `taskTargetBranch.js` | Pure task-branch contract: `resolveTaskTargetBranch(metadata)` reads a retry's legacy `existingBranch` or a review-loop follow-up's canonical `reviewLoopPRBranch`; `shouldStripTaskTargetBranch(metadata)` identifies only retry-owned pointers for terminal cleanup. || `claimContinuation.js` | Claim-flow relaunch pointer. `claimContinuationBranch(claimTarget)` is the `claim/issue-<n>` or `claim/<key>` branch a pinned target checks out. `claimContinuationPointer(...)` names the `claim-*` worktree already holding that branch when a relaunch should finish it in place (locked, prunable, unmanaged, or occupied by another running/paused agent → null). `claimContinuationWorkspace(...)` turns a still-on-disk pointer into the cwd the next agent uses without moving the directory. || `scheduledTaskTypes.js` | Registered scheduled task names (`SELF_IMPROVEMENT_TASK_TYPES`), shared by schedule configuration and authoritative skill routing; plus the retired-name map (`TASK_TYPE_RENAMES`, `currentTaskTypeName`, `taskExecutionKey`) for tasks and records written before a task rename. |+| `scheduleExecutionFieldsValidation.js` | `scheduleExecutionFieldsSchema` validates optional prompt and provider/model selections before schedule writes, preserving null/empty clears. || `scheduleRunOrder.js` | Storage rules for a task's advisory `suggestedAfter` list — which OTHER scheduled tasks to run first. `normalizeSuggestedAfter` drops blanks, duplicates and self-references and caps at `SUGGESTED_AFTER_MAX`; the shipped order it defaults to is `auditCatalog.AUDIT_SUGGESTED_AFTER`, layered at read time in `getScheduleStatus`. Advisory only — the ENFORCED dependency field is `runAfter`. Pure — no I/O. || `taskReadinessReasons.js` | Stable scheduled-task readiness reason codes, membership set, shared by the server and Schedule UI (pure browser-safe leaf). || `taskTargetScope.js` | Target scope for a scheduled task type: `INSTALL_WIDE_TASK_TYPES`, `MANAGED_APP_TARGET_TASK_TYPES`, `PROGRAMMATIC_SCHEDULED_TASK_TYPES`, `isProgrammaticScheduledTaskType`, `requiresManagedAppTarget`, `requiresInstallWideTarget`. Declared here (not in `services/taskScheduleRegistry.js`, which re-exports it) so `quotaBurnValidation.js` can reject a burn reference with the wrong target scope without importing upward into services. |diff --git a/server/lib/cosValidation.js b/server/lib/cosValidation.jsindex f1e573f9c6..a27e994822 100644--- a/server/lib/cosValidation.js+++ b/server/lib/cosValidation.js@@ -51,6 +51,8 @@ import {resolveReviewUsernames,} from './reviewerConfig.js';+export { scheduleExecutionFieldsSchema } from './scheduleExecutionFieldsValidation.js';+export { TASK_DATA_INPUT_DEFINITIONS, TASK_DATA_INPUT_IDS } from './taskDataInputCatalog.js';// Transitional shim: the reviewer vocabulary lives in reviewerConfig.js but is// still reachable from every existing `cosValidation.js` / `validation.js` import.diff --git a/server/lib/index.js b/server/lib/index.jsindex 7721fd29a7..e9c9b5e3df 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -808,3 +808,5 @@ export * from './codeAnimationProjects.js';export * from './musicVideoNarrativeEvents.js';export * from './persistentMindContextEvents.js';++export * from './scheduleExecutionFieldsValidation.js';diff --git a/server/lib/scheduleExecutionFieldsValidation.js b/server/lib/scheduleExecutionFieldsValidation.jsnew file mode 100644index 0000000000..0220bd2b5d--- /dev/null+++ b/server/lib/scheduleExecutionFieldsValidation.js@@ -0,0 +1,9 @@+import { z } from 'zod';+import { providerRefFieldSchema } from './zodCompat.js';++// Optional fields preserve omitted values; null/empty selections clear overrides.+export const scheduleExecutionFieldsSchema = z.object({+ prompt: z.string().nullable().optional(),+ providerId: providerRefFieldSchema.nullable().optional(),+ model: z.string().nullable().optional(),+});diff --git a/server/routes/cosScheduleRoutes.js b/server/routes/cosScheduleRoutes.jsindex e29516544a..391516df55 100644--- a/server/routes/cosScheduleRoutes.js+++ b/server/routes/cosScheduleRoutes.js@@ -9,7 +9,7 @@ import * as taskSchedule from '../services/taskSchedule.js';import { logCosScheduleUpdate } from '../services/userActionScheduleLog.js';import { asyncHandler, ServerError } from '../lib/errorHandler.js';import { sanitizeTaskMetadata, taskDataInputsSchema, validateRequest, parsePagination } from '../lib/validation.js';-import { promptSourceSchema, PROMPT_SOURCES } from '../lib/cosValidation.js';+import { promptSourceSchema, PROMPT_SOURCES, scheduleExecutionFieldsSchema } from '../lib/cosValidation.js';import { EFFORT_LEVELS } from '../lib/providerModels.js';import { INTERVAL_TYPES, decodeIntervalType, isCronExpression, isKnownIntervalType } from '../services/taskScheduleConstants.js';import { normalizeSuggestedAfter, SUGGESTED_AFTER_MAX } from '../lib/scheduleRunOrder.js';@@ -77,10 +77,12 @@ const SCHEDULE_FIELDS = ['type', 'autoStart', 'perpetual', 'enabled', 'intervalM* `suggestedAfter`) can be cleaned here rather than again at the call site.*/function pickScheduleSettings(body, taskType) {+ const executionFields = validateRequest(scheduleExecutionFieldsSchema, body);const settings = {};for (const key of SCHEDULE_FIELDS) {if (body[key] !== undefined) settings[key] = body[key];}+ Object.assign(settings, executionFields);if (settings.enabled !== undefined && typeof settings.enabled !== 'boolean') {throw new ServerError('enabled must be a boolean', { status: 400, code: 'VALIDATION_ERROR' });}diff --git a/server/routes/cosScheduleRoutes.test.js b/server/routes/cosScheduleRoutes.test.jsindex 53710d9396..5ea766ebde 100644--- a/server/routes/cosScheduleRoutes.test.js+++ b/server/routes/cosScheduleRoutes.test.js@@ -166,6 +166,30 @@ describe('CoS Schedule Routes', () => {});describe('PUT /api/cos/schedule/task/:taskType', () => {+ it('rejects malformed execution fields before writing any schedule settings', async () => {+ for (const field of ['prompt', 'providerId', 'model']) {+ for (const value of [{ text: 'Example prompt' }, ['example'], true, 42]) {+ const response = await request(app).put('/api/cos/schedule/task/documentation').send({ [field]: value });+ expect(response.status).toBe(400);+ expect(response.body.code).toBe('VALIDATION_ERROR');+ }+ }+ expect(taskSchedule.updateTaskInterval).not.toHaveBeenCalled();+ });++ it('preserves valid execution fields, picker clears, and omitted values', async () => {+ taskSchedule.updateTaskInterval.mockResolvedValue({});+ for (const fields of [+ { prompt: ' Example custom prompt ', providerId: 'example-provider', model: 'example-model' },+ { prompt: null, providerId: null, model: null },+ { prompt: '', providerId: '', model: '' },+ { enabled: true },+ ]) {+ expect((await request(app).put('/api/cos/schedule/task/documentation').send(fields)).status).toBe(200);+ expect(taskSchedule.updateTaskInterval).toHaveBeenLastCalledWith('documentation', fields);+ }+ });+it('should update interval for task type', async () => {taskSchedule.updateTaskInterval.mockResolvedValue({ type: 'daily' });diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex c069d08c04..d3f8d21eca 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -19,6 +19,8 @@* perpetual gate in cosTaskGenerator.prepareManagedAppImprovementTask.*/+import { scheduleExecutionFieldsSchema } from '../lib/scheduleExecutionFieldsValidation.js';+import { ServerError } from '../lib/errorHandler.js';import { taskExecutionKey as executionKey } from '../lib/scheduledTaskTypes.js';import { TASK_READINESS_REASON } from '../lib/taskReadinessReasons.js';import { cosEvents, emitLog } from './cosEvents.js';@@ -190,6 +192,11 @@ export async function getTaskInterval(taskType) {}export async function updateTaskInterval(taskType, settings) {+ const executionFields = scheduleExecutionFieldsSchema.safeParse(settings);+ if (!executionFields.success) {+ throw new ServerError('Invalid schedule execution fields', { status: 400, code: 'VALIDATION_ERROR' });+ }+ settings = { ...settings, ...executionFields.data };const { task, unparkedScopes } = await updateSchedule(async (schedule) => {if (!schedule.tasks[taskType]) {schedule.tasks[taskType] = { type: INTERVAL_TYPES.ON_DEMAND, perpetual: false, enabled: false, providerId: null, model: null, createdAt: new Date().toISOString() };diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 1877268a07..52fec60299 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -1566,6 +1566,26 @@ describe('taskSchedule', () => {})})+ describe('execution field write safety', () => {+ it('keeps a persisted custom prompt readable after rejecting malformed updates', async () => {+ mockSchedule();+ await updateTaskInterval('documentation', { prompt: 'Example custom prompt', providerId: 'example-provider', model: 'example-model' });+ const saved = JSON.parse(writeFile.mock.calls.at(-1)[1]);+ const original = saved.tasks.documentation;+ readJSONFile.mockResolvedValue(saved);+ writeFile.mockClear();+ for (const field of ['prompt', 'providerId', 'model']) {+ for (const value of [{ text: 'Example malformed prompt' }, ['example'], true, 42]) {+ await expect(updateTaskInterval('documentation', { [field]: value })).rejects.toMatchObject({ status: 400, code: 'VALIDATION_ERROR' });+ }+ }+ expect(writeFile).not.toHaveBeenCalled();+ expect(saved.tasks.documentation).toEqual(original);+ expect(await getTaskPrompt('documentation')).toBe('Example custom prompt');+ expect(original).toMatchObject({ promptSource: 'user', providerId: 'example-provider', model: 'example-model' });+ });+ });+describe('getTaskPrompt', () => {it('should return default prompt when no custom prompt set', async () => {const prompt = await getTaskPrompt('security')