Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(migrations): v0.14.0 never lowers max_stalled; v0.60.31 notice writes no marker without sources

garrytan33c2c1ccc35c
diff --git a/src/commands/migrations/v0_14_0.ts b/src/commands/migrations/v0_14_0.ts
index 1e7eb59d5a..cc5135222c 100644
--- a/src/commands/migrations/v0_14_0.ts
+++ b/src/commands/migrations/v0_14_0.ts
@@ -3,7 +3,8 @@
*
* Ships two phases:
*
- * A. Schema: `ALTER TABLE minion_jobs ALTER COLUMN max_stalled SET DEFAULT 3`.
+ * A. Schema: `ALTER TABLE minion_jobs ALTER COLUMN max_stalled SET DEFAULT 3`
+ * when the current default is below 3 (never lowers schema v15's 5).
* New installs already get the bumped default from schema-embedded.ts +
* pglite-schema.ts. This ALTER is for existing brains where the table
* was created under v0.13.x (default 1). Idempotent — running twice is
@@ -53,23 +54,19 @@ async function phaseASchema(opts: OrchestratorOpts): Promise<{ result: Orchestra
}
const engine = await createEngine(toEngineConfig(config));
await engine.connect(toEngineConfig(config));
- try {
- // Both Postgres and PGLite accept this ALTER. Idempotent at the
- // table level — setting the default to 3 twice is fine.
- await engine.executeRaw('ALTER TABLE minion_jobs ALTER COLUMN max_stalled SET DEFAULT 3');
- } catch (e) {
- // If minion_jobs doesn't exist yet (brand new install), the schema
- // file already has the new default, so this is moot. Skip instead of
- // fail.
- const msg = e instanceof Error ? e.message : String(e);
- if (/does not exist|no such table|relation .* does not exist/i.test(msg)) {
- return {
- result: { name: 'schema', status: 'skipped', detail: 'minion_jobs not yet created (fresh install)' },
- engine,
- };
- }
- throw e;
+ // Only a default below 3 is raised: schema migration v15 later set 5,
+ // which a fresh brain already has, and lowering it would undo that fix.
+ const [column] = await engine.executeRaw<{ column_default: string | null }>(
+ `SELECT column_default FROM information_schema.columns
+ WHERE table_schema = current_schema() AND table_name = 'minion_jobs' AND column_name = 'max_stalled'`);
+ if (!column) {
+ return { result: { name: 'schema', status: 'skipped', detail: 'minion_jobs not yet created (fresh install)' }, engine };
}
+ const current = parseInt(column.column_default ?? '', 10);
+ if (current >= 3) {
+ return { result: { name: 'schema', status: 'skipped', detail: `max_stalled default already ${current}` }, engine };
+ }
+ await engine.executeRaw('ALTER TABLE minion_jobs ALTER COLUMN max_stalled SET DEFAULT 3');
return { result: { name: 'schema', status: 'complete' }, engine };
} catch (e) {
return {
diff --git a/src/commands/migrations/v0_60_31-google-file-modes.ts b/src/commands/migrations/v0_60_31-google-file-modes.ts
index 99121b728d..be08afd087 100644
--- a/src/commands/migrations/v0_60_31-google-file-modes.ts
+++ b/src/commands/migrations/v0_60_31-google-file-modes.ts
@@ -4,7 +4,8 @@
* the permissions they were written with (typically 0644), and only a rewrite
* tightens them. Detection only: the notice names each directory, the count
* of group/world-readable entries found now and the opt-in repair commands.
- * Nothing is chmod-ed here. A config marker makes it print once per brain.
+ * Nothing is chmod-ed here. A config marker makes it print once per brain; a
+ * brain with no such source has nothing to remember, so no marker is written.
*/
import type { BrainEngine } from '../../core/engine.ts';
import { googleFileModesApplyCommand, googleFileModesPreviewCommand, scanGoogleFileModes } from '../../core/google/file-modes.ts';
@@ -24,6 +25,7 @@ export async function googleFileModesNoticePhase(engine: BrainEngine | null, opt
if (!engine) return { name: 'google_file_modes_notice', status: 'skipped', detail: 'no_brain_configured' };
if (await engine.getConfig(GOOGLE_FILE_MODES_NOTICE_KEY)) return { name: 'google_file_modes_notice', status: 'skipped', detail: 'already_shown' };
const lines = googleFileModesNoticeLines(await scanGoogleFileModes(engine));
+ if (lines.length === 0) return { name: 'google_file_modes_notice', status: 'complete', detail: '0 custom-dir Google source(s)' };
for (const line of lines) (opts.print ?? console.log)(line);
await engine.setConfig(GOOGLE_FILE_MODES_NOTICE_KEY, new Date().toISOString());
return { name: 'google_file_modes_notice', status: 'complete', detail: `${lines.length} custom-dir Google source(s)` };