Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: Tier 2 serves gbrain's starter surface so the agent's request stays under OpenAI's 128-tool cap (review blocker)
garrytan7265d6884e1f
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 82ef473bb3..66039489c9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,7 +14,7 @@ identifiers and attribution are available in the pre-removal Git revision**Tier 2's keyed nightly now actually gives the agent gbrain's MCP tools and fails any test in which the agent never called one, and a Tier 1 graduation shard that executed nothing now fails instead of passing.**-Tier 2 wrote its gbrain MCP server into `~/.openclaw/config.json`, which OpenClaw 2026.4.9 never reads, since it reads `mcp.servers` in `~/.openclaw/openclaw.json`. The agent ran with no gbrain tools, and each test checked only that OpenClaw exited 0 and printed something, which it also does when the model key is rejected (#8002). The job now saves the server with `openclaw mcp set` and fails unless `openclaw mcp show` reads it back. The server runs behind `scripts/ci-mcp-tap.sh`, which logs every JSON-RPC request, and each Tier 2 test fails unless the agent made a gbrain tool call while it ran. The `tier1-graduation` shards now run `scripts/require-executed-tests.ts` after their tests, because the graduation files skip without `DATABASE_URL` and `run-e2e.sh` exits 0 on an all-skip run, so a shard with a broken database env used to pass with nothing executed (#8003).+Tier 2 wrote its gbrain MCP server into `~/.openclaw/config.json`, which OpenClaw 2026.4.9 never reads, since it reads `mcp.servers` in `~/.openclaw/openclaw.json`. The agent ran with no gbrain tools, and each test checked only that OpenClaw exited 0 and printed something, which it also does when the model key is rejected (#8002). The job now saves the server with `openclaw mcp set` and fails unless `openclaw mcp show` reads it back. It serves gbrain's starter surface (31 tools), because OpenClaw's default agent model is `openai/gpt-5.4`, OpenAI refuses a request with more than 128 tools, and OpenClaw's own 31 tools plus gbrain's full 158 come to 189. The server runs behind `scripts/ci-mcp-tap.sh`, which logs every JSON-RPC request, and each Tier 2 test fails unless the agent made a gbrain tool call while it ran. The `tier1-graduation` shards now run `scripts/require-executed-tests.ts` after their tests, because the graduation files skip without `DATABASE_URL` and `run-e2e.sh` exits 0 on an all-skip run, so a shard with a broken database env used to pass with nothing executed (#8003).### Itemized changesdiff --git a/docs/architecture/key-files/ci-health-and-test-guards.md b/docs/architecture/key-files/ci-health-and-test-guards.mdindex ff56bd845d..d440bb2d9a 100644--- a/docs/architecture/key-files/ci-health-and-test-guards.md+++ b/docs/architecture/key-files/ci-health-and-test-guards.md@@ -17,7 +17,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `scripts/ci-manifest-diff.sh` — parsed-JSON classification of manifest diffs for CI scoping: `version-only` (only the top-level `version` differs), `dependency-change` (any dependency field differs), `dependency-scope` (whether a changed-file list touches lockfiles, `patches/` or dependency fields) and `drop-version-only` (filters version-only `package.json` and `openclaw.plugin.json` entries out of a changed-file list, so a release bump does not widen the native scope). Used by test.yml's `changes` job (before `scripts/ci-native-scope.sh`) and its dependency-audit scope step. Tests: `test/scripts/ci-manifest-diff.test.ts`.- `scripts/ci-dependency-audit.sh` — runs `bun audit` for the root and `admin/` lockfiles. It blocks (`BLOCKING=true`) on pushes, schedules and dispatches, on lockfile, `patches/` or dependency-field changes, with the `dependency-audit` label, or when the diff cannot be read; elsewhere an advisory is a `::warning::` naming why the run does not block.- `scripts/require-executed-tests.ts` — fails a lane whose receipts show zero passed tests, any skipped, todo or failed test, a missing or truncated JUnit report, or no receipt at all (GBRA-135 L6). The keyed Tier 2 nightly (`e2e.yml` `tier2`) runs it after its test step, because `bun test` exits 0 when every key-gated test self-skips, and each `tier1-graduation` shard runs it on lane `tier1`, because those files skip without `DATABASE_URL` and `run-e2e.sh` exits 0 (#8003).-- `scripts/ci-openclaw-mcp.sh`, `scripts/ci-mcp-tap.sh`, `scripts/mcp-tap-calls.ts` — Tier 2's gbrain MCP wiring (#8002). The first saves gbrain under `mcp.servers` in `~/.openclaw/openclaw.json` with `openclaw mcp set` and fails unless `openclaw mcp show` reads it back; the server runs behind the tap, which logs every JSON-RPC request to `GBRAIN_TEST_TIER2_MCP_TAP_LOG`; `test/e2e/skills.test.ts` reads that log with `tapToolCalls` and fails a test in which the agent made no gbrain tool call. `executedProblems(dir, lane)` reads receipts through `loadReceiptDir` (`scripts/ci-executed-counts.ts`). Test: `test/scripts/require-executed-tests.test.ts` (includes the real keyless `test/e2e/skills.test.ts` run).+- `scripts/ci-openclaw-mcp.sh`, `scripts/ci-mcp-tap.sh`, `scripts/mcp-tap-calls.ts` — Tier 2's gbrain MCP wiring (#8002). The first saves gbrain under `mcp.servers` in `~/.openclaw/openclaw.json` with `openclaw mcp set` (serving the starter surface, so the agent's request stays under OpenAI's 128-tool cap) and fails unless `openclaw mcp show` reads it back; the server runs behind the tap, which logs every JSON-RPC request to `GBRAIN_TEST_TIER2_MCP_TAP_LOG`; `test/e2e/skills.test.ts` reads that log with `tapToolCalls` and fails a test in which the agent made no gbrain tool call. `executedProblems(dir, lane)` reads receipts through `loadReceiptDir` (`scripts/ci-executed-counts.ts`). Test: `test/scripts/require-executed-tests.test.ts` (includes the real keyless `test/e2e/skills.test.ts` run).- `scripts/ci-install-openclaw.sh` — e2e.yml's Tier 2 `Install OpenClaw` step. Each `npm install -g openclaw@<pin>` attempt is bounded (`timeout 120`); a failure whose npm log carries `code ETARGET` or `E404` is a registry race (a dependency version published but not yet visible for every package of its release, the 2026-10-12 master Tier 2 red on `@aws-sdk/credential-provider-node@^3.972.86`) and is retried up to 4 attempts 20/40/80 s apart; any other failure keeps the 3 attempts 10 s apart. Nothing else is retried, and the last attempt fails the step with npm's own log. Knobs (`OPENCLAW_SPEC`, `OPENCLAW_INSTALL_ATTEMPT_S`, `OPENCLAW_INSTALL_RETRY_SLEEP_S`, `OPENCLAW_INSTALL_RACE_SLEEPS_S`) exist for the test: `test/scripts/ci-install-openclaw.test.ts` installs a one-file package from a loopback registry (`test/helpers/npm-stub-registry.ts`) that answers ETARGET or E404 to the first three packument requests, forever, or publishes for an impossible `os` (`EBADPLATFORM`, the generic path). The lockfile route (a committed `package-lock.json` per pin) was weighed and not taken: two pins live in the workflows (`e2e.yml` 2026.4.9, `native-locks.yml` 2026.9.4), every bump would regenerate a multi-hundred-kilobyte lockfile, and the race the retry waits out is a propagation delay of minutes.- `scripts/e2e-provider-key-notice.sh` — e2e.yml's visible-skip step: when `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` is empty, prints a `::warning::` and step-summary line naming the empty secret and the owner-only fix, so a green keyless run is never read as keyed coverage. Exits 0 always.- `scripts/scale/watchdog.ts` — out-of-process phase watchdog for the scale harness. `scripts/scale/run.ts` re-runs itself as a child; the supervisor times the `import`, `extract`, `vectors` and `budgets` phases from the child's `[scale] phase <name> start` lines and kills the child's process group at 1.5x the phase's gate ceiling (`scripts/scale/gates.ts` `phaseLimitsMs`), names the phase, elapsed time and last progress line, then removes the brain home and scale database. `GBRAIN_SCALE_PHASE_LIMIT_MS_<PHASE>` overrides one limit; `GBRAIN_SCALE_SUPERVISED` is the internal handshake. Tests: `test/scripts/scale-watchdog.test.ts`.diff --git a/scripts/ci-openclaw-mcp.sh b/scripts/ci-openclaw-mcp.shindex 18165676fb..08080a3aa0 100755--- a/scripts/ci-openclaw-mcp.sh+++ b/scripts/ci-openclaw-mcp.sh@@ -9,6 +9,10 @@# gbrain tools. `openclaw mcp set` writes the file OpenClaw reads, and# `openclaw mcp show` reads it back.#+# gbrain serves its starter surface (31 tools): OpenClaw's default agent model+# is openai/gpt-5.4, OpenAI refuses a request with more than 128 tools, and+# OpenClaw adds about 31 of its own to gbrain's 158 on the full surface.+## The server runs behind scripts/ci-mcp-tap.sh, which logs every request to# $GBRAIN_TEST_TIER2_MCP_TAP_LOG for test/e2e/skills.test.ts.#@@ -23,7 +27,7 @@ server=$(GBRAIN_REPO="$PWD" bun -e 'const e = process.env;console.log(JSON.stringify({command: "bash",- args: ["scripts/ci-mcp-tap.sh", e.GBRAIN_TEST_TIER2_MCP_TAP_LOG, "--", "bun", "run", "src/cli.ts", "serve"],+ args: ["scripts/ci-mcp-tap.sh", e.GBRAIN_TEST_TIER2_MCP_TAP_LOG, "--", "bun", "run", "src/cli.ts", "serve", "--surface", "starter"],cwd: e.GBRAIN_REPO,env: { DATABASE_URL: e.DATABASE_URL },}));diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsvindex 114fa74115..f1fb35cead 100644--- a/scripts/structural-suites.tsv+++ b/scripts/structural-suites.tsv@@ -351,7 +351,7 @@ test/scripts/stress-plan.test.ts shards 5 readFileSynctest/scripts/test-env-opt-ins-guard.test.ts check-test-env-opt-ins 5 readFileSynctest/scripts/test-shard.slow.test.ts test-shard.sh — LPT balance contract 5 readFileSynctest/scripts/test-shard.slow.test.ts test-shard.sh — exclusion contract 7 readFileSync-test/scripts/tier2-openclaw-mcp.test.ts Tier 2 OpenClaw MCP wiring (#8002) 6 readFileSync+test/scripts/tier2-openclaw-mcp.test.ts Tier 2 OpenClaw MCP wiring (#8002) 7 readFileSynctest/scripts/ubicloud-typecheck-state.test.ts (file-level) 3 readFileSynctest/search/graph-signals-wire-integration.test.ts v0.40.4 — source-grep regression guard 1 source-surface-helpertest/serve-behavior-notice-6543.test.ts (file-level) 3 readFileSyncdiff --git a/test/e2e/skills.test.ts b/test/e2e/skills.test.tsindex a11c3f3193..a5b77432a8 100644--- a/test/e2e/skills.test.ts+++ b/test/e2e/skills.test.ts@@ -200,7 +200,7 @@ describeT2('E2E Tier 2: Health Skill', () => {test('health skill reports brain status', async () => {const { result: { text, exitCode, durationMs }, calls } = gbrainToolCalls(() => runOpenClaw(- 'Use the gbrain MCP get_health tool to check the brain\'s health and tell me the results.',+ 'Use the gbrain MCP tools to report the brain\'s status: call whoami and list_pages, then tell me what you found.',180_000,));diff --git a/test/scripts/tier2-openclaw-mcp.test.ts b/test/scripts/tier2-openclaw-mcp.test.tsindex a2437411fa..91c9e9fc2e 100644--- a/test/scripts/tier2-openclaw-mcp.test.ts+++ b/test/scripts/tier2-openclaw-mcp.test.ts@@ -13,6 +13,7 @@ import { join } from 'node:path';import { spawnSync } from 'node:child_process';import { load } from 'js-yaml';import { tapToolCalls } from '../../scripts/mcp-tap-calls.ts';+import { STARTER_OPS } from '../../src/mcp/surface.ts';const REPO = join(import.meta.dir, '../..');type Step = { name?: string; run?: string; env?: Record<string, string> };@@ -62,7 +63,7 @@ describe('Tier 2 OpenClaw MCP wiring (#8002)', () => {expect(r.status, r.stdout + r.stderr).toBe(0);expect(JSON.parse(readFileSync(join(dir, 'saved.json'), 'utf8'))).toEqual({command: 'bash',- args: ['scripts/ci-mcp-tap.sh', tap, '--', 'bun', 'run', 'src/cli.ts', 'serve'],+ args: ['scripts/ci-mcp-tap.sh', tap, '--', 'bun', 'run', 'src/cli.ts', 'serve', '--surface', 'starter'],cwd: REPO,env: { DATABASE_URL: 'postgresql://u@localhost:5432/db' },});@@ -82,6 +83,16 @@ describe('Tier 2 OpenClaw MCP wiring (#8002)', () => {} finally { rmSync(dir, { recursive: true, force: true }); }});+ test('the server stays under the model API tool cap: it serves the starter surface', () => {+ // OpenClaw's default agent model is openai/gpt-5.4, and OpenAI refuses a+ // request with more than 128 tools. OpenClaw adds about 31 of its own;+ // gbrain's full surface is 158 tools, the starter surface 31.+ const script = readFileSync(join(REPO, 'scripts/ci-openclaw-mcp.sh'), 'utf8');+ expect(script).toContain('"serve", "--surface", "starter"');+ expect(STARTER_OPS.size).toBeLessThanOrEqual(64);+ for (const op of ['put_page', 'search', 'query', 'whoami', 'list_pages']) expect(STARTER_OPS.has(op)).toBe(true);+ });+test('the tap passes the stream through unchanged and logs what the client sent', () => {const dir = mkdtempSync(join(tmpdir(), 'gbrain-mcp-tap-'));try {