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: wake scheduler for per-app cron overrides
[._.]/ Adam Eivy0bca7e15bd75
diff --git a/server/services/cosJobScheduler.js b/server/services/cosJobScheduler.jsindex 7815dfc16b..85cb819c39 100644--- a/server/services/cosJobScheduler.js+++ b/server/services/cosJobScheduler.js@@ -466,8 +466,8 @@ export async function scheduleNextImprovementCheck() {const upcoming = await taskSchedule.getUpcomingTasks(50);// Default: check again in 1 hour if nothing scheduled- // Cap at 1 hour so per-app cron tasks (e.g. feature-ideas at 1am) are always checked- // on time — getUpcomingTasks only sees global tasks, not per-app schedules+ // Cap at 1 hour as a fallback for work whose next boundary is not known;+ // getUpcomingTasks also includes per-app cron overrides.const MAX_CHECK_INTERVAL = 60 * 60 * 1000;let delayMs = MAX_CHECK_INTERVAL;let description = 'Periodic improvement check (1h)';diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 7c23a7f5d2..92436761f7 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -1449,20 +1449,57 @@ export async function getUpcomingTasks(limit = 10) {const now = Date.now();const upcoming = [];const featureEnabled = createFeatureGate();+ // The improvement daemon queues per-app work, so its wake-up preview must+ // include app-scoped cadence overrides. In particular, an app can opt into a+ // cron expression while the global task remains on-demand; omitting that+ // boundary leaves the hourly fallback as the only chance to notice the slot.+ const activeApps = await getActiveApps().catch(() => []);+ const activeAppOverrides = activeApps.length > 0+ ? await mapWithConcurrency(activeApps, 8, (app) =>+ getAppTaskTypeOverrides(app.id).catch(() => ({})))+ : [];for (const [taskType, interval] of Object.entries(schedule.tasks)) {if (!interval.enabled) continue;if (!(await featureEnabled(interval))) continue;if (getTaskTypeInvocation(taskType).visibility === 'hidden') continue;- // On-demand tasks have no wall-clock position — unless they are perpetual,- // whose park/recheck boundary IS the schedule the daemon must wake on.- if (interval.type === INTERVAL_TYPES.ON_DEMAND && (!interval.perpetual || interval.autoStart === false)) continue;const check = await shouldRunTask(taskType, null, { featureEnabled });const execution = schedule.executions[`task:${taskType}`] || { lastRun: null, count: 0 };- let eligibleAt = now;- let taskStatus = 'ready';+ // `shouldRunTask(taskType, appId)` resolves the same effective cadence used+ // by the queue path, including an app's raw cron override and its own last+ // run. A due app makes the task ready; otherwise the soonest app boundary+ // is the wake-up deadline. This also handles a globally on-demand task that+ // has no global candidate but is cron-scheduled for one managed app.+ const scheduledApps = activeApps.filter((app, index) => {+ const override = activeAppOverrides[index]?.[taskType];+ if (override?.enabled !== true) return false;+ const decoded = decodeIntervalType(override.interval, { intervalMs: override.intervalMs });+ return decoded.type === INTERVAL_TYPES.CRON && isCronExpression(decoded.cronExpression);+ });+ const appChecks = scheduledApps.length > 0+ ? await mapWithConcurrency(scheduledApps, 8, (app) =>+ shouldRunTask(taskType, app.id, { featureEnabled }).catch(() => null))+ : [];+ const appUpcoming = appChecks.reduce((soonest, appCheck) => {+ if (!appCheck) return soonest;+ if (appCheck.shouldRun) return { status: 'ready', eligibleAt: now };+ const eligibleAt = Date.parse(appCheck.nextRunAt);+ if (!Number.isFinite(eligibleAt) || eligibleAt <= now) return soonest;+ if (!soonest || soonest.status !== 'scheduled' || eligibleAt < soonest.eligibleAt) {+ return { status: 'scheduled', eligibleAt };+ }+ return soonest;+ }, null);++ // On-demand tasks have no wall-clock position — unless they are perpetual,+ // whose park/recheck boundary IS the schedule the daemon must wake on, or+ // an enabled managed app supplies a scheduled override.+ if (interval.type === INTERVAL_TYPES.ON_DEMAND && (!interval.perpetual || interval.autoStart === false) && !appUpcoming) continue;++ let eligibleAt = null;+ let taskStatus = null;if (check.shouldRun) {eligibleAt = now;@@ -1472,6 +1509,21 @@ export async function getUpcomingTasks(limit = 10) {taskStatus = 'scheduled';}+ if (appUpcoming) {+ if (appUpcoming.status === 'ready') {+ taskStatus = 'ready';+ eligibleAt = now;+ } else if (taskStatus !== 'ready' && (eligibleAt === null || appUpcoming.eligibleAt < eligibleAt)) {+ taskStatus = 'scheduled';+ eligibleAt = appUpcoming.eligibleAt;+ }+ }++ // No global or per-app wall-clock candidate (for example a plain+ // on-demand task, or a task blocked by a weekday/dependency gate) has no+ // place in an upcoming schedule preview.+ if (!taskStatus) continue;+// Perpetual tasks park per-app, so the global `check` above can't see the// recheck boundary — re-derive status/eligibility from the park records so// scheduleNextImprovementCheck wakes the daemon AT the next recheck (e.g. 9am)diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 8304a1ec10..b40cf36d2b 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -189,7 +189,7 @@ import { loadState } from './cosState.js'import { readJSONFile } from '../lib/fileUtils.js'import { writeFile } from 'fs/promises'-import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, clearAllPrWatcherState, clearAllIssueWatcherState } from './apps.js'+import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, getAppTaskTypeOverrides, getActiveApps, clearAllPrWatcherState, clearAllIssueWatcherState } from './apps.js'import { getLocalParts } from '../lib/timezone.js'import { getAdaptiveCooldownMultiplier } from './taskLearning.js'import { parseCronToNextRun } from './eventScheduler.js'@@ -2663,6 +2663,33 @@ describe('taskSchedule', () => {})})+ describe('getUpcomingTasks — per-app cron overrides', () => {+ it('surfaces an enabled app cron boundary even when the global task is on-demand', async () => {+ vi.useFakeTimers()+ vi.setSystemTime(new Date('2026-01-01T16:00:00Z')) // 08:00 in the mocked America/Los_Angeles zone+ const actual = await vi.importActual('./eventScheduler.js')+ const actualTimezone = await vi.importActual('../lib/timezone.js')+ parseCronToNextRun.mockImplementation(actual.parseCronToNextRun)+ getLocalParts.mockImplementation(actualTimezone.getLocalParts)+ getActiveApps.mockResolvedValueOnce([{ id: 'app-1', name: 'Acme' }])+ isTaskTypeEnabledForApp.mockResolvedValueOnce(true)+ getAppTaskTypeInterval.mockResolvedValueOnce('15 9 * * *')+ getAppTaskTypeOverrides.mockResolvedValueOnce({+ 'release-check': { enabled: true, interval: '15 9 * * *' }+ })+ mockSchedule({+ tasks: { 'release-check': { type: 'on-demand', enabled: true, runAfter: [] } }+ })+ const upcoming = await getUpcomingTasks(50)+ const release = upcoming.find(t => t.taskType === 'release-check')++ expect(release).toMatchObject({+ status: 'scheduled',+ eligibleAt: new Date('2026-01-01T17:15:00Z').getTime()+ })+ })+ })+describe('parkPerpetual / perpetual park state', () => {it('parkPerpetual stamps parkedUntil + reason on the per-app record', async () => {mockSchedule({ tasks: { 'claim-issue': { type: 'on-demand', perpetual: true, enabled: true, recheckIntervalMs: 3600000 } } })