Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

large pages x #6696: embedding_state reads the effective bytes_block; a keyword_only marker under it points at the free reindex --oversized, never a lowered limit

garrytancf63d5874888
diff --git a/docs/guides/troubleshooting.md b/docs/guides/troubleshooting.md
index e8700fa6a3..4ad14c61f6 100644
--- a/docs/guides/troubleshooting.md
+++ b/docs/guides/troubleshooting.md
@@ -383,7 +383,7 @@ derived from the rows against the active embedding column (no stored status):
|---|---|---|
| `embedded` | The chunk has a vector in the active column. | None. |
| `pending` | The embed job will embed it (no vector, page live, no `embed_skip`). Doctor `embeddings` ages this backlog and owns its warning. | `gbrain embed --stale --catch-up --source <id> --yes` (paid; preview with `--dry-run`). On a brain keyless by choice keyword search reads these chunks and they do not count as unsearchable. |
-| `keyword_only` | The page carries `embed_skip`: the import gate found its body over `content_sanity.bytes_block` (info, by design; its chunks still feed keyword search and are never purged). Removing the marker alone is undone on the next import. | Split the page, or, after the operator approves, `gbrain config set content_sanity.bytes_block <bytes>` then `gbrain sync --source <id> --full`, which re-imports and embeds it. |
+| `keyword_only` | The page carries `embed_skip`: the import gate found its body over `content_sanity.bytes_block` (info, by design; its chunks still feed keyword search and are never purged). Removing the marker alone is undone on the next import. | A marker under the current `bytes_block` (written by an older release under its 500 KB default): `gbrain reindex --oversized --source <id>` clears it for free. Otherwise split the page, or, after the operator approves, `gbrain config set content_sanity.bytes_block <bytes>` then `gbrain sync --source <id> --full`, which re-imports and embeds it. |
| `quarantined` | The content-quality gate hid the page as junk; it has no searchable chunks. Doctor `quarantined_pages` owns its warning. | Review with `gbrain quarantine list --json`; clear a false positive with `gbrain quarantine clear <slug> --source-id <id> --force` (the owner's call). |
| `empty` | A live page with no body text: nothing to index. | Write content to it, or delete the stub (`gbrain delete <slug> --source <id> --force`, restorable) after the user agrees. |
| `deleted_page_chunks` | Chunks of a soft-deleted page. Search never reads them; the purge lifecycle removes them after 72 h (info until then, a warning past it, code `deleted_page_chunks_overdue`). | `gbrain pages purge-deleted --dry-run --json`, then `gbrain pages purge-deleted --yes` once the user agrees (brain-wide, irreversible). |
diff --git a/llms-full.txt b/llms-full.txt
index f7e44565f1..4fcef43e8f 100644
--- a/llms-full.txt
+++ b/llms-full.txt
@@ -10664,7 +10664,7 @@ derived from the rows against the active embedding column (no stored status):
|---|---|---|
| `embedded` | The chunk has a vector in the active column. | None. |
| `pending` | The embed job will embed it (no vector, page live, no `embed_skip`). Doctor `embeddings` ages this backlog and owns its warning. | `gbrain embed --stale --catch-up --source <id> --yes` (paid; preview with `--dry-run`). On a brain keyless by choice keyword search reads these chunks and they do not count as unsearchable. |
-| `keyword_only` | The page carries `embed_skip`: the import gate found its body over `content_sanity.bytes_block` (info, by design; its chunks still feed keyword search and are never purged). Removing the marker alone is undone on the next import. | Split the page, or, after the operator approves, `gbrain config set content_sanity.bytes_block <bytes>` then `gbrain sync --source <id> --full`, which re-imports and embeds it. |
+| `keyword_only` | The page carries `embed_skip`: the import gate found its body over `content_sanity.bytes_block` (info, by design; its chunks still feed keyword search and are never purged). Removing the marker alone is undone on the next import. | A marker under the current `bytes_block` (written by an older release under its 500 KB default): `gbrain reindex --oversized --source <id>` clears it for free. Otherwise split the page, or, after the operator approves, `gbrain config set content_sanity.bytes_block <bytes>` then `gbrain sync --source <id> --full`, which re-imports and embeds it. |
| `quarantined` | The content-quality gate hid the page as junk; it has no searchable chunks. Doctor `quarantined_pages` owns its warning. | Review with `gbrain quarantine list --json`; clear a false positive with `gbrain quarantine clear <slug> --source-id <id> --force` (the owner's call). |
| `empty` | A live page with no body text: nothing to index. | Write content to it, or delete the stub (`gbrain delete <slug> --source <id> --force`, restorable) after the user agrees. |
| `deleted_page_chunks` | Chunks of a soft-deleted page. Search never reads them; the purge lifecycle removes them after 72 h (info until then, a warning past it, code `deleted_page_chunks_overdue`). | `gbrain pages purge-deleted --dry-run --json`, then `gbrain pages purge-deleted --yes` once the user agrees (brain-wide, irreversible). |
diff --git a/src/commands/pages-unsearchable.ts b/src/commands/pages-unsearchable.ts
index 2e34831e1f..a47fd8626b 100644
--- a/src/commands/pages-unsearchable.ts
+++ b/src/commands/pages-unsearchable.ts
@@ -65,8 +65,10 @@ export async function runPagesUnsearchable(engine: BrainEngine, args: string[]):
const embeddingsEnabled = !(await embeddingsDisabled(engine));
const found = await engine.listEmbeddingStateRows({ sourceIds: [sourceId], states, limit: parsed.limit + 1, purgeWindowHours: DELETED_PAGE_PURGE_WINDOW_HOURS });
const render = cliRenderContext();
+ const summary = await readEmbeddingState(engine, { mode: 'full', sourceIds: [sourceId] });
+ const blockBytes = (summary.keyword_only as { threshold_bytes?: number } | undefined)?.threshold_bytes;
const rows = found.slice(0, parsed.limit).map(row => {
- const fix = embeddingStateFix(row.state, { sourceId, slug: row.slug, markerBytes: row.marker_bytes, embeddingsEnabled });
+ const fix = embeddingStateFix(row.state, { sourceId, slug: row.slug, markerBytes: row.marker_bytes, blockBytes, embeddingsEnabled });
return {
slug: row.slug, source_id: row.source_id, state: row.state, reason: reasonFor(row, embeddingsEnabled), chunks: row.chunks, bytes: row.bytes,
...(row.marker_bytes !== null ? { marker_bytes: row.marker_bytes } : {}),
@@ -74,7 +76,6 @@ export async function runPagesUnsearchable(engine: BrainEngine, args: string[]):
fix: fix ? renderAction(fix, render) : null,
};
});
- const summary = await readEmbeddingState(engine, { mode: 'full', sourceIds: [sourceId] });
const complete = found.length <= parsed.limit;
if (parsed.json) {
console.log(JSON.stringify({ source_id: sourceId, state: parsed.state, limit: parsed.limit, complete, active_column: summary.active_column,
diff --git a/src/core/embedding-state.ts b/src/core/embedding-state.ts
index 3de0693242..c643f9ce50 100644
--- a/src/core/embedding-state.ts
+++ b/src/core/embedding-state.ts
@@ -154,12 +154,10 @@ function ratio(embedded: number | undefined, pending: number): number | null {
return total === 0 ? null : Math.round(((embedded ?? 0) / total) * 10_000) / 10_000;
}
-/** The effective `content_sanity.bytes_block` the import gate applies (env > file > DB > default). */
+/** The effective `content_sanity.bytes_block` the import gate applies (env > file > DB > default, capped at the page ceiling). */
async function effectiveBlockThreshold(engine: BrainEngine): Promise<number> {
try {
- const { loadImportSanityConfig } = await import('./import-screen.ts');
- const configured = (await loadImportSanityConfig(engine)).cs.bytes_block;
- return typeof configured === 'number' && configured > 0 ? configured : DEFAULT_BYTES_BLOCK;
+ return await (await import('./import-screen.ts')).effectiveBytesBlock(engine);
} catch {
return DEFAULT_BYTES_BLOCK;
}
@@ -176,7 +174,7 @@ export function embeddingStateVerify(sourceId: string, state: EmbeddingState): {
* docs). Null for `embedded`, which needs none. Without `sourceId` the
* commands run brain-wide; pass `verify` then (doctor verifies with itself).
*/
-export function embeddingStateFix(state: EmbeddingState, ctx: { sourceId?: string; slug?: string; markerBytes?: number | null; embeddingsEnabled: boolean; verify?: { argv: string[] } }): Action | null {
+export function embeddingStateFix(state: EmbeddingState, ctx: { sourceId?: string; slug?: string; markerBytes?: number | null; blockBytes?: number; embeddingsEnabled: boolean; verify?: { argv: string[] } }): Action | null {
const verify = ctx.verify ?? embeddingStateVerify(ctx.sourceId ?? 'default', state);
const base = { verify, docs: EMBEDDING_STATE_DOCS, requires_exclusive: false };
const source = ctx.sourceId ? ['--source', ctx.sourceId] : [];
@@ -194,6 +192,12 @@ export function embeddingStateFix(state: EmbeddingState, ctx: { sourceId?: strin
user_message: 'Some notes are not indexed for search yet. Indexing them sends their text to your embedding provider and costs a little money. OK to run it?' };
}
case 'keyword_only': {
+ // A marker written under an older, lower limit: the free backfill clears it; raising the limit to the marker would lower it.
+ if (ctx.markerBytes && ctx.blockBytes && ctx.markerBytes <= ctx.blockBytes) {
+ const reindex = ['gbrain', 'reindex', '--oversized', ...source];
+ return { ...base, argv: reindex, preview_argv: [...reindex, '--dry-run'], consent: [], actor: 'agent',
+ why: `This page was marked embed_skip under an older, lower size limit; at ${ctx.markerBytes} bytes it is under the current content_sanity.bytes_block (${ctx.blockBytes}). The backfill removes the stale marker and re-chunks it on the CPU at no cost; a page over 1 MiB then waits for the user's approval before paid embedding.` };
+ }
const threshold = ctx.markerBytes && ctx.markerBytes > 0 ? String(ctx.markerBytes + 1) : null;
const why = 'The import gate marked this page embed_skip because its body exceeds content_sanity.bytes_block; keyword search still reads its chunks. Removing the marker alone is undone on the next import. Two exits: split the page into smaller pages, or raise the threshold (a brain-wide setting the operator approves) and re-import, which embeds it.';
const reimport: Action = { ...base, argv: ['gbrain', 'sync', ...source, '--full'], consent: ['paid'], actor: 'agent',
diff --git a/test/embedding-state.test.ts b/test/embedding-state.test.ts
index 486cbb5f10..3eb4c0777c 100644
--- a/test/embedding-state.test.ts
+++ b/test/embedding-state.test.ts
@@ -11,6 +11,7 @@
* embed job's predicate, or scans in ops mode. No existing owner: the classifier
* is new. PGLite in-memory; the SQL is shared by both engines.
*/
+import { PAGE_MAX_BYTES } from '../src/core/page-size-policy.ts';
import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
import { PGLiteEngine } from '../src/core/pglite-engine.ts';
import { resetPgliteState } from './helpers/reset-pglite.ts';
@@ -86,7 +87,8 @@ describe('embedding state classifier (full mode)', () => {
expect(s.unsearchable).toBe(2 + 3 + 1 + 1);
expect(s.unsearchable_complete).toBe(true);
expect(s.deleted_page_chunks).toEqual({ within_window: 1, past_window: 2, window_hours: 72 });
- expect(s.keyword_only).toMatchObject({ reason: 'embed_skip', pages: 2, marker_bytes: 1_300_000, threshold_bytes: 500_000 });
+ // The default bytes_block is the 24 MiB page ceiling (large pages Wave A); these markers predate it.
+ expect(s.keyword_only).toMatchObject({ reason: 'embed_skip', pages: 2, marker_bytes: 1_300_000, threshold_bytes: PAGE_MAX_BYTES });
const unstamped = s.unstamped_pending as { count: number; created_at_lower_bound: string | null; writer_version: string };
expect(unstamped.count).toBe(1);
expect(unstamped.created_at_lower_bound).not.toBeNull();
diff --git a/test/pages-unsearchable.test.ts b/test/pages-unsearchable.test.ts
index f0781204fe..c64657c390 100644
--- a/test/pages-unsearchable.test.ts
+++ b/test/pages-unsearchable.test.ts
@@ -94,7 +94,18 @@ describe('gbrain pages unsearchable', () => {
expect(row.fix!.verify?.argv).toEqual(['gbrain', 'pages', 'unsearchable', '--source', 'default', '--state', row.state, '--json']);
}
expect(out.rows.find(r => r.state === 'pending')!.fix).toMatchObject({ argv: ['gbrain', 'embed', '--stale', '--catch-up', '--source', 'default', '--yes'], consent: ['paid'] });
- expect(out.rows.find(r => r.state === 'keyword_only')!.fix).toMatchObject({ next: 'ask_user', argv: ['gbrain', 'config', 'set', 'content_sanity.bytes_block', '600001'] });
+ // A marker under the current bytes_block (the 24 MiB default) predates it: the free backfill clears it, never a lowered limit.
+ expect(out.rows.find(r => r.state === 'keyword_only')!.fix).toMatchObject({ next: 'run', argv: ['gbrain', 'reindex', '--oversized', '--source', 'default'], consent: [] });
+ });
+
+ test('a page over the operator\'s bytes_block is asked about raising the limit to just above its marker', async () => {
+ await engine.setConfig('content_sanity.bytes_block', '500000');
+ try {
+ const out = JSON.parse(await run(['--source', 'default', '--state', 'keyword_only', '--json'])) as Listing;
+ expect(out.rows[0]!.fix).toMatchObject({ next: 'ask_user', argv: ['gbrain', 'config', 'set', 'content_sanity.bytes_block', '600001'] });
+ } finally {
+ await engine.unsetConfig('content_sanity.bytes_block');
+ }
});
test('--state filters, embedded is reachable only through --state, and the source scope holds', async () => {