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
Merge main and retain cleanup dispatch regressions
[._.]/ Adam Eivy16f616d64389
diff --cc server/services/cosTaskPreStepBlocks.compose.test.jsindex 335d2a2650,bf79b4611b..3a4044935c--- a/server/services/cosTaskPreStepBlocks.compose.test.js+++ b/server/services/cosTaskPreStepBlocks.compose.test.js@@@ -111,10 -105,7 +111,10 @@@ vi.mock('./cosState.js', () => (readAgentsStateForSafetyCheck: vi.fn(async () => ({ trusted: true, agents: {} })),}));+import { emitLog } from './cosEvents.js';+import { inspectOpenDeliveryRepair } from './repoCleanupObservation.js';+import { inspectOrQueueCompletedReview } from './repoCleanupRecovery.js';- import { generateManagedAppImprovementTaskForType } from './cosTaskGenerator.js';+ import { prepareManagedAppImprovementTask, recordDeferredPerpetualDispatch } from './cosTaskGenerator.js';import { getTaskInterval, getBranchReconcileOutcome, recordBranchReconcileOutcome } from './taskSchedule.js';import { applyPerpetualDrainCap } from './cosTaskPreStepBlocks.js';import { readAgentsStateForSafetyCheck } from './cosState.js';@@@ -132,16 -123,17 +132,21 @@@ const scan = (over = {}) => (...over,});- const generate = () =>- generateManagedAppImprovementTaskForType('branch-reconcile', APP, STATE, { skipPreconditions: true });+ const generate = async (options = {}) => {+ const prepared = await prepareManagedAppImprovementTask('branch-reconcile', APP, STATE, { skipPreconditions: true, ...options });+ // This suite's direct prepare call simulates a caller that has admitted the+ // task; production records only after its own admission gate succeeds.+ await recordDeferredPerpetualDispatch(prepared.pendingPerpetualDispatch, await import('./taskSchedule.js'));+ return prepared.task;+ };- describe('generateManagedAppImprovementTaskForType composes the extracted pre-step layer', () => {+ describe('prepareManagedAppImprovementTask composes the extracted pre-step layer', () => {beforeEach(() => {vi.clearAllMocks();+ inspectOpenDeliveryRepair.mockResolvedValue({ reason: 'delivery-ci-or-review-pending' });+ inspectOrQueueCompletedReview.mockResolvedValue({ disposition: 'held', reason: 'review-recorded-handoff-missing' });+ reserveReview.mockResolvedValue({ admitted: true });+ retireCheckout.mockResolvedValue({ ok: true, archiveDir: '/private/archive', branchDeleted: true });getBranchReconcileOutcome.mockResolvedValue(null);recordBranchReconcileOutcome.mockImplementation(async (_appId, update) => ({ ...update, retirementObligations: retainRetirementObligations(null, update.remaining || [], '2026-10-20T00:00:00Z') }));parkPerpetual.mockReset().mockResolvedValue();@@@ -159,8 -151,8 +164,8 @@@branch: row.branch, path: row.worktreePath, head: row.tip, managed: true, locked: false, lockReason: null,})) }));mergedPrRead.mockImplementation(async (_app, name) => `https://github.com/example/repo/pull/${name.split('-').at(-1)}`);- prepareRetirement.mockResolvedValue({ ok: true, review: { digest: 'd'.repeat(64), policy: { policies: [{ id: 'completed-owner' }] } } });+ prepareRetirement.mockResolvedValue({ ok: true, review: { digest: 'd'.repeat(64), policy: { policies: [{ id: 'completed-owner' }] }, comparison: { disposition: 'review-supersession', localPatch: '+old', difference: '+replacement' } } });- const task = await generateManagedAppImprovementTaskForType('branch-reconcile', APP, STATE, { skipPreconditions: true, onDemand: true });+ const task = await generate({ onDemand: true });expect(task).not.toBeNull();expect(task.metadata.reconcileRetirements).toHaveLength(3);expect(task.description).toContain('[REVIEW_RETIREMENT]');@@@ -172,63 -164,6 +177,63 @@@}));});+ it('does not generate repeated agents for a healthy open PR waiting for CI', async () => {+ reconcileMock.mockResolvedValue(scan({ inFlight: [{ branch: 'fix/waiting', state: 'IN_REVIEW', openPr: { url: 'https://github.com/example/repo/pull/9', isDraft: false } }] }));+ for (let i = 0; i < 70; i++) expect(await generate()).toBeNull();+ expect(recordPerpetualDispatch).not.toHaveBeenCalled();+ const parkedMessage = emitLog.mock.calls.findLast(([, message]) => message.includes('branch-reconcile parked'))?.[1];+ expect(parkedMessage).toContain('delivery branch(es) awaiting completion (delivery-ci-or-review-pending)');+ expect(parkedMessage).not.toContain('skipped by disabled action toggles');+ expect(recordBranchReconcileOutcome).toHaveBeenLastCalledWith(APP.id, expect.objectContaining({ remaining: expect.arrayContaining([+ expect.objectContaining({ branch: 'fix/waiting', reason: 'delivery-ci-or-review-pending' }),+ ]) }));+ });++ it.each([false, true])('does not grant merge-capable review work with autoMerge disabled (resolveConflicts=%s)', async resolveConflicts => {+ getTaskInterval.mockResolvedValue({ type: 'on-demand', taskMetadata: { autoMerge: false, resolveConflicts } });+ const branch = 'fix/no-auto-merge';+ const path = '/example/checkouts/held';+ reconcileMock.mockResolvedValue(scan({ inFlight: [], wip: [{ branch, worktreePath: path, completionPolicyReason: 'pr-completion-review-required', openPr: { url: 'https://github.com/example/repo/pull/9', isDraft: false } }],+ worktreeInventory: [{ branch, path, head: 'a'.repeat(40), locked: false, managed: true }] }));+ inspectOpenDeliveryRepair.mockResolvedValue({ headSha: 'a'.repeat(40), evidence: { head: 'a'.repeat(40), conflicts: true } });+ expect(await generate()).toBeNull();+ expect(inspectOrQueueCompletedReview).not.toHaveBeenCalled();+ expect(recordPerpetualDispatch).not.toHaveBeenCalled();+ expect(recordBranchReconcileOutcome).toHaveBeenLastCalledWith(APP.id, expect.objectContaining({ remaining: expect.arrayContaining([+ expect.objectContaining({ branch, reason: 'auto-merge-disabled' }),+ ]) }));+ });++ it('routes a genuine missing-review obligation through the pinned review loop without a generic reconcile agent', async () => {+ const branch = 'fix/needs-review';+ const path = '/example/checkouts/review';+ const head = 'a'.repeat(40);+ reconcileMock.mockResolvedValue(scan({ inFlight: [{ branch, worktreePath: path, state: 'IN_REVIEW', openPr: { url: 'https://github.com/example/repo/pull/9', isDraft: false } }],+ worktreeInventory: [{ branch, path, head, locked: false, managed: true }] }));+ inspectOpenDeliveryRepair.mockResolvedValue({ headSha: head, reason: 'delivery-ci-or-review-pending' });+ inspectOrQueueCompletedReview.mockResolvedValue({ disposition: 'queued-review', reason: 'required-code-review-queued', taskId: 'exact-review' });+ expect(await generate()).toBeNull();+ expect(inspectOrQueueCompletedReview).toHaveBeenCalledExactlyOnceWith(expect.objectContaining({ repoPath: APP.repoPath, branch, worktreePath: path, headSha: head }));+ expect(recordPerpetualDispatch).not.toHaveBeenCalled();+ expect(recordBranchReconcileOutcome).toHaveBeenLastCalledWith(APP.id, expect.objectContaining({ remaining: expect.arrayContaining([+ expect.objectContaining({ branch, reason: 'required-code-review-queued' }),+ ]) }));+ });++ it('a normal user reconcile drains machine-proven retirement without generating an agent', async () => {+ const release = { branch: 'claim/issue-1', path: '/example/checkouts/1', head: 'a'.repeat(40), managed: true, locked: false };+ reconcileMock.mockResolvedValue(scan({ inFlight: [], wip: [{ branch: release.branch, worktreePath: release.path, tip: release.head,+ completionPolicyReason: 'pr-completion-review-required' }], worktreeInventory: [release] }));+ mergedPrRead.mockResolvedValue('https://github.com/example/repo/pull/1');+ prepareRetirement.mockResolvedValue({ ok: true, review: { digest: 'd'.repeat(64), policy: { policies: [{ id: 'completed-owner' }] },+ forge: { prHead: release.head }, comparison: { disposition: 'integrated', localPatch: '', difference: '' } } });- expect(await generateManagedAppImprovementTaskForType('branch-reconcile', APP, STATE, { skipPreconditions: true, onDemand: true })).toBeNull();++ expect(await generate({ onDemand: true })).toBeNull();+ expect(retireCheckout).toHaveBeenCalledOnce();+ expect(retireCheckout.mock.calls[0][0].review.acceptSuperseded).toBe(false);+ expect(reserveReview).not.toHaveBeenCalled();+ expect(recordPerpetualDispatch).not.toHaveBeenCalled();+ });+it('keeps an unresolved retirement visible after the checkout disappears on a later refill', async () => {const release = { branch: 'claim/issue-42', path: '/example/missing', head: 'a'.repeat(40), createdAt: '2026-10-20T00:00:00Z', reason: 'retirement-receipt-unverified' };getBranchReconcileOutcome.mockResolvedValue({ retirementObligations: [release], remaining: [] });