Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
doctor: self_upgrade_health warns only on blockers gbrain upgrade cannot clear, after held and failed auto-upgrades (#8776)
garrytan49b95b29600b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 21f007406c..0bff08e32c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,7 +20,7 @@ The upgrade restarted autopilot only through an installed launchd or systemd ser|---|---|---|| Autopilot started by this brain's gbrain cron line | `restart_refused` | handed to the cron line and verified back on the new build || Autopilot started by your own cron entry or wrapper | `restart_refused`, fix `kill <pid>` | still refuses, naming `gbrain autopilot --install` or `gbrain config set self_upgrade.autopilot_launcher external` (declare it only when the launcher starts autopilot again within 5 minutes); declared, it is handed over like the cron line |-| doctor `self_upgrade_health` | silent until an upgrade failed | runs the same pre-swap plan read-only: warns while `gbrain upgrade` would refuse, naming each process and its step (autopilot outside gbrain's service, a process from another install), and names a hand-off or a second Bun global install the upgrade replaces itself |+| doctor `self_upgrade_health` | silent until an upgrade failed | runs the same pre-swap plan read-only: warns while `gbrain upgrade` would refuse, naming each process and its step (autopilot outside gbrain's service, a process from another install), and names a hand-off or a second Bun global install the upgrade replaces itself; a harness MCP server or a running sync does not warn, and a held or failed auto-upgrade is reported first |**The daily stable check no longer sticks on a rolled-back release.** A release that was stable before (its `stable-v<version>` record tag exists) or that `stable.json` lists in `known_bad` is skipped and logged, so the newest release gets its soak instead of a refused promotion on every scheduled run (#8792).diff --git a/docs/guides/upgrades-auto-update.md b/docs/guides/upgrades-auto-update.mdindex 567d2197d2..c19c28db5b 100644--- a/docs/guides/upgrades-auto-update.md+++ b/docs/guides/upgrades-auto-update.md@@ -332,7 +332,9 @@ warns while the next `gbrain upgrade` would refuse, naming each process and itsstep (for an autopilot started outside gbrain's service, `gbrain autopilot--install`, after retiring the launcher that starts it now, or the declaredhand-off above), and names a hand-off or a second Bun global install the-upgrade replaces itself.+upgrade replaces itself. An MCP server a harness started (`--stop-mcp` stops+it) and a running `gbrain sync` (it finishes) do not make it warn, and a held+or failed auto-upgrade is reported first.On an always-on host, start with `gbrain autopilot pause --reason "upgrade"`and wait until `gbrain jobs list --status active --json` returns no jobs, so nodiff --git a/src/commands/doctor/checks/upgrade-health.ts b/src/commands/doctor/checks/upgrade-health.tsindex e929a925d5..a330e4fe76 100644--- a/src/commands/doctor/checks/upgrade-health.ts+++ b/src/commands/doctor/checks/upgrade-health.ts@@ -163,20 +163,6 @@ export function checkSelfUpgradeHealth(restart?: RestartPlan | null): Check {}}- if (restart?.manual.length) {- const autopilot = restart.manual.find((m) => m.role === 'autopilot');- return {- name: 'self_upgrade_health',- status: 'warn',- message: `gbrain upgrade refuses on this host, so ${mode === 'auto' ? 'auto-upgrades' : 'upgrades'} cannot finish: ${restart.manual.map((m) => m.instruction).join(' ')} (${parts.join('; ')}).`,- fix: autopilot- ? agentFix(['gbrain', 'autopilot', '--install'], 'Runs autopilot under launchd, systemd or a gbrain cron line, which every upgrade restarts; the launcher that starts it now has to be retired first.', 'self_upgrade_health', {- ask_user: true, docs: 'docs/guides/upgrades-auto-update.md#restart',- user_message: `autopilot pid ${autopilot.pid} was started outside gbrain's autopilot service, so gbrain upgrade refuses on this host. May I run gbrain autopilot --install, which runs autopilot under launchd, systemd or a gbrain cron line so upgrades restart it, after you retire whatever starts it now? If that launcher starts autopilot again within 5 minutes of it exiting, gbrain config set self_upgrade.autopilot_launcher external keeps it and lets upgrades hand autopilot to it instead.`,- })- : agentFix(['gbrain', 'upgrade', '--restart-only', '--dry-run', '--json'], 'Read-only: lists every gbrain process on this host with the restart each one needs and the steps the upgrade cannot take.', 'self_upgrade_health', { docs: 'docs/guides/upgrades-auto-update.md#restart' }),- };- }// readRecent lists the current week before the previous one; order by ts.const recent = (readRecentSelfUpgrades(7) as SelfUpgradeAuditEvent[]).toSorted((a, b) => (a.ts < b.ts ? -1 : a.ts > b.ts ? 1 : 0));@@ -201,6 +187,21 @@ export function checkSelfUpgradeHealth(restart?: RestartPlan | null): Check {};}+ const blockers = (restart?.manual ?? []).filter((m) => m.role !== 'sync' && !(m.role === 'mcp' && m.argv[0] === 'kill'));+ if (blockers.length) {+ const autopilot = blockers.find((m) => m.role === 'autopilot');+ return {+ name: 'self_upgrade_health',+ status: 'warn',+ message: `gbrain upgrade refuses on this host: ${blockers.map((m) => m.instruction).join(' ')} (${parts.join('; ')}).`,+ fix: autopilot+ ? agentFix(['gbrain', 'autopilot', '--install'], 'Runs autopilot under launchd, systemd or a gbrain cron line, which every upgrade restarts; the launcher that starts it now has to be retired first.', 'self_upgrade_health', {+ ask_user: true, docs: 'docs/guides/upgrades-auto-update.md#restart',+ user_message: `autopilot pid ${autopilot.pid} was started outside gbrain's autopilot service, so gbrain upgrade refuses on this host. May I run gbrain autopilot --install, which runs autopilot under launchd, systemd or a gbrain cron line so upgrades restart it, after you retire whatever starts it now? If that launcher starts autopilot again within 5 minutes of it exiting, gbrain config set self_upgrade.autopilot_launcher external keeps it and lets upgrades hand autopilot to it instead.`,+ })+ : agentFix(['gbrain', 'upgrade', '--restart-only', '--dry-run', '--json'], 'Read-only: lists every gbrain process on this host with the restart each one needs and the steps the upgrade cannot take.', 'self_upgrade_health', { docs: 'docs/guides/upgrades-auto-update.md#restart' }),+ };+ }return { name: 'self_upgrade_health', status: 'ok', message: parts.join('; ') };} catch (e) {return {diff --git a/test/upgrade-restart-external-autopilot-8776.test.ts b/test/upgrade-restart-external-autopilot-8776.test.tsindex e7e6ed26b1..13d058af84 100644--- a/test/upgrade-restart-external-autopilot-8776.test.ts+++ b/test/upgrade-restart-external-autopilot-8776.test.ts@@ -14,6 +14,9 @@ import { checkSelfUpgradeHealth } from '../src/commands/doctor/checks/upgrade-heimport { resolveAutopilotJob } from '../src/core/autopilot-paths.ts';import { parseSelfUpgradeConfigValue, SELF_UPGRADE_CONFIG_LEAVES } from '../src/core/self-upgrade.ts';import { withEnv } from './helpers/with-env.ts';+import { mkdtempSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { logSelfUpgrade } from '../src/core/audit/self-upgrade-audit.ts';const NEW = '0.60.400.0';const OLD = '0.60.390.0';@@ -121,7 +124,8 @@ describe('doctor self_upgrade_health with the restart plan', () => {await withEnv({ GBRAIN_SELF_UPGRADE_MODE: 'auto' }, () => {const check = checkSelfUpgradeHealth(planRestart([autopilot()], ctx({ expected: PENDING_BUILD })));expect(check.status).toBe('warn');- expect(check.message).toContain('gbrain upgrade refuses on this host, so auto-upgrades cannot finish');+ expect(check.message).toContain('gbrain upgrade refuses on this host: ');+ expect(check.message).not.toContain('auto-upgrades cannot finish');expect(check.message).toContain('autopilot pid 30');expect(check.fix).toMatchObject({ ask_user: true, argv: ['gbrain', 'autopilot', '--install'] });expect(check.fix?.user_message).toContain('self_upgrade.autopilot_launcher external');@@ -141,4 +145,27 @@ describe('doctor self_upgrade_health with the restart plan', () => {expect(checkSelfUpgradeHealth(planRestart([], ctx({ expected: PENDING_BUILD }))).message).toBe(plain);});});+test('an MCP server a harness started and a running sync do not warn: --stop-mcp and the sync finishing clear them', async () => {+ await withEnv({ GBRAIN_SELF_UPGRADE_MODE: 'auto' }, () => {+ const mcp: HostProcess = { pid: 40, ppid: null, role: 'mcp', version: OLD, started_ms: 1_000, ancestors: [99], args: ['serve'] };+ const sync: HostProcess = { pid: 41, ppid: null, role: 'sync', version: OLD, started_ms: 1_000, ancestors: [98], args: ['sync'] };+ const plan = planRestart([mcp, sync], ctx({ expected: PENDING_BUILD }));+ expect(plan.manual.map(m => m.role)).toEqual(['mcp', 'sync']);+ expect(checkSelfUpgradeHealth(plan).status).toBe('ok');+ });+ });++ test('a held auto-upgrade is reported ahead of the restart warning', async () => {+ const dir = mkdtempSync(join(tmpdir(), 'gbrain-8776-held-'));+ try {+ await withEnv({ GBRAIN_HOME: dir, GBRAIN_AUDIT_DIR: join(dir, 'audit'), GBRAIN_SELF_UPGRADE_MODE: 'auto' }, () => {+ logSelfUpgrade({ channel: 'autopilot', action: 'unsupported_runtime', current: '0.43.0', latest: '0.99.0', outcome: 'skipped', reason: 'gbrain 0.99.0 requires Bun >=9.0.0' });+ const check = checkSelfUpgradeHealth(planRestart([autopilot()], ctx({ expected: PENDING_BUILD })));+ expect(check.status).toBe('warn');+ expect(check.message).toContain('Auto-upgrade to 0.99.0 held');+ });+ } finally {+ rmSync(dir, { recursive: true, force: true });+ }+ });});