Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
core memory defaults off (held-out core gate failed on gpt-6.1-sol); opt-in hints in gbrain core and doctor; core and pressure verdict records; release notes and the behavior-change notice row
garrytan255d3526162c
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 83974b39a0..169af34d04 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,23 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.87.0] - 2026-10-06++**Agents now save what matters before their context is compacted: a one-time notice tells them the context is nearly full, and `remember` takes up to 20 facts in one call. Always-loaded core memory is new and off by default.**++When a Claude Code or OpenClaw session nears its automatic compaction point, the user-prompt hook adds one notice per compaction segment telling the agent to save what it will need with `remember`. The trigger watches how fast the context is growing, so a session that arrives in large turns still gets warned before it compacts. `remember` accepts `items` (up to 20 facts, each a string or an object with its own `entity`, `kind`, `ttl`, `provenance` and `replaces`) and returns a compact receipt per item, so a save before compaction is one call.++On the held-out BEAM-500K set (23 conversations, 460 questions, claude-sonnet-5-5, each conversation streamed through a 32k-token window so it compacts many times), answer accuracy went from 51.7% to 63.0%: +11.3 points, 95% CI [+8.3, +14.4]. The agent saved a fact from the evidence session in 60.7% of questions instead of 39.6%. It costs more: $0.870 per question instead of $0.679 (+28%), and $1.381 per correct answer instead of $1.315 (+5%), because the agent makes more `remember` calls. `gbrain config set memory.pressure.enabled false` turns the notice off.++Core memory loads a few owner-designated pages (who the user is, how they like to work) into every session through the session-start hook, `context_pack` and compiled context files, under a brain-wide character budget. Only the owner marks pages core; remote edits to core pages are recorded for the owner to review (`gbrain core diff`, `gbrain core ack`). It is off by default because its held-out test failed: on preference and instruction questions it helped claude-sonnet-5-5 (+4.6 points) but cost gpt-6.1-sol 2.4 points, most of it on instruction following. To use it: `gbrain config set memory.core.enabled true`, then `gbrain core init` or `gbrain core add <slug>`.++### For contributors++- Migration `core_edit_notices` records remote edits to core pages. Core writes lock their source rows in id order after the protocol declaration's brain-row lock, and `put_pages` batch groups never carry a core-locked write.+- `gbrain core` (list, show, status, add, remove, diff, ack, init, suggest), the doctor `core_memory` check and `compile-context --include-core` / `--remove-core` manage and deliver core. `scripts/check-core-guard-coverage.mjs` (in `verify`) keeps every page mutation routed through the core guard.+- An argument-less `remember` call (a tool call cut off at the model's output limit) now says so and suggests fewer items per call.+- Eval records: `docs/eval/CORE_MEMORY_PREREGISTRATION.md`, `docs/eval/decisions/p4-heldout-pressure-2026-10-05/` and `docs/eval/decisions/p4-heldout-core-2026-10-06/`; gbrain-evals#82 holds the harness and receipts.+## [0.60.86.0] - 2026-10-06**Tests that start a real `gbrain serve --http` no longer fail when the random port they picked is already taken by another socket on the machine.**diff --git a/docs/eval/decisions/p4-heldout-core-2026-10-06/README.md b/docs/eval/decisions/p4-heldout-core-2026-10-06/README.mdnew file mode 100644index 0000000000..60fde6ac45--- /dev/null+++ b/docs/eval/decisions/p4-heldout-core-2026-10-06/README.md@@ -0,0 +1,65 @@+# P4 always-loaded core memory: held-out verdict++The custodian ran the core gate on BEAM-100k sealed (all 14 conversations,+the 56 `preference_following` and `instruction_following` questions) under+the preregistration in+[`docs/eval/CORE_MEMORY_PREREGISTRATION.md`](../../CORE_MEMORY_PREREGISTRATION.md).+Every arm got the same question-blind standing-preferences page; only arm C+marked it core, so C − A′ measures always-loaded delivery against retrieval of+the same page. The sealed receipts stay with the custodian; the eval records+are in garrytan/gbrain-evals#82. Verdict: **fail**, so `memory.core.enabled`+defaults to `false`. Core stays available as an opt-in.++## Gate++The preregistered bar is C − A′ ≥ 0 on every model not at ceiling, and+neither category's CI entirely below −2.0 points. 95% cluster bootstrap+intervals resample whole conversations.++| Model | Questions | A′ | C | C − A′ (points) | 95% CI |+|---|---|---|---|---|---|+| claude-sonnet-5-5 | 56 of 56 | 86.8% | 91.4% | +4.6 | [−0.4, +10.7] |+| gpt-6.1-sol | 56 of 56 | 88.1% | 85.7% | **−2.4** | [−5.4, +0.3] |+| claude-opus-5-5 | 32 of 56 | | | +3.4 | |+| claude-fable-5-1 | 28 of 56 | | | +2.3 | |++gpt-6.1-sol is below zero, so the model-level rule fails. No category's CI+lies entirely below −2.0, so the category guard alone would not have failed.+claude-opus-5-5 and claude-fable-5-1 stopped at their budget caps; their+remaining questions are still running and are recorded here when they land.+They cannot change the outcome, which gpt-6.1-sol already decides.++By category:++- claude-sonnet-5-5, preference following: +8.6 points, CI [+1.8, +17.5].+- gpt-6.1-sol, instruction following: 91.1% → 85.7% (−5.4 points). This is+ the drop that fails the gate.++## Cost per correct answer (reported, not gated)++| Model | A′ | C |+|---|---|---|+| claude-sonnet-5-5 | $0.78 | $0.83 |+| gpt-6.1-sol | $0.32 | $0.37 |+| claude-opus-5-5 | $1.19 | $1.39 |+| claude-fable-5-1 | $2.97 | $2.83 |++## Diagnosis lead++The failure is gpt-6.1-sol on instruction following: with the standing+instructions loaded at the top of every session, it followed them less often+than when it found the same page by retrieval. Where to look first is how the+core block reads to that model (its placement before the conversation, its+"always loaded" framing, and whether instructions in a profile block are+treated as context rather than as instructions in force), comparing its C and+A′ answers on the failing instruction questions. A change there needs a new+preregistered run; this verdict stands for this build.++## Defaults++- `memory.core.enabled`: `false`. An owner who wants it turns it on with+ `gbrain config set memory.core.enabled true` and marks pages with+ `gbrain core init` or `gbrain core add`; `gbrain core` and `gbrain doctor`+ say so when pages are marked while it is off.+- `memory.pressure.enabled`: `true`, from its own pass+ ([pressure verdict](../p4-heldout-pressure-2026-10-05/README.md)).diff --git a/docs/eval/decisions/p4-heldout-pressure-2026-10-05/README.md b/docs/eval/decisions/p4-heldout-pressure-2026-10-05/README.mdindex 0b030b1a75..b9268a832e 100644--- a/docs/eval/decisions/p4-heldout-pressure-2026-10-05/README.md+++ b/docs/eval/decisions/p4-heldout-pressure-2026-10-05/README.md@@ -61,9 +61,10 @@ post-upgrade notice state these costs.arrives in one large turn can jump past the warning point before the nextprompt; those misses are where the notice can improve next.-## Still to come+## Related verdicts-The core gate (BEAM-100k sealed, all four models) and the report-only slice-(claude-opus-5-5, gpt-6.1-sol and claude-fable-5-1 on four BEAM-500K sealed-conversations) run next. This PR lands only after the core verdict is-recorded.+The core gate (BEAM-100k sealed, all four models) failed, so core memory is+off by default and available as an opt-in:+[core verdict](../p4-heldout-core-2026-10-06/README.md). The report-only+slice (claude-opus-5-5, gpt-6.1-sol and claude-fable-5-1 on four BEAM-500K+sealed conversations) decides nothing and is recorded when it lands.diff --git a/docs/guides/core-memory.md b/docs/guides/core-memory.mdindex 8491c161d1..f0c7ccd132 100644--- a/docs/guides/core-memory.md+++ b/docs/guides/core-memory.md@@ -9,6 +9,20 @@ Everything else in the brain stays on demand (search, `query`, `recall`,per-turn context). Core is for the few facts an agent should never have tolook up.+Core memory is opt-in: it is off until the owner turns it on. In the held-out+evaluation, loading a standing-preferences page in every session helped one+model and hurt another on instruction following, so it is not on by default+(see [the verdict](../eval/decisions/p4-heldout-core-2026-10-06/README.md)).+To use it:++```bash+gbrain config set memory.core.enabled true+gbrain core init # or: gbrain core add <slug>+```++The save-before-compaction notice ([below](#saving-before-compaction)) is a+separate feature and is on by default.+## What makes a page coreA page is core when its frontmatter says so:@@ -121,7 +135,7 @@ Two pieces cover that:| Key | Default | Meaning ||---|---|---|-| `memory.core.enabled` | `true` | Deliver core in sessions. |+| `memory.core.enabled` | `false` | Deliver core in sessions (opt-in). || `memory.core.max_chars` | `4000` | Brain-wide rendered budget, 500 to 6,000. || `memory.core.remote_edit` | `notify` | `allow`, `notify` or `refuse` for remote edits to core pages. || `memory.pressure.enabled` | `true` | The save-before-compaction notice. |diff --git a/src/commands/core.ts b/src/commands/core.tsindex a2aea6591e..af41b1e4b6 100644--- a/src/commands/core.ts+++ b/src/commands/core.ts@@ -23,6 +23,9 @@ import {import { serializePageToMarkdown } from '../core/markdown.ts';import { setCliExitVerdict } from '../core/cli-force-exit.ts';+/** Core is opt-in: marking a page does nothing for sessions until the owner turns delivery on. */+const CORE_OFF_HINT = 'Core memory is off (the default), so sessions do not load it yet. If the user wants it always loaded: gbrain config set memory.core.enabled true';+const USAGE = `Usage: gbrain core <list|show|status|add|remove|diff|ack|init|suggest> [options]list [--source <id>] [--json]show [--source <id>] [--json]@@ -180,6 +183,7 @@ export async function runCore(engine: BrainEngine, args: string[]): Promise<voidconst usage = await coreUsage(engine);const settings = await readCoreSettings(engine);console.log(`${result === 'unchanged' ? 'Already' : 'Now'} ${sub === 'add' ? 'in' : 'out of'} core: ${sourceId}:${slug}. Core uses ${usage.chars}/${settings.maxChars} chars.`);+ if (sub === 'add' && !settings.enabled) console.log(CORE_OFF_HINT);} catch (e) {fail((e as Error).message, sub === 'add' ? 'run gbrain core status to see where the budget goes' : undefined);}@@ -217,6 +221,7 @@ export async function runCore(engine: BrainEngine, args: string[]): Promise<voidif (existing && !existing.page.deleted_at) {const result = await setMarking(engine, sourceId, target, { core: true, priority: 10 }).catch((e: Error) => { fail(e.message); return null; });if (result) console.log(`${sourceId}:${target} exists and is ${result === 'unchanged' ? 'already' : 'now'} in core.`);+ if (result && !(await readCoreSettings(engine)).enabled) console.log(CORE_OFF_HINT);return;}const content = `---\ntitle: About the user\nalways_load: true\ncore_priority: 10\n---\n\n${STARTER_BODY}\n`;@@ -224,6 +229,7 @@ export async function runCore(engine: BrainEngine, args: string[]): Promise<voidawait handleToolCall(engine, 'put_page', { slug: target, content, source_id: sourceId }, { sourceId });} catch (e) { fail((e as Error).message); return; }console.log(`Created ${sourceId}:${target} in core. Next: ask the user the four questions on that page and replace each "(fill in)" with edit_page, keeping it short.`);+ if (!(await readCoreSettings(engine)).enabled) console.log(CORE_OFF_HINT);return;}case 'suggest': {diff --git a/src/commands/doctor/checks/core-memory.ts b/src/commands/doctor/checks/core-memory.tsindex 17aeb37f8a..df983c5ac4 100644--- a/src/commands/doctor/checks/core-memory.ts+++ b/src/commands/doctor/checks/core-memory.ts@@ -46,7 +46,9 @@ export async function coreMemoryCheck(engine: BrainEngine): Promise<Omit<Check,const issues = [...badConfig, ...compiled];return {status: issues.length ? 'warn' : 'ok',- message: issues.length ? `No core pages. ${issues.join('; ')}.` : 'No core pages. Start one with gbrain core init, then fill it in with the user.',+ message: issues.length ? `No core pages. ${issues.join('; ')}.`+ : settings.enabled ? 'No core pages. Start one with gbrain core init, then fill it in with the user.'+ : 'Core memory is off (opt-in). If the user wants a profile loaded in every session: gbrain config set memory.core.enabled true, then gbrain core init.',details: { pages: 0, chars_used: 0, chars_limit: settings.maxChars, enabled: settings.enabled, bad_config: badConfig, compiled, docs: CORE_DOCS },};}@@ -56,6 +58,7 @@ export async function coreMemoryCheck(engine: BrainEngine): Promise<Omit<Check,const over = usage.chars - settings.maxChars;const largest = [...usage.pages].sort((a, b) => b.chars - a.chars)[0]!;if (over > 0) problems.push(`core is ${usage.chars} chars, over the ${settings.maxChars}-char budget by ${over}, so sessions get a truncated block; shorten the largest page (${largest.source_id}:${largest.slug}, ${largest.chars} chars) or raise memory.core.max_chars`);+ if (!settings.enabled) problems.push(`${usage.pages.length} page(s) are marked core but core memory is off, so no session loads them; turn it on with gbrain config set memory.core.enabled true, or unmark them with gbrain core remove`);problems.push(...badConfig, ...compiled);if (withheld.length) problems.push(`${withheld.length} core page(s) withheld from delivery for sensitive content: ${withheld.map(w => `${w.source_id}:${w.slug}`).join(', ')}`);if (notices.length) problems.push(`${notices.length} remote edit(s) to core pages await the user's review (gbrain core diff, then gbrain core ack)`);diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex cf47d654ef..62ad93befa 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -19,6 +19,8 @@* 0.60.77.0 quote grounding on by default (think, syntheses, concepts,* patterns); forget's `similar_active` and the TypeSafe-gated* overnight withdrawal review.+ * 0.60.87.0 the save-before-compaction notice in Claude Code and OpenClaw+ * sessions (core memory ships off, so it is not a change).* A release that changes behavior appends its rows; a shipped row's release* never changes.*@@ -242,6 +244,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }{ since: '0.60.77.0', text: 'forget responses list close active facts it did not withdraw (`similar_active`); with a TypeSafe key, forgetting also queues an overnight review that only proposes withdrawing rewordings (`gbrain decide proposals list`; `gbrain config set decide.slots.conflict.review_withdraw false` turns it off).' },{ since: '0.60.78.0', text: 'On a brain with embedding turned off, search, query, recall, think and fact writes no longer send text to an embedding provider: reads run keyword-only and say so, and `gbrain doctor --json` names the enable command if the user wants semantic search back.' },{ since: '0.60.79.0', text: 'Frontmatter is parsed as YAML 1.2: clock-like values such as `10:30` stay text (they were read as base-60 numbers, so 10:30 became 630), a leading zero is decimal (`010` is 10, not 8), `0o` marks octal, and `1_000` stays text. Re-syncing a page whose frontmatter used those forms stores the new values.' },+ { since: '0.60.87.0', text: 'Near automatic context compaction, Claude Code and OpenClaw sessions get one notice per compaction segment asking the agent to save what it needs with `remember` (up to 20 facts per call). In the held-out test it raised accuracy after compaction from 51.7% to 63.0% and cost about 28% more per question (5% more per correct answer). `gbrain config set memory.pressure.enabled false` turns it off. Always-loaded core memory is new and off; `gbrain config set memory.core.enabled true` turns it on.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/core-memory.ts b/src/core/core-memory.tsindex 308ea93eb1..7238f48adf 100644--- a/src/core/core-memory.ts+++ b/src/core/core-memory.ts@@ -78,7 +78,7 @@ export function validateCoreConfigValue(key: string, value: string): string | nureturn `${key} must be an integer from ${CORE_MIN_MAX_CHARS} to ${CORE_MAX_MAX_CHARS} (default ${CORE_DEFAULT_MAX_CHARS}).`;}if (key === CORE_CONFIG_KEYS.remoteEdit && parseCoreRemoteEdit(value) === null) return `${key} must be allow, notify or refuse (default notify).`;- if (key === CORE_CONFIG_KEYS.enabled && parseBool(value) === null) return `${key} must be true or false (default true).`;+ if (key === CORE_CONFIG_KEYS.enabled && parseBool(value) === null) return `${key} must be true or false (default false).`;return null;}@@ -92,7 +92,7 @@ export async function readCoreSettings(engine: Pick<BrainEngine, 'getConfig'>):engine.getConfig(CORE_CONFIG_KEYS.remoteEdit).catch(() => null),]);return {- enabled: parseBool(enabled) ?? true,+ enabled: parseBool(enabled) ?? false,maxChars: parseCoreMaxChars(max) ?? CORE_DEFAULT_MAX_CHARS,remoteEdit: parseCoreRemoteEdit(remote) ?? 'notify',};diff --git a/test/compile-context-core.serial.test.ts b/test/compile-context-core.serial.test.tsindex 4255628e0a..1526c84ca4 100644--- a/test/compile-context-core.serial.test.ts+++ b/test/compile-context-core.serial.test.ts@@ -33,6 +33,7 @@ beforeAll(async () => {engine = new PGLiteEngine();await engine.connect({});await engine.initSchema();+ await engine.setConfig('memory.core.enabled', 'true');await engine.putPage('people/ada-example', { type: 'note', title: 'Ada Example', compiled_truth: 'A collaborator profile used by the compile fixtures.' });await engine.putPage('concepts/core-prefs', {type: 'note', title: 'Working preferences', compiled_truth: 'Prefers short answers with the command to run.',diff --git a/test/core-cli.test.ts b/test/core-cli.test.tsindex f2f72830df..a378a7e065 100644--- a/test/core-cli.test.ts+++ b/test/core-cli.test.ts@@ -35,6 +35,7 @@ beforeEach(async () => {fixture = mkdtempSync(join(tmpdir(), 'gb-core-cli-'));mkdirSync(join(fixture, 'brain'));await engine.setConfig('sync.repo_path', join(fixture, 'brain'));+ await engine.setConfig('memory.core.enabled', 'true');});afterEach(async () => { await disposePersistenceConsumer(engine); rmSync(fixture, { recursive: true, force: true }); });@@ -91,6 +92,16 @@ describe('gbrain core CLI', () => {expect((await cli(['add', 'notes/missing'])).err).toContain('No live page default:notes/missing');});+ test('core is opt-in: with memory.core.enabled unset, add and init say how to turn it on', async () => {+ await engine.unsetConfig('memory.core.enabled');+ await put('notes/prefs', page('Working preferences', 'Prefers short answers.'), false);+ const added = (await cli(['add', 'notes/prefs'])).out;+ expect(added).toContain('Now in core: default:notes/prefs');+ expect(added).toContain('gbrain config set memory.core.enabled true');+ expect((await cli(['init'])).out).toContain('gbrain config set memory.core.enabled true');+ expect(JSON.parse((await cli(['status', '--json'])).out)).toMatchObject({ enabled: false, pages: 2 });+ });+test('init creates a marked starter page; the owner add is held to the budget', async () => {expect((await cli(['init'])).out).toContain('Created default:core/about-the-user');expect(await corePages()).toEqual(['core/about-the-user']);diff --git a/test/core-memory.test.ts b/test/core-memory.test.tsindex e11174fdb3..646f2e15b0 100644--- a/test/core-memory.test.ts+++ b/test/core-memory.test.ts@@ -18,6 +18,8 @@ beforeAll(async () => {await engine.connect({});await engine.initSchema();await engine.executeRaw(`INSERT INTO sources (id, name) VALUES ('wiki', 'wiki') ON CONFLICT DO NOTHING`);+ // Core is opt-in (off by default, per the held-out core gate); these tests exercise it turned on.+ await engine.setConfig('memory.core.enabled', 'true');}, 60_000);afterAll(async () => { if (engine) await engine.disconnect(); }, 60_000);@@ -124,6 +126,10 @@ describe('listing (PGLite)', () => {expect(defaultOnly.pages.map(p => p.source_id)).toEqual(['default']);const granted = await loadCoreBlock(engine, { sessionSourceId: 'wiki', allowedSources: ['wiki'] });expect(granted.pages.map(p => p.source_id)).toEqual(['wiki']);+ await engine.unsetConfig('memory.core.enabled');+ const unset = await loadCoreBlock(engine, { sessionSourceId: 'wiki' });+ expect(unset.enabled).toBe(false);+ expect(unset.text).toBe('');await engine.setConfig('memory.core.enabled', 'false');const off = await loadCoreBlock(engine, { sessionSourceId: 'wiki' });expect(off.enabled).toBe(false);