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: guard development watchdog GitHub reads (#8024)
[._.]/ Adam Eivy9bede4541849
diff --git a/server/services/developmentWatchdog.js b/server/services/developmentWatchdog.jsindex 0b781a8827..86b24ea4f6 100644--- a/server/services/developmentWatchdog.js+++ b/server/services/developmentWatchdog.js@@ -5,10 +5,12 @@ import { normalizePersistentMindMaintainer } from '../lib/persistentMindMaintainimport { normalizePersistentMindCapabilities } from '../lib/persistentMindCapabilities.js';import { getDomainMode } from '../lib/domainAutonomy.js';import { DEVELOPMENT_ACTIVE_STATUSES, sameDevelopmentWork } from '../lib/developmentWorkIdentity.js';+import { safeJSONParse } from '../lib/jsonIo.js';let scanTail = Promise.resolve();const tasksFrom = data => [...data.user.tasks, ...data.cos.tasks];const ownershipTask = (app, pr) => ({ metadata: { app: app.id, reviewLoopPRUrl: pr.url } });+const parseGithubJson = value => safeJSONParse(value, null, { allowArray: false });function authorized(state, appId, write = false) {const role = normalizePersistentMindMaintainer(state.config?.persistentMindMaintainer);@@ -96,8 +98,10 @@ async function inspectApp(app, tasks) {const number = issueNumberFromRef(pr.headBranch);if (!number) disposition = 'unknown';else {- const claim = JSON.parse(await execGh(['issue', 'view', String(number), '--repo', target.repoSpec, '--json', 'state,labels'], undefined, exec));- if (claim.state === 'OPEN' && claim.labels?.some(label => label.name === 'in-progress')) disposition = 'unknown';+ const claim = await execGh(['issue', 'view', String(number), '--repo', target.repoSpec, '--json', 'state,labels'], undefined, exec)+ .then(parseGithubJson).catch(() => null);+ if (!claim || typeof claim !== 'object' || typeof claim.state !== 'string' || !Array.isArray(claim.labels)+ || (claim.state === 'OPEN' && claim.labels.some(label => label.name === 'in-progress'))) disposition = 'unknown';}}row.pullRequests.push({ number: pr.number, headSha: pr.headSha, fingerprint: JSON.stringify([pr.headSha, pr.reviewDecision, pr.mergeStateStatus, pr.checks, pr.labels]), disposition, taskId: owner?.id || null,@@ -180,9 +184,13 @@ async function dispatch(app, decision) {const exec = await resolveForgeExecOptions(app.repoPath, { forgeAccount: target.fullName.startsWith('atomantic/') ? 'atomantic' : app.forgeAccount });const { execGh } = await import('./github.js');const { parseBlockingIssueNumbers } = await import('./blockedIssueReconcile.js');- const body = JSON.parse(await execGh([decision.kind === 'pr' ? 'pr' : 'issue', 'view', String(item.number), '--repo', target.repoSpec, '--json', 'body'], undefined, exec));+ const body = await execGh([decision.kind === 'pr' ? 'pr' : 'issue', 'view', String(item.number), '--repo', target.repoSpec, '--json', 'body'], undefined, exec)+ .then(parseGithubJson).catch(() => null);+ if (!body || typeof body.body !== 'string') return { reason: 'forge-read-failed' };for (const number of parseBlockingIssueNumbers(body.body)) {- const dependency = JSON.parse(await execGh(['issue', 'view', String(number), '--repo', target.repoSpec, '--json', 'state'], undefined, exec));+ const dependency = await execGh(['issue', 'view', String(number), '--repo', target.repoSpec, '--json', 'state'], undefined, exec)+ .then(parseGithubJson).catch(() => null);+ if (!dependency || typeof dependency.state !== 'string') return { reason: 'dependency-read-failed' };if (dependency.state !== 'CLOSED') return { reason: 'open-dependency' };}const finalState = await loadState();diff --git a/server/services/developmentWatchdog.test.js b/server/services/developmentWatchdog.test.jsindex a0df7c943f..2d889d6728 100644--- a/server/services/developmentWatchdog.test.js+++ b/server/services/developmentWatchdog.test.js@@ -1,5 +1,5 @@import { beforeEach, describe, expect, it, vi } from 'vitest';-const m = vi.hoisted(() => ({ state: null, tasks: [], prs: [], backlog: [], peers: [], adds: [], save: vi.fn(), branch: '', account: 'atomantic', nextPrs: null, prReads: 0, dependencies: [], dependencyOpen: false, issueTruncated: false, readiness: { shouldRun: true }, requests: [], duplicate: false, prepare: vi.fn(), record: vi.fn(), execution: vi.fn(), metadata: vi.fn() }));+const m = vi.hoisted(() => ({ state: null, tasks: [], prs: [], backlog: [], peers: [], adds: [], save: vi.fn(), branch: '', account: 'atomantic', nextPrs: null, prReads: 0, dependencies: [], dependencyOpen: false, execGhFailureOn: null, invalidGhJsonOn: null, issueTruncated: false, readiness: { shouldRun: true }, requests: [], duplicate: false, prepare: vi.fn(), record: vi.fn(), execution: vi.fn(), metadata: vi.fn() }));vi.mock('./cosState.js', () => ({ loadState: async () => m.state, saveState: m.save, withStateLock: async fn => fn(), isImprovementEnabled: state => state.config.improvementEnabled }));vi.mock('./apps.js', () => ({ getActiveApps: async () => [{ id: 'app', name: 'Example', repoPath: '/example' }] }));vi.mock('./cosTaskStore.js', () => ({ getAllTasks: async () => ({ user: { tasks: [] }, cos: { tasks: m.tasks } }), addTask: async task => { if (m.duplicate) return { id: 'existing', duplicate: true }; const result = { ...task, id: 'queued', status: 'pending' }; m.tasks.push(result); m.adds.push(result); return result; } }));@@ -18,7 +18,12 @@ vi.mock('./taskSchedule.js', () => ({getOnDemandRequests: async () => m.requests,recordExecution: (...args) => m.execution(...args),}));-vi.mock('./github.js', () => ({ execGh: async args => args[0] === 'api' ? m.account : JSON.stringify({ body: '', state: m.dependencyOpen ? 'OPEN' : 'CLOSED', labels: m.dependencyOpen ? [{ name: 'in-progress' }] : [] }) }));+vi.mock('./github.js', () => ({ execGh: async args => {+ if (args[0] === 'api') return m.account;+ if (args[0] === m.execGhFailureOn) throw new Error('forge unavailable');+ if (args[0] === m.invalidGhJsonOn) return 'not json';+ return JSON.stringify({ body: '', state: m.dependencyOpen ? 'OPEN' : 'CLOSED', labels: m.dependencyOpen ? [{ name: 'in-progress' }] : [] });+} }));vi.mock('./forgeExecOptions.js', () => ({ resolveForgeExecOptions: async () => ({}) }));vi.mock('./forgeActorTrust.js', () => ({ createGithubActorTrust: async () => ({ isTrusted: async () => true }) }));vi.mock('../lib/execGit.js', () => ({ execGit: async () => ({ stdout: m.branch }) }));@@ -36,7 +41,7 @@ import { readPersistentMindMaintenanceContext } from './persistentMindMaintenancbeforeEach(() => {m.state = { config: { improvementEnabled: true, persistentMindMaintainer: { enabled: true, appIds: ['app'] }, persistentMindCapabilities: { readPortos: true, createTasks: true }, maxConcurrentAgents: 3 }, agents: {} };- m.tasks = []; m.prs = []; m.backlog = []; m.peers = []; m.adds = []; m.branch = ''; m.account = 'atomantic'; m.save.mockClear(); m.nextPrs = null; m.prReads = 0; m.dependencies = []; m.dependencyOpen = false; m.issueTruncated = false;+ m.tasks = []; m.prs = []; m.backlog = []; m.peers = []; m.adds = []; m.branch = ''; m.account = 'atomantic'; m.save.mockClear(); m.nextPrs = null; m.prReads = 0; m.dependencies = []; m.dependencyOpen = false; m.execGhFailureOn = null; m.invalidGhJsonOn = null; m.issueTruncated = false;m.readiness = { shouldRun: true }; m.requests = []; m.duplicate = false;m.metadata.mockReset().mockResolvedValue({ metadata: {} });m.prepare.mockReset().mockResolvedValue({@@ -114,6 +119,25 @@ it('keeps explicit live claim and open dependency evidence out of dispatch', asyexpect(receipt.decisions[0].reason).toBe('open-dependency'); expect(m.adds).toEqual([]);});+it('turns failed or malformed claim reads into unknown evidence instead of aborting the scan', async () => {+ m.prs = [orphan]; m.execGhFailureOn = 'issue';+ let receipt = await runDevelopmentWatchdog({ force: true });+ expect(receipt.apps[0].pullRequests[0]).toMatchObject({ disposition: 'unknown', reason: 'external-claim-owner-unverified' });+ m.prs = [orphan]; m.execGhFailureOn = null; m.invalidGhJsonOn = 'issue';+ receipt = await runDevelopmentWatchdog({ force: true });+ expect(receipt.apps[0].pullRequests[0]).toMatchObject({ disposition: 'unknown', reason: 'external-claim-owner-unverified' });+ expect(m.adds).toEqual([]);+});++it('withholds dispatch when PR or dependency evidence cannot be read', async () => {+ m.prs = [{ ...orphan, headBranch: 'fix' }]; m.dependencies = [10]; m.execGhFailureOn = 'pr';+ let receipt = await runDevelopmentWatchdog({ force: true });+ expect(receipt.decisions[0].reason).toBe('forge-read-failed'); expect(m.adds).toEqual([]);+ m.execGhFailureOn = 'issue';+ receipt = await runDevelopmentWatchdog({ force: true });+ expect(receipt.decisions[0].reason).toBe('dependency-read-failed'); expect(m.adds).toEqual([]);+});+it('does not repeatedly resolve unchanged PR evidence after its task completes', async () => {m.prs = [orphan];await runDevelopmentWatchdog({ force: true });