Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(doctor): fresh-install stamps are not forward progress; pending_fresh_install is an info row (E8)

garrytan9b2a0fc62df1
diff --git a/src/commands/doctor/checks/local-runtime.ts b/src/commands/doctor/checks/local-runtime.ts
index 2c0654ff91..6c55d3b707 100644
--- a/src/commands/doctor/checks/local-runtime.ts
+++ b/src/commands/doctor/checks/local-runtime.ts
@@ -8,6 +8,8 @@
*/
import { loadCompletedMigrations } from '../../../core/preferences.ts';
+import { isFreshInstallStamp } from '../../../core/migration-ledger.ts';
+import { pendingFreshInstallCheck } from './pending-fresh-install.ts';
import { compareVersions } from '../../migrations/index.ts';
import { bootstrapDoctorChecks } from '../bootstrap-checks.ts';
import { buildMemorableRelayCheck } from './integrations-memorable.ts';
@@ -125,15 +127,18 @@ async function runMinionsMigration(ctx: DoctorContext): Promise<Check[]> {
// flag forever, even on installs that have been at v0.22+ for months.
try {
const completed = loadCompletedMigrations();
- const byVersion = new Map<string, { complete: boolean; partial: boolean }>();
+ const byVersion = new Map<string, { complete: boolean; partial: boolean; ran: boolean }>();
for (const entry of completed) {
- const seen = byVersion.get(entry.version) ?? { complete: false, partial: false };
+ const seen = byVersion.get(entry.version) ?? { complete: false, partial: false, ran: false };
if (entry.status === 'complete') seen.complete = true;
+ if (entry.status === 'complete' && !isFreshInstallStamp(entry)) seen.ran = true;
if (entry.status === 'partial') seen.partial = true;
byVersion.set(entry.version, seen);
}
+ // Init's fresh-install stamps are not forward progress: a newer stamped
+ // no-op must never hide a real partial on a new brain.
const completedVersions = Array.from(byVersion.entries())
- .filter(([, s]) => s.complete)
+ .filter(([, s]) => s.ran)
.map(([v]) => v);
const stuck = Array.from(byVersion.entries())
.filter(([v, s]) => {
@@ -179,6 +184,9 @@ async function runMinionsMigration(ctx: DoctorContext): Promise<Check[]> {
status: 'fail',
message: `MINIONS HALF-INSTALLED (partial migration: ${stuck.join(', ')}). Run: gbrain apply-migrations --yes`,
});
+ } else {
+ const setup = pendingFreshInstallCheck();
+ if (setup) checks.push(setup);
}
// Note: the "no preferences.json but schema is v7+" case is detected
// in the DB section below (needs schema version).
diff --git a/src/commands/doctor/checks/pending-fresh-install.ts b/src/commands/doctor/checks/pending-fresh-install.ts
new file mode 100644
index 0000000000..50fdbd8394
--- /dev/null
+++ b/src/commands/doctor/checks/pending-fresh-install.ts
@@ -0,0 +1,29 @@
+/**
+ * Doctor row for E8 fresh-install migrations, shared by the local doctor
+ * (`checks/local-runtime.ts`) and the remote report (`report-remote.ts`).
+ * Filesystem-only (the migration ledger); no subprocess, no engine.
+ */
+import { migrationLedgerSummary } from '../../../core/migration-ledger.ts';
+import { VERSION } from '../../../version.ts';
+import type { Check } from '../../doctor.ts';
+import { agentFix } from '../check-fix.ts';
+
+/**
+ * E8: setup migrations a brain created by `gbrain init` has not run yet
+ * (`pending_fresh_install`). Expected work, so `ok` + `severity: 'info'` with
+ * the command that finishes it; null when there are none.
+ */
+export function pendingFreshInstallCheck(): Check | null {
+ const setup = migrationLedgerSummary(VERSION).pending_fresh_install;
+ if (setup.length === 0) return null;
+ return {
+ name: 'minions_migration',
+ status: 'ok',
+ severity: 'info',
+ message: `${setup.length} setup migration(s) not run yet on this new brain (pending_fresh_install: ${setup.join(', ')}). Expected after gbrain init, not a failed upgrade.`,
+ fix: agentFix(['gbrain', 'apply-migrations', '--yes', '--no-autopilot-install'],
+ 'Runs the setup migrations gbrain init left pending (preferences, host-work notes, shared-skill checkpoints) on the brain host, without installing background services.',
+ 'minions_migration', { requires_exclusive: true }),
+ details: { pending_fresh_install: setup },
+ };
+}
diff --git a/src/commands/doctor/report-remote.ts b/src/commands/doctor/report-remote.ts
index 57d5e537b5..38fdca7866 100644
--- a/src/commands/doctor/report-remote.ts
+++ b/src/commands/doctor/report-remote.ts
@@ -13,6 +13,8 @@ import type { BrainEngine } from '../../core/engine.ts';
import { LATEST_VERSION } from '../../core/migrate.ts';
import { loadConfig } from '../../core/config.ts';
import { loadCompletedMigrations } from '../../core/preferences.ts';
+import { isFreshInstallStamp } from '../../core/migration-ledger.ts';
+import { pendingFreshInstallCheck } from './checks/pending-fresh-install.ts';
import { compareVersions } from '../migrations/index.ts';
import { resolveHoursEnv } from '../../core/env-number.ts';
import { schemaVersionHealth } from '../../core/schema-version-health.ts';
@@ -216,14 +218,16 @@ export async function doctorReportRemote(
// --yes. Same shape as the local doctor at line ~336.
try {
const completed = loadCompletedMigrations();
- const byVersion = new Map<string, { complete: boolean; partial: boolean }>();
+ const byVersion = new Map<string, { complete: boolean; partial: boolean; ran: boolean }>();
for (const entry of completed) {
- const seen = byVersion.get(entry.version) ?? { complete: false, partial: false };
+ const seen = byVersion.get(entry.version) ?? { complete: false, partial: false, ran: false };
if (entry.status === 'complete') seen.complete = true;
+ if (entry.status === 'complete' && !isFreshInstallStamp(entry)) seen.ran = true;
if (entry.status === 'partial') seen.partial = true;
byVersion.set(entry.version, seen);
}
- const completedVersions = Array.from(byVersion.entries()).filter(([, s]) => s.complete).map(([v]) => v);
+ // Fresh-install stamps are not forward progress (same rule as the local doctor).
+ const completedVersions = Array.from(byVersion.entries()).filter(([, s]) => s.ran).map(([v]) => v);
const stuck = Array.from(byVersion.entries())
.filter(([v, s]) => {
if (!s.partial || s.complete) return false;
@@ -249,6 +253,9 @@ export async function doctorReportRemote(
status: 'fail',
message: `MINIONS HALF-INSTALLED on brain host: ${stuck.join(', ')}. Run on the host: gbrain apply-migrations --yes`,
});
+ } else {
+ const setup = pendingFreshInstallCheck();
+ if (setup) checks.push(setup);
}
} catch {
// Best-effort. A broken JSONL on the brain server should not stop the
diff --git a/test/fixtures/goldens/doctor/json-pglite-degraded.json b/test/fixtures/goldens/doctor/json-pglite-degraded.json
index 1d61b7fe77..5275752286 100644
--- a/test/fixtures/goldens/doctor/json-pglite-degraded.json
+++ b/test/fixtures/goldens/doctor/json-pglite-degraded.json
@@ -218,6 +218,45 @@
"name": "dream_paid_loop",
"status": "ok"
},
+ {
+ "category": "meta",
+ "details": {
+ "pending_fresh_install": [
+ "0.11.0",
+ "0.14.0",
+ "0.22.4",
+ "0.28.0",
+ "0.53.0"
+ ]
+ },
+ "fix": {
+ "actor": "agent",
+ "argv": [
+ "gbrain",
+ "apply-migrations",
+ "--yes",
+ "--no-autopilot-install"
+ ],
+ "command": "gbrain apply-migrations --yes --no-autopilot-install",
+ "consent": [],
+ "next": "run",
+ "requires_exclusive": true,
+ "verify": {
+ "argv": [
+ "gbrain",
+ "doctor",
+ "--only",
+ "minions_migration",
+ "--json"
+ ]
+ },
+ "why": "Runs the setup migrations gbrain init left pending (preferences, host-work notes, shared-skill checkpoints) on the brain host, without installing background services."
+ },
+ "message": "5 setup migration(s) not run yet on this new brain (pending_fresh_install: 0.11.0, 0.14.0, 0.22.4, 0.28.0, 0.53.0). Expected after gbrain init, not a failed upgrade.",
+ "name": "minions_migration",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "ops",
"message": "mode=notify",
diff --git a/test/fixtures/goldens/doctor/json-pglite-fast.json b/test/fixtures/goldens/doctor/json-pglite-fast.json
index c21f42999b..d175ebf0db 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fast.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fast.json
@@ -180,6 +180,45 @@
"name": "memory_writeback",
"status": "ok"
},
+ {
+ "category": "meta",
+ "details": {
+ "pending_fresh_install": [
+ "0.11.0",
+ "0.14.0",
+ "0.22.4",
+ "0.28.0",
+ "0.53.0"
+ ]
+ },
+ "fix": {
+ "actor": "agent",
+ "argv": [
+ "gbrain",
+ "apply-migrations",
+ "--yes",
+ "--no-autopilot-install"
+ ],
+ "command": "gbrain apply-migrations --yes --no-autopilot-install",
+ "consent": [],
+ "next": "run",
+ "requires_exclusive": true,
+ "verify": {
+ "argv": [
+ "gbrain",
+ "doctor",
+ "--only",
+ "minions_migration",
+ "--json"
+ ]
+ },
+ "why": "Runs the setup migrations gbrain init left pending (preferences, host-work notes, shared-skill checkpoints) on the brain host, without installing background services."
+ },
+ "message": "5 setup migration(s) not run yet on this new brain (pending_fresh_install: 0.11.0, 0.14.0, 0.22.4, 0.28.0, 0.53.0). Expected after gbrain init, not a failed upgrade.",
+ "name": "minions_migration",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "ops",
"message": "mode=notify",
diff --git a/test/fixtures/goldens/doctor/json-pglite-fresh.json b/test/fixtures/goldens/doctor/json-pglite-fresh.json
index 755a73d013..3e79972374 100644
--- a/test/fixtures/goldens/doctor/json-pglite-fresh.json
+++ b/test/fixtures/goldens/doctor/json-pglite-fresh.json
@@ -221,6 +221,45 @@
"name": "dream_paid_loop",
"status": "ok"
},
+ {
+ "category": "meta",
+ "details": {
+ "pending_fresh_install": [
+ "0.11.0",
+ "0.14.0",
+ "0.22.4",
+ "0.28.0",
+ "0.53.0"
+ ]
+ },
+ "fix": {
+ "actor": "agent",
+ "argv": [
+ "gbrain",
+ "apply-migrations",
+ "--yes",
+ "--no-autopilot-install"
+ ],
+ "command": "gbrain apply-migrations --yes --no-autopilot-install",
+ "consent": [],
+ "next": "run",
+ "requires_exclusive": true,
+ "verify": {
+ "argv": [
+ "gbrain",
+ "doctor",
+ "--only",
+ "minions_migration",
+ "--json"
+ ]
+ },
+ "why": "Runs the setup migrations gbrain init left pending (preferences, host-work notes, shared-skill checkpoints) on the brain host, without installing background services."
+ },
+ "message": "5 setup migration(s) not run yet on this new brain (pending_fresh_install: 0.11.0, 0.14.0, 0.22.4, 0.28.0, 0.53.0). Expected after gbrain init, not a failed upgrade.",
+ "name": "minions_migration",
+ "severity": "info",
+ "status": "ok"
+ },
{
"category": "ops",
"message": "mode=notify",