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: retain future app cron deadlines alongside ready tasks

[._.]/ Adam Eivy3d3305f7b4a8
diff --git a/server/services/cosJobScheduler.js b/server/services/cosJobScheduler.js
index 85cb819c39..54d08c3757 100644
--- a/server/services/cosJobScheduler.js
+++ b/server/services/cosJobScheduler.js
@@ -472,12 +472,16 @@ export async function scheduleNextImprovementCheck() {
let delayMs = MAX_CHECK_INTERVAL;
let description = 'Periodic improvement check (1h)';
- // Pick the soonest *scheduled* task (status='scheduled' with positive eligibleIn).
+ // Keep future app deadlines even when another app makes the same task ready.
// Ready tasks don't gate the delay — they'll be queued on whatever the next check
// ends up being. Cron tasks DO gate the delay, because their firing window is a
// single minute; missing it pushes the next attempt out by a full period.
+ const now = Date.now();
const nextScheduled = upcoming
- .filter(t => t.status === 'scheduled' && t.eligibleIn > 0)
+ .map(t => ({ ...t, eligibleIn: t.nextScheduledAt > now
+ ? t.nextScheduledAt - now
+ : t.status === 'scheduled' ? t.eligibleIn : 0 }))
+ .filter(t => t.eligibleIn > 0)
.sort((a, b) => a.eligibleIn - b.eligibleIn)[0];
if (nextScheduled && nextScheduled.eligibleIn < MAX_CHECK_INTERVAL) {
diff --git a/server/services/cosJobScheduler.test.js b/server/services/cosJobScheduler.test.js
index 4ef0498d3b..8ddd2757d9 100644
--- a/server/services/cosJobScheduler.test.js
+++ b/server/services/cosJobScheduler.test.js
@@ -101,12 +101,15 @@ vi.mock('./jobGates.js', () => ({
}));
import {
+ scheduleNextImprovementCheck,
executeScheduledJob,
getScheduledActionReservations,
clearSpawningJob,
registerSingleJobSchedule,
} from './cosJobScheduler.js';
import { schedule as scheduleEvent, cancel as cancelEvent } from './eventScheduler.js';
+vi.mock('./taskSchedule.js', () => ({ getUpcomingTasks: vi.fn() }));
+import { getUpcomingTasks } from './taskSchedule.js';
import { getJob } from './autonomousJobs.js';
import { getDomainBudgetStatus } from './domainUsage.js';
@@ -294,3 +297,18 @@ describe('registerSingleJobSchedule', () => {
expect(scheduleEvent.mock.calls[0][0].delayMs).toBeGreaterThan(0);
});
});
+
+it('wakes at a future app deadline even while the task is ready for another app', async () => {
+ vi.useFakeTimers();
+ vi.setSystemTime(new Date('2026-01-01T16:00:00Z'));
+ try {
+ getUpcomingTasks.mockResolvedValue([{ taskType: 'release-check', status: 'ready', eligibleIn: 0,
+ nextScheduledAt: Date.now() + 300000 }]);
+ await scheduleNextImprovementCheck();
+ expect(scheduleEvent).toHaveBeenLastCalledWith(expect.objectContaining({
+ id: 'cos-improvement-check', delayMs: 300000
+ }));
+ } finally {
+ vi.useRealTimers();
+ }
+});
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.js
index 92436761f7..e36c7571e2 100644
--- a/server/services/taskSchedule.js
+++ b/server/services/taskSchedule.js
@@ -1482,16 +1482,16 @@ export async function getUpcomingTasks(limit = 10) {
? 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);
+ const appReady = appChecks.some(appCheck => appCheck?.shouldRun);
+ const futureAppTimes = appChecks.map(appCheck => Date.parse(appCheck?.nextRunAt))
+ .filter(time => Number.isFinite(time) && time > now);
+ const nextAppAt = futureAppTimes.length ? Math.min(...futureAppTimes) : null;
+ const appUpcoming = appReady
+ ? { status: 'ready', eligibleAt: now }
+ : nextAppAt !== null ? { status: 'scheduled', eligibleAt: nextAppAt } : null;
+ const futureTimes = [Date.parse(check.nextRunAt), nextAppAt]
+ .filter(time => Number.isFinite(time) && time > now);
+ const nextScheduledAt = futureTimes.length ? Math.min(...futureTimes) : 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
@@ -1539,6 +1539,7 @@ export async function getUpcomingTasks(limit = 10) {
upcoming.push({
taskType,
intervalType: interval.type,
+ nextScheduledAt,
status: taskStatus,
eligibleAt,
eligibleIn: eligibleAt - now,
diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.js
index b40cf36d2b..0752479276 100644
--- a/server/services/taskSchedule.test.js
+++ b/server/services/taskSchedule.test.js
@@ -2664,6 +2664,29 @@ describe('taskSchedule', () => {
})
describe('getUpcomingTasks — per-app cron overrides', () => {
+ it.each([false, true])('preserves a future deadline alongside a ready app (reverse=%s)', async (reverse) => {
+ vi.useFakeTimers()
+ vi.setSystemTime(new Date('2026-01-01T16:00:00Z'))
+ const actual = await vi.importActual('./eventScheduler.js')
+ const actualTimezone = await vi.importActual('../lib/timezone.js')
+ parseCronToNextRun.mockImplementation(actual.parseCronToNextRun)
+ getLocalParts.mockImplementation(actualTimezone.getLocalParts)
+ const apps = [{ id: 'ready' }, { id: 'future' }]
+ getActiveApps.mockResolvedValueOnce(reverse ? apps.reverse() : apps)
+ const cron = id => id === 'ready' ? '0 8 * * *' : '5 8 * * *'
+ for (const app of apps) {
+ getAppTaskTypeInterval.mockResolvedValueOnce(cron(app.id))
+ getAppTaskTypeOverrides.mockResolvedValueOnce({
+ 'release-check': { enabled: true, interval: cron(app.id) }
+ })
+ }
+ mockSchedule({ tasks: { 'release-check': { type: 'on-demand', enabled: true, runAfter: [] } } })
+ const upcoming = await getUpcomingTasks(50)
+ expect(upcoming.find(t => t.taskType === 'release-check')).toMatchObject({
+ status: 'ready', nextScheduledAt: new Date('2026-01-01T16:05:00Z').getTime()
+ })
+ })
+
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