Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(cycle): thread cycleSourceId into the schema-suggest phase (#3701)
Tyler Singletary4c0ec60275a5
diff --git a/src/core/cycle.ts b/src/core/cycle.tsindex dcc18c1e8f..ee5eb6d300 100644--- a/src/core/cycle.ts+++ b/src/core/cycle.ts@@ -2441,7 +2441,7 @@ export async function runCycle(try {const { runSchemaSuggestPhase } = await import('./cycle/schema-suggest.ts');const { result, duration_ms } = await timePhase(async () => {- const r = await runSchemaSuggestPhase(engine, { dryRun: !!opts.dryRun });+ const r = await runSchemaSuggestPhase(engine, { sourceId: cycleSourceId, dryRun: !!opts.dryRun });return {phase: 'schema-suggest' as const,status: (r.skipped ? 'skipped' : 'ok') as PhaseStatus,diff --git a/test/core/cycle.serial.test.ts b/test/core/cycle.serial.test.tsindex 98acf86647..335866fe42 100644--- a/test/core/cycle.serial.test.ts+++ b/test/core/cycle.serial.test.ts@@ -22,6 +22,7 @@ let extractCalls: Array<{ mode: string; dir: string; slugs: string[] | undefinedlet embedCalls: Array<{ stale: boolean | undefined; dryRun: boolean | undefined }> = [];let orphansCalls: number = 0;let orphansOpts: Array<{ sourceId?: string } | undefined> = [];+let schemaSuggestOpts: Array<{ sourceId?: string; dryRun?: boolean } | undefined> = [];// Mock lintmock.module('../../src/commands/lint.ts', () => ({@@ -116,6 +117,14 @@ mock.module('../../src/commands/orphans.ts', () => ({formatOrphansText: () => '',}));+// Mock schema-suggest+mock.module('../../src/core/cycle/schema-suggest.ts', () => ({+ runSchemaSuggestPhase: async (_engine: any, opts?: { sourceId?: string; dryRun?: boolean }) => {+ schemaSuggestOpts.push(opts);+ return { suggestions_emitted: 0, source_id: opts?.sourceId ?? 'default', skipped: false };+ },+}));+// Import after mocks.const { runCycle, ALL_PHASES } = await import('../../src/core/cycle.ts');const { PGLiteEngine } = await import('../../src/core/pglite-engine.ts');@@ -151,6 +160,7 @@ beforeEach(() => {embedCalls = [];orphansCalls = 0;orphansOpts = [];+ schemaSuggestOpts = [];});// ─── dryRun propagation (regression guards) ────────────────────────@@ -519,6 +529,20 @@ describe('runCycle — sourceId resolution (regression #475)', () => {expect(orphansOpts.at(-1)).toEqual({ sourceId: 'alpha' });});+ // schema-suggest (T12 cathedral phase) was never threaded through+ // cycleSourceId — it silently fell back to 'default' for every source,+ // the same bug class as #1586 (synthesize) and #2666 (patterns), just+ // undiscovered for this phase. Pins the fix: the resolved per-source id+ // must reach runSchemaSuggestPhase the same way it reaches orphans/sync.+ test('seeded sources row → schema-suggest phase receives matching sourceId (not "default")', async () => {+ await (sharedEngine as any).db.query(+ `INSERT INTO sources (id, name, local_path) VALUES ($1, $2, $3)`,+ ['bravo', 'bravo', '/tmp/brain-schema-suggest-bravo'],+ );+ await runCycle(sharedEngine, { brainDir: '/tmp/brain-schema-suggest-bravo', phases: ['schema-suggest'] });+ expect(schemaSuggestOpts.at(-1)?.sourceId).toBe('bravo');+ });+test('forceGlobalOrphans keeps orphans brain-wide even when brainDir maps to a source', async () => {await (sharedEngine as any).db.query(`INSERT INTO sources (id, name, local_path) VALUES ($1, $2, $3)`,