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: retry stalled GitHub notification schedule migration
[._.]/ Adam Eivy0c27911791a7
diff --git a/scripts/migrations/438-retry-github-notifications-task-move.js b/scripts/migrations/438-retry-github-notifications-task-move.jsnew file mode 100644index 0000000000..4e108f337c--- /dev/null+++ b/scripts/migrations/438-retry-github-notifications-task-move.js@@ -0,0 +1,38 @@+/**+ * Repair migration 437's successful return on an unreadable jobs file. The+ * runner recorded that return as applied, so the retained schedule never+ * retried. Keep the frozen transform, but refuse damaged inputs before using+ * it: this repair must stay pending until the operator restores those bytes.+ */+import { existsSync } from 'fs';+import { join } from 'path';+import moveTask from './437-github-notifications-system-task.js';+import { readJsonOrNull } from './_lib.js';++const isObject = (value) => value && typeof value === 'object' && !Array.isArray(value);++export default {+ async up({ rootDir }) {+ const schedulePath = join(rootDir, 'data/cos/task-schedule.json');+ const schedule = await readJsonOrNull(schedulePath);+ if (schedule === null && existsSync(schedulePath)) {+ throw new Error('Cannot retry the GitHub notifications task move: repair data/cos/task-schedule.json before retrying migrations');+ }+ const task = schedule?.tasks?.['github-notifications'];+ if (!task) return;++ if (task.enabled !== false && task.type === 'cron'+ && typeof task.cronExpression === 'string' && task.cronExpression.trim()) {+ const jobsPath = join(rootDir, 'data/cos/autonomous-jobs.json');+ const jobs = await readJsonOrNull(jobsPath);+ if ((jobs === null && existsSync(jobsPath))+ || (jobs !== null && (!isObject(jobs) || !Array.isArray(jobs.jobs)))) {+ throw new Error('Cannot retry the GitHub notifications task move: repair data/cos/autonomous-jobs.json before retrying migrations');+ }+ }++ // An existing System task remains authoritative, including an explicit+ // disabled state. The frozen move also retains unrelated jobs and queues.+ await moveTask.up({ rootDir });+ },+};diff --git a/scripts/migrations/438-retry-github-notifications-task-move.test.js b/scripts/migrations/438-retry-github-notifications-task-move.test.jsnew file mode 100644index 0000000000..04dd58ee37--- /dev/null+++ b/scripts/migrations/438-retry-github-notifications-task-move.test.js@@ -0,0 +1,101 @@+import { afterEach, beforeEach, describe, expect, it } from 'vitest';+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'fs';+import { tmpdir } from 'os';+import { dirname, join } from 'path';+import { fileURLToPath, pathToFileURL } from 'url';+import { runMigrations } from '../run-migrations.js';++const ORIGINAL = '437-github-notifications-system-task.js';+const REPAIR = '438-retry-github-notifications-task-move.js';+const here = dirname(fileURLToPath(import.meta.url));+let rootDir;+let migrationsDir;+const path = (name) => join(rootDir, 'data', name);+const write = (name, value) => writeFileSync(path(name), JSON.stringify(value));+const read = (name) => JSON.parse(readFileSync(path(name), 'utf8'));+const run = () => runMigrations({ rootDir, migrationsDir });+const installMigration = (name) => writeFileSync(join(migrationsDir, name),+ `export { default } from ${JSON.stringify(pathToFileURL(join(here, name)).href)};\n`);+const schedule = (task = { type: 'cron', enabled: true, cronExpression: '*/15 * * * 1-5' }) => ({+ version: 2,+ tasks: { 'github-notifications': task, security: { type: 'on-demand', enabled: true } },+ executions: { 'task:github-notifications': { lastRun: 1 }, 'task:security': { lastRun: 2 } },+ onDemandRequests: [{ taskType: 'github-notifications' }, { taskType: 'security' }],+});++beforeEach(() => {+ rootDir = mkdtempSync(join(tmpdir(), 'migration-438-'));+ migrationsDir = join(rootDir, 'migrations');+ mkdirSync(join(rootDir, 'data/cos'), { recursive: true });+ mkdirSync(migrationsDir);+});+afterEach(() => rmSync(rootDir, { recursive: true, force: true }));++describe('migration 438 through the migration runner', () => {+ it('recovers a schedule 437 marked applied, keeping the repair pending until its jobs input is readable', async () => {+ installMigration(ORIGINAL);+ write('cos/task-schedule.json', schedule());+ writeFileSync(path('cos/autonomous-jobs.json'), '{ not json');+ await run();+ expect(read('migrations.applied.json')).toEqual([ORIGINAL]);++ installMigration(REPAIR);+ await expect(run()).rejects.toThrow('repair data/cos/autonomous-jobs.json');+ expect(read('migrations.applied.json')).toEqual([ORIGINAL]);+ expect(readFileSync(path('cos/autonomous-jobs.json'), 'utf8')).toBe('{ not json');+ expect(read('cos/task-schedule.json')).toEqual(schedule());++ write('cos/autonomous-jobs.json', { version: 1, jobs: [{ id: 'job-example', enabled: false }] });+ expect(await run()).toBe(1);+ expect(read('migrations.applied.json')).toEqual([ORIGINAL, REPAIR]);+ expect(read('cos/autonomous-jobs.json').jobs).toEqual([+ { id: 'job-example', enabled: false },+ expect.objectContaining({ id: 'job-github-notifications', enabled: true, cronExpression: '*/15 * * * 1-5' }),+ ]);+ expect(read('cos/task-schedule.json')).toEqual({+ version: 2, tasks: { security: { type: 'on-demand', enabled: true } },+ executions: { 'task:security': { lastRun: 2 } }, onDemandRequests: [{ taskType: 'security' }],+ });+ const before = readFileSync(path('cos/autonomous-jobs.json'), 'utf8');+ expect(await run()).toBe(0);+ expect(readFileSync(path('cos/autonomous-jobs.json'), 'utf8')).toBe(before);+ });++ it('preserves an existing replacement job and its explicit operator choices', async () => {+ installMigration(REPAIR);+ write('cos/task-schedule.json', schedule());+ const jobs = { version: 1, jobs: [{ id: 'job-github-notifications', enabled: false, cronExpression: '0 9 * * *' }] };+ write('cos/autonomous-jobs.json', jobs);+ await run();+ expect(read('cos/autonomous-jobs.json')).toEqual(jobs);+ expect(read('cos/task-schedule.json').tasks['github-notifications']).toBeUndefined();+ });++ it('leaves a malformed jobs container pending rather than overwriting it with defaults', async () => {+ installMigration(REPAIR);+ write('cos/task-schedule.json', schedule());+ write('cos/autonomous-jobs.json', { version: 1, jobs: { retained: true } });+ await expect(run()).rejects.toThrow('repair data/cos/autonomous-jobs.json');+ expect(existsSync(path('migrations.applied.json'))).toBe(false);+ expect(read('cos/autonomous-jobs.json')).toEqual({ version: 1, jobs: { retained: true } });+ });++ it('does not inspect damaged jobs when retiring an on-demand schedule', async () => {+ installMigration(REPAIR);+ write('cos/task-schedule.json', schedule({ type: 'on-demand', enabled: true }));+ writeFileSync(path('cos/autonomous-jobs.json'), '{ not json');+ await run();+ expect(read('cos/task-schedule.json').tasks['github-notifications']).toBeUndefined();+ expect(readFileSync(path('cos/autonomous-jobs.json'), 'utf8')).toBe('{ not json');+ });++ it('keeps unreadable schedule bytes pending for a later repaired input', async () => {+ installMigration(REPAIR);+ writeFileSync(path('cos/task-schedule.json'), '{ not json');+ await expect(run()).rejects.toThrow('repair data/cos/task-schedule.json');+ expect(existsSync(path('migrations.applied.json'))).toBe(false);+ write('cos/task-schedule.json', schedule());+ await run();+ expect(read('cos/autonomous-jobs.json').jobs[0]).toMatchObject({ enabled: true, cronExpression: '*/15 * * * 1-5' });+ });+});