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: prune stale failure-park notification on unpark so a re-park re-notifies (#2616)
Adam Eivyf7716cc2d850
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 30f789839a..c19e6d2bc9 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -694,11 +694,17 @@ export async function updateTaskInterval(taskType, settings) {// Config change unparks a failure-parked type (#2616): editing a type's// settings is an explicit "I've addressed the cause" signal, so clear the// consecutive-failure ledger + auto-park (global + every per-app record) so- // the type gets a fresh start on its next tick.+ // the type gets a fresh start on its next tick. Track the scopes that were+ // actually parked so their stale notifications can be pruned after the save.const topExec = schedule.executions[`task:${taskType}`];+ const unparkedScopes = [];if (topExec) {+ if (topExec.failureParkedAt) unparkedScopes.push(null);clearFailureLedgerFields(topExec);- for (const rec of Object.values(topExec.perApp || {})) clearFailureLedgerFields(rec);+ for (const [id, rec] of Object.entries(topExec.perApp || {})) {+ if (rec.failureParkedAt) unparkedScopes.push(id);+ clearFailureLedgerFields(rec);+ }}// Globally disabling pr-watcher also drops its execution cooldown so a later@@ -741,6 +747,10 @@ export async function updateTaskInterval(taskType, settings) {});}+ for (const scope of unparkedScopes) {+ await clearTaskTypeFailureParkNotification(taskType, scope);+ }+emitLog('info', `Updated task interval for ${taskType}`, { taskType, settings }, '📅 TaskSchedule');cosEvents.emit('schedule:changed', { taskType, settings });@@ -964,6 +974,11 @@ export async function resetPerpetualForManualRun(taskType, appId = null) {// Type-level consecutive-failure ledger (#2616)// ============================================================+/** Dedup / notification key for a type+app failure park. */+function failureParkKeyFor(taskType, appId) {+ return appId ? `${taskType}:${appId}` : taskType;+}+/** Delete every failure-ledger field from a record. Returns true if any changed. */function clearFailureLedgerFields(record) {if (!record) return false;@@ -974,6 +989,17 @@ function clearFailureLedgerFields(record) {return changed;}+/**+ * Remove any lingering auto-park notification for a now-unparked type+app so the+ * bell stops showing a stale "parked" warning AND a later re-park can re-notify+ * (the `exists` dedup in notifyTaskTypeFailurePark keys on this same field, and+ * scans read notifications too). Best-effort — lazy-imported, never throws out.+ */+async function clearTaskTypeFailureParkNotification(taskType, appId) {+ const { removeByMetadata } = await import('./notifications.js');+ await removeByMetadata('failureParkKey', failureParkKeyFor(taskType, appId)).catch(() => {});+}+/*** Surface a user-facing notification when a task type auto-parks. Lazy-imports* the notifications service so taskSchedule has no static dependency on it (and@@ -982,7 +1008,7 @@ function clearFailureLedgerFields(record) {*/async function notifyTaskTypeFailurePark(taskType, appId, record) {const { addNotification, exists, NOTIFICATION_TYPES, PRIORITY_LEVELS } = await import('./notifications.js');- const dedupeKey = appId ? `${taskType}:${appId}` : taskType;+ const dedupeKey = failureParkKeyFor(taskType, appId);if (await exists(NOTIFICATION_TYPES.AGENT_WARNING, 'failureParkKey', dedupeKey)) return;const scope = appId ? `app ${appId}` : 'global';const category = record.failureParkReason || record.lastErrorCategory || 'unknown';@@ -1046,9 +1072,11 @@ export async function recordTaskTypeFailure(taskType, appId = null, { errorCategexport async function recordTaskTypeSuccess(taskType, appId = null) {const schedule = await loadSchedule();const record = resolveExecutionRecord(schedule, taskType, appId);+ const wasParked = !!record?.failureParkedAt;if (!clearFailureLedgerFields(record)) return false;await saveSchedule(schedule);emitLog('info', `Task type ${taskType}${appId ? ` (app ${appId})` : ''} succeeded — failure ledger reset`, { taskType, appId }, '📅 TaskSchedule');+ if (wasParked) await clearTaskTypeFailureParkNotification(taskType, appId);return true;}@@ -1080,16 +1108,27 @@ export async function clearTaskTypeFailurePark(taskType, appId = null) {const schedule = await loadSchedule();const top = schedule.executions[executionKey(taskType)];if (!top) return false;+ // Collect the type+app scopes whose park we clear so their stale+ // notifications can be pruned after the write (so a re-park re-notifies).+ const unparkedScopes = [];let changed = false;if (appId) {+ const wasParked = !!top.perApp?.[appId]?.failureParkedAt;changed = clearFailureLedgerFields(top.perApp?.[appId]);+ if (wasParked) unparkedScopes.push(appId);} else {+ if (top.failureParkedAt) unparkedScopes.push(null);changed = clearFailureLedgerFields(top);- for (const rec of Object.values(top.perApp || {})) {+ for (const [id, rec] of Object.entries(top.perApp || {})) {+ const wasParked = !!rec.failureParkedAt;if (clearFailureLedgerFields(rec)) changed = true;+ if (wasParked) unparkedScopes.push(id);}}if (changed) await saveSchedule(schedule);+ for (const scope of unparkedScopes) {+ await clearTaskTypeFailureParkNotification(taskType, scope);+ }return changed;}diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex 6c379e834e..8ddf7642f3 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -79,6 +79,7 @@ vi.mock('./eventScheduler.js', () => ({vi.mock('./notifications.js', () => ({addNotification: vi.fn().mockResolvedValue({}),exists: vi.fn().mockResolvedValue(false),+ removeByMetadata: vi.fn().mockResolvedValue({ success: true, removedIds: [] }),NOTIFICATION_TYPES: { AGENT_WARNING: 'agent_warning' },PRIORITY_LEVELS: { HIGH: 'high' }}))@@ -149,7 +150,7 @@ import { isTaskTypeEnabledForApp, getAppTaskTypeInterval, clearAllPrWatcherStateimport { getLocalParts } from '../lib/timezone.js'import { getAdaptiveCooldownMultiplier } from './taskLearning.js'import { parseCronToNextRun, parseCronToPrevRun } from './eventScheduler.js'-import { addNotification, exists as notificationExists } from './notifications.js'+import { addNotification, exists as notificationExists, removeByMetadata } from './notifications.js'const mockSchedule = ({ tasks = {}, executions = {}, templates = [] } = {}) => {readJSONFile.mockResolvedValue({ version: 2, tasks, executions, templates })@@ -1511,6 +1512,28 @@ describe('taskSchedule', () => {expect(addNotification).not.toHaveBeenCalled()})+ it('recordTaskTypeSuccess prunes the stale park notification (so a re-park re-notifies)', async () => {+ mockSchedule({+ tasks: { security: { type: 'rotation', enabled: true } },+ executions: { 'task:security': { lastRun: null, count: 0, perApp: {+ 'app-1': { lastRun: null, count: 0, consecutiveFailures: 5, failureParkedAt: new Date().toISOString(), failureParkReason: 'auth-error' }+ } } }+ })+ await recordTaskTypeSuccess('security', 'app-1')+ expect(removeByMetadata).toHaveBeenCalledWith('failureParkKey', 'security:app-1')+ })++ it('recordTaskTypeSuccess does NOT prune when the type was not parked', async () => {+ mockSchedule({+ tasks: { security: { type: 'rotation', enabled: true } },+ executions: { 'task:security': { lastRun: null, count: 0, perApp: {+ 'app-1': { lastRun: null, count: 0, consecutiveFailures: 2 }+ } } }+ })+ await recordTaskTypeSuccess('security', 'app-1')+ expect(removeByMetadata).not.toHaveBeenCalled()+ })+it('recordTaskTypeSuccess resets the ledger and returns false when already clean', async () => {mockSchedule({tasks: { security: { type: 'rotation', enabled: true } },