Skip to content

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

fix: keep unresolved preservation from reporting drained (#13271)

Adam Eivy537a6b34e967
diff --git a/server/services/branchReconcileInventoryPrune.js b/server/services/branchReconcileInventoryPrune.js
index 1a1173f288..f467debaf3 100644
--- a/server/services/branchReconcileInventoryPrune.js
+++ b/server/services/branchReconcileInventoryPrune.js
@@ -36,9 +36,14 @@ export async function findGoneInventoryRows(repoPath, rows, { includeObligations
if (row?.reason === 'remote-branch-held') continue;
if (!includeObligations && (isObligationRow(row) || row?.reason === 'claim-reservation-owner-unverified')) continue;
if (typeof row?.path === 'string' && row.path) {
- if (!registered.has(row.path) && await readCheckoutPathPresence(row.path) === false) gone.push(row);
+ if (registered.has(row.path)) continue;
+ const present = await readCheckoutPathPresence(row.path);
+ if (present === null) throw new Error('checkout-presence-unavailable');
+ if (present === false) gone.push(row);
} else if (typeof row?.branch === 'string' && row.branch) {
- if (await readLocalBranchPresence(repoPath, row.branch) === false) gone.push(row);
+ const present = await readLocalBranchPresence(repoPath, row.branch);
+ if (present === null) throw new Error('branch-presence-unavailable');
+ if (present === false) gone.push(row);
}
}
return gone;
diff --git a/server/services/heldCheckoutRecovery.test.js b/server/services/heldCheckoutRecovery.test.js
index d3bd20b724..2be512d126 100644
--- a/server/services/heldCheckoutRecovery.test.js
+++ b/server/services/heldCheckoutRecovery.test.js
@@ -62,7 +62,7 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()
const noOwners = async () => [];
beforeEach(async () => {
- Object.assign(injected, { policies: [], schedule: { executions: {} }, app: { id: 'app-1', repoPath: null }, fetchRemote: null, fetches: [], onBundle: null, onEvidence: null });
+ Object.assign(injected, { policies: [], schedule: { tasks: {}, executions: {} }, app: { id: 'app-1', repoPath: null }, fetchRemote: null, fetches: [], onBundle: null, onEvidence: null });
scratch = realpathSync(await mkdtemp(join(tmpdir(), 'portos-held-checkout-')));
const safeRepo = join(scratch, 'repo');
await mkdir(safeRepo);
@@ -440,6 +440,7 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()
it('retains vanished active claim provenance instead of reporting an unarchived checkout retired', async () => {
const { path, release } = await heldCheckout('already-gone', { branch: 'claim/issue-42' });
+ await execGit(['branch', 'other', 'main'], repo);
const gitDir = (await execGit(['rev-parse', '--absolute-git-dir'], path)).stdout.trim();
await writeFile(join(gitDir, 'portos-review-status'), 'private synthetic evidence');
await recordBranchReconcileOutcome('app-1', {
@@ -481,8 +482,10 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()
const createdAt = pending.retirementObligations[0].createdAt;
// A receipt for another head cannot explain the original disappearance.
await recordHeldCheckoutRetirement('app-1', { ...release, head: 'f'.repeat(40), branchDeleted: true, archiveDir: '/example/other-archive' });
- await recordBranchReconcileOutcome('app-1', { status: 'running', remaining: [] });
- expect((await getBranchReconcileOutcome('app-1')).retirementObligations[0].createdAt).toBe(createdAt);
+ await recordBranchReconcileOutcome('app-1', { status: 'drained', remaining: [] });
+ expect(await getBranchReconcileOutcome('app-1')).toMatchObject({ status: 'incomplete', reason: 'retirement-provenance-unverified',
+ retirementObligations: [{ ...release, reason: 'retirement-provenance-unverified', createdAt }],
+ });
// Only the trusted service writer can supply recovered preservation evidence.
await recordHeldCheckoutRetirement('app-1', { ...release, branchDeleted: true, archiveDir: '/example/recovered-original' });
expect(await getBranchReconcileOutcome('app-1')).toMatchObject({ retirementObligations: [], remaining: [] });
diff --git a/server/services/taskSchedule.js b/server/services/taskSchedule.js
index 95ee4116b6..5c922965d2 100644
--- a/server/services/taskSchedule.js
+++ b/server/services/taskSchedule.js
@@ -790,7 +790,7 @@ export async function recordBranchReconcileOutcome(appId, { status, reason, rema
...previous, status, reason, nextAction, updatedAt: now, retirementObligations,
remaining: retained.length ? [...(current || []), ...retained] : current,
observedAt: remaining === undefined ? record.branchReconcileOutcome?.observedAt ?? null : now,
- ...(missing.length && missingPreservationStatus),
+ ...(retirementObligations.some(row => row.reason === 'retirement-provenance-unverified') && missingPreservationStatus),
};
return { result: record.branchReconcileOutcome, changed: true };
});
diff --git a/server/services/taskSchedule.test.js b/server/services/taskSchedule.test.js
index ec06133195..3adefc553e 100644
--- a/server/services/taskSchedule.test.js
+++ b/server/services/taskSchedule.test.js
@@ -3344,6 +3344,19 @@ describe('taskSchedule', () => {
expect(reloaded.remaining).toEqual(outcome.retirementObligations);
});
+ it('keeps the previous observation when a replacement sweep cannot read source presence', async () => {
+ let saved = { version: 2, tasks: { 'branch-reconcile': { enabled: true, type: 'on-demand' } }, executions: {}, templates: [] };
+ readJSONFile.mockImplementation(async () => structuredClone(saved));
+ writeFile.mockImplementation(async (_path, contents) => { saved = JSON.parse(contents); });
+ const remaining = [{ branch: 'fix/example', path: '/example/checkout', head: 'a'.repeat(40), reason: 'worktree-locked' }];
+ const previous = await recordBranchReconcileOutcome('app-1', { status: 'incomplete', remaining });
+ getAppById.mockResolvedValueOnce({ repoPath: '/example/repo' });
+ findGoneInventoryRows.mockRejectedValueOnce(new Error('checkout-presence-unavailable'));
+ await expect(recordBranchReconcileOutcome('app-1', { status: 'drained', remaining: [] }))
+ .rejects.toThrow('checkout-presence-unavailable');
+ expect(saved.executions['task:branch-reconcile'].perApp['app-1'].branchReconcileOutcome).toEqual(previous);
+ });
+
it('never loses exact retirement obligations across empty scans, restart reads or unrelated receipts', async () => {
let saved = { version: 2, tasks: { 'branch-reconcile': { enabled: true, type: 'on-demand', perpetual: true } }, executions: {}, templates: [] };
readJSONFile.mockImplementation(async () => structuredClone(saved));