Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(onboard): MCP onboarding stale-chunk count excludes embed_skip pages (#5256)
time-attack55d9e74cbc61
diff --git a/src/core/onboard/mcp-onboarding.ts b/src/core/onboard/mcp-onboarding.tsindex 2c35dcefa0..a8d0b4bcde 100644--- a/src/core/onboard/mcp-onboarding.ts+++ b/src/core/onboard/mcp-onboarding.ts@@ -17,6 +17,7 @@ import type { Action, Notice, RenderContext } from '../agent-output.ts';import { gbrainPath, type GBrainConfig } from '../config.ts';import { configReadiness } from '../readiness.ts';import { recallStagesFor } from '../interop-notices.ts';+import { EMBED_SKIP_FILTER_FRAGMENT } from '../embed-skip.ts';export const LINK_COVERAGE_MIN = 0.7;export const TIMELINE_COVERAGE_MIN = 0.9;@@ -41,7 +42,8 @@ export interface OnboardCounts {}const COUNT_SQL = [- `SELECT COUNT(*) AS count FROM content_chunks WHERE embedding IS NULL`,+ `SELECT COUNT(*) AS count FROM content_chunks cc JOIN pages p ON p.id = cc.page_id+ WHERE cc.embedding IS NULL AND p.deleted_at IS NULL AND ${EMBED_SKIP_FILTER_FRAGMENT}`,`SELECT COUNT(*) AS count FROM pagesWHERE type IN ('person', 'company', 'organization', 'entity')AND deleted_at IS NULL`,diff --git a/test/mcp-onboarding.test.ts b/test/mcp-onboarding.test.tsindex 7cf38521b3..80aa7219e8 100644--- a/test/mcp-onboarding.test.ts+++ b/test/mcp-onboarding.test.ts@@ -15,8 +15,9 @@ import { withEnv } from './helpers/with-env.ts';import { operations } from '../src/core/operations.ts';import { allowedOpNames, isReadOnlyOperation, STARTER_OPS } from '../src/mcp/surface.ts';import { dispatchToolCall, dispatchRenderContext, __resetBackupNoticeForTests, type ToolResult } from '../src/mcp/dispatch.ts';+import { installFixtureChunks } from './helpers/page-projection.ts';import {- ONBOARD_CALL_AFFINITY, mcpOnboardingNotices, startOnboardingRefresher,+ ONBOARD_CALL_AFFINITY, collectOnboardOpportunities, mcpOnboardingNotices, startOnboardingRefresher,__awaitOnboardingRefreshForTests, __resetMcpOnboardingForTests, __warmOnboardingCacheForTests,} from '../src/core/onboard/mcp-onboarding.ts';import { processNoticeLedger, setNoticeMuted } from '../src/core/notice-ledger.ts';@@ -348,3 +349,17 @@ describe('first-run decisions over stdio', () => {});});});++describe('stale-chunk count (#5256)', () => {+ test('counts only chunks the embedder would pick up: embed_skip and soft-deleted pages are not backlog', async () => {+ for (const slug of ['notes/stale-example', 'notes/skip-example', 'notes/deleted-example']) {+ await engine.putPage(slug, { type: 'note', title: slug, compiled_truth: slug, timeline: '' });+ await installFixtureChunks(engine, slug, [{ chunk_index: 0, chunk_text: `${slug} body`, chunk_source: 'compiled_truth', token_count: 2 }]);+ }+ await engine.executeRaw(`UPDATE pages SET frontmatter = COALESCE(frontmatter, '{}'::jsonb) || '{"embed_skip": true}'::jsonb WHERE slug = 'notes/skip-example'`);+ await engine.executeRaw(`UPDATE pages SET deleted_at = now() WHERE slug = 'notes/deleted-example'`);+ const counts = await collectOnboardOpportunities(engine, new AbortController().signal);+ expect(counts.staleChunks).toBe(await engine.countStaleChunks());+ expect(counts.staleChunks).toBe(1);+ });+});