Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(config): resolve publish-gate keys DB-first in config get (#5434)

time-attack3623c09e68f3
diff --git a/scripts/check-operations-filter-bypass.sh b/scripts/check-operations-filter-bypass.sh
index 77333445c6..a28935f84f 100755
--- a/scripts/check-operations-filter-bypass.sh
+++ b/scripts/check-operations-filter-bypass.sh
@@ -65,7 +65,7 @@ ALLOWED=(
"src/commands/edge-proposals.ts" # local CLI review of edge proposals; calls trusted handlers with remote=false, not network-exposed
"src/core/cycle/edge-contradictions.ts" # dream phase appends closure lines via add_timeline_entry with remote=false; never exposes operations
"src/commands/tools-json.ts" # gbrain --tools-json introspection; full op list IS the purpose
- "src/mcp/publish-gates.ts" # reads op.publishGateKey/name only to compute gate-DISABLED sets; never lists/exposes ops
+ "src/mcp/publish-gates.ts" # reads op.publishGateKey/name only to compute gate-DISABLED sets and the gate key set; never lists/exposes ops
"src/mcp/tool-catalog.ts" # docs/TOOL_CATALOG.md renderer; filters !op.localOnly at the boundary; never a transport surface
"src/commands/serve-http.ts" # MUST APPLY .filter(op => !op.localOnly) — verified by grep below
"src/core/ops/request-tools.ts" # visibleOpsForCaller loads the assembled list lazily (verbs.ts house pattern) and applies (isLocal || !op.localOnly) + surface + gate filtering
diff --git a/src/commands/config.ts b/src/commands/config.ts
index b5ef90d96d..a81d37fbae 100644
--- a/src/commands/config.ts
+++ b/src/commands/config.ts
@@ -11,6 +11,7 @@ import {
} from '../core/search/embedding-column.ts';
import { redactPgUrl } from '../core/url-redact.ts';
+import { PUBLISH_GATE_KEYS } from '../mcp/publish-gates.ts';
import { isConsentConfigKey, setConsentPreapproval, unsetConsentPreapproval } from '../core/consent-preapproval.ts';
import { WRITER_ADMIN_LOCK_KEY } from '../core/persistence/admin-contract.ts';
import {
@@ -133,6 +134,7 @@ const MEMORY_DUAL_PLANE_KEYS: ReadonlySet<string> = new Set(
* shared-declared brain never gets the enable-nudge advisory. */
const BRAIN_AUDIENCE_KEY = 'brain.audience';
+
/** `embedding_disabled` is dual-plane too: the DB row is authoritative (a
* mounted brain has no other plane) and the host's file mirror keeps the
* engine-free readers in step. Runtime gates treat `true` on EITHER plane as
@@ -876,7 +878,10 @@ export async function runConfig(engine: BrainEngine, args: string[]) {
// serves the previous DB value — exactly the lie the off switch's
// non-zero exit exists to prevent. Everything else keeps the #2120
// file/env-wins resolution.
- const dbAuthoritative = MEMORY_DUAL_PLANE_KEYS.has(key) || key === BRAIN_AUDIENCE_KEY;
+ // Publish-gate keys (#5358) are DB-authoritative too: readPublishGate
+ // resolves DB > file, so a file-first answer would print a stale mirror
+ // while the gate already hides the tools.
+ const dbAuthoritative = MEMORY_DUAL_PLANE_KEYS.has(key) || key === BRAIN_AUDIENCE_KEY || (PUBLISH_GATE_KEYS as ReadonlySet<string>).has(key);
// File-plane keys have no DB reader: a DB row is a stale pre-routing
// write, never the answer (#5489).
const fileOnly = isFilePlaneDottedKey(key);
diff --git a/src/mcp/publish-gates.ts b/src/mcp/publish-gates.ts
index 3f6c40695c..a894b31408 100644
--- a/src/mcp/publish-gates.ts
+++ b/src/mcp/publish-gates.ts
@@ -23,6 +23,9 @@ import { operations, type Operation } from '../core/operations.ts';
export type PublishGateKey = NonNullable<Operation['publishGateKey']>;
+/** Every config key an operation's publish gate reads; `config get` resolves these DB-first like the gate (#5358). */
+export const PUBLISH_GATE_KEYS: ReadonlySet<PublishGateKey> = new Set(operations.flatMap(op => (op.publishGateKey ? [op.publishGateKey] : [])));
+
/**
* Gates that default ON for the owner's stdio pipe when neither plane sets
* them (agent contract v1, F7): the read-only advisor is coaching the local
diff --git a/test/config-get-plane.test.ts b/test/config-get-plane.test.ts
index eb55ce54f9..dc1c78a014 100644
--- a/test/config-get-plane.test.ts
+++ b/test/config-get-plane.test.ts
@@ -14,6 +14,9 @@ import { mkdtempSync, writeFileSync, mkdirSync } from 'node:fs';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { runConfig } from '../src/commands/config.ts';
+import { operations } from '../src/core/operations.ts';
+import { readPublishGate, type PublishGateKey } from '../src/mcp/publish-gates.ts';
+import { loadConfig } from '../src/core/config.ts';
import { withEnv } from './helpers/with-env.ts';
import type { BrainEngine } from '../src/core/engine.ts';
@@ -144,3 +147,38 @@ describe('#3943 — config get redacts sensitive values by default (--raw opts o
expect(logs).toContain('anthropic:claude-sonnet-4-6');
});
});
+
+describe('#5358 — config get resolves publish-gate keys the way the runtime gate does (DB > file)', () => {
+ const gateKeys = [...new Set(operations.flatMap((op) => (op.publishGateKey ? [op.publishGateKey] : [])))];
+
+ test('the operation contract still registers publish gates (the set config get derives from)', () => {
+ expect(gateKeys).toContain('mcp.publish_skills');
+ expect(gateKeys.length).toBeGreaterThan(0);
+ });
+
+ test('mcp.publish_skills prints the DB value and warns about the diverged file mirror', async () => {
+ writeFileConfig({ engine: 'pglite', mcp: { publish_skills: true } });
+ const { logs, errs, exit } = await runGet({ 'mcp.publish_skills': 'false' }, 'mcp.publish_skills');
+ expect(exit).toBeNull();
+ expect(logs).toEqual(['false']);
+ expect(errs.join('\n')).toContain('db plane (authoritative for this key)');
+ expect(errs.join('\n')).toContain('file mirror disagrees');
+ });
+
+ test('mcp.publish_skills falls back to the file plane when no DB row exists', async () => {
+ writeFileConfig({ engine: 'pglite', mcp: { publish_skills: true } });
+ const { logs, errs } = await runGet({}, 'mcp.publish_skills');
+ expect(logs).toEqual(['true']);
+ expect(errs.join('\n')).toContain('file mirror (no DB row)');
+ });
+
+ test.each(gateKeys)('%s: config get reports the value the runtime gate resolves when the planes differ', async (key) => {
+ const leaf = key.slice('mcp.'.length);
+ writeFileConfig({ engine: 'pglite', mcp: { [leaf]: true } });
+ const db = { [key]: 'false' };
+ const { logs } = await runGet(db, key);
+ const runtime = await withEnv({ GBRAIN_HOME: home }, () =>
+ readPublishGate(stubEngine(db), loadConfig(), key as PublishGateKey, 'http'));
+ expect(logs).toEqual([String(runtime)]);
+ });
+});