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
feat: distinguish a user-pinned scheduled-task prompt from a legacy mis-flag (#5432)
[._.]/ Adam Eivye1c729f0c189
diff --git a/server/lib/apiRouteCatalog.generated.json b/server/lib/apiRouteCatalog.generated.jsonindex b482cd2d36..fdedefdc8a 100644--- a/server/lib/apiRouteCatalog.generated.json+++ b/server/lib/apiRouteCatalog.generated.json@@ -6018,7 +6018,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 95+ "line": 107}]},@@ -6029,7 +6029,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 129+ "line": 141}]},@@ -6040,7 +6040,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 135+ "line": 147}]},@@ -6051,7 +6051,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 219+ "line": 231}]},@@ -6062,7 +6062,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 157+ "line": 169}]},@@ -6073,7 +6073,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 163+ "line": 175}]},@@ -6084,7 +6084,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 173+ "line": 185}]},@@ -6095,7 +6095,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 108+ "line": 120}]},@@ -6106,7 +6106,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 116+ "line": 128}]},@@ -6117,7 +6117,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 188+ "line": 200}]},@@ -6128,7 +6128,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 194+ "line": 206}]},@@ -6139,7 +6139,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 209+ "line": 221}]},@@ -6150,7 +6150,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 142+ "line": 154}]},@@ -6491,7 +6491,7 @@"sources": [{"source": "server/routes/cosScheduleRoutes.js",- "line": 101+ "line": 113}]},diff --git a/server/lib/cosValidation.js b/server/lib/cosValidation.jsindex bb7015b005..a7b969da59 100644--- a/server/lib/cosValidation.js+++ b/server/lib/cosValidation.js@@ -1427,6 +1427,25 @@ export const createLoopSchema = z.object({runImmediately: z.boolean().optional(),});+// =============================================================================+// TASK SCHEDULE SCHEMAS+// =============================================================================++// Provenance of a schedule config's stored prompt. `promptCustomized` alone cannot+// tell a deliberate user pin from a flag the legacy migration inferred, so the+// self-heal in taskScheduleStore.js reads this instead (#5432):+// 'user' — written by updateTaskInterval from an explicit prompt write.+// 'legacy-inferred' — written by the legacy migration's "differs from every known+// shipped default" branch.+// Absent/null is pre-existing state and is treated as 'legacy-inferred', so an+// install upgrading into this keeps today's self-heal behavior. Additive and+// absent-tolerant, so no migration is required.+export const PROMPT_SOURCES = ['user', 'legacy-inferred'];++// Empty string from a client clears the provenance rather than 400ing, matching+// the clearable-null convention the other schedule overrides use.+export const promptSourceSchema = z.preprocess(emptyToNull, z.enum(PROMPT_SOURCES).nullable().optional());+// =============================================================================// COS JOB SCHEMAS// =============================================================================diff --git a/server/routes/cosScheduleRoutes.js b/server/routes/cosScheduleRoutes.jsindex c4081a96c8..35dd5505ab 100644--- a/server/routes/cosScheduleRoutes.js+++ b/server/routes/cosScheduleRoutes.js@@ -7,6 +7,7 @@ import { z } from 'zod';import * as taskSchedule from '../services/taskSchedule.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 { EFFORT_LEVELS } from '../lib/providerModels.js';const templateTaskSchema = z.object({@@ -24,7 +25,11 @@ const SCHEDULE_FIELDS = ['type', 'enabled', 'intervalMs', 'cronExpression', 'pro// Perpetual (drain-until-done) recheck cadence: after a perpetual task drains// its backlog and parks, it re-probes its work-detector on this cadence.// `recheckCron` (5-field) takes precedence over `recheckIntervalMs`.- 'recheckCron', 'recheckIntervalMs'];+ 'recheckCron', 'recheckIntervalMs',+ // Provenance of the stored prompt ('user' | 'legacy-inferred' | null). An+ // explicit prompt write re-stamps it below in updateTaskInterval, so a body+ // carrying it only matters when the prompt itself is not being changed.+ 'promptSource'];/*** Pick only defined values from body for schedule settings updates@@ -74,6 +79,13 @@ function pickScheduleSettings(body) {}settings.dataInputs = parsed.data;}+ if (settings.promptSource !== undefined) {+ const parsed = promptSourceSchema.safeParse(settings.promptSource);+ if (!parsed.success) {+ throw new ServerError(`promptSource must be one of ${PROMPT_SOURCES.join(', ')} or null`, { status: 400, code: 'VALIDATION_ERROR' });+ }+ settings.promptSource = parsed.data ?? null;+ }if (settings.effort !== undefined && settings.effort !== null && !EFFORT_LEVELS.includes(settings.effort)) {throw new ServerError(`effort must be one of ${EFFORT_LEVELS.join(', ')} or null`, { status: 400, code: 'VALIDATION_ERROR' });}diff --git a/server/routes/cosScheduleRoutes.test.js b/server/routes/cosScheduleRoutes.test.jsindex 5b8e89b8c8..7831677122 100644--- a/server/routes/cosScheduleRoutes.test.js+++ b/server/routes/cosScheduleRoutes.test.js@@ -176,6 +176,44 @@ describe('CoS Schedule Routes', () => {expect(response.status).toBe(400);expect(taskSchedule.updateTaskInterval).not.toHaveBeenCalled();});++ // promptSource carries the stored prompt's provenance (#5432). It must reach+ // updateTaskInterval, or a PUT that round-trips a task config would strip a+ // user's pin and hand the prompt back to the auto-upgrade.+ it('forwards a valid promptSource', async () => {+ taskSchedule.updateTaskInterval.mockResolvedValue({ type: 'weekly' });++ const response = await request(app)+ .put('/api/cos/schedule/task/documentation')+ .send({ promptSource: 'user' });++ expect(response.status).toBe(200);+ expect(taskSchedule.updateTaskInterval).toHaveBeenCalledWith('documentation', expect.objectContaining({+ promptSource: 'user'+ }));+ });++ it('normalizes an empty promptSource to null', async () => {+ taskSchedule.updateTaskInterval.mockResolvedValue({ type: 'weekly' });++ const response = await request(app)+ .put('/api/cos/schedule/task/documentation')+ .send({ promptSource: '' });++ expect(response.status).toBe(200);+ expect(taskSchedule.updateTaskInterval).toHaveBeenCalledWith('documentation', expect.objectContaining({+ promptSource: null+ }));+ });++ it('rejects an unknown promptSource', async () => {+ const response = await request(app)+ .put('/api/cos/schedule/task/documentation')+ .send({ promptSource: 'made-up' });++ expect(response.status).toBe(400);+ expect(taskSchedule.updateTaskInterval).not.toHaveBeenCalled();+ });});describe('GET /api/cos/schedule/due', () => {diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex b8f3491353..f2a4a1b862 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -161,8 +161,15 @@ export async function updateTaskInterval(taskType, settings) {}// If user is setting a custom prompt, mark it so auto-upgrade won't overwrite it.// If user clears the prompt (null), remove the customized flag to resume defaults.+ //+ // `promptSource` records that this write was an EXPLICIT user action, which is+ // what the store's self-heal reads to leave the pin alone (#5432). Without it,+ // pasting an older SHIPPED body into Settings → Scheduled Tasks was un-pinnable:+ // the self-heal saw a body matching a retired default, cleared the flag on the+ // next load, and the next PROMPT_VERSIONS bump overwrote the chosen text.if ('prompt' in settings) {settings.promptCustomized = settings.prompt != null;+ settings.promptSource = settings.prompt != null ? 'user' : null;}schedule.tasks[taskType] = {diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 3971afb2a0..4f0e8471ec 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -427,6 +427,108 @@ describe('taskSchedule', () => {})})+ describe('promptSource provenance (issue #5432)', () => {+ // The self-heal above clears promptCustomized whenever the stored prompt+ // byte-matches ANY shipped default (current or retired). That is right for a+ // flag the legacy migration guessed at, but it cannot tell that apart from a+ // user who deliberately pasted an older SHIPPED body into Settings →+ // Scheduled Tasks — that pin was cleared on the next load and the next+ // PROMPT_VERSIONS bump silently overwrote their chosen text. promptSource+ // records which of the two wrote the flag.+ const portosDocPrompt = PREVIOUS_DEFAULT_PROMPTS['documentation'].find((p) => p.includes('PortOS'))++ const loadDocumentation = async (config) => {+ mockSchedule({+ tasks: { 'documentation': { type: 'once', enabled: false, providerId: null, model: null, ...config } }+ })+ return (await loadSchedule()).tasks['documentation']+ }++ it('keeps a user-pinned retired default pinned instead of self-healing it', async () => {+ const task = await loadDocumentation({+ prompt: portosDocPrompt,+ promptVersion: 1,+ promptCustomized: true,+ promptSource: 'user'+ })+ expect(task.promptCustomized).toBe(true)+ expect(task.prompt).toBe(portosDocPrompt)+ })++ it('still self-heals a legacy-inferred flag on a retired default', async () => {+ const task = await loadDocumentation({+ prompt: portosDocPrompt,+ promptVersion: 1,+ promptCustomized: true,+ promptSource: 'legacy-inferred'+ })+ expect(task.promptCustomized).toBe(false)+ expect(task.prompt).toBe(DEFAULT_TASK_PROMPTS['documentation'])+ })++ // Every install that upgrades into this field carries no promptSource at all.+ // Absent must keep behaving exactly as it does today, or the upgrade itself+ // would freeze thousands of mis-flagged prompts on their retired bodies.+ it('treats an absent promptSource as legacy-inferred (self-heals, as today)', async () => {+ const task = await loadDocumentation({+ prompt: portosDocPrompt,+ promptVersion: 1,+ promptCustomized: true+ })+ expect(task.promptSource).toBeUndefined()+ expect(task.promptCustomized).toBe(false)+ expect(task.prompt).toBe(DEFAULT_TASK_PROMPTS['documentation'])+ })++ it('stamps legacy-inferred when the legacy migration flags an unrecognized body', async () => {+ const custom = 'A documentation prompt that matches no shipped default at all.'+ // No promptVersion → the legacy-migration branch runs.+ const task = await loadDocumentation({ prompt: custom })+ expect(task.promptCustomized).toBe(true)+ expect(task.promptSource).toBe('legacy-inferred')+ })++ it('drops a stale promptSource when the config has no prompt to pin', async () => {+ const task = await loadDocumentation({ prompt: null, promptSource: 'user' })+ expect(task.prompt).toBe(DEFAULT_TASK_PROMPTS['documentation'])+ expect(task.promptSource).toBeNull()+ })++ it('survives a PROMPT_VERSIONS bump when the pin is user-sourced', async () => {+ const original = PROMPT_VERSIONS['documentation']+ PROMPT_VERSIONS['documentation'] = original + 1+ try {+ const task = await loadDocumentation({+ prompt: portosDocPrompt,+ promptVersion: original,+ promptCustomized: true,+ promptSource: 'user'+ })+ expect(task.prompt).toBe(portosDocPrompt)+ expect(task.promptVersion).toBe(original)+ } finally {+ PROMPT_VERSIONS['documentation'] = original+ }+ })++ it('upgrades the same body across a bump when the pin is legacy-inferred', async () => {+ const original = PROMPT_VERSIONS['documentation']+ PROMPT_VERSIONS['documentation'] = original + 1+ try {+ const task = await loadDocumentation({+ prompt: portosDocPrompt,+ promptVersion: original,+ promptCustomized: true,+ promptSource: 'legacy-inferred'+ })+ expect(task.prompt).toBe(DEFAULT_TASK_PROMPTS['documentation'])+ expect(task.promptVersion).toBe(original + 1)+ } finally {+ PROMPT_VERSIONS['documentation'] = original+ }+ })+ })+describe('pre-unification prompt generations (self- + app-improvement split)', () => {// Before the two improvement schedules were unified, every basic task// shipped up to two bodies with different headers — `[Self-Improvement] …`@@ -614,6 +716,37 @@ describe('taskSchedule', () => {expect(result.promptCustomized).toBe(false)})+ // An explicit prompt write is the ONE source of a 'user' pin (#5432) — it is+ // what makes the store's self-heal leave a retired-but-deliberate body alone.+ it('should stamp promptSource "user" when a custom prompt is written', async () => {+ const result = await updateTaskInterval('security', {+ prompt: 'Custom security audit prompt'+ })+ expect(result.promptSource).toBe('user')+ })++ it('should clear promptSource when the prompt is set to null', async () => {+ const result = await updateTaskInterval('security', {+ prompt: null+ })+ expect(result.promptSource).toBeNull()+ })++ it('should preserve an existing pin when the write does not touch the prompt', async () => {+ mockSchedule({+ tasks: {+ 'security': {+ type: 'weekly', enabled: false, providerId: null, model: null,+ prompt: 'A pinned body that matches no shipped default.',+ promptVersion: 2, promptCustomized: true, promptSource: 'user'+ }+ }+ })+ const result = await updateTaskInterval('security', { enabled: true })+ expect(result.promptSource).toBe('user')+ expect(result.promptCustomized).toBe(true)+ })+it('should create new task entry for unknown type', async () => {const result = await updateTaskInterval('custom-type', {type: 'daily',diff --git a/server/services/taskScheduleStore.js b/server/services/taskScheduleStore.jsindex a626be131c..93a8346502 100644--- a/server/services/taskScheduleStore.js+++ b/server/services/taskScheduleStore.js@@ -199,6 +199,9 @@ async function readSchedule() {// No prompt set — initialize with current default and versionconfig.prompt = DEFAULT_TASK_PROMPTS[taskType];config.promptVersion = PROMPT_VERSIONS[taskType] || 1;+ // A prompt-less config pins nothing, so drop any stale provenance rather+ // than let it freeze the freshly-installed default off the upgrade path.+ if (config.promptSource) config.promptSource = null;needsSave = true;} else {// Legacy migration: infer customization when promptVersion is missing@@ -216,8 +219,12 @@ async function readSchedule() {config.promptVersion = 1;needsSave = true;} else {- // Prompt differs from all known defaults — treat as user-customized+ // Prompt differs from all known defaults — treat as user-customized.+ // Stamp the provenance as INFERRED, not 'user': this branch is a guess+ // made from a body we don't recognize, so the self-heal below must stay+ // free to undo it once the body turns out to be a retired default.config.promptCustomized = true;+ config.promptSource = 'legacy-inferred';config.promptVersion = PROMPT_VERSIONS[taskType] || 1;needsSave = true;}@@ -241,7 +248,17 @@ async function readSchedule() {// forever, now un-flagged so nothing else notices. Reset the version to 1// whenever the body is a prior default rather than the current one, which// is the same stamp the version-inference branch above applies.- if (config.promptCustomized && promptMatchesShippedDefault(config.prompt, taskType)) {+ //+ // Gated on provenance (#5432): a user who deliberately pastes an older+ // SHIPPED body into Settings → Scheduled Tasks also byte-matches a shipped+ // default, and clearing THAT flag would let the next PROMPT_VERSIONS bump+ // overwrite their chosen text. `promptSource === 'user'` marks an explicit+ // write through updateTaskInterval and is left alone; 'legacy-inferred' and+ // absent (every install upgrading into this field) self-heal exactly as+ // they do today.+ if (config.promptSource !== 'user'+ && config.promptCustomized+ && promptMatchesShippedDefault(config.prompt, taskType)) {config.promptCustomized = false;if (config.prompt !== DEFAULT_TASK_PROMPTS[taskType]) config.promptVersion = 1;needsSave = true;