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 archive carrier root permissions (#13487)
[._.]/7de64402bf2b
diff --git a/scripts/lib/initialized_checkout_archive.py b/scripts/lib/initialized_checkout_archive.pyindex 5126819bee..04d1fe7b60 100644--- a/scripts/lib/initialized_checkout_archive.py+++ b/scripts/lib/initialized_checkout_archive.py@@ -497,8 +497,10 @@ def copy_tree_contents(source, destination):# Only NEW copies are changed, without following even dangling links.# chown may clear set-id bits; restore the original mode afterward.os.chown(target, original_stat.st_uid, original_stat.st_gid, follow_symlinks=False)- if stat.S_IMODE(target.lstat().st_mode) != stat.S_IMODE(original_stat.st_mode):- os.chmod(target, stat.S_IMODE(original_stat.st_mode), follow_symlinks=False)+ # The inherited-group carrier starts private (0700). ditto may leave+ # that existing root mode unchanged even when ownership already matches.+ if stat.S_IMODE(target.lstat().st_mode) != stat.S_IMODE(original_stat.st_mode):+ os.chmod(target, stat.S_IMODE(original_stat.st_mode), follow_symlinks=False)# ditto creates symlinks with the current timestamp and leaves a# pre-created root directory's timestamp changed by its child writes.# Restore only NEW-copy metadata; never resolve a dependency link.diff --git a/scripts/lib/initialized_checkout_archive_test.py b/scripts/lib/initialized_checkout_archive_test.pyindex bf64373c41..fdf9a11c1c 100644--- a/scripts/lib/initialized_checkout_archive_test.py+++ b/scripts/lib/initialized_checkout_archive_test.py@@ -170,6 +170,7 @@ class NativeArchive(unittest.TestCase):self.skipTest('Requires the Darwin inherited temporary group outside the caller groups')work = Path(tempfile.mkdtemp(prefix='initialized-inherited-group-', dir='/private/tmp'))try:+ work.chmod(0o755)self.git(self.repo, 'worktree', 'add', '-b', 'feature/inherited', str(work))self.git(work, '-c', 'protocol.file.allow=always', 'submodule', 'update', '--init')(work / 'ignored-evidence').write_text('recoverable bytes\n')@@ -186,6 +187,7 @@ class NativeArchive(unittest.TestCase):for prefix in ('archive', 'restore'):copied = archive.manifest(self.txn / prefix / 'working')self.assertTrue(all(row['gid'] == group for row in copied))+ self.assertEqual((self.txn / prefix / 'working').stat().st_mode & 0o7777, 0o755)self.assertEqual(archive.manifest(work), before)self.assertTrue(archive.verify({**self.request, 'mode': 'standalone'})['standalone'])finally:diff --git a/server/services/branchCompletionPolicy.js b/server/services/branchCompletionPolicy.jsindex 32b1dcfd4a..309a7452c3 100644--- a/server/services/branchCompletionPolicy.js+++ b/server/services/branchCompletionPolicy.js@@ -143,7 +143,7 @@ function reviewedOrphanCheckout(policy, input) {&& agent.result.validationPassed !== false && retirementPr(policy) === input.prUrl&& input.verifiedPrHead === input.tip && !!input.tip&& agent.metadata?.completedCheckouts?.some(row => completedCheckoutReceiptValid(agent, row)- && row.repoPath === input.repoPath && row.branch === input.branch && row.path === input.checkoutPath+ && samePath(row.repoPath, input.repoPath) && row.branch === input.branch && samePath(row.path, input.checkoutPath)&& row.head === input.tip && row.incarnation?.pointer && row.incarnation?.gitdir);}diff --git a/server/services/heldCheckoutRecovery.js b/server/services/heldCheckoutRecovery.jsindex 932d8014a1..df36509d42 100644--- a/server/services/heldCheckoutRecovery.js+++ b/server/services/heldCheckoutRecovery.js@@ -22,7 +22,7 @@ import { readRetirementCheckoutIdentity } from '../lib/retirementCheckoutObservaimport { findGoneInventoryRows } from './branchReconcileInventoryPrune.js';import { realpathSync, constants } from 'node:fs';import { pipeline } from 'node:stream/promises';-import { lstat, stat, readlink, readdir, opendir, readFile, chmod, open, mkdtemp } from 'node:fs/promises';+import { lstat, stat, realpath, readlink, readdir, opendir, readFile, chmod, open, mkdtemp } from 'node:fs/promises';import { tmpdir } from 'node:os';import { createHash, randomUUID } from 'node:crypto';import { basename, dirname, isAbsolute, join, resolve, relative, sep } from 'node:path';@@ -589,6 +589,10 @@ export async function prepareInventoriedCheckoutRetirement({ appId, release, prUconst forge = await (opts.readForge || readRetirementForgeEvidence)(app.repoPath, release.branch, prUrl,{ forgeAccount: app.forgeAccount ?? null }).catch(() => null);if (forge?.prUrl === prUrl && forge.prHead === release.head) {+ const [repoPath, checkoutPath] = await Promise.all([+ realpath(app.repoPath).catch(() => null), realpath(release.path).catch(() => null),+ ]);+ if (!repoPath || !checkoutPath) return prepared;const { readBranchCompletionPolicies } = await import('./branchCompletionPolicy.js');const policies = await (opts.readPolicies || (() => readBranchCompletionPolicies({ repairIndex: false })))().catch(() => null);const retry = opts.recoverCheckoutCapture || (await import('./cosAgentLifecycle.js')).retryCompletionCheckoutCapture;@@ -598,8 +602,8 @@ export async function prepareInventoriedCheckoutRetirement({ appId, release, prUconst knownPr = meta.branchCompletionPolicy?.prUrl || meta.reviewLoopMergeTarget?.url;if (agent.status !== 'completed' || agent.result?.orphaned !== true || agent.result.validationPassed === false|| knownPr !== prUrl || meta.checkoutCapture?.status !== 'captured' || meta.completedCheckouts?.length !== 0- || !meta.checkoutSeeds?.some(seed => seed.repoPath === app.repoPath && seed.branch === release.branch && seed.path === release.path)) continue;- recovered = await retry(agent.id || agent.agentId, { retirement: { repoPath: app.repoPath, ...release } }).catch(() => false) || recovered;+ || !meta.checkoutSeeds?.some(seed => seed.repoPath === repoPath && seed.branch === release.branch && seed.path === checkoutPath)) continue;+ recovered = await retry(agent.id || agent.agentId, { retirement: { ...release, repoPath, path: checkoutPath } }).catch(() => false) || recovered;}if (recovered) prepared = await review();}diff --git a/server/services/heldCheckoutRecovery.test.js b/server/services/heldCheckoutRecovery.test.jsindex 1556db7bf5..7b284bae97 100644--- a/server/services/heldCheckoutRecovery.test.js+++ b/server/services/heldCheckoutRecovery.test.js@@ -1555,7 +1555,7 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()expect(await readFile(join(result.archiveDir, 'files/ignored.txt'), 'utf8')).toBe('ignored work\n');});- it.each(['original', 'recreated-pointer', 'active-owner', 'different-pr-head', 'failed-validation'])('recovers a merged orphan only from its exact early generation: %s', async scenario => {+ it.each(['original', 'repo-alias', 'recreated-pointer', 'active-owner', 'different-pr-head', 'failed-validation'])('recovers a merged orphan only from its exact early generation: %s', async scenario => {const c = await reviewedCheckout(`orphan-${scenario}`);await execGit(['worktree', 'unlock', c.path], repo);Object.assign(c.release, { locked: false, lockReason: null });@@ -1570,13 +1570,14 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()agent.completedAt = new Date().toISOString();agent.metadata.completedCheckouts = [];agent.metadata.checkoutCapture = { status: 'captured' };+ if (scenario === 'repo-alias') injected.app.repoPath = `${repo}/../repo`;if (scenario === 'failed-validation') agent.result.validationPassed = false;injected.policies = [agent];const originalResult = structuredClone(agent.result);let recoveries = 0;c.opts.recoverCheckoutCapture = async (id, { retirement }) => {expect(id).toBe(agent.id);- expect(retirement).toMatchObject({ repoPath: repo, ...c.release });+ expect(retirement).toMatchObject({ ...c.release, repoPath: realpathSync(repo), path: realpathSync(c.path) });const captured = await evidence.captureSeededCompletionCheckouts(agent);if (!captured) return false;agent.metadata.completedCheckouts = captured;@@ -1592,14 +1593,14 @@ describe.skipIf(SKIP_HEAVY_INTEGRATION)('held checkout recovery (real git)', ()if (scenario === 'different-pr-head') c.forge.prHead = 'b'.repeat(40);const prepared = await c.prepare();expect(agent.result).toEqual(originalResult);- if (scenario !== 'original') {+ if (!['original', 'repo-alias'].includes(scenario)) {expect(prepared.ok).toBe(false);expect(await registered(c.path)).toBe(true);expect(await archives()).toEqual([]);expect(recoveries).toBe(0);return;}- expect(prepared).toMatchObject({ ok: true, review: { policy: { policies: [{ success: false, orphanedExecution: true }] } } });+ expect(prepared, JSON.stringify(prepared)).toMatchObject({ ok: true, review: { policy: { policies: [{ success: false, orphanedExecution: true }] } } });const receipt = agent.metadata.completedCheckouts[0];expect(receipt).toMatchObject({ version: 2, head: c.release.head });expect(evidence.completedCheckoutReceiptValid(agent, receipt)).toBe(true);