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
Preserve legacy cleanup admission coverage without dispatching routine agents
[._.]/ Adam Eivy8e41c08d92ac
diff --git a/server/services/cosMergeAdmission.cleanupRecovery.test.js b/server/services/cosMergeAdmission.cleanupRecovery.test.jsindex f43d17e72b..1507b67b60 100644--- a/server/services/cosMergeAdmission.cleanupRecovery.test.js+++ b/server/services/cosMergeAdmission.cleanupRecovery.test.js@@ -3,10 +3,10 @@ import { join } from 'node:path';import { createFileWriteQueue } from '../lib/fileWriteQueue.js';import { generateTasksMarkdown, parseTasksMarkdown } from '../lib/taskParser.js';-// Repository-cleanup recovery (#12251): the post-completion audit files a-// recovery for a parent whose PR is still open; that recovery lands the PR-// inside repository merge admission. Authority comes from the audit's own-// forge observation and its backlink on the parent, never a caller claim.+// Existing repository-cleanup recoveries (#12251) retain merge admission+// after an upgrade. Authority comes from the persisted server backlink on+// the completed parent, never a caller claim. The current audit must not+// create another cognitive task for an absent, unverified original checkout.vi.mock('../lib/backupSnapshotBoundary.js', () => ({ withBackupAssetPublication: work => work() }));const f = vi.hoisted(() => ({ state: null, disk: null, tasks: {}, archive: {} }));vi.mock('./cosState.js', () => ({@@ -47,9 +47,8 @@ vi.mock('./git.js', () => ({vi.mock('./github.js', () => ({ findPullRequestForBranch: vi.fn() }));vi.mock('./apps.js', () => ({ getAppById: async () => ({ id: 'example-app', name: 'Example App' }) }));vi.mock('./brainTaskThreads.js', () => ({ ensureTaskThread: async () => ({}) }));-// The parent's worktree and local branch are already gone.+// The original checkout is absent; Git cannot verify its local ref state.vi.mock('../lib/execGit.js', () => ({ execGit: async () => ({ exitCode: 1, stdout: '', stderr: '' }) }));-vi.mock('fs', async () => ({ ...await vi.importActual('fs'), existsSync: () => false }));vi.mock('../lib/gitRemote.js', () => ({ getOriginInfo: async path => ({ host: 'github.com', fullName: path === '/repos/other' ? 'example/other' : 'example/repo' }) }));const BRANCH = vi.hoisted(() => 'cos/task-parent/parent-1');@@ -78,12 +77,23 @@ const queue = (id, taskData) => {const register = (agentId, task) => registerAgent(agentId, task.id, buildAgentRegistration({ task, provider: { id: 'test' },modelSelection: {}, sourceWorkspace: '/repos/source', workspacePath: '/repos/source' }));-// The real audit files the recovery for the completed parent; the real-// intake, registration and admission then run on what it produced.-async function fileAndLaunch() {- const audit = await verifyAgentRepoState({ agentId: 'parent-1', task: parentTask, agentState: f.state.agents['parent-1'], success: true, prExpected: true });- expect(audit.recoveryTaskId).toBe('task-recovery-1');- const task = queue('task-recovery-1', addTask.mock.calls.at(-1)[0]);+const legacyRecoveryPayload = (branch = BRANCH, url = PR_URL) => ({+ description: `Finish delivery for ${branch}`,+ context: `Land the parent PR ${url || '(unverified)'}`,+ app: 'example-app',+ isRecovery: true,+ useWorktree: false,+ metadata: { recoveryOrigin: { parentAgentId: 'parent-1', parentTaskId: parentTask.id,+ subsystem: 'repository-cleanup', attempt: 1, observation: 'a'.repeat(64), noProgress: false },+ ...(url ? { recoveryMergeTarget: { url, branch } } : {}) },+});++// Model a recovery already filed before upgrade. Keep the real TASKS.md+// intake round-trip, server-only backlink writer, registration and admission;+// do not make the new deterministic audit manufacture legacy authority.+async function resumeLegacyRecovery({ id = 'task-recovery-1', branch = BRANCH, url = PR_URL, claimRun = false } = {}) {+ const task = queue(id, legacyRecoveryPayload(branch, url));+ if (url) expect(await recordRepoStateRecovery('parent-1', { taskId: id, url, branch }, { claimRun })).toBeTruthy();await register('recovery-1', task);return task;}@@ -100,10 +110,11 @@ beforeEach(() => {});describe('repository-cleanup recovery merge admission', () => {- it('lands the registered parent PR with no parent checkout, from creation through release', async () => {- await fileAndLaunch();- expect(addTask.mock.calls[0][0].metadata.recoveryMergeTarget).toEqual({ url: PR_URL, branch: BRANCH });+ it('resumes a persisted recovery with no parent checkout, through intake, registration and release', async () => {+ await resumeLegacyRecovery();+ expect(f.tasks['task-recovery-1'].metadata.recoveryMergeTarget).toEqual({ url: PR_URL, branch: BRANCH });expect(f.state.agents['recovery-1'].metadata.recoveryMergeTarget).toEqual({ url: PR_URL, branch: BRANCH });+ expect(f.state.agents['recovery-1'].metadata.recoveryOrigin).toEqual(legacyRecoveryPayload().metadata.recoveryOrigin);const backlink = { taskId: 'task-recovery-1', url: PR_URL, branch: BRANCH };expect(f.state.agents['parent-1'].metadata.repoStateRecovery).toEqual(backlink);const lease = await admission('acquire');@@ -118,13 +129,15 @@ describe('repository-cleanup recovery merge admission', () => {const parent = f.state.agents['parent-1'];parent.metadata = { ...parent.metadata, isWorktree: false, worktreeBranch: null,claimPicksOwnBranch: true, claimBranches: ['claim/issue-11', 'claim/issue-12'] };- findPullRequestForBranch.mockImplementation(async branch => ({ status: 'found', detail: 'OPEN',- url: `https://github.com/example/repo/pull/${branch.endsWith('11') ? 11 : 12}` }));- addTask.mockResolvedValueOnce({ id: 'task-first' }).mockResolvedValueOnce({ id: 'task-second' });- await verifyAgentRepoState({ agentId: 'parent-1', task: parentTask, agentState: parent, success: true });- expect(Object.keys(f.state.agents['parent-1'].metadata.repoStateRecoveries)).toEqual(['claim/issue-11', 'claim/issue-12']);for (const [index, id] of ['task-first', 'task-second'].entries()) {- await register('recovery-1', queue(id, addTask.mock.calls[index][0]));+ const branch = parent.metadata.claimBranches[index];+ const url = `https://github.com/example/repo/pull/${index + 11}`;+ queue(id, legacyRecoveryPayload(branch, url));+ expect(await recordRepoStateRecovery('parent-1', { taskId: id, url, branch }, { claimRun: true })).toBeTruthy();+ }+ expect(Object.keys(f.state.agents['parent-1'].metadata.repoStateRecoveries)).toEqual(['claim/issue-11', 'claim/issue-12']);+ for (const id of ['task-first', 'task-second']) {+ await register('recovery-1', f.tasks[id]);const lease = await admission('acquire');expect(lease.admitted).toBe(true);await admission('release', lease.token, { outcome: 'merged' });@@ -133,7 +146,7 @@ describe('repository-cleanup recovery merge admission', () => {});it('verifies a parent already archived out of live state through its persisted backlink', async () => {- await fileAndLaunch();+ await resumeLegacyRecovery();delete f.state.agents['parent-1']; persist();const lease = await admission('acquire');expect(lease).toMatchObject({ admitted: true, repository: REPOSITORY });@@ -141,11 +154,8 @@ describe('repository-cleanup recovery merge admission', () => {});it('binds a recovery after the parent has already left live retention', async () => {- const parent = f.state.agents['parent-1'];delete f.state.agents['parent-1']; persist();- const audit = await verifyAgentRepoState({ agentId: 'parent-1', task: parentTask, agentState: parent, success: true, prExpected: true });- expect(audit.recoveryTaskId).toBe('task-recovery-1');- await register('recovery-1', queue('task-recovery-1', addTask.mock.calls.at(-1)[0]));+ await resumeLegacyRecovery();expect(await admission('acquire')).toMatchObject({ admitted: true });});@@ -157,7 +167,7 @@ describe('repository-cleanup recovery merge admission', () => {});it('keeps the repository-wide lease exclusive against claim runs and the sweep', async () => {- await fileAndLaunch();+ await resumeLegacyRecovery();f.state.agents.claim = { id: 'claim', taskId: 'claim-task', status: 'running', startedAt: new Date().toISOString(),metadata: { claimPicksOwnBranch: true, sourceWorkspace: '/repos/source' } }; persist();const claim = await claimMergeAdmission({ agentId: 'claim', action: 'acquire' });@@ -173,7 +183,7 @@ describe('repository-cleanup recovery merge admission', () => {'parent-other-task', 'parent-other-branch', 'parent-unbound', 'backlink-other-task', 'parent-other-repository','other-lineage', 'completed-task',])('refuses %s with a non-retryable blocker', async mode => {- const task = await fileAndLaunch();+ const task = await resumeLegacyRecovery();const agent = f.state.agents['recovery-1'];const parent = f.state.agents['parent-1'];if (mode === 'changed-task-target') task.metadata.recoveryMergeTarget = { url: 'https://github.com/example/repo/pull/8', branch: BRANCH };@@ -195,8 +205,8 @@ describe('repository-cleanup recovery merge admission', () => {});it('refuses a copied recovery the parent never named, and copied prose alone', async () => {- const original = await fileAndLaunch();- const payload = addTask.mock.calls[0][0];+ const original = await resumeLegacyRecovery();+ const payload = legacyRecoveryPayload();// Identical lineage and target written through the task API: no backlink.await register('copy-1', queue('task-copy', payload));expect(await claimMergeAdmission({ agentId: 'copy-1', action: 'acquire' }))@@ -209,17 +219,27 @@ describe('repository-cleanup recovery merge admission', () => {});it('refuses completed and unregistered callers', async () => {- await fileAndLaunch();+ await resumeLegacyRecovery();expect(await claimMergeAdmission({ agentId: 'missing', action: 'acquire' })).toMatchObject({ admitted: false, reason: 'claim-owner-unverified' });f.state.agents['recovery-1'].status = 'completed'; persist();expect(await admission('acquire')).toMatchObject({ admitted: false, reason: 'claim-owner-unverified' });});- it('files no merge authority when the forge reported no PR, and reports that blocker', async () => {- findPullRequestForBranch.mockResolvedValue({ status: 'none', url: null, detail: null });- await fileAndLaunch();- expect(addTask.mock.calls[0][0].metadata.recoveryMergeTarget).toBeUndefined();+ it('refuses a persisted recovery without a verified PR target or parent backlink', async () => {+ await resumeLegacyRecovery({ url: null });+ expect(f.tasks['task-recovery-1'].metadata.recoveryMergeTarget).toBeUndefined();expect(f.state.agents['parent-1'].metadata.repoStateRecovery).toBeUndefined();expect(await admission('acquire')).toMatchObject({ admitted: false, reason: 'recovery-merge-target-unverified', retryable: false });});++ it('does not dispatch a new recovery for an absent original checkout with unverified delivery evidence', async () => {+ const audit = await verifyAgentRepoState({ agentId: 'parent-1', task: parentTask,+ agentState: f.state.agents['parent-1'], success: true, prExpected: true });+ expect(audit).toMatchObject({ verified: false, recoveryTaskId: null, skipReason: 'delivery-evidence-unavailable',+ observed: { worktreePresent: false, localBranchPresent: null, prState: 'OPEN' } });+ expect(addTask).not.toHaveBeenCalled();+ expect(f.state.agents['parent-1'].metadata.repoStateRecovery).toBeUndefined();+ expect(f.state.agents['parent-1'].metadata.cleanupOutcome).toMatchObject({ status: 'blocked', reason: 'delivery-evidence-unavailable' });+ expect(f.disk.mergeAdmissions).toEqual({});+ });});