Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Keyword search on an entity's name keeps the labels it had before

garrytan3a58de1499ac
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 364020fd92..8bd5fa20d4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,7 +18,7 @@ identifiers and attribution are available in the pre-removal Git revision
- `get_backlinks` with a `type` that other pages in the brain have, but no page linking to this one has, now returns the normal empty answer plus a note listing the types the linking pages do have. Before, it refused with `unknown type`, so an agent walking several accounts by type was refused once per account. A type no page has is still refused, and the refusal now also lists the brain's own page types. For a remote caller, both checks count only pages that caller can read. A type found only on private pages, pages whose readers leave the caller out, deleted pages or another source is treated as a type that does not exist and is never named.
- `list_pages` with a `type` that no page has still returns the same empty list, but now adds a note naming the page types the brain does have, most common first (up to 12, with counts). Before, a guessed type such as `account` on a brain that files accounts as `crm` came back as a bare `[]`, which reads like "no such pages". A remote caller's note names only types of pages it can read.
-- `search` with `match: "keyword"` now labels every row that matches the query as written `keyword_exact`, including rows from your own `"A" OR "B"` query or a one-word query. Their match scores sit below the cutoff the label used to need, so they were labelled `weak_semantic`, which told agents the batched lookup the instructions recommend had found nothing solid. `create_safety` (the "don't write a duplicate" hint) is unchanged for these rows. Rows found only by gbrain's own fallback of loosening a query to any-word matching stay `weak_semantic`, and default (hybrid) search is unchanged.
+- `search` with `match: "keyword"` now labels every row that matches the query as written `keyword_exact`, including rows from your own `"A" OR "B"` query or a one-word query. Their match scores sit below the cutoff the label used to need, so they were labelled `weak_semantic`, which told agents the batched lookup the instructions recommend had found nothing solid. `create_safety` (the "don't write a duplicate" hint) is unchanged for these rows. Rows found only by gbrain's own fallback of loosening a query to any-word matching stay `weak_semantic`. A query that is an entity's name, which keyword search also runs under the entity's other names, keeps the labels it had before, and default (hybrid) search is unchanged.
- `request_tools` accepts `tools` and `surface` in one call. It changes the tool surface exactly as a `surface`-only call does (same limits and refusals), then returns the requested tool schemas, with the surface answer under `surface_change`. Before, the pair was refused, and some models send it every night. Calls with only one of the two answer as before.
## [0.60.651.0] - 2026-11-10
diff --git a/src/core/ops/search.ts b/src/core/ops/search.ts
index 949607c2dc..6879f30b21 100644
--- a/src/core/ops/search.ts
+++ b/src/core/ops/search.ts
@@ -773,7 +773,7 @@ const search: Operation = {
let keywordBound: DegradedStageEntry | undefined;
const results = await keepFrontmatterMatches(ctx.engine, (page ? page.rows : dedupResults(await timings.stage('lexical', () => ctx.engine.searchKeyword(queryText, { limit, offset, ...keywordOpts,
onKeywordIncomplete: reason => { keywordBound = { stage: 'keyword_candidates_incomplete', reason }; } })).finally(lexicalDone.resolve))).map(r => ({ ...r })), where);
- await stampKeywordRows(ctx, results, { ...scope, excludePrivate }, queryText, startedAt, timings, paging.match === 'keyword');
+ await stampKeywordRows(ctx, results, { ...scope, excludePrivate }, queryText, startedAt, timings, paging.match === 'keyword' && !names);
// #3800: cap AFTER capture/meta so eval + cache see the real payload.
return evidenceOutput(ctx, p, results, plan, { ...scope, excludePrivate }, null, snippetCap, timings,
async rows => withCountMeta(withCountMeta(await buildRetrievalResponseMeta(ctx, scope, queryText, rows, null, { conceptHint: true, types, typeFilterNotice: typeFilter.notice, filterHintFor: { op: 'search', p }, timings }),
diff --git a/test/search-keyword-evidence-label-gbra449.test.ts b/test/search-keyword-evidence-label-gbra449.test.ts
index 905dc2ee69..eb1f996101 100644
--- a/test/search-keyword-evidence-label-gbra449.test.ts
+++ b/test/search-keyword-evidence-label-gbra449.test.ts
@@ -14,7 +14,13 @@
* (keyword_relaxed) or only through an entity name the engine added
* (matched_alias) stays weak_semantic under the floor, and so does a
* below-floor row outside keyword mode (stampEvidence unit cases);
- * - hybrid search (the default match) keeps its labels.
+ * - hybrid search (the default match) keeps its labels;
+ * - a cursor page labels the caller's own matches keyword_exact as page 1 does;
+ * - a query that is an entity's name (searched under every name the entity
+ * goes by) keeps master's score-floor labels on every page: a row found
+ * only under another name written with different punctuation
+ * ("Copper-Fox" for the alias "Copper Fox") is not keyword_exact, and
+ * neither is the page whose title holds the entity's own name.
* Database-only (repo-less) brain: pages are imported straight into the
* database (importFromContent, the put_page import path), no checkout; keyless (no embedding provider). PGLite always, Postgres when
* DATABASE_URL is set.
@@ -29,6 +35,8 @@ import { dispatchToolCall } from '../src/mcp/dispatch.ts';
import { __setEmbedTransportForTests, configureGateway, resetGateway } from '../src/core/ai/gateway.ts';
import { SOLID_MATCH_FLOOR, stampEvidence } from '../src/core/search/evidence.ts';
import { requirePostgresTestDatabase, testBackends } from './helpers/test-backends.ts';
+import { resetMentionBrain, sweep } from './helpers/mention-brain.ts';
+import { setCliOptions } from '../src/core/cli-options.ts';
type Row = { slug: string; evidence: string; create_safety: string; score: number };
@@ -126,9 +134,92 @@ for (const backend of testBackends()) {
expect(await search('Escalated zebra', { match: 'keyword' })).toEqual([]);
});
+ test('a cursor page labels the caller\'s own matches keyword_exact, as page 1 does', async () => {
+ for (const [query, limit] of [['"2026-08-04" OR "2026-08-08"', 1], ['Escalated', 2]] as const) {
+ const pages: Row[][] = [];
+ let next: Record<string, unknown> | undefined = { query, match: 'keyword', limit };
+ while (next) {
+ const r = await dispatchToolCall(engine, 'search', next, remote as never);
+ expect(r.isError).not.toBe(true);
+ pages.push(JSON.parse(r.content[0]!.text) as Row[]);
+ next = (r._meta?.retrieval as { next?: Record<string, unknown> } | undefined)?.next;
+ }
+ expect(pages.length).toBeGreaterThan(1);
+ for (const rows of pages) for (const r of rows) expect(r.evidence).toBe('keyword_exact');
+ }
+ });
+
test('hybrid search (default match) keeps its labels', async () => {
expect(labels(await search('"2026-08-04" OR "2026-08-08"', {}))).toEqual(['contracts/c1 weak_semantic unknown', 'contracts/c2 weak_semantic unknown']);
expect(labels(await search('Escalated', {}))).toEqual([1, 2, 3, 4, 5, 6].map(i => 'tickets/t' + i + ' weak_semantic unknown'));
});
});
}
+
+for (const backend of testBackends()) {
+ describe('[' + backend + '] search match: keyword on an entity\'s name keeps master\'s labels (GBRA-449)', () => {
+ let engine: BrainEngine;
+ const remote = { remote: true, transport: 'stdio' as const, sourceId: 'default', takesHoldersAllowList: ['world'], config: { engine: backend } as never };
+
+ beforeAll(async () => {
+ setCliOptions({ quiet: true, progressJson: false, progressInterval: 1000, explain: false, timeoutMs: null, brain: null });
+ if (backend === 'postgres') {
+ const pg = new PostgresEngine();
+ await pg.connect({ database_url: requirePostgresTestDatabase() });
+ engine = pg;
+ } else {
+ const lite = new PGLiteEngine();
+ await lite.connect({});
+ engine = lite;
+ }
+ await engine.initSchema();
+ await engine.setConfig('schema_pack', 'gbrain-base-v2');
+ }, 180_000);
+ afterAll(async () => { await engine.disconnect(); });
+
+ const put = (slug: string, type: string, title: string, body: string) =>
+ importFromContent(engine, slug, ['---', 'type: ' + type, 'title: "' + title + '"', '---', body, ''].join('\n'), { noEmbed: true, forceRechunk: true });
+
+ beforeEach(async () => {
+ await resetMentionBrain(engine);
+ await put('accounts/widget-co', 'account', 'Account sheet: Widget Co', 'Internal nickname: Copper Fox');
+ await put('tickets/t2', 'ticket', 'Ticket 2', 'Copper-Fox asked about the invoice.');
+ await put('tickets/t1', 'ticket', 'Ticket 1', 'Copper Fox asked for a refund.');
+ for (let i = 0; i < 3; i++) await put('notes/n' + i, 'note', 'Note ' + i, 'Weekly check-in number ' + i + ' with Widget Co.');
+ await sweep(engine);
+ });
+
+ async function walk(limit: number) {
+ const rows: Array<Row & { matched_alias?: string; page: number }> = [];
+ let next: Record<string, unknown> | undefined = { query: 'Widget Co', match: 'keyword', limit };
+ for (let page = 0; next; page++) {
+ const r = await dispatchToolCall(engine, 'search', next, remote as never);
+ expect(r.isError).not.toBe(true);
+ for (const row of JSON.parse(r.content[0]!.text) as Array<Row & { matched_alias?: string }>) rows.push({ ...row, page });
+ next = (r._meta?.retrieval as { next?: Record<string, unknown> } | undefined)?.next;
+ }
+ return rows;
+ }
+
+ test('a row found only under another name written with other punctuation, and the page titled with the entity\'s own name, keep the floor label', async () => {
+ const rows = await walk(10);
+ const bySlug = new Map(rows.map(r => [r.slug, r]));
+ for (const slug of ['tickets/t2', 'accounts/widget-co']) {
+ const r = bySlug.get(slug)!;
+ expect(r).toBeDefined();
+ expect(r.score).toBeLessThan(SOLID_MATCH_FLOOR);
+ expect(r.evidence).toBe('weak_semantic');
+ }
+ });
+
+ test('every page of the walk keeps the floor labels, and page 2 on still marks rows found only under another name', async () => {
+ const rows = await walk(1);
+ expect(rows.length).toBeGreaterThan(2);
+ for (const r of rows) if (r.score < SOLID_MATCH_FLOOR) expect(r.evidence).toBe('weak_semantic');
+ const t1 = rows.find(r => r.slug === 'tickets/t1')!;
+ expect(t1.page).toBeGreaterThan(0);
+ expect(t1.matched_alias).toBe('Copper Fox');
+ expect(t1.evidence).toBe('weak_semantic');
+ });
+ });
+}