Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/master' into capy/v0601310-fixsearch-scoped-vector
garrytanc12e14adf9ce
diff --cc CHANGELOG.mdindex 4232f533b9,29826a0c9c..63b9fee6c9--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,41 -10,26 +10,61 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.134.0] - 2026-10-09++**Scoped vector search that reaches the candidate pool finds its true nearest pages, and a freshly imported brain keeps its vector index plan. Unscoped search returns the same results.**++A vector search under a visibility scope, a type or date filter, or a source too large for the exact scope scan ends in the bounded candidate pool. Its first attempt visited at most 2,000 index entries and was accepted as soon as the eligible chunks it found covered the requested pages. Under a 10% scope that was about 200 chunks, which was enough to be accepted but too few to hold the true neighbours. Every pooled attempt now visits up to 20,000, pgvector's own default. Separately, import, sync, reindex and embed drains refreshed only two page columns' planner statistics, so on a freshly loaded large brain the vector statement sorted every eligible chunk instead of walking the HNSW index until autovacuum ran. They now analyze `content_chunks(model, modality, page_id)` and the page columns search filters read.++### What you'd see++16 vCPU host, Postgres 16 + pgvector 0.8.7, 1,024-dim vectors, 100 queries, `limit 50`, recall of result pages against the exact statement, measured on top of 0.60.131.0's exact scope scan:++| corpus and scope | recall@50 before | after | p50 cost |+|---|---|---|---|+| 1M voyage-4 Wikipedia chunks, random 10% visibility scope | 0.767 | 0.969 | +25 ms |+| same, topic-coherent 50% source | 0.870 | 0.954 | none |+| same, topic-coherent 10% source (104,000 chunks) | 0.655 | 0.758 | +36 ms |+| 1M synthetic chunks, random 10% visibility scope | 0.615 | 0.984 | +18 ms |+| 1M synthetic chunks, 10% source + type filter | 0.601 | 0.979 | +18 ms |+| 352k synthetic chunks, 30% source | 0.860 | 0.985 | +14 ms |+| unscoped, and sources the exact scope scan covers | unchanged | unchanged | none |++On a freshly imported 1M to 2M chunk brain, scoped searches took 0.5 to 8 s, and up to half of the broad ones fell back to keyword only. After the import's own refresh they plan on the HNSW index at 8 to 75 ms p50 with no incomplete results.++### What to watch for++- Searches that reach the pool visit more index entries: about 15 to 35 ms more p50 on 1M to 2M chunks. A source of 4% to 30% of pages that is too large for the exact scan still answers from the share-scaled walk, at recall@50 about 0.82 for a 10% source of 1M chunks; this release does not change that path.+- An embed drain or import now ends with an ANALYZE of a few columns, bounded by a 30 s statement timeout and a 2 s lock timeout. When the lock is held (for example by an index build), the refresh is skipped with a warning that names the command to run.++### Itemized changes++- **Pooled scan budget (`src/core/search/vector-pool.ts`).** `POOL_MAX_SCAN_TUPLES` (20,000) for every pooled and exact-fallback attempt. The index walk and the scope scan keep their window-sized budget.+- **Planner statistics (`src/core/search/projection-statistics.ts`, `src/commands/embed.ts`).** On Postgres, `refreshProjectionStatistics` analyzes `pages(text_projection_revision, knowledge_revision, deleted_at, source_id, type, slug)`, then `content_chunks(model, modality, page_id)` behind a savepoint. `refreshChunkStatistics` runs the chunk step once at the end of an embed drain that embedded something.+- **Bench (`scripts/bench/hnsw-iterative-scan.ts`).** Synthetic-latent corpora (`--corpus latent`), prepared real-text corpora embedded with voyage-4 (`--corpus dir`, `scripts/bench/hnsw-real-corpus-prep.py`), `ef_search` and `max_scan_tuples` sweeps, share buckets (`--source-shares`), statistics states with EXPLAIN capture, and an index build grid. The method and every table are in `docs/eval/hnsw-scale-bench.md`.+- **Docs.** `docs/ENGINES.md` sizes `maintenance_work_mem` for the deferred ANN build. It records `halfvec` (a third of the index size, same recall) and `ef_construction` 128 (+0.02 to 0.03 unscoped recall@10) as measured candidates, not shipped.+- **CI.** Nightly shard-weight refresh (`scripts/{test,serial,e2e}-weights.json`).++ ## [0.60.133.0] - 2026-10-09++ **A page with ` ```lua ` fences no longer stalls the writer: the Lua grammar is replaced, Lua definitions become semantic chunks for the first time, and only Lua files re-chunk on upgrade.**++ GBRA-49's LongMemEval scoreboard found `gbrain serve --surface starter` on PGLite at 99.5% CPU for 9.5 hours after a `put_page` had been admitted, never reading stdin again, with `[persistence] phase=preparation reason=deadline_exceeded` repeating (376 times) and 47 later writes queued behind it. The page was an exported chat whose assistant turns wrapped shell commands in ChatGPT-style ` ```lua ` fences (`sudo aa-status`, `sudo aa-status | grep snap.discord.discord`). The vendored Lua grammar (the `tree-sitter-wasms` build of the unmaintained Azganoth/tree-sitter-lua 2.1.3) allocated its external scanner state with `malloc` and reset it only when `deserialize` was handed two bytes, so every parse after the first in a process started from whatever the recycled heap held: `x = 1` misparsed as an error, and the fence texts spun inside the parser until the chunker's 30 s timeout. Five fences made each preparation attempt about 150 s of blocked event loop (a CPU profile puts about 80% in the runtime's parse loop driven by the scanner), past its 30 s deadline, so the consumer abandoned and retried it. On 0.60.106.0 that loop never ended; since #6278 (`persistence.max_preparation_attempts`, default 2) the request fails `preparation_stalled` after two attempts, which still costs five minutes of unresponsive serve and loses the write. Reproduced on current master before the fix. Independently, no Lua definition had ever become a semantic chunk, because the old grammar's node types never matched `TOP_LEVEL_TYPES.lua`.++ ### What you see++ | Where | What changed |+ |---|---|+ | A page or file with Lua fences or `.lua` code | Chunks in milliseconds, on every parse, with `function`, `local function` and `function M.f()` definitions as named semantic chunks (`code-def` / `code-callers` work for Lua). |+ | `gbrain serve` writing such a page | The write commits as any other; no preparation deadline, no retry loop, stdin keeps being read. |+ | Existing indexes, on the next sync | Each source is walked once (hash compare) and only its `.lua` files re-import, re-chunk and re-embed; every other code page keeps its hash and its chunks. `CHUNKER_VERSION` stays 8. The sync cost gate prices the walk by the Lua files alone (`grammar_drift`), not the whole tree. Lua fences inside Markdown pages already indexed stay text chunks until the page changes or `gbrain sync --source <id> --full`. |++ ### Itemized changes++ - `src/assets/wasm/grammars/tree-sitter-lua.wasm`: the official tree-sitter-grammars/tree-sitter-lua v0.3.0 release asset (ABI 14, the newest the pinned `[email protected]` accepts; v0.4.0+ are ABI 15), SHA-256 `8fe0afe3…ee0d`; `scripts/vendor-lua-wasm.sh` downloads it and checks the checksum before writing; provenance in `src/assets/wasm/README.md`.+ - `src/core/chunkers/code.ts`: `GRAMMAR_REVISIONS` (`{ lua: 1 }`) and `chunkerStamp()` (`8;lua=1`). `import-file.ts` folds a language's grammar revision into that language's code-file hash only. The `sources.chunker_version` gate (`sync/preflight.ts`, `sync/full.ts`, `sync/finalize.ts`, `persistence/sync-prepare.ts`, the doctor's extraction check) reads and writes the stamp. `sync-cost-gate.ts`: `grammarOnlyDrift` and a per-language estimate for a stamp whose version is unchanged.+ - Tests: `test/chunkers/code-lua.test.ts` (ABI and import check; forced probes: the same text parses identically on every parser instance, the stuck page's five fences chunk in under a second with a 1.5 s per-fence timeout pinned, a conversation page with them prepares in one pass, Lua definitions become named chunks; all five fail on the previous grammar; the stamp, `grammarOnlyDrift`, and the cost gate pricing a grammar drift by Lua files alone). End to end on a fresh keyless PGLite brain, `gbrain put` of the stuck page: 1.8 s committed (previous grammar on current master: the CLI's wait ran out after 92 s with the request still `queued` and `deadline_exceeded` on stderr).+## [0.60.132.0] - 2026-10-09**Sync holds clear themselves. gbrain merges repeated fact tables, closes tables that were never ended, and removes stray `slug:` lines on its own; a repair model decides the cases that need judgment; a person is asked only when gbrain says so, in plain words, with the one command that applies what it proposes.**