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

Preserve accurate cleanup holds across path aliases

[._.]/ Adam Eivyce9ad2b8de9b
diff --git a/server/services/completedCheckoutEvidence.js b/server/services/completedCheckoutEvidence.js
index 0069eb2a41..cc5ecfb35c 100644
--- a/server/services/completedCheckoutEvidence.js
+++ b/server/services/completedCheckoutEvidence.js
@@ -60,7 +60,11 @@ export async function captureCompletedCheckouts(agent, { success } = {}) {
for (const branch of new Set(branches)) {
if (typeof branch !== 'string' || !branch) continue;
const holders = trees.filter(tree => shortBranch(tree.branch) === branch);
- if (holders.length !== 1 || (!claim && resolve(holders[0].path) !== resolve(meta.workspacePath || ''))) continue;
+ if (holders.length !== 1) continue;
+ if (!claim) {
+ const recordedPath = typeof meta.workspacePath === 'string' ? await realpath(meta.workspacePath).catch(() => null) : null;
+ if (!recordedPath || await realpath(holders[0].path).catch(() => null) !== recordedPath) continue;
+ }
const target = { repoPath: meta.sourceWorkspace, branch, path: holders[0].path, head: holders[0].head };
const first = await readCompletedCheckoutIdentity(target).catch(() => null);
if (!first || !same(first, await readCompletedCheckoutIdentity(target).catch(() => null))) continue;
diff --git a/server/services/cosTaskPreStepBlocks.compose.test.js b/server/services/cosTaskPreStepBlocks.compose.test.js
index 54c25a6db1..335d2a2650 100644
--- a/server/services/cosTaskPreStepBlocks.compose.test.js
+++ b/server/services/cosTaskPreStepBlocks.compose.test.js
@@ -32,6 +32,8 @@ const BRANCH_RECONCILE_TEMPLATE = [
'{inFlightBranches}',
].join('\n');
+vi.mock('./cosEvents.js', async original => ({ ...await original(), emitLog: vi.fn() }));
+
vi.mock('./taskPromptService.js', () => ({
getTaskPrompt: vi.fn(async () => BRANCH_RECONCILE_TEMPLATE),
getStagePrompt: vi.fn(async () => BRANCH_RECONCILE_TEMPLATE),
@@ -109,6 +111,7 @@ 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';
@@ -173,6 +176,9 @@ describe('generateManagedAppImprovementTaskForType composes the extracted pre-st
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' }),
]) }));
diff --git a/server/services/cosTaskPreStepBlocks.js b/server/services/cosTaskPreStepBlocks.js
index 0c9cd53823..27e7675636 100644
--- a/server/services/cosTaskPreStepBlocks.js
+++ b/server/services/cosTaskPreStepBlocks.js
@@ -612,8 +612,9 @@ export async function resolveBranchReconcileBlock(app, taskType, metadata, taskS
// toggle are the OTHER way "nothing in-flight" can lie — say so, or the user
// sees a park while real branches sit there (the same invisibility that hid
// the abandoned-worktree case).
- const gatedSuffix = countSuffix(result.inFlight, 'in-flight branch(es) skipped by disabled action toggles', (b) => b.state);
- emitLog('info', `🔀 branch-reconcile parked for ${app.name}: nothing actionable (cleaned ${result.cleaned.length}${heldSuffix}${gatedSuffix}${heldLiveSuffix}${supersededSuffix}${detachedSuffix})`, { appId: app.id });
+ const gatedSuffix = countSuffix(cognitiveInFlight.filter(branch => !allActionable.includes(branch)), 'in-flight branch(es) skipped by disabled action toggles', (b) => b.state);
+ const deliverySuffix = countSuffix(routineDeliveryHolds, 'delivery branch(es) awaiting completion', branch => branch.reason);
+ emitLog('info', `🔀 branch-reconcile parked for ${app.name}: nothing actionable (cleaned ${result.cleaned.length}${heldSuffix}${gatedSuffix}${deliverySuffix}${heldLiveSuffix}${supersededSuffix}${detachedSuffix})`, { appId: app.id });
return { skip: true };
}
// Retain attempted revisions across caps/manual retries. A blocked prefix must
diff --git a/server/services/repoCleanupObservation.js b/server/services/repoCleanupObservation.js
index 4439385791..bb3fd56de1 100644
--- a/server/services/repoCleanupObservation.js
+++ b/server/services/repoCleanupObservation.js
@@ -1,6 +1,7 @@
import { constants } from 'fs';
import { lstat, open } from 'fs/promises';
import { join } from 'path';
+import { isSafeGitRef } from '../lib/gitArgs.js';
import { parsePullRequestUrl } from '../lib/gitForge.js';
import { execGit } from '../lib/execGit.js';
@@ -62,12 +63,18 @@ export async function readLocalBranchPresence(repoPath, branch) {
length += read.bytesRead;
}
if (BigInt(length) !== stat.size) return null;
- const text = bytes.subarray(0, length).toString('utf8');
+ const text = new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(0, length));
+ let canPeel = false;
for (const line of text.split('\n')) {
- if (!line || line.startsWith('#')) continue;
- if (/^\^[a-f0-9]{40}(?:[a-f0-9]{24})?$/.test(line)) continue;
+ if (!line || line.startsWith('#')) { canPeel = false; continue; }
+ if (/^\^[a-f0-9]{40}(?:[a-f0-9]{24})?$/.test(line)) {
+ if (!canPeel) return null;
+ canPeel = false;
+ continue;
+ }
const row = /^([a-f0-9]{40}(?:[a-f0-9]{24})?) (refs\/[^\s]+)$/.exec(line);
- if (!row || row[2] === ref) return null;
+ if (!row || !isSafeGitRef(row[2]) || row[2].split('/').some(part => !part || part.startsWith('.') || part.endsWith('.lock')) || row[2] === ref) return null;
+ canPeel = true;
}
if (!same(identity(await packed.stat({ bigint: true })), packedBefore)) return null;
} finally { await packed.close(); }
diff --git a/server/services/repoCleanupObservation.test.js b/server/services/repoCleanupObservation.test.js
index 39fee616ee..a940caa0b7 100644
--- a/server/services/repoCleanupObservation.test.js
+++ b/server/services/repoCleanupObservation.test.js
@@ -49,6 +49,15 @@ describe('exact local branch absence accounting', () => {
expect(await readLocalBranchPresence(root, 'claim/absent')).toBe(null);
expect(count).toBe(2);
});
+ it.each([
+ ['invalid ref grammar', Buffer.from(`${'a'.repeat(40)} refs/heads/a..b\n`)],
+ ['invalid encoding', Buffer.concat([Buffer.from(`${'a'.repeat(40)} refs/heads/`), Buffer.from([0xff]), Buffer.from('\n')])],
+ ['orphan peeled row', Buffer.from(`^${'a'.repeat(40)}\n`)],
+ ])('keeps %s in packed refs unknown rather than proving absence', async (_name, bytes) => {
+ await writeFile(join(root, '.git', 'packed-refs'), bytes);
+ expect(await readLocalBranchPresence(root, 'claim/absent')).toBe(null);
+ });
+
it('refuses malformed packed metadata and unknown repository errors as absence proof', async () => {
await writeFile(join(root, '.git', 'packed-refs'), `${'a'.repeat(40)} refs/heads/claim/absent trailing-token\n`);
expect(await readLocalBranchPresence(root, 'claim/absent')).toBe(null);