Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
feat(p5): put_page.similar_pages off by default (held-out H5b failed its wrong-merge bar); record first-run verdicts
garrytanb01eb426640c
diff --git a/docs/architecture/key-files/graph-and-facts.md b/docs/architecture/key-files/graph-and-facts.mdindex 9491cacd41..957cf13230 100644--- a/docs/architecture/key-files/graph-and-facts.md+++ b/docs/architecture/key-files/graph-and-facts.md@@ -113,7 +113,7 @@ rejection of serve-only flags before a brain opens.- `src/core/wanted-links.ts` + `src/core/wanted-links-store.ts` — wanted pages. `collectWantedLinks` turns an origin's link candidates (each body markdown link / wikilink carries an `authoredRef` from `extractPageLinks`) and unresolved frontmatter names into `wanted_links` rows: a reference is wanted only when every alternative resolution failed with `missing_target`/`cross_source` (an unqualified target existing only in another source is wanted in the origin source; a qualified target in a source the origin may not link to is not). Bare prose paths never become rows. `replaceWantedLinks` runs inside `replaceDerivedLinks` (`opts.wanted`, per producer `body`/`frontmatter`), so every extraction path (managed put_page and stale sweep via `links-preparation.ts`, unmanaged `extract`, the serve sweep, source reconciliation) replaces rows atomically with links; it locks slug targets and stamps a row `-infinity` when its exact target already exists. `WANTED_ORIGIN_IS_STALE` in `engine-sql/pages.ts` joins the stale-for-extraction predicate: a live target (exact slug, or basename for `ref_kind='name'`) updated after `checked_at` makes the origin stale, so the next sweep creates the edge; restore and rename bump `updated_at`. `listWantedPages` backs the `wanted_pages` op (`gbrain wanted`): source-scoped, private origins excluded before aggregation for remote callers, soft-deleted origins never count, bare-name targets list `existing_matches`. `wanted_pages.enabled` (default on). Migration v213. Pinned by `test/wanted-links.test.ts` + `test/e2e/wanted-links-postgres.test.ts`.-- `src/core/similar-pages.ts` — put_page's similar-pages advisory on creates (`page-advisories.ts`): exact title (`ILIKE`, served by `idx_pages_trgm`), `page_aliases`, same slug basename in another directory (`idx_pages_slug_basename`), and title trigram similarity >= 0.55 in the same top-level directory; up to 3 slugs with their evidence, private pages excluded for callers that may not read them, `semantic: 'not_checked'` (the page's embedding is queued after publication). A question, never a merge. `put_page.similar_pages` (default on). Pinned by `test/put-page-similar-pages.test.ts` + `test/e2e/p5-graph-postgres.test.ts`.+- `src/core/similar-pages.ts` — put_page's similar-pages advisory on creates (`page-advisories.ts`): exact title (`ILIKE`, served by `idx_pages_trgm`), `page_aliases`, same slug basename in another directory (`idx_pages_slug_basename`), and title trigram similarity >= 0.55 in the same top-level directory; up to 3 slugs with their evidence, private pages excluded for callers that may not read them, `semantic: 'not_checked'` (the page's embedding is queued after publication). A question, never a merge. `put_page.similar_pages` (default off: held-out verdict H5b failed its wrong-merge bar). Pinned by `test/put-page-similar-pages.test.ts` + `test/e2e/p5-graph-postgres.test.ts`.- `src/core/schema-pack/field-usage.ts` — `gbrain schema detect --fields`: per page type (top 50, up to 500 sampled pages each), frontmatter key, fact-category and relation-type usage; share 1 → required, >= 0.25 → optional. Identity and write-provenance keys are ignored. Read-only. Pinned by `test/schema-field-usage.test.ts`.diff --git a/docs/eval/decisions/p5-delta-2026-10-05/verdicts.md b/docs/eval/decisions/p5-delta-2026-10-05/verdicts.mdindex 2b79e08f4b..881c6177a2 100644--- a/docs/eval/decisions/p5-delta-2026-10-05/verdicts.md+++ b/docs/eval/decisions/p5-delta-2026-10-05/verdicts.md@@ -28,6 +28,7 @@ and idiomatic leaves, exchange moves, first-day starts). Link typing is as at `0"moved to [X] (role)") and idiomatic leave phrases the cue lexicon does not read. A future change needs its ownpreregistration and held-out set.-## Pending+## First run-First-run verdicts H3 (junk audit), H5b (agent loop duplicates) and H6 (typed lines help answers).+First-run verdicts are in `../p5-dev-2026-10-04/verdicts.md`: H5b (agent loop duplicates) failed, so+`put_page.similar_pages` is off by default. H3 (junk audit) and H6 (typed lines help answers) are pending.diff --git a/docs/eval/decisions/p5-dev-2026-10-04/verdicts.md b/docs/eval/decisions/p5-dev-2026-10-04/verdicts.mdnew file mode 100644index 0000000000..00f41758d3--- /dev/null+++ b/docs/eval/decisions/p5-dev-2026-10-04/verdicts.md@@ -0,0 +1,26 @@+# P5 first run: held-out verdicts++The custodian (P0) ran every first-run cell on frozen build `21befeb5b` against baseline master `6622a119e`, under+`preregistration.md` and its amendments. Each verdict sets the default the preregistration's feature table names.+Delta-run verdicts (H7 to H11) are in `../p5-delta-2026-10-05/verdicts.md`.++| Hypothesis | Result | Verdict | Outcome |+|---|---|---|---|+| H1, link typing does not regress (world-v1) | any-type match 0.493 → 0.493; type accuracy 0.747 → 0.767; 240/240 pages extract identically with the grammar on and off | PASS | counts toward `line_grammar.enabled` |+| H2, written relation types reach the graph (template set B) | typed recall 0.811 → 1.000; 0 of 120 decoy types added | PASS | counts toward `line_grammar.enabled` |+| H4, forward references heal (local writes) | edges lost 1,849/3,810 → 0/3,738; withheld-entity recall 0 → 1.000 | PASS | `wanted_pages.enabled` on by default |+| H5a, similar-page hint on held-out name pools | lexical recall@3 0 → 0.980; hint on no-referent names 4.7% | PASS | H5b decides the default |+| H5b, agent loop duplicates (Claude Sonnet 5.5 and `gpt-6.1-sol`, 60 held-out tasks each) | duplicate-page rate 3.06% → 2.22% (−27% relative; 95% CI of the difference [−2.8, +1.1] points, crosses 0); wrong-merge rate 2.50% → 3.75% (+1.25 points against a bar of at most +1) | FAIL | `put_page.similar_pages` off by default; still available with `gbrain config set put_page.similar_pages true` |+| H3, junk stays out | | pending | `line_grammar.enabled` needs H3 and H6 |+| H6, typed lines help answers | | pending | runs after H3 |++## H5b by model++| Model | Duplicate-page rate | Wrong-merge rate |+|---|---|---|+| Claude Sonnet 5.5 | unchanged | unchanged |+| `gpt-6.1-sol` | 2.8% → 1.1% | 5.0% → 7.5% |++All of the movement is in the GPT arm, where duplicates fell and wrong merges rose. The wrong-merge bar fails, so the+hint ships off by default. The duplicate reduction would not have passed on its own either, since its interval+includes zero.diff --git a/docs/guides/line-grammar.md b/docs/guides/line-grammar.mdindex 153be06bf0..e8e7ab4661 100644--- a/docs/guides/line-grammar.md+++ b/docs/guides/line-grammar.md@@ -2,8 +2,8 @@Three write-path features keep the graph honest without an LLM call: typedrelation and fact lines a person can type in any editor, a queue of link-targets that have no page yet, and a "did you mean an existing page?" hint-when a write creates a page.+targets that have no page yet, and an opt-in "did you mean an existing page?"+hint when a write creates a page.## Typed relation lines@@ -83,18 +83,26 @@ Off switch: `gbrain config set wanted_pages.enabled false`.## Similar-page hints-When a write creates a page, a few indexed lexical checks look for an existing-page in the same source that is probably the same thing: the same title, a-declared alias, the same name in another directory, or a very similar title in-the same directory. Up to three slugs come back in `similar_pages` with the-evidence that matched. It is a question, never a merge: move the content with-`edit_page` and delete the new page if it is the same thing, keep both if not.-Semantic (embedding) duplicate detection is not part of this check+Off by default; turn it on with `gbrain config set put_page.similar_pages true`.+In the held-out agent test, the hint cut duplicate pages from 3.06% to 2.22%,+but the 95% interval of that change ([−2.8, +1.1] points) includes zero, and+wrong merges rose from 2.50% to 3.75%, past the one-point limit. Claude Sonnet+5.5 behaved the same with and without it. All of the change came from+`gpt-6.1-sol`, whose duplicates fell from 2.8% to 1.1% while its wrong merges+rose from 5.0% to 7.5%.++When it is on and a write creates a page, a few indexed lexical checks look for+an existing page in the same source that is probably the same thing: the same+title, a declared alias, the same name in another directory, or a very similar+title in the same directory. Up to three slugs come back in `similar_pages` with+the evidence that matched. It is a question, never a merge: move the content+with `edit_page` and delete the new page if it is the same thing, keep both if+not. Semantic (embedding) duplicate detection is not part of this check(`semantic: "not_checked"`).**Say to your agent:** *"Before you file this, check whether we already have a page for this company."*-Off switch: `gbrain config set put_page.similar_pages false`.+Turn off again: `gbrain config set put_page.similar_pages false`.## Field usagediff --git a/src/core/config.ts b/src/core/config.tsindex 30b552d382..b489d3c887 100644--- a/src/core/config.ts+++ b/src/core/config.ts@@ -1611,7 +1611,7 @@ export const KNOWN_CONFIG_KEYS: readonly string[] = [// Validity ranges on typed relation lines stored as dated edge transitions// (core/link-effective.ts). On by default (held-out verdict H7).'line_grammar.effective_ranges',- // put_page "did you mean an existing page?" advisory on creates (core/similar-pages.ts).+ // put_page "did you mean an existing page?" advisory on creates (core/similar-pages.ts). Off by default (held-out verdict H5b).'put_page.similar_pages',// #5584: skillopt optimizer output cap (default 32000 thinking / 4096 otherwise).'skillopt.reflect_max_tokens',diff --git a/src/core/similar-pages.ts b/src/core/similar-pages.tsindex 0b946ca326..1f33d339f3 100644--- a/src/core/similar-pages.ts+++ b/src/core/similar-pages.ts@@ -27,7 +27,7 @@ const MAX_CANDIDATES = 3;* Existing pages in `sourceId` that a newly created `slug` probably* duplicates. `excludePrivate` keeps private pages out for callers that may* not read them. Returns null when `slug` already existed (not a create) or- * when `put_page.similar_pages` is off.+ * when `put_page.similar_pages` is not turned on (default off).*/export async function findSimilarPages(engine: Pick<BrainEngine, 'executeRaw'>, input: {sourceId: string; slug: string; title: string; excludePrivate: boolean;@@ -43,8 +43,8 @@ export async function findSimilarPages(engine: Pick<BrainEngine, 'executeRaw'>,SELECT NULL::text AS slug, 'page_exists' AS evidence, 0 AS tier, 0::real AS sim FROM pages pWHERE p.source_id = $1 AND p.slug = $2 AND p.deleted_at IS NULLUNION ALL- SELECT NULL::text, 'disabled', 0, 0::real FROM config c- WHERE c.key = 'put_page.similar_pages' AND lower(trim(c.value)) IN ('false', '0', 'no', 'off')+ SELECT NULL::text, 'disabled', 0, 0::real WHERE NOT EXISTS (SELECT 1 FROM config c+ WHERE c.key = 'put_page.similar_pages' AND lower(trim(c.value)) IN ('true', '1', 'yes', 'on'))UNION ALLSELECT p.slug, 'exact_title' AS evidence, 1 AS tier, 1.0::real AS sim FROM pages pWHERE p.source_id = $1 AND p.slug <> $2 AND p.deleted_at IS NULL AND $3 <> '' AND p.title ILIKE $7 ESCAPE '\\'${privacy}@@ -62,7 +62,7 @@ export async function findSimilarPages(engine: Pick<BrainEngine, 'executeRaw'>,SELECT DISTINCT ON (slug) slug, evidence, tier, sim FROM hits ORDER BY slug, tier, sim DESC`,[input.sourceId, input.slug, title, normalizeAlias(title), basename, dir, title.replace(/[\\%_]/g, ch => `\\${ch}`)]);// The page already exists (a create raced another writer, or this is an update): not a create, no advisory.- // `put_page.similar_pages` false (default on) turns the advisory off; read in the same statement.+ // The advisory runs only when `put_page.similar_pages` is true (default off, held-out verdict H5b); read in the same statement.if ((rows as Array<{ evidence: string }>).some(row => row.evidence === 'page_exists' || row.evidence === 'disabled')) return null;const ranked = (rows as Array<{ slug: string; evidence: SimilarPageEvidence; tier: number; sim: number }>).sort((a, b) => a.tier - b.tier || b.sim - a.sim || a.slug.localeCompare(b.slug)).slice(0, MAX_CANDIDATES);diff --git a/test/helpers/similar-pages-scenarios.ts b/test/helpers/similar-pages-scenarios.tsindex f5884cf087..8f47534cb2 100644--- a/test/helpers/similar-pages-scenarios.ts+++ b/test/helpers/similar-pages-scenarios.ts@@ -15,11 +15,14 @@ const put = async (ctx: OperationContext, slug: string, title: string, extra = 'return written.outcome ?? written;};-/** Creates get lexical candidates with their evidence; updates and distinct pages get none. */+/** Off by default (held-out verdict H5b); once on, creates get lexical candidates with their evidence and updates and distinct pages get none. */export async function similarPagesOnCreate(databaseUrl?: string) {await managedBrain(async ({ engine, ctx }) => {const acme = await put(ctx, 'companies/acme-example', 'Acme Example', 'aliases: [Acme Corp]\n');expect(acme.similar_pages).toBeUndefined();+ const { findSimilarPages } = await import('../../src/core/similar-pages.ts');+ expect(await findSimilarPages(engine, { sourceId: 'default', slug: 'companies/acme-example-2', title: 'Acme Example', excludePrivate: false })).toBeNull();+ await engine.setConfig('put_page.similar_pages', 'true');expect((await put(ctx, 'companies/acme-example-2', 'Acme Example')).similar_pages).toMatchObject({ candidates: [{ slug: 'companies/acme-example', source_id: 'default', evidence: 'exact_title' }], semantic: 'not_checked' });const aliasHit = await put(ctx, 'companies/acme-corp', 'Acme Corp');@@ -42,7 +45,8 @@ export async function similarPagesOnCreate(databaseUrl?: string) {/** A caller that may not read private pages is never pointed at one. */export async function similarPagesSkipPrivate(databaseUrl?: string) {- await managedBrain(async ({ ctx }) => {+ await managedBrain(async ({ engine, ctx }) => {+ await engine.setConfig('put_page.similar_pages', 'true');await put(ctx, 'people/secret-example', 'Secret Example', 'visibility: private\n');const local = await put(ctx, 'people/secret-example-2', 'Secret Example');expect(local.similar_pages.candidates).toContainEqual(expect.objectContaining({ slug: 'people/secret-example' }));