Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
wip(#6803 lane B): fixture, docs
garrytana7e0b0a2ee06
diff --git a/docs/guides/memory-boundaries.md b/docs/guides/memory-boundaries.mdindex 51ee18b0cf..58a7acc6ce 100644--- a/docs/guides/memory-boundaries.md+++ b/docs/guides/memory-boundaries.md@@ -84,7 +84,7 @@ running `gbrain embed`.**Say to your agent:** *"I upgraded gbrain. Which of my big pages couldn't befound before, and what would it cost to embed them now?"* The agent runs`gbrain reindex --oversized --dry-run --json` and `gbrain doctor --json`, then-asks before `gbrain embed --held --max-usd <N>`.+asks before `gbrain embed --held --source <id> --max-usd <N>`, one source at a time.A page stays one page whatever its size: one slug, one title, one set oflinks. Size no longer decides whether search can find it. Every Markdown page@@ -127,7 +127,7 @@ An ordinary page carries no field.| --- | --- | --- || `deferred` | `large_page` | Over 1 MiB: committed with chunks and no vectors; the embedding sweep embeds it after the commit, under `embed.max_usd_per_page`. || `partial` | `spend_cap` | The per-page cap stopped embedding; the rest stays keyword-only. |-| `held` | e.g. `upgrade_backfill` | Embedding waits for the user's approval of the previewed cost (`gbrain embed --held`). |+| `held` | e.g. `upgrade_backfill` | Embedding waits for the user's approval of the previewed cost (`gbrain embed --held --dry-run`, then one source at a time). || `skipped` | `oversized` | Over the operator's `bytes_block`: chunked and keyword-searchable, never embedded. || `skipped` | `operator_marker` | Another `embed_skip` marker: chunked and keyword-searchable, never embedded. |@@ -174,9 +174,10 @@ are not yet metered by this cap. When several caps apply,the lowest wins: the per-page cap, the run's consent cap (`--max-usd`),`embed.backfill_max_usd` and `embed.backfill_max_usd_per_source_24h`. A pageover its cap is still keyword-searchable, and its newest chunks are embedded-first, up to the cap. Doctor's `partial_embedding` check names each such page-with the exact fix, `gbrain embed --slugs <slug> --max-usd <N>`; raising a cap-is the user's call.+first, up to the cap. Doctor's `partial_embedding` check counts such pages by+source and prints each source's approve command with a concrete N,+`gbrain embed --held --source <id> --max-usd <N>`; raising a cap is the+user's call.<a id="large-pages-upgrade"></a>**After upgrading.** Older releases stored a page over 500 KB with an@@ -188,16 +189,32 @@ resumes where it stopped. It removes only gate-written markers whose reason is`oversized`, and the matching `content_flag: oversized`; a page above theoperator's effective `bytes_block` keeps both and is re-chunked for keywordsearch with no vectors. The backfill never embeds.-Backfilled pages over 1 MiB are held for consent; the post-upgrade notice and-doctor's `partial_embedding` check show how many are held and what embedding-them would cost. Pages between 500 KB and 1 MiB cost a cent or two each and-embed through the normal sweep under the existing caps.+Backfilled pages over 1 MiB are held for consent; the post-upgrade notice,+`gbrain embed --stale` (its `budget_limited` line) and doctor's+`partial_embedding` check show how many are held and what embedding them+would cost. Pages between 500 KB and 1 MiB cost a cent or two each and embed+through the normal sweep under the existing caps.++Nothing releases a hold automatically. `gbrain embed --held --dry-run` lists+every source, writes nothing and prints one approve command per source; an+approval covers one source, so `--held --max-usd` needs `--source` when held+pages span several sources. `--max-usd N` is two things at once: the run's+hard cap and the extra allowance saved on each page it approves, so the+printed N is a ceiling (the estimate x1.5, at least $0.25), not the estimate.+It works on every provider; on a local one that bills nothing the printed N is+$0.01 and the run costs nothing. A run stopped by its cap, or interrupted,+keeps every vector it wrote: the page it was on is no longer held and the stale+sweep finishes it under its new allowance, and pages it never reached stay+held for the next approval. `--yes` never approves a held page. An approval is+refused, with every hold and cap unchanged, when embeddings are unavailable+(disabled, no provider credentials) or the paid model has no price.```bashgbrain reindex --oversized --dry-run --json # preview the backfill: free, no provider callsgbrain reindex --oversized --source <id> # run it now for one source-gbrain embed --held --max-usd 2 # embed every held page, capped at $2 (paid)-gbrain embed --slugs <slug> --max-usd 1 # embed one page, capped at $1 (paid)+gbrain embed --held --dry-run # every source: held pages, the cost to finish, one approve command each (free)+gbrain embed --held --source <id> --max-usd 2 # embed one source's held pages: $2 caps the run and is each page's extra allowance (paid)+gbrain embed --slugs <slug> --source <id> --max-usd 1 # embed one page, capped at $1 (paid)gbrain search "<a phrase from deep in the page>" # keyword search finds it before any embeddinggbrain doctor --only partial_embedding --json # pages embedded only up to their capgbrain config set embed.max_usd_per_page 5 # raise the per-page cap (ask the user first)diff --git a/docs/guides/troubleshooting.md b/docs/guides/troubleshooting.mdindex e52dec1db3..af2644aec1 100644--- a/docs/guides/troubleshooting.md+++ b/docs/guides/troubleshooting.md@@ -61,7 +61,8 @@| `gbrain init` or `gbrain upgrade` stops with `schema_lock_blocked` naming a pid (or, before #5227, sat in `wait_event_type=Lock` with no output) | let the named session finish, or with the user's agreement end it on the database host: `SELECT pg_terminate_backend(<pid>)`; then rerun the same command ([ENGINES.md](../ENGINES.md#schema-lock-blocked)) | brain host, after the user agrees | `destructive` when it ends another session | the rerun completes; `gbrain doctor --json` shows the schema at head || [`queue_capacity`, `persistence_capacity` or `persistence_request_growth`](#write-capacity) | run the printed `gbrain config set persistence.limits.<limit> <value>` | brain host | none | `gbrain doctor --only persistence_capacity,persistence_request_growth --json` || [`dream_paid_loop`, or dream keeps skipping one transcript](#dream-paid-loop) | fix the cause, then `gbrain dream reset-key --list` and `gbrain dream reset-key '<key>'` | agent, after the user agrees | `paid` (the key is retried) | `gbrain doctor --only dream_paid_loop --json` |-| [A page exists (`gbrain get <slug>` returns it) but search never finds text from it](memory-boundaries.md#large-pages) | find the cause: `gbrain reindex --oversized --dry-run --json` lists pages stored before the upgrade with a size-based `embed_skip` marker (run it without `--dry-run` to keyword-index them, free); a page above an operator-lowered `content_sanity.bytes_block` keeps its marker until the operator raises or unsets it; a page the content-quality gate quarantined as junk shows in `gbrain quarantine list`, and `gbrain quarantine clear <slug>` re-checks it once the user agrees; a file over the 24 MiB page ceiling was never stored ([`file_too_large`](write-refusals.md#file_too_large)). Embedding the re-indexed pages is a separate paid step: `gbrain embed --held --max-usd <N>` | agent for the reindex; the user decides embedding spend, a `bytes_block` change and a quarantine clear | none for the reindex (CPU only); `paid` for `gbrain embed` | `gbrain reindex --oversized --dry-run --json` lists nothing; `gbrain doctor --json`; `gbrain search "<phrase from deep in the page>"` returns the page |+| [A page exists (`gbrain get <slug>` returns it) but search never finds text from it](memory-boundaries.md#large-pages) | find the cause: `gbrain reindex --oversized --dry-run --json` lists pages stored before the upgrade with a size-based `embed_skip` marker (run it without `--dry-run` to keyword-index them, free); a page above an operator-lowered `content_sanity.bytes_block` keeps its marker until the operator raises or unsets it; a page the content-quality gate quarantined as junk shows in `gbrain quarantine list`, and `gbrain quarantine clear <slug>` re-checks it once the user agrees; a file over the 24 MiB page ceiling was never stored ([`file_too_large`](write-refusals.md#file_too_large)). Embedding the re-indexed pages is a separate paid step: `gbrain embed --held --dry-run`, then `gbrain embed --held --source <id> --max-usd <N>` per source | agent for the reindex; the user decides embedding spend, a `bytes_block` change and a quarantine clear | none for the reindex (CPU only); `paid` for `gbrain embed` | `gbrain reindex --oversized --dry-run --json` lists nothing; `gbrain doctor --json`; `gbrain search "<phrase from deep in the page>"` returns the page |+| [Large pages stay out of meaning-based search; `gbrain embed --stale` prints `large page(s) have chunks waiting for embedding approval` or doctor `partial_embedding` warns](memory-boundaries.md#large-pages) | preview with `gbrain embed --held --dry-run` (every source, free); with the user's approval `gbrain embed --held --source <id> --max-usd <N>` per source, with the N the preview prints (a ceiling: the run's cap and each page's extra allowance) | agent, after the user agrees | `paid`, `egress` (none on a local provider that bills nothing) | `gbrain embed --held --dry-run --source <id> --json` shows `held: 0` and `capped: 0` for that source; `gbrain doctor --only partial_embedding --json` || [Search answers look keyword-only on a large Postgres brain](#hybrid-search-returns-only-keyword-hits) | read doctor's `vector_plan`; run the index command it prints | brain host | none | `gbrain doctor --only vector_plan --json` || [Broad keyword queries take about 8 s and come back vector-only (`keyword_arm_failed`, or `skipped_after_timeout` for 10 minutes after a timeout) on a large Postgres brain](#keyword-search-times-out-on-a-large-postgres-brain) | read doctor's `keyword_plan`; narrow with `--source-id`, or raise `search.keyword_statement_timeout_ms` on the brain host and restart the serving process | brain host | none | `gbrain doctor --only keyword_plan --json` || A second `gbrain serve` cannot open the brain | the readiness `harness_wiring` fix: every session shares one `gbrain serve --http` | user | `persistent_install`, `credentials` | `gbrain doctor --only harness_wiring --json` |diff --git a/test/helpers/held-embedding-fixture.ts b/test/helpers/held-embedding-fixture.tsindex c3f5a70de8..1cc9d963a1 100644--- a/test/helpers/held-embedding-fixture.ts+++ b/test/helpers/held-embedding-fixture.ts@@ -31,7 +31,7 @@ export function startFakeEmbeddings(opts: { dense?: boolean; dims?: number } = {const tokens = opts.dense ? chars : Math.ceil(chars / 4);fake.calls++;fake.tokens += tokens;- const dims = body.dimensions ?? opts.dims ?? 1536;+ const dims = body.dimensions ?? opts.dims ?? 1024;return Response.json({ object: 'list', model: 'fixture-embedder', usage: { prompt_tokens: tokens, total_tokens: tokens },data: inputs.map((_, index) => ({ object: 'embedding', index, embedding: new Array(dims).fill(0.01) })) });},@@ -50,7 +50,7 @@ export function gbrain(brain: HeldBrain, args: string[], env: Record<string, strreturn runCli(args, { home: brain.home, env: { ...brain.env, ...env }, timeoutMs: 120_000 });}-/** A PGLite brain made by `gbrain init` (keyless), then pointed at `model` with 1536 dimensions. */+/** A PGLite brain made by `gbrain init` (keyless), then pointed at `model` at the keyless column's 1024 dimensions, writer management off. */export async function makeHeldBrain(model: string, env: Record<string, string | undefined>): Promise<HeldBrain> {const home = mkdtempSync(join(tmpdir(), 'gb-held-'));const brain: HeldBrain = { home, env: { ...Object.fromEntries(SCRUB.map(k => [k, undefined])), ...env }, cleanup: () => rmSync(home, { recursive: true, force: true }) };@@ -59,7 +59,9 @@ export async function makeHeldBrain(model: string, env: Record<string, string |const path = join(home, '.gbrain', 'config.json');const cfg = JSON.parse(readFileSync(path, 'utf8')) as Record<string, unknown>;delete cfg.embedding_disabled;- writeFileSync(path, JSON.stringify({ ...cfg, embedding_model: model, embedding_dimensions: 1536 }));+ writeFileSync(path, JSON.stringify({ ...cfg, embedding_model: model, embedding_dimensions: 1024 }));+ // Direct writes (seeding sources, pages and holds in-process) need an unmanaged brain; the embed paths under test are the same.+ await withBrain(brain, engine => engine.executeRaw('UPDATE persistence_brain SET enabled=false WHERE singleton=1'));return brain;}