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: scope shared Git retirement inspection to captured data (#12630)

[._.]/8fc1fe4e423a
diff --git a/scripts/lib/initialized_checkout_archive.py b/scripts/lib/initialized_checkout_archive.py
index dcd63e4824..9eedccb735 100644
--- a/scripts/lib/initialized_checkout_archive.py
+++ b/scripts/lib/initialized_checkout_archive.py
@@ -235,7 +235,7 @@ def checked_config(admin):
fail('unknown-git-extension')
-def check_admin(admin, module=False):
+def check_admin(admin, module=False, common=False):
if any((admin / name).exists() for name in OPERATIONS):
fail('active-or-partial-git-state')
for name in ('objects/info/alternates', 'objects/info/http-alternates', 'info/grafts'):
@@ -243,10 +243,18 @@ def check_admin(admin, module=False):
fail('external-object-dependency')
if module and any((admin / name).exists() for name in ('commondir', 'worktrees', 'modules')):
fail('shared-or-nested-module')
- # Only walk the current private administration; the common worktrees/ tree
- # belongs to other live agents and is deliberately outside this capture.
+ # Shared capture includes only COMMON_PARTS. Primary-checkout modules and
+ # runtime sockets remain live outside it; private module administration is
+ # captured in full and must still reject every special file. Root locks and
+ # operation/config/object dependencies remain guards even outside the copy.
for current, dirs, files in os.walk(admin, followlinks=False):
- if Path(current) == admin and not module:
+ if Path(current) == admin and common:
+ if any(name.endswith(('.lock', '.promisor')) or name.startswith('sharedindex.')
+ for name in [*dirs, *files]):
+ fail('active-or-dependent-git-state')
+ dirs[:] = [name for name in dirs if name in COMMON_PARTS]
+ files = [name for name in files if name in COMMON_PARTS]
+ elif Path(current) == admin and not module:
dirs[:] = [d for d in dirs if d not in ('worktrees', 'portos-checkout-admission')]
for name in [*dirs, *files]:
path = Path(current) / name
@@ -376,7 +384,7 @@ def inspect(request, full=False):
work, admin, common = scan(request)
release = request['release']
check_admin(admin)
- check_admin(common)
+ check_admin(common, common=True)
parent = git_facts(admin, work)
branch = git(admin, work, 'symbolic-ref', '--short', 'HEAD')
if parent['head'] != release['head'] or branch != release['branch']:
@@ -634,7 +642,7 @@ def verify(request):
if manifest(path) != facts['sources'][label]:
fail('source-content-or-identity-changed:' + label)
common = safe_path(facts['commonGitDir'])
- check_admin(common)
+ check_admin(common, common=True)
if identity(common) != facts['identity']['common']:
fail('common-store-incarnation-changed')
restoring = request.get('mode') == 'restore'
diff --git a/scripts/lib/initialized_checkout_archive_test.py b/scripts/lib/initialized_checkout_archive_test.py
index 238f8ae57a..d0cf40bb2a 100644
--- a/scripts/lib/initialized_checkout_archive_test.py
+++ b/scripts/lib/initialized_checkout_archive_test.py
@@ -4,6 +4,7 @@ import json
import os
from pathlib import Path
import shutil
+import socket
import subprocess
import sys
import tempfile
@@ -77,6 +78,65 @@ class NativeArchive(unittest.TestCase):
(admission / 'writer.lock').write_text('owned service bookkeeping')
self.assertEqual(archive.inspect(self.request), before)
+ def test_common_runtime_sockets_are_outside_capture_but_private_and_captured_sockets_hold(self):
+ facts = archive.inspect(self.request)
+ common = Path(facts['commonGitDir'])
+ private = Path(facts['privateGitDir'])
+ # Relative bind avoids Darwin's short AF_UNIX path limit. No daemon is
+ # started; sockets and stores belong exclusively to this fixture.
+ def bind(path):
+ listener = socket.socket(socket.AF_UNIX)
+ previous = Path.cwd()
+ try:
+ os.chdir(path.parent)
+ listener.bind(path.name)
+ finally:
+ os.chdir(previous)
+ self.addCleanup(listener.close)
+ return listener
+
+ excluded = (common / 'fsmonitor--daemon.ipc',
+ common / 'modules/sub/fsmonitor--daemon.ipc')
+ for path in excluded:
+ bind(path)
+ socket_leases = [(path.lstat().st_ino, path.lstat().st_mode) for path in excluded]
+ self.assertEqual(archive.inspect(self.request), facts)
+ self.preserve()
+ self.assertTrue(archive.verify(self.request)['verified'])
+ self.assertFalse((self.txn / 'archive/common/fsmonitor--daemon.ipc').exists())
+ self.assertFalse((self.txn / 'archive/common/modules').exists())
+ self.assertTrue(archive.verify({**self.request, 'mode': 'standalone'})['standalone'])
+ self.assertEqual([(path.lstat().st_ino, path.lstat().st_mode) for path in excluded], socket_leases)
+
+ for path in (common / 'objects/fixture.ipc', common / 'refs/fixture.ipc',
+ common / 'rr-cache', private / 'fixture.ipc',
+ Path(facts['modules'][0]['gitDir']) / 'fixture.ipc'):
+ parent_stat = path.parent.stat()
+ listener = bind(path)
+ try:
+ with self.assertRaisesRegex(RuntimeError, 'special-git-file-unsupported'):
+ archive.inspect(self.request)
+ with self.assertRaisesRegex(RuntimeError, 'special-(git-)?file-unsupported'):
+ archive.verify(self.request)
+ finally:
+ listener.close()
+ path.unlink()
+ os.utime(path.parent, ns=(parent_stat.st_atime_ns, parent_stat.st_mtime_ns))
+ # Shared operation and dependency guards must not disappear with the
+ # narrower payload walk, including locks outside COMMON_PARTS.
+ for relative, reason in (('index.lock', 'active-or-dependent-git-state'),
+ ('MERGE_HEAD', 'active-or-partial-git-state'),
+ ('objects/info/alternates', 'external-object-dependency')):
+ path = common / relative
+ path.write_text('held')
+ try:
+ with self.assertRaisesRegex(RuntimeError, reason):
+ archive.inspect(self.request)
+ with self.assertRaisesRegex(RuntimeError, reason):
+ archive.verify(self.request)
+ finally:
+ path.unlink()
+
def test_restore_is_offline_and_preserves_staged_private_and_metadata(self):
subprocess.run(['/usr/bin/xattr', '-w', 'fixture.attribute', 'preserved', str(self.work / 'ignored')], check=True)
subprocess.run(['/usr/bin/xattr', '-w', 'com.apple.decmpfs', 'fixture-residual',