Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge origin/master (a14760075, v0.60.198.0) into capy/mpw2-w3-rerank-gate
garrytan95512c1a6340
diff --cc CHANGELOG.mdindex f2937b190d,c8c2f5c583..4f66012ab6--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,17 -10,29 +10,40 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased] - memory proof wave 2 W3 + W5, confidence-gated reranking and the page-unit ranking cut (#6445)++**A page-unit call with its own budget now gets whole pages that fill that budget instead of many partial ones, and search can grade its candidates before the cross-encoder to report how often the reranker was paying for an answer retrieval already found. The page cut is on by default (`gbrain config set search.page_rank_cut off` restores the old path); the grade is off by default and never changes results.**++### Itemized changes++- `search.reranker.gate` (off by default) grades search candidates before the cross-encoder. `shadow` records how often the reranker was paying for an answer retrieval already found, in the response's `rerank_gate` metadata, on `--explain` and in a new `rerank_gate` section of `gbrain search stats`, and leaves results unchanged. A grade is strong when the top result is a vector match with cosine at least `search.evidence_cosine_floor` and `search.reranker.gate_min_gap` ahead of every other page. There is no skip mode: on the dev sets no question reached the 0.8 floor with voyage-4 embeddings, and the reranker changed about half the delivered tokens, so skipping it is not shipped. The cache key now includes the gate keys and `search.evidence_cosine_floor`.+- `search.page_rank_cut` (default `whole_pages`) lets a `return_unit: "page"` call's own budget decide how many pages delivery gets. Before, ranking cut hits by chunk tokens to the mode's `search.tokenBudget` whatever the caller asked for: under tokenmax delivery was handed far more pages than fit and returned them as slivers, and under a mode cut small pages under-filled the budget. Now `search`, `query` and `recall` lift the mode cut, and delivery keeps ranked pages while their whole delivered size fits `search.page_rank_cut_factor` (default 1.5) × the budget, reporting `delivery.page_rank_cut`. Calls without a budget and other units are unchanged. On 72 BEAM conversations it was non-inferior to the cut off: −0.25 points, lower bound −1.00 against a −3 margin, with delivered context at budget. Those conversations are regression evidence, not a held-out test, and the 1.5 factor was picked under a rule amended after the dev results ([gbrain-evals #126 results](https://github.com/garrytan/gbrain-evals/blob/8b764e3e/docs/benchmarks/2026-10-13-memory-proof-wave-2-results.md)).+- `recall` with `return_unit` and `budget_tokens` fills its budget. Delivery used to be sized to the whole budget, and the facts-first packer then dropped whole delivered blocks. It also re-costed those blocks with a chars/4 estimate while delivery had counted cl100k tokens, so even a call with no facts came back about 7% short. Delivery now gets what the facts leave (except under `query_first`), and delivered blocks cost what delivery counted.+- The brain-ops and query skills and the ambient-recall guide now tell agents to pass the user's question as `recall`'s `question` for question-shaped lookups, so facts come back ranked by relevance (`facts_order: "relevance"`) instead of newest first, and to say so when `facts_degraded` reports keyword-only ranking. The `question` parameter's own description is unchanged.++ ## [0.60.198.0] - 2026-10-13++ **The lock-order race test retries a topology change that ran out of lock wait, as the product tells callers to, so a single lock timeout on a loaded runner no longer fails it (#6586).** `test/e2e/persistence-publish-lock-order-postgres.test.ts` checks that ordinary writes racing claims and topology changes never form a lock-wait cycle and never deadlock. Each topology change runs with the production 1 s `lock_timeout`. When that wait runs out, the change ends `write_pending` with "Retry the same lifecycle request_id after the current writer finishes". The race recorded that as a failure. On #6591's gate-ahead run it did, once: one topology step hit 55P03 on a loaded gate VM with `cycles: []` and `deadlocks: 0`. The rerun on the same head passed, and 60 local runs with four CPU burners passed.++ ### Itemized changes++ - **The race retries a lone timeout and keeps everything else strict.** Each topology step now has a fixed `request_id`. A step that ends `write_pending` right after its own 55P03 is retried with that same `request_id`, up to three attempts. That's what the error tells a caller to do, and it matches how the file already treats writer lock timeouts. The test still requires no lock-wait cycle in its `pg_blocking_pids` sampling, no deadlock in `pg_stat_database`, no write error, and every topology change committed. The retry count appears in the `[lock-order race]` line as `topologyRetries`.+ - **Forced probes (scratch copies, not committed):**+ - A lone lock timeout with no inversion: a separate session holds the `persistence_brain` row for 1.5 s just before one topology step. The old test fails on `write_pending`, plus two `not_found` steps that followed it. The new test passes with `topologyRetries: 1`.+ - A real inversion: two sessions take `persistence_brain` and `sources` in opposite orders during the race. Both the old and the new test fail on it, through the sampled cycle on the old file and `deadlocks: 2` on the new one.+ - With four CPU burners on a 4-CPU machine, the whole file passed 10 of 10 runs on Bun 1.4.3.++ ## [0.60.197.0] - 2026-10-13++ **A fresh Claude Code session wired by `gbrain setup claude-code` now gets its first push, and a declined provider decision stops every provider request, `gbrain doctor`'s included.** The wave 2 Cat 41 setup run (gbrain-evals v0.10.80) found both: the SessionStart hook printed nothing in 3 of 3 fresh sessions because Claude Code starts gbrain's stdio server in parallel with the hook and the server binds its socket about 2 seconds later, and every run's `gbrain doctor` sent an unbilled `GET /v1/models` with the user's key after providers were declined.++ ### Itemized changes++ - **SessionStart waits for the server it needs** (`src/core/context/session-start-pack.ts`, `src/commands/hook.ts`): on a `startup` or `resume` session of Claude Code in a directory covered by this install's `gbrain setup claude-code` receipt, the hook's deadline widens from 1.5 s to 4 s (under the 5 s harness timeout) and the context-pack request retries every 100 ms, re-resolving the socket and secret each round. The hook still never opens the brain, so there is no second PGLite owner and Postgres works the same way; a wait that runs out fails open with `serve_not_ready`. Without a setup receipt nothing changes. With real Claude Code 2.1.285 the fixed hook printed the remembered fact after a 786 ms wait; master printed nothing.+ - **A recorded provider decline holds everywhere** (`src/core/setup/local-receipts.ts`, `src/core/ai/openai-latest.ts`): OpenAI model discovery, which ran on every engine connect whenever `OPENAI_API_KEY` was set, returns before any request when this install's setup receipts record providers as declined (an unreadable record fails closed). `gbrain doctor --probe` skips the embedding probe under a decline.+ - **New doctor check `provider_consent`** (filesystem lane, also in `--fast`): reports a decline as "skipped by consent", names the provider variables present (names only) and gives `gbrain setup <harness> --providers` as the user's choice; `not_applicable` without a setup receipt.+ - **Tests:** `test/hook-session-start-serve-wait.serial.test.ts` (an IPC server bound 800 ms after SessionStart over in-memory PGLite; PGLite, Postgres keying, resume, a project receipt, a server that never comes, and no-wait controls) and `test/doctor-provider-consent.serial.test.ts` (a request counter behind `OPENAI_BASE_URL`: zero requests under a decline for `doctor --json` and `doctor --probe --yes`, 4 of 5 cases fail on master), plus a unit case in `test/openai-latest.serial.test.ts` and the doctor goldens.+## [0.60.196.0] - 2026-10-13### Itemized changesdiff --cc src/core/behavior-change-notice.tsindex 5672b2f22f,673bf29940..277ccf4db2--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@@ -520,11 -520,9 +520,14 @@@ export const BEHAVIOR_CHANGES: Readonly{ since: '0.60.190.0', text: 'Pools count reconnects of connections retired after an incident (stuck, desynced, or closed under running statements): `recovered` and `recovery_failed` in `/health?deep=1` and `getPoolDiagnostics()`, and a failed reconnect logs `pg_connection_recovery_failed`. `gbrain serve` writes its stuck, desync and recovery events to the pool-recovery audit, so `gbrain doctor --only pool_reap_health` now fails on a recovery failure and warns on a stuck or desynced connection in the last hour.' },// #6554 (GBRA-60 D8). `since` is provisional (current VERSION); the integrator restamps it at the merge slot.{ since: '0.60.191.0', text: '`gbrain bootstrap harness` now wires the Codex SessionEnd transcript-capture hook (its `hooks.json` group and `config.toml` trust entry) only when capture is on: turning capture off with its no-capture flag skips it, and registrar mode (a non-loopback `--url`) skips it like every other hook, because the hook talks to the local brain rather than the registered remote serve. The consent block names the hook when it is wired. A hook an earlier run installed stays until `gbrain bootstrap harness --remove`. New: `gbrain setup codex` wires Codex MCP and read-context hooks with hash-owned entries.' },+ // Cat 41 wave 2 findings (GBRA-60). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.+ { since: '0.60.197.0', text: 'In a fresh Claude Code session wired by `gbrain setup claude-code` (SessionStart source `startup` or `resume`), the SessionStart hook now waits up to 4 seconds for the stdio `gbrain serve` Claude Code is starting, then prints its context pack (recent world-visible facts). Before, it gave up at once and the session got no pack. Sessions without a setup receipt, and `clear`/`compact` sessions, do not wait; a serve that never answers ends the wait fail-open with heartbeat reason `serve_not_ready`.' },+ { since: '0.60.197.0', text: 'When `gbrain setup` recorded provider use as declined, gbrain no longer sends the OpenAI model-discovery request (`GET /v1/models`) on engine connect even if `OPENAI_API_KEY` is set, and `gbrain doctor --probe` skips the embedding probe. Doctor gains `provider_consent`, which reports the recorded decision; a decline shows as skipped by consent with the user-run fix `gbrain setup <harness> --providers`.' },+ // W3 confidence-gated reranking (memory proof wave 2). `since` is a placeholder equal to the branch's VERSION until the merge-slot stamp.- { since: '0.60.196.0', text: '`gbrain search stats --json` and the `search_stats` tool now always include a `rerank_gate` section, all zeros until you set `search.reranker.gate` to `shadow`; search results and ranking are unchanged. The search cache key now includes `search.evidence_cosine_floor` and the new gate keys (the result cache stays disabled).' },- { since: '0.60.196.0', text: '`recall` with `budget_tokens` and a `return_unit` now fills its budget: saved facts are packed first and the delivered evidence gets the budget they leave, so the same parameters return more evidence (up to about 16% more on long conversations). Before, delivered blocks were dropped after the facts and re-counted with a rougher estimate. `budget_policy: "query_first"` is unchanged.' },++ { since: '0.60.198.0', text: '`gbrain search stats --json` and the `search_stats` tool now always include a `rerank_gate` section, all zeros until you set `search.reranker.gate` to `shadow`; search results and ranking are unchanged. The search cache key now includes `search.evidence_cosine_floor` and the new gate keys (the result cache stays disabled).' },++ { since: '0.60.198.0', text: '`recall` with `budget_tokens` and a `return_unit` now fills its budget: saved facts are packed first and the delivered evidence gets the budget they leave, so the same parameters return more evidence (up to about 16% more on long conversations). Before, delivered blocks were dropped after the facts and re-counted with a rougher estimate. `budget_policy: "query_first"` is unchanged.' },+ // W5 adaptive page-unit cut, default on after memory proof wave 2 (gbrain-evals #126). `since` is the VERSION placeholder.- { since: '0.60.196.0', text: 'A `return_unit: "page"` call that passes its own budget (`token_budget` on `search` and `query`, `budget_tokens` on `recall`) now stops adding pages once their whole delivered pages fill 1.5 times that budget (`search.page_rank_cut: whole_pages`, `search.page_rank_cut_factor: 1.5`), and the search mode\'s chunk-token cut no longer limits it: you get fewer pages, more of them whole, filling the budget, instead of many partial ones. On 72 BEAM conversations (regression evidence, not held-out) accuracy moved -0.25 points against the cut off (lower bound -1.00, non-inferior at the -3 margin) with delivered context at budget. The response reports it as `delivery.page_rank_cut`. `gbrain config set search.page_rank_cut off` restores the old behavior.' },++ { since: '0.60.198.0', text: 'A `return_unit: "page"` call that passes its own budget (`token_budget` on `search` and `query`, `budget_tokens` on `recall`) now stops adding pages once their whole delivered pages fill 1.5 times that budget (`search.page_rank_cut: whole_pages`, `search.page_rank_cut_factor: 1.5`), and the search mode\'s chunk-token cut no longer limits it: you get fewer pages, more of them whole, filling the budget, instead of many partial ones. On 72 BEAM conversations (regression evidence, not held-out) accuracy moved -0.25 points against the cut off (lower bound -1.00, non-inferior at the -3 margin) with delivered context at budget. The response reports it as `delivery.page_rank_cut`. `gbrain config set search.page_rank_cut off` restores the old behavior.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */