Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/foundry-boot-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ FileVault is enabled on Foundry. Boot services run after macOS can access its st
The Plex share currently uses the existing user/Finder mapping method; mounting before login has not been established. Keychain-backed GitHub credentials may also require unlock. This migration does not change mounts or move credentials into plaintext. Validate both separately.

Evidence on 2026-11-15: all three existing services running as login agents; clean idle migration plan on Foundry; four isolated migration tests cover preserved non-root configuration, existing-system-service/root-account refusal, busy preflight with no changes, and restoration after a synthetic bootstrap failure. Administrator installation and actual reboot acceptance remain pending.

## Corrected KeepAlive stop handling — 2026-11-15

The initial administrator attempt rolled back before installing system jobs: the controller received SIGTERM, then launchd immediately restarted its KeepAlive job. Waiting for a persistent stopped state timed out. All original login services and 4,303 visible Curator tasks were verified healthy afterward. The installer now unloads KeepAlive jobs with bootout, preventing respawn while launchd handles shutdown. Curator retains its successful SIGINT exit before unloading.

Five focused tests pass, including a regression for the restart race. The corrected sequence was also exercised on idle Foundry: all three jobs unloaded without respawn, then their unchanged login definitions were restored; authenticated Forge readiness, Ollama readiness and all 4,303 unchanged Curator records were verified. This validates the corrected stop/restore sequence, not system installation or reboot acceptance. A new staged installer version requires a fresh administrator invocation.
18 changes: 11 additions & 7 deletions scripts/foundry_boot_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ def verify_ready(home):

def stop(target,label):
if not loaded(target):return
command('/bin/launchctl','kill','SIGINT' if label=='com.curator.foundry' else 'SIGTERM',target)
end=time.monotonic()+30
while time.monotonic()<end:
info=command('/bin/launchctl','print',target,check=False)
if info.returncode or not re.search(r'^\s*state = running$',info.stdout,re.M):break
time.sleep(.2)
else:raise RuntimeError('Service did not stop gracefully: '+label)
if label=='com.curator.foundry':
# Curator exits successfully on SIGINT and does not respawn on success.
command('/bin/launchctl','kill','SIGINT',target)
end=time.monotonic()+30
while time.monotonic()<end:
info=command('/bin/launchctl','print',target,check=False)
if info.returncode or not re.search(r'^\s*state = running$',info.stdout,re.M):break
time.sleep(.2)
else:raise RuntimeError('Service did not stop gracefully: '+label)
# Unload KeepAlive jobs rather than signalling and waiting for a stopped
# state: launchd can respawn a signalled job before the next observation.
if loaded(target):command('/bin/launchctl','bootout',target)
end=time.monotonic()+10
while loaded(target) and time.monotonic()<end:time.sleep(.2)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_foundry_boot_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def command(*args,**kw):
with self.assertRaisesRegex(RuntimeError,'synthetic bootstrap'):boot.apply('mike')
for label in boot.LABELS:
self.assertEqual((self.sources/(label+'.plist')).read_bytes(),self.originals[label]);self.assertFalse((self.daemons/(label+'.plist')).exists())
def test_keepalive_jobs_are_unloaded_without_a_signal_restart_race(self):
for label in ('org.forge.local.controller','org.forge.local.ollama'):
with self.subTest(label=label):
active=True;calls=[]
def command(*args,**kwargs):
nonlocal active
calls.append(args)
if args[1]=='kill':self.fail('Signalling a KeepAlive job lets launchd respawn it')
if args[1]=='bootout':active=False
return SimpleNamespace(returncode=0 if active else 113,stdout='state = running' if active else '')
with patch.object(boot,'command',side_effect=command):boot.stop('gui/501/'+label,label)
self.assertFalse(active);self.assertEqual(sum(call[1]=='bootout' for call in calls),1)
def test_busy_preflight_changes_no_files(self):
with patch.object(boot,'assert_idle',side_effect=ValueError('busy')):
with self.assertRaisesRegex(ValueError,'busy'):boot.apply('mike')
Expand Down
Loading