Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge commit 'fb785e9a18ac49b4245ff9460ce20fc0e6dc7841' into gateahead-7217
garrytanb2b6503390df
diff --cc CHANGELOG.mdindex 7c9210d681,aef543079f..3f6de30bd5--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,35 -10,33 +10,62 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased]++**A timeline entry no longer rewrites the passages it didn't change, and a big passage replacement can't time out the write that carries it (#7172).** A managed write replaced its page's passages inside its publication, under the publication's 5 s statement bound. A passage whose index moved (a long entry near the top of a descending timeline adds a passage above the others) was deleted and inserted again with its vector, and on a large index each inserted row can cost about half a second, so the write ended `write_interrupted` (SQLSTATE 57014) on every attempt. Separately, a page whose stored embedding signature was missing or in an older format had every passage re-embedded after each write, which looked the same from outside: every passage got a new embedding time.++### What changed++| Situation | Before | Now |+|---|---|---|+| An entry shifts unchanged passages to new indexes | each moved passage deleted and re-inserted (vector copied) | the row keeps its id and vector and changes index in place |+| A managed put_page, edit_page, add_timeline_entry, tag write, import or sync whose passages need more than 5 vector-index writes (a passage that carries a vector, inserted or renumbered) | all of them in one statement inside the publication; on a slow index, 57014 on every attempt, then `write_interrupted` | the page commits first; its passages finish in post-commit transactions of at most 5 vector-index writes each, then the projection is sealed. Passages without a vector (new text, a new page) are still written in the publication, as before |+| Search during those steps | n/a | the page's passages are hidden until the seal (as for any pending projection); the receipt says `searchable: "pending"` and turns `true` when sealed |+| The embedding step after a write, page signature missing or older format | every passage re-embedded (paid) | passages whose recorded embedding input is current keep their vectors; the page signature is restamped |++The bound of 5 is derived in `src/core/page-state/chunk-moves.ts` (`CHUNK_VECTOR_WRITE_BUDGET`): a row version that carries a vector adds an HNSW entry, a graph search over the whole index that nothing amortizes across rows, while one without a vector adds no HNSW entry and only cheap b-tree and GIN pending-list entries (measured on pgvector: 300 passages inserted in 2.2 s with vectors and 0.06 s without; 300 renumbered in about 1 s with vectors and 0.002 s without). The slowest reported rate on a large index is about 0.5 s per vector-carrying row, and half of the 5 s statement bound is left for the rest of the write. No timeout, retry or deadline is raised, and nothing is configurable.++### What to watch for after you upgrade++- A write that was blocked by repeated `write_interrupted` (57014) on a large page can be submitted again; it commits and finishes its passages right after.+- If a page's receipt stays `searchable: "pending"` for more than a minute, no process is finishing it: run `gbrain projections drain`.+- When a top entry changes the text of every passage below it (the chunker packs about 300 words with a 50-word overlap, so a short entry can shift every boundary), those passages are new text and are embedded again; this release does not change the chunker.++### Itemized changes++- `reuseStoredChunkVectors` matches a stored row by source and text at any index (its own index first), so a kept row can move.+- New `src/core/page-state/chunk-moves.ts`: the vector-index write bound and the move planner (one UPDATE per wave; a cycle parks one row at a negative index).+- `continueDeferredProjection` runs the bounded steps after commit, holding the page's queue row under a claim it renews each step (the lease a segmented projection claim uses); the projection drain resumes a page whose steps stopped (queue reason `chunk_replacement_deferred`). A group publication now runs its members' post-commit work, as a single publication does.+- Writes that wrap a page publication in their own (takes, the facts fence, maintenance pages) still replace passages in one transaction.+- `readEmbeddingEffectProjection` accepts a vector whose recorded input hash is one the current page accepts, whatever the page-level signature says, and restamps the page.++ ## [0.60.344.0] - 2026-10-21++ **A managed brain on remote Postgres syncs a no-op commit in about half the time, sync work no longer stalls searches running beside it, sync status grades a commit that is still waiting, and an aborted sync returns at once.** A no-op `gbrain sync` used to pay 70 to 90 dependent round trips, more on a bigger brain. It now pays about 32 at any brain size: at 57 ms RTT, p50 drops from 5.9 s to 3.3 s on a direct connection and from 6.1 s to 2.9 s behind PgBouncer. A single-file commit behind PgBouncer goes from 400 round trips to 282. On Postgres, no part of a sync holds a concurrent search past 100 ms anymore.++ ### What changed++ | Situation | Before | Now |+ |---|---|---|+ | A transaction behind a transaction-mode pooler (PgBouncer, Supabase 6543, `prepare=false`) | one round trip per statement | the statements of one transaction are pipelined on the connection the pooler pins for it; autocommit statements never are, and nothing is sent after COMMIT. `GBRAIN_PG_TXN_PIPELINE=0` turns it off |+ | Postgres array-type lookup | a `pg_type` fetch on every connection of every pool | one per process (`GBRAIN_PG_TYPE_CACHE=0` turns it off) |+ | An idle sync tick | ran all six post-sync checks | skips each check whose pin found no work for it (`GBRAIN_SYNC_IDLE_FAST_PATH=0` turns the skips off) |+ | The ghost-page report | read every page batch on each sync | is answered from `op_checkpoints` and rescanned in the background at most every 5 minutes (`GBRAIN_SYNC_GHOST_INTERVAL_MS`) |+ | Link and timeline extraction at the end of a sync | two tree walks, and on PGLite every page in one event-loop turn | one walk, yielding after each page |+ | A first sync, a confirm round or a dirtiness probe on 10k pages | stretches of 0.9 to 1.4 s that held every concurrent search | the loops yield |+ | PGLite after a small sync | a full ANALYZE every time | ANALYZE only when the tables really grew |+ | Doctor `managed_sync_latency` with a commit still waiting | `ok` until the commit synced | grades the waiting commit, dated from the reflog, and reports keyword and embedding freshness separately |+ | `gbrain sources mirror-readonly` / `mirror-writable --dry-run` (#7086) | wrote the flag | prints the change under a dry-run banner and writes nothing |+ | A SIGTERM to stdio `gbrain serve` on Postgres | the commit-notifier lease stayed live for about 20 s | the next resident owns it in 0.5 s |+ | An aborted sync waiting on its accepted write | waited out the 5 s write wait | returns within 1.5 s; work accepted and committed is kept, and a write blocked by another owner stays queued |+ | A Postgres socket that died after an error while a statement was queued | the statement could wait on the replacement socket until the drain gave up (331 s seen) | every queued statement is rejected with `CONNECTION_CLOSED`, so the retry runs at once |++ ### For contributors++ - `test/helpers/cpu-time.ts` measures loop lag in the thread's own CPU time, so a loaded CI VM no longer counts its run-queue waits as a held loop. The 100 ms bounds are unchanged.+ - `src/core/sync-idle-skips.ts` defines each idle-tick skip once, and a coverage test seeds a state that makes each skipped check run.+ - `test/postgres-driver-startup-death.test.ts` reproduces the stranded statement against a scripted server.+## [0.60.343.0] - 2026-10-21**An opt-in warm CLI socket lets `gbrain search`, `query`, `get` and `recall` skip most of a cold start's database round trips.** A cold CLI process connects, loads config and resolves its source before it can answer. Behind a transaction-mode pooler at 40 ms RTT, that cost a 305k-page brain about 3.4 s per search. With `gbrain serve --cli-socket` running, the same CLI call goes through a local Unix socket to the running serve and returns byte-identical output: 2.3 s for that search and 0.66 s for a get, against 1.19 s cold. It is off by default.diff --cc src/core/behavior-change-notice.tsindex 2b10469f06,c860518a7a..5ea6fe6e9d--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@@ -1058,9 -1058,10 +1058,13 @@@ export const BEHAVIOR_CHANGES: Readonly{ since: '0.60.341.0', text: 'Nothing derived from a private page is stored wider than the page. Facts extracted from a `visibility: private` page are private even when `facts.default_visibility` is world (before, a fact with no fence page was then returned to remote callers by recall and the entity card), and a page marked private only by `access: private|restricted|confidential` or `confidentiality: confidential|secret|private|restricted` counts as private for its facts, chronicle events, timeline rows and remember saves. `remember` without a `visibility` now saves private when its target page is private or `facts.default_visibility` is explicitly private; otherwise the default stays world. Google Calendar events marked private or confidential sync as `visibility: private` pages, and a connector re-render keeps a page\'s private label. Remote page reads honor the privacy aliases only after `gbrain config set visibility.honor_aliases true`.' },{ since: '0.60.341.0', text: 'Doctor `derived_visibility` also reports pages that carry a privacy alias but no `visibility`, chronicle events of a private origin, and world facts held in or extracted from a private page (fact ids a remote caller can read today are listed). `gbrain repair visibility` previews all of them and, with `--apply` only, makes them private; nothing runs on upgrade.' },{ since: '0.60.343.0', text: 'New opt-in warm CLI socket for Postgres brains, off by default: `gbrain serve --cli-socket` (or `gbrain config set serve.cli_socket true`) lets that serve answer this user\'s CLI `search`, `query`, `get` and op-backed `recall` (`--query`, `--budget-tokens`, `--question`, `--budget-policy`) over a private Unix socket in `$GBRAIN_HOME/.gbrain/run/` (directory 0700, socket 0600, peer uid checked by the kernel on every connection, never TCP), so those calls skip a cold database connection. Only the host brain is served (a serve on a mount brain never opens the socket), and only when the CLI\'s identity (database target, config home and file, gbrain version, every `GBRAIN_*` setting but the socket, debug and SQL-trace switches and `GBRAIN_SOURCE` (sent with each call), which provider keys are set, and the provider base URLs, endpoints, deployments and ids) matches the serve\'s; otherwise, and whenever the socket is missing, stale or busy, the answer is malformed, or it takes over 30 s (or the call\'s shorter `--timeout`), the CLI takes its usual path. Without the option nothing listens. Guide: docs/guides/cli-socket.md.' },+ // GBRA-133 PR 2b (Postgres round trips #6930, the idle fast path, truthful status, #7086). `since` is stamped at the merge slot.+ { since: '0.60.344.0', text: 'On a transaction-mode pooler URL (PgBouncer or Supabase port 6543, `prepare=false`, or `GBRAIN_PREPARE=false`), gbrain now pipelines the statements of one transaction on the server connection the pooler pins for it, instead of waiting one round trip per statement, so a sync or write over a slow link finishes in fewer round trips. It still never sends a statement behind one that may end the transaction (COMMIT, ROLLBACK, END, ABORT, PREPARE TRANSACTION), never pipelines autocommit statements on such a URL, and keeps prepared statements off, so the pooler cannot hand a statement to another client\'s connection. Set `GBRAIN_PG_TXN_PIPELINE=0` to send one statement per round trip again.' },+ { since: '0.60.344.0', text: 'Doctor `managed_sync_latency` now grades the commit that is still waiting, not only commits that already synced: with `sync.on_commit` on or `sync.freshness_target_seconds` set, a source whose checkout HEAD has waited past the target (default 300 s) warns and past one hour fails, dated from the reflog entry that moved HEAD or the notifier\'s recorded first_due_at, and a waiting commit it cannot date (no reflog, rewritten history) warns as unknown. It grades classic sources the same way and reports keyword-visible and embedded freshness per source (`details.freshness_by_source`). `gbrain sources status` compares HEAD only (an uncommitted edit is no longer lag) and dates a behind source\'s lag from when the commit landed instead of from the last no-op sync.' },+ { since: '0.60.344.0', text: '`gbrain sources mirror-readonly <id> --dry-run` and `gbrain sources mirror-writable <id> --dry-run` now print the change they would make with a `(dry-run; no side effects)` banner and write nothing (#7086); before, both ignored `--dry-run` and set or cleared the read-only mirror flag.' },+ // #7172. `since` is restamped at the merge slot.+ { since: 'TBD', text: 'A managed put_page, edit_page, add_timeline_entry, add_tag or remove_tag, managed import or sync whose passages need more than 5 vector-index writes (a passage carrying a vector, inserted or renumbered) commits the page first and finishes its passages in post-commit transactions of at most 5 vector-index writes each, instead of writing them all inside the publication, where a slow index could end it 57014 `write_interrupted`. Search sees the page once the last step seals it; until then its receipt says `searchable: "pending"`, and `gbrain projections drain` finishes a page whose writer stopped. A passage whose text is unchanged keeps its row and vector when an entry above it moves it to another index.' },+ { since: 'TBD', text: 'The embedding step after a managed write no longer re-embeds every passage of a page whose stored embedding signature is missing or in an older format: a passage whose recorded embedding input is still current keeps its vector and the page signature is restamped, so only passages whose text changed reach the embedding provider.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */