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: execute tasks in queue order, prioritize critical auto-fix tasks
Adam Eivyeb6210c077f9
diff --git a/server/lib/taskParser.js b/server/lib/taskParser.jsindex e57447281f..90bcf6d7c5 100644--- a/server/lib/taskParser.js+++ b/server/lib/taskParser.js@@ -273,13 +273,36 @@ export function removeTask(tasks, taskId) {}/**- * Get next pending task (highest priority)+ * Check if a task is a critical auto-fix task that should be prioritized+ */+function isCriticalAutoFix(task) {+ const desc = (task.description || '').toLowerCase();+ const isSysTask = task.id?.startsWith('sys-');+ const isCritical = task.priority === 'CRITICAL';+ const isHighPriorityFix = task.priority === 'HIGH' && (+ desc.includes('fix critical error') ||+ desc.includes('[auto-fix]') ||+ desc.includes('fix error:') ||+ task.metadata?.autoFix === true+ );++ return isSysTask && (isCritical || isHighPriorityFix);+}++/**+ * Get next pending task+ * Priority: Critical auto-fix tasks first, then queue order*/export function getNextTask(tasks) {const pending = tasks.filter(t => t.status === 'pending');if (pending.length === 0) return null;- return sortByPriority(pending)[0];+ // First, check for critical auto-fix tasks that need immediate attention+ const criticalAutoFix = pending.find(isCriticalAutoFix);+ if (criticalAutoFix) return criticalAutoFix;++ // Otherwise, return tasks in queue order (first pending task)+ return pending[0];}/**diff --git a/server/lib/taskParser.test.js b/server/lib/taskParser.test.jsindex 6c55970176..6e0118955d 100644--- a/server/lib/taskParser.test.js+++ b/server/lib/taskParser.test.js@@ -413,16 +413,55 @@ describe('Task Parser', () => {});describe('getNextTask', () => {- it('should return highest priority pending task', () => {+ it('should return first pending task in queue order', () => {const tasks = [- { id: 'task-001', status: 'pending', priorityValue: 1 },- { id: 'task-002', status: 'pending', priorityValue: 4 },- { id: 'task-003', status: 'pending', priorityValue: 2 }+ { id: 'task-001', status: 'pending', priority: 'LOW', priorityValue: 1 },+ { id: 'task-002', status: 'pending', priority: 'HIGH', priorityValue: 4 },+ { id: 'task-003', status: 'pending', priority: 'MEDIUM', priorityValue: 2 }];const next = getNextTask(tasks);- expect(next.id).toBe('task-002');+ // Should return first in queue, not highest priority+ expect(next.id).toBe('task-001');+ });++ it('should prioritize critical auto-fix tasks over queue order', () => {+ const tasks = [+ { id: 'task-001', status: 'pending', priority: 'LOW', priorityValue: 1 },+ { id: 'sys-002', status: 'pending', priority: 'HIGH', priorityValue: 3, description: 'Fix critical error: something broke' },+ { id: 'task-003', status: 'pending', priority: 'MEDIUM', priorityValue: 2 }+ ];++ const next = getNextTask(tasks);++ // Should return the critical auto-fix task even though it's not first+ expect(next.id).toBe('sys-002');+ });++ it('should prioritize CRITICAL priority system tasks', () => {+ const tasks = [+ { id: 'task-001', status: 'pending', priority: 'HIGH', priorityValue: 3 },+ { id: 'sys-002', status: 'pending', priority: 'CRITICAL', priorityValue: 4, description: 'System issue' },+ { id: 'task-003', status: 'pending', priority: 'MEDIUM', priorityValue: 2 }+ ];++ const next = getNextTask(tasks);++ expect(next.id).toBe('sys-002');+ });++ it('should not prioritize regular system tasks without critical indicators', () => {+ const tasks = [+ { id: 'task-001', status: 'pending', priority: 'LOW', priorityValue: 1 },+ { id: 'sys-002', status: 'pending', priority: 'MEDIUM', priorityValue: 2, description: 'Regular system task' },+ { id: 'task-003', status: 'pending', priority: 'HIGH', priorityValue: 3 }+ ];++ const next = getNextTask(tasks);++ // Should return first in queue since sys-002 is not a critical auto-fix+ expect(next.id).toBe('task-001');});it('should return null if no pending tasks', () => {diff --git a/server/services/memory.js b/server/services/memory.jsindex 85788a09bb..04cff48d4f 100644--- a/server/services/memory.js+++ b/server/services/memory.js@@ -366,6 +366,27 @@ export async function deleteMemory(id, hard = false) {});}+/**+ * Helper to decrement agent's pendingApproval count+ */+async function decrementAgentPendingApproval(sourceAgentId) {+ if (!sourceAgentId) return;++ const { getAgent } = await import('./cos.js');+ const agent = await getAgent(sourceAgentId).catch(() => null);+ if (!agent?.memoryExtraction?.pendingApproval) return;++ const currentPending = agent.memoryExtraction.pendingApproval;+ if (currentPending > 0) {+ await updateAgent(sourceAgentId, {+ memoryExtraction: {+ ...agent.memoryExtraction,+ pendingApproval: currentPending - 1+ }+ });+ }+}+/*** Approve a pending memory (changes status from pending_approval to active)*/@@ -395,6 +416,9 @@ export async function approveMemory(id) {// Remove associated notificationawait notifications.removeByMetadata('memoryId', id);+ // Decrement agent's pendingApproval count+ await decrementAgentPendingApproval(memory.sourceAgentId);+return { success: true, memory };});}@@ -410,6 +434,9 @@ export async function rejectMemory(id) {return { success: false, error: 'Memory is not pending approval' };}+ // Store sourceAgentId before deletion+ const sourceAgentId = memory.sourceAgentId;+// Hard delete - remove filesawait deleteMemoryFiles(id);@@ -430,6 +457,9 @@ export async function rejectMemory(id) {// Remove associated notificationawait notifications.removeByMetadata('memoryId', id);+ // Decrement agent's pendingApproval count+ await decrementAgentPendingApproval(sourceAgentId);+return { success: true, id };});}