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(cos): prevent duplicate improvement task scheduling

Adam Eivy9c943173f5d8
diff --git a/server/services/cos.js b/server/services/cos.js
index 376b0a10c0..3801c0640f 100644
--- a/server/services/cos.js
+++ b/server/services/cos.js
@@ -1312,7 +1312,7 @@ async function generateIdleReviewTask(state) {
* Tasks are queued to COS-TASKS.md and will be picked up in Priority 2
*/
async function queueEligibleImprovementTasks(state, cosTaskData) {
- const { getDueTasks, shouldRunTask, getNextTaskType } = await import('./taskSchedule.js');
+ const { getDueTasks, shouldRunTask, getNextTaskType, recordExecution } = await import('./taskSchedule.js');
// Check unified improvement flag (with backward compat)
const improvementEnabled = state.config.improvementEnabled ??
@@ -1372,6 +1372,8 @@ async function queueEligibleImprovementTasks(state, cosTaskData) {
approvalRequired: false
}, 'internal');
+ await recordExecution(`task:${nextType}`, app.id);
+
emitLog('info', `Queued improvement task: ${nextType} for ${app.name}`, { taskId: newTask.id, appId: app.id });
existingTaskTypes.add(taskKey);
queued++;
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.js
index 152b84c8c7..b13d556d27 100644
--- a/server/services/taskSchedule.js
+++ b/server/services/taskSchedule.js
@@ -1749,6 +1749,11 @@ export async function getNextTaskType(appId = null, lastType = '') {
return { taskType: onceDue[0].taskType, reason: 'once-first-run' };
}
+ const cronDue = dueTasks.filter(t => t.interval.type === INTERVAL_TYPES.CRON || t.interval.type === INTERVAL_TYPES.CUSTOM);
+ if (cronDue.length > 0) {
+ return { taskType: cronDue[0].taskType, reason: `${cronDue[0].interval.type}-due` };
+ }
+
// Fall back to rotation among enabled rotation tasks
const rotationTasks = taskTypes.filter(t =>
schedule.tasks[t].enabled &&