Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
instructions: readInstructionContent fails closed when the engine has no config reader
garrytan9679ae5633f2
diff --git a/src/mcp/instructions.ts b/src/mcp/instructions.tsindex 1756904fa0..c2f5995812 100644--- a/src/mcp/instructions.ts+++ b/src/mcp/instructions.ts@@ -63,7 +63,8 @@ export interface InstructionContent {/** Brain config behind InstructionContent. Fail-closed: a read error yields the defaults. */export async function readInstructionContent(engine: { getConfig(key: string): Promise<string | null> }): Promise<InstructionContent> {const refs = await readEntityReferencesConfig(engine);- const rule = await engine.getConfig(GOVERNING_RULE_CONFIG_KEY).catch(() => null);+ let rule: string | null = null;+ try { rule = await engine.getConfig(GOVERNING_RULE_CONFIG_KEY); } catch { /* defaults */ }return {references: { namesRow: refs.namesRow, records: refs.recordTypes.length > 0 },governingRule: rule?.trim() === 'newest' ? 'newest' : 'in_effect',diff --git a/test/mcp-instructions-governing-rule.test.ts b/test/mcp-instructions-governing-rule.test.tsindex 93be2c75e4..8b8a8bf717 100644--- a/test/mcp-instructions-governing-rule.test.ts+++ b/test/mcp-instructions-governing-rule.test.ts@@ -79,9 +79,11 @@ describe('governing rule (F4)', () => {expect(buildMcpInstructions({ governingRule: 'in_effect' })).toBe(GBRAIN_MCP_INSTRUCTIONS);});- test('a read error fails closed to `in_effect`', async () => {+ test('a read error (or an engine with no config reader) fails closed to the defaults', async () => {const broken = { getConfig: async () => { throw new Error('db down'); } };expect((await readInstructionContent(broken)).governingRule).toBe('in_effect');+ const noReader = {} as { getConfig(key: string): Promise<string | null> };+ expect(await readInstructionContent(noReader)).toEqual({ references: { namesRow: true, records: false }, governingRule: 'in_effect' });});describe('on PGLite', () => {