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: retain held checkouts through orphan discovery fallback (#13405)
[._.]/ Adam Eivy2ce79afd1a91
diff --git a/server/services/retirementAppScope.test.js b/server/services/retirementAppScope.test.jsindex 6ee24182d9..686158e70f 100644--- a/server/services/retirementAppScope.test.js+++ b/server/services/retirementAppScope.test.js@@ -10,12 +10,23 @@ import { materializeGitRepo, SKIP_HEAVY_INTEGRATION } from '../lib/gitTestRepo.jimport { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../lib/mockPathsDataRoot.js';import { PATHS } from '../lib/paths.js';-const injected = vi.hoisted(() => ({ app: null, apps: null, schedule: null, scheduleWrites: 0, failScheduleWrite: null }));+const injected = vi.hoisted(() => ({ app: null, apps: null, schedule: null, scheduleWrites: 0, failScheduleWrite: null, failOrphanInventory: false, inventoryFailureArmed: false, inventoryFailures: 0 }));vi.mock('../lib/paths.js', async importOriginal => makePathsProxy(await importOriginal(), {dataRoot: () => realpathSync.native(lazyTempDataRoot('portos-cleanup-receipts-')),extraOverrides: () => ({ root: injected.app?.repoPath || lazyTempDataRoot('portos-cleanup-receipts-') }),}));afterAll(cleanupTempDataRoots);+vi.mock('../lib/execGit.js', async importOriginal => {+ const actual = await importOriginal();+ return { ...actual, execGit: async (args, cwd, options) => {+ if (injected.inventoryFailureArmed && args[0] === 'worktree' && args[1] === 'list') {+ injected.inventoryFailureArmed = false;+ injected.inventoryFailures++;+ throw new Error('synthetic orphan inventory failure');+ }+ return actual.execGit(args, cwd, options);+ } };+});vi.mock('./apps.js', () => ({getAllApps: async () => { if (injected.apps instanceof Error) throw injected.apps; return injected.apps ?? (injected.app ? [injected.app] : []); },getAppById: async id => injected.app?.id === id ? injected.app : null,@@ -28,7 +39,10 @@ vi.mock('./branchCompletionPolicy.js', () => ({ readBranchCompletionHold: asyncvi.mock('./taskScheduleStore.js', async importOriginal => ({...await importOriginal(), loadSchedule: async () => injected.schedule,updateSchedule: async mutate => {- if (++injected.scheduleWrites === injected.failScheduleWrite) throw new Error('synthetic receipt persistence failure');+ if (++injected.scheduleWrites === injected.failScheduleWrite) {+ injected.inventoryFailureArmed = injected.failOrphanInventory;+ throw new Error('synthetic receipt persistence failure');+ }return (await mutate(injected.schedule)).result;},}));@@ -38,7 +52,7 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('outside reconciliation retirement receilet scratch;let repo;beforeEach(async () => {- Object.assign(injected, { app: null, apps: null, schedule: { tasks: {}, executions: {} }, scheduleWrites: 0, failScheduleWrite: null });+ Object.assign(injected, { app: null, apps: null, schedule: { tasks: {}, executions: {} }, scheduleWrites: 0, failScheduleWrite: null, failOrphanInventory: false, inventoryFailureArmed: false, inventoryFailures: 0 });scratch = realpathSync.native(await mkdtemp(join(tmpdir(), 'portos-cleanup-repo-')));await mkdir(join(scratch, 'repo'));await materializeGitRepo(join(scratch, 'repo'), { identity: { email: '[email protected]', name: 'Test' } });@@ -105,6 +119,20 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('outside reconciliation retirement receiexpect(outcome.retirementObligations, JSON.stringify(result)).toContainEqual(expect.objectContaining({ path: release.path, head: release.head }));});+ it('retains a failed daily preservation even when orphan inventory fails and external discovery retries it', async () => {+ const { release, run } = await outsideCleanupFixture('daily cleanup');+ injected.failScheduleWrite = injected.scheduleWrites + 3;+ injected.failOrphanInventory = true;+ const result = await run();+ expect(injected.inventoryFailures).toBe(1);+ expect(result).toMatchObject({ mergedReaped: 0, worktreesReaped: 0,+ worktreeHolds: [expect.objectContaining({ path: release.path, reason: 'archive-failed' })] });+ expect(existsSync(release.path)).toBe(true);+ expect(await registered(release.path)).toBe(true);+ expect((await execGit(['rev-parse', release.branch], repo)).stdout.trim()).toBe(release.head);+ expect((await getBranchReconcileOutcome('app-1')).retired || []).toEqual([]);+ });+it.each(['Git UI', 'daily cleanup'])('keeps failed %s completion and a recreated checkout separate from its old archive', async entryPoint => {const { release, unrelated, run } = await outsideCleanupFixture(entryPoint);injected.failScheduleWrite = injected.scheduleWrites + 4;diff --git a/server/services/worktreeManager.js b/server/services/worktreeManager.jsindex 0afeecc2ac..a19cb2b0c5 100644--- a/server/services/worktreeManager.js+++ b/server/services/worktreeManager.js@@ -2109,7 +2109,7 @@ export async function cleanupOrphanedWorktrees(sourceWorkspace, getActiveIds, {// Scan for external-repo worktrees (directories whose .git points to a different repo).// These are invisible to `git worktree list` run against PortOS.- cleaned += await cleanupExternalRepoWorktrees(readActiveIds, handledAgentIds, readOwners);+ cleaned += await cleanupExternalRepoWorktrees(readActiveIds, handledAgentIds, readOwners, retainedPaths);if (cleaned > 0) {console.log(`🌳 Cleaned ${cleaned} orphaned worktree(s)`);@@ -2300,7 +2300,7 @@ export async function reapMergedWorktrees(sourceWorkspace, {* These are created when agents work on apps outside PortOS but use the shared* worktrees directory. They're invisible to PortOS's `git worktree list`.*/-async function cleanupExternalRepoWorktrees(readActiveIds, alreadyHandled, readOwners) {+async function cleanupExternalRepoWorktrees(readActiveIds, alreadyHandled, readOwners, retainedPaths) {const { getDefaultBranch, hasBranchMergeEvidence } = await import('./git.js');const { retireWithUnlockedArchive } = await import('./cosClaimOwnershipState.js');const entries = await readdir(WORKTREES_DIR, { withFileTypes: true }).catch(() => []);@@ -2330,7 +2330,7 @@ async function cleanupExternalRepoWorktrees(readActiveIds, alreadyHandled, readO// keeps them. Compare Git's own spelling with its registration output.const gitWorktreePath = await execGit(['rev-parse', '--show-toplevel'], worktreePath).then(r => r.stdout.trim()).catch(() => null);- if (!gitWorktreePath) continue;+ if (!gitWorktreePath || retainedPaths.has(gitWorktreePath)) continue;const registrations = await listWorktrees(worktreePath).catch(() => []);const wt = registrations.find(candidate => pathsEqual(candidate.path, gitWorktreePath));const primary = registrations[0];