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: distinguish missing historical checkouts in branch reconciliation
Adam Eivy1e66cd178172
diff --git a/client/src/components/cos/tabs/schedule/BranchReconcileOutcome.jsx b/client/src/components/cos/tabs/schedule/BranchReconcileOutcome.jsxindex edf86e6c9f..e0a7ad8521 100644--- a/client/src/components/cos/tabs/schedule/BranchReconcileOutcome.jsx+++ b/client/src/components/cos/tabs/schedule/BranchReconcileOutcome.jsx@@ -6,7 +6,7 @@ const STATUS_LABELS = { drained: 'No remaining work in last scan', incomplete: '// Only a post-cleanup inventory row carries the exact checkout identity a// scoped release must name; branch-only holds have nothing to release.-const isInventoriedCheckout = entry => Boolean(entry.path && entry.head && typeof entry.locked === 'boolean');+const isInventoriedCheckout = entry => Boolean(!entry.checkoutMissing && entry.path && entry.head && typeof entry.locked === 'boolean');const checkoutKey = (appId, entry) => `${appId}\0${entry.path}\0${entry.head}`;const NONE = new Set();@@ -104,6 +104,7 @@ export default function BranchReconcileOutcome({ outcomes, apps }) {{apps?.find(app => app.id === appId)?.name || (appId === 'null' ? 'Repository' : appId)}{' · '}{STATUS_LABELS[outcome.status] || 'Outcome unavailable'}{remaining && ` · ${formatCount(remaining.length)} remaining`}+ {remaining?.some(entry => entry.checkoutMissing) && ' · missing checkout evidence'}</summary><div className="mt-2 space-y-2 text-gray-400"><p>{outcome.observedAt ? `Last inventory: ${formatDateTime(outcome.observedAt)}` : 'No readable inventory yet.'}</p>@@ -115,6 +116,7 @@ export default function BranchReconcileOutcome({ outcomes, apps }) {<li key={`${entry.path || entry.branch || entry.issue || entry.reason}:${index}`} className="break-words border-t border-port-border pt-2"><p className="text-gray-300">{entry.branch || (entry.detached ? 'Detached checkout' : entry.issue ? `Issue #${entry.issue}` : 'Repository scan')}: {entry.reason}</p>{entry.path && <p className="break-all">{entry.path}</p>}+ {entry.checkoutMissing && <p>Checkout no longer exists. This is a historical preservation obligation, not an extra worktree. Its archive receipt must be recovered or investigated before it can be cleared.</p>}{entry.head && <p className="break-all">HEAD: {entry.head}</p>}{entry.locked && <p>Lock: {entry.lockReason || 'No reason recorded'}</p>}{entry.managed === false && <p>Outside managed worktree roots</p>}@@ -122,7 +124,7 @@ export default function BranchReconcileOutcome({ outcomes, apps }) {</li>))}</ul>- {(remaining || []).some(entry => entry.path) && (+ {(remaining || []).some(isInventoriedCheckout) && (<p>Retiring a checkout is a scoped release of the exact row shown. It needs merged work, no live owner or manual handoff, and a verified archive of unique tracked, untracked and ignored content. Lock age, an absent process, and lock text never release a checkout on their own.</p>)}{Array.isArray(outcome.retired) && outcome.retired.length > 0 && (diff --git a/client/src/components/cos/tabs/schedule/BranchReconcileOutcome.test.jsx b/client/src/components/cos/tabs/schedule/BranchReconcileOutcome.test.jsxindex c338afd872..fb4012451f 100644--- a/client/src/components/cos/tabs/schedule/BranchReconcileOutcome.test.jsx+++ b/client/src/components/cos/tabs/schedule/BranchReconcileOutcome.test.jsx@@ -93,3 +93,10 @@ describe('BranchReconcileOutcome checkout retirement', () => {expect(screen.getByRole('button', { name: 'Yes, archive and retire' })).toBeDisabled();});});++ it('explains missing historical checkouts without offering retirement or claiming completion', () => {+ render(<BranchReconcileOutcome outcomes={{ 'app-1': { status: 'incomplete', remaining: [{ ...held, checkoutMissing: true, reason: 'retirement-receipt-unverified' }] } }} apps={[{ id: 'app-1', name: 'Example App' }]} />);+ expect(screen.getByText(/Example App · Incomplete · 1 remaining · missing checkout evidence/)).toBeTruthy();+ expect(screen.getByText(/historical preservation obligation, not an extra worktree/)).toBeTruthy();+ expect(screen.queryByRole('button', { name: 'Archive and retire checkout…' })).toBeNull();+});diff --git a/server/services/branchReconcileInventoryPrune.js b/server/services/branchReconcileInventoryPrune.jsindex e5eea21b22..efdbdad2d6 100644--- a/server/services/branchReconcileInventoryPrune.js+++ b/server/services/branchReconcileInventoryPrune.js@@ -9,7 +9,7 @@ import { execGit } from '../lib/execGit.js';import { pathExists } from '../lib/fileCore.js';// Rows that bind a retirement-receipt obligation are evidence, not display data.-const isObligationRow = row => ['retirement-review-pending', 'retirement-receipt-unverified'].includes(row?.reason);+export const isObligationRow = row => ['retirement-review-pending', 'retirement-receipt-unverified'].includes(row?.reason);async function registeredPaths(repoPath) {const { stdout } = await execGit(['worktree', 'list', '--porcelain'], repoPath);@@ -24,14 +24,15 @@ async function registeredPaths(repoPath) {** @param {string} repoPath* @param {object[]} rows+ * @param {{ includeObligations?: boolean }} [options] Include missing originals for display only; never prune these obligations.* @returns {Promise<object[]>}*/-export async function findGoneInventoryRows(repoPath, rows) {+export async function findGoneInventoryRows(repoPath, rows, { includeObligations = false } = {}) {if (!Array.isArray(rows) || !rows.length) return [];const registered = await registeredPaths(repoPath);const gone = [];for (const row of rows) {- if (isObligationRow(row)) continue;+ if (!includeObligations && isObligationRow(row)) continue;if (typeof row?.path === 'string' && row.path) {if (!registered.has(row.path) && !await pathExists(row.path)) gone.push(row);} else if (typeof row?.branch === 'string' && row.branch) {diff --git a/server/services/branchReconcileInventoryPrune.test.js b/server/services/branchReconcileInventoryPrune.test.jsnew file mode 100644index 0000000000..1e73225594--- /dev/null+++ b/server/services/branchReconcileInventoryPrune.test.js@@ -0,0 +1,20 @@+import { describe, it, expect, vi } from 'vitest';+vi.mock('../lib/execGit.js', () => ({ execGit: vi.fn(async () => ({ stdout: 'worktree /repo\nbranch refs/heads/main\n\n', exitCode: 0 })) }));+vi.mock('../lib/fileCore.js', () => ({ pathExists: vi.fn(async () => false) }));+import { findGoneInventoryRows } from './branchReconcileInventoryPrune.js';+import { execGit } from '../lib/execGit.js';+import { pathExists } from '../lib/fileCore.js';++describe('historical checkout inventory', () => {+ it('reports missing obligation originals only for display, preserving the default pruning contract', async () => {+ const primary = { path: '/repo', branch: 'main' };+ const obligation = { path: '/old', branch: 'fix/example', reason: 'retirement-receipt-unverified' };+ const rows = [primary, obligation];+ expect(await findGoneInventoryRows('/repo', rows)).toEqual([]);+ expect(await findGoneInventoryRows('/repo', rows, { includeObligations: true })).toEqual([obligation]);+ pathExists.mockResolvedValueOnce(true);+ expect(await findGoneInventoryRows('/repo', rows, { includeObligations: true })).toEqual([]);+ execGit.mockRejectedValueOnce(new Error('git unavailable'));+ await expect(findGoneInventoryRows('/repo', rows, { includeObligations: true })).rejects.toThrow('git unavailable');+ });+});diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.jsindex 2236eb94af..6082e5e710 100644--- a/server/services/taskSchedule.js+++ b/server/services/taskSchedule.js@@ -21,7 +21,7 @@import { scheduleExecutionFieldsSchema } from '../lib/scheduleExecutionFieldsValidation.js';import { unresolvedRetirements, retainRetirementObligations, sameRetirementCheckout } from '../lib/reconcileRetirementEvidence.js';-import { findGoneInventoryRows } from './branchReconcileInventoryPrune.js';+import { findGoneInventoryRows, isObligationRow } from './branchReconcileInventoryPrune.js';import { createHash, randomUUID } from 'node:crypto';import { ServerError } from '../lib/errorHandler.js';import { taskExecutionKey as executionKey } from '../lib/scheduledTaskTypes.js';@@ -834,9 +834,16 @@ async function pruneGoneInventory(appId, outcome) {if (!appId || !outcome?.remaining?.length) return outcome;const app = await getAppById(appId).catch(() => null);if (!app?.repoPath) return outcome;- const gone = await findGoneInventoryRows(app.repoPath, outcome.remaining).catch(() => []);+ const gone = await findGoneInventoryRows(app.repoPath, outcome.remaining, { includeObligations: true }).catch(() => []);if (!gone.length) return outcome;- return await dropInventoryRows(appId, gone).catch(() => null) ?? outcome;+ const obsolete = gone.filter(row => !isObligationRow(row));+ const current = obsolete.length ? await dropInventoryRows(appId, obsolete).catch(() => null) ?? outcome : outcome;+ // Missing originals do not prove preservation. Keep obligations, but do not+ // present their historical tuple as a checkout that can still be retired.+ return { ...current, remaining: current.remaining.map(row => ({+ ...row,+ ...(row.path && gone.some(missing => sameRetirementCheckout(missing, row)) && { checkoutMissing: true }),+ })) };}const RETIRED_CHECKOUTS_KEPT = 20;diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.jsindex c6c26df818..293228a7a1 100644--- a/server/services/taskSchedule.test.js+++ b/server/services/taskSchedule.test.js@@ -1,5 +1,10 @@import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'+vi.mock('./branchReconcileInventoryPrune.js', async importOriginal => ({+ ...await importOriginal(), findGoneInventoryRows: vi.fn(async () => []),+}));+import { findGoneInventoryRows } from './branchReconcileInventoryPrune.js';+vi.mock('./cosEvents.js', () => ({cosEvents: { emit: vi.fn() },emitLog: vi.fn()@@ -146,6 +151,7 @@ import {getPerpetualDrainState,recordPerpetualDispatch,recordBranchReconcileOutcome,+ getBranchReconcileOutcome,recordInitializedRetirementRecovery,recordHeldCheckoutRetirement,applyOnDemandRunResets,@@ -2551,6 +2557,24 @@ describe('taskSchedule', () => {})describe('getScheduleStatus', () => {+ it('keeps missing preservation obligations while marking their checkout unavailable only in the response', async () => {+ const row = { branch: 'fix/example', path: '/example/gone', head: 'abc', locked: false, reason: 'retirement-receipt-unverified' };+ const outcome = { status: 'incomplete', remaining: [row], retirementObligations: [row] };+ mockSchedule({ tasks: { 'branch-reconcile': { type: 'on-demand', enabled: true } }, executions: {+ 'task:branch-reconcile': { perApp: { 'app-1': { branchReconcileOutcome: outcome } } },+ } });+ getAppById.mockResolvedValue({ id: 'app-1', repoPath: '/example' });+ findGoneInventoryRows.mockResolvedValueOnce([row]);+ const status = await getScheduleStatus();+ expect(status.tasks['branch-reconcile'].reconcileOutcomes['app-1']).toMatchObject({+ status: 'incomplete', remaining: [{ ...row, checkoutMissing: true }], retirementObligations: [row],+ });+ expect(await getBranchReconcileOutcome('app-1')).toEqual(outcome);+ findGoneInventoryRows.mockRejectedValueOnce(new Error('inventory unavailable'));+ const unknown = await getScheduleStatus();+ expect(unknown.tasks['branch-reconcile'].reconcileOutcomes['app-1'].remaining).toEqual([row]);+ });+beforeEach(() => {loadState.mockResolvedValue({ config: { improvementEnabled: true } })})