Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(autopilot): see and remove a pre-upgrade brain's shared launchd job before it has an install id
garrytan93c62c42299b
diff --git a/src/commands/autopilot.ts b/src/commands/autopilot.tsindex 9b901535cb..b7c7e29f26 100644--- a/src/commands/autopilot.ts+++ b/src/commands/autopilot.ts@@ -1347,7 +1347,7 @@ export function uninstallDaemon() {// macOS launchdconst labels: Array<{ label: string; legacy: boolean }> = [];if (assigned) labels.push({ label: job.launchdLabel, legacy: false });- if (job.kind !== 'default' && autopilotLaunchdLabel(null) !== job.launchdLabel) labels.push({ label: autopilotLaunchdLabel(null), legacy: true });+ if (job.kind !== 'default' && (!assigned || autopilotLaunchdLabel(null) !== job.launchdLabel)) labels.push({ label: autopilotLaunchdLabel(null), legacy: true });for (const { label, legacy } of labels) {const path = plistPath(label);if (!existsSync(path)) continue;diff --git a/src/commands/autopilot/jobs.ts b/src/commands/autopilot/jobs.tsindex de15c16c84..7c1500043f 100644--- a/src/commands/autopilot/jobs.ts+++ b/src/commands/autopilot/jobs.ts@@ -219,7 +219,7 @@ export function detectInstalledJob(job: AutopilotJob): { installed: InstalledJobconst candidates: Array<() => InstalledJob | null> = [];if (process.platform === 'darwin') {if (assigned) candidates.push(() => consider('macos', job.launchdLabel, readIfExists(plistPath(job.launchdLabel)), plistWrapperPath, false));- if (job.kind !== 'default' && autopilotLaunchdLabel(null) !== job.launchdLabel) {+ if (job.kind !== 'default' && (!assigned || autopilotLaunchdLabel(null) !== job.launchdLabel)) {candidates.push(() => consider('macos', autopilotLaunchdLabel(null), readIfExists(plistPath(autopilotLaunchdLabel(null))), plistWrapperPath, true));}}diff --git a/test/e2e/autopilot-multi-brain.serial.test.ts b/test/e2e/autopilot-multi-brain.serial.test.tsindex 34e592531f..c0fe307844 100644--- a/test/e2e/autopilot-multi-brain.serial.test.ts+++ b/test/e2e/autopilot-multi-brain.serial.test.ts@@ -255,6 +255,22 @@ describe('#5195 legacy shared-name jobs and moved brains', () => {expect(run(brainC, ['--uninstall']).status).toBe(0);}, 240_000);+ test('a pre-upgrade brain with no install id still sees and removes its legacy shared launchd job', () => {+ const brainD = join(root, 'brain-d');+ seedBrain(brainD);+ writeFileSync(join(brainD, '.gbrain', 'autopilot-run.sh'), '#!/bin/sh\n', { mode: 0o755 });+ mkdirSync(agentsDir(), { recursive: true });+ const plist = join(agentsDir(), 'com.gbrain.autopilot.plist');+ writeFileSync(plist, `<plist><dict><key>Label</key><string>com.gbrain.autopilot</string><key>ProgramArguments</key><array>\n <string>${brainD}/.gbrain/autopilot-run.sh</string>\n </array></dict></plist>`);+ expect(existsSync(join(brainD, '.gbrain', 'autopilot-install-id'))).toBe(false);+ rmSync(launchctlLog, { force: true });+ const r = run(brainD, ['--uninstall']);+ expect(r.status).toBe(0);+ expect(r.out).toContain('Removed launchd service: com.gbrain.autopilot');+ expect(existsSync(plist)).toBe(false);+ expect(lines(launchctlLog)).toContain(`unload ${plist}`);+ }, 120_000);+test('an unmarked legacy crontab line naming this brain is replaced by its marked line', () => {const legacy = `*/5 * * * * '${brainC}/.gbrain/autopilot-run.sh' >> '${home}/.gbrain/autopilot.log' 2>&1`;writeFileSync(cronState, FOREIGN + legacy + '\n');