Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
docs(sync): follow-up wave numbers, cache file, G7 correction
garrytan57e271910a11
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 31a49dc883..4db3e3ca54 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,46 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [0.60.118.0] - 2026-10-08++**A managed catch-up starts committing about 4 seconds sooner, and a page you save during it no longer waits on locks the sync never needed.**++On a managed Postgres brain 57 ms from the database, the first page of a catch-up used to land about 19 seconds after `gbrain sync` started; now it lands after about 15.5. A page save during the catch-up stays within a second of its idle time at the slow end, where one run in three on the previous release went over two seconds and lost a write to its wait.++### How to use it++```bash+gbrain sync --source <id> # nothing to change+GBRAIN_PG_TYPE_CACHE_PERSIST=0 gbrain sync # keep described parameter types in this process only+GBRAIN_PG_TYPE_CACHE=0 gbrain sync # no sharing of described parameter types at all+```++### The numbers that matter++Ubicloud 16-core VMs, Postgres behind a 57 ms proxy, 1,500 files with 34 already-deleted files first, default settings, three runs each.++| What you do | v0.60.117.0 | Now |+|---|---|---|+| Time until the first page is committed | 19.0 to 19.6 s | 15.5 to 15.6 s |+| Slowest saves during a catch-up (p95), over the same save with nothing running | +0.5 to +2.3 s, one save failed | +0.5 to +0.8 s, none failed |+| Catch-up speed while your agent saves a page every 5 s | 61 to 65% of idle | 55 to 64% of idle |+| Catch-up pages per minute with nothing else running | 370 to 379 | 370 to 393 |++### Things to watch++- **gbrain now keeps a small cache file per database** under `~/.gbrain/cache/pg-types/`: the parameter types Postgres described for gbrain's statements, so the next command skips asking again. It holds hashes and type numbers only (no SQL text, no credentials), is ignored when the Postgres version or the brain's schema version differs, and is deleted when a migration runs.+- **The first catch-up after an upgrade is slower than the next one.** A statement only the catch-up runs still asks Postgres for its types the first time.+- **The first page still takes 15.5 s, not the 15 s target.** What remains is serial startup reads, screening already-deleted files four at a time, and the first group's own round trips.++### Itemized changes++- Postgres: a pool's `shared_types` takes the Map to share described parameter types in; every pool in a process that reaches one database shares one, and it is saved for the next process, scoped to the server version, the schema version and the database as the server names it.+- Sync: a waiver run screens each entry it froze against that freeze's page read and authority check instead of repeating both, and each freeze reads the page beside its origin check.+- Lanes: claiming a lane group's followers locks only the group's rows, not the write queued after it.+- Lanes: a foreground write another process claimed but has not started publishing holds back new lane groups, as a queued one does; before, groups kept starting ahead of it until that process handed it back.+- Benchmarks: `docs/eval/managed-sync-catchup.md` corrects v0.60.111.0's catch-up-while-saving figure (45%, one low run) to the 57 to 71% every later run of that code measured.+- Driver: `patches/[email protected]` matches the vendored driver again (`bash vendor/update-postgres.sh --check` passes).+## [0.60.117.0] - 2026-10-08**A managed brain no longer calls itself healthy while its sync moves nothing: one consumer per host, a stall the drain can see from the same host, and `gbrain sources writer movement` as the deploy gate.**diff --git a/docs/architecture/key-files/engines-2.md b/docs/architecture/key-files/engines-2.mdindex 02f0f065f3..f5bcd8aee9 100644--- a/docs/architecture/key-files/engines-2.md+++ b/docs/architecture/key-files/engines-2.md@@ -4,6 +4,7 @@Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.- `patches/[email protected]` — auditable delta for the driver ownership and cancellation repair already applied to the shipped `vendor/postgres` ESM/CommonJS/workerd source (not an install hook; `bash vendor/update-postgres.sh --check` verifies it), consumed by `PostgresEngine.runUnsafe` through `#postgres`. Abortable reservations settle atomically; shared transaction queues isolate cancellable SQL from tagged/savepoint siblings while preserving unfenced pipelining. A pooled connection (pool `max` above 1) or a released reservation whose last ReadyForQuery status is not idle is terminated instead of reused, and the `onpoisoned(status)` option reports it (pinned by `test/e2e/postgres-poisoned-connection.test.ts`). See [PostgreSQL cancellation ownership](../postgres-cancellation.md) for settlement, deadline, transport and clean-install invariants. Pinned by `test/e2e/persistence-chaos.test.ts`. The patch also shares each pool's described parameter types across its connections (`shared_types`; `db.resolveSharedTypes()` reads the `GBRAIN_PG_TYPE_CACHE=0` kill switch at the four pool construction sites, `db.clearSharedTypes()` runs after `initSchema` applies migrations), so a first run on another connection, and every run under `prepare: false`, skips the describe round trip; pinned by `test/e2e/postgres-shared-types.test.ts`.+- `src/core/pg-type-cache.ts` — the store `shared_types` uses: one `SharedParameterTypes` Map per database target in this process (`sharedParameterTypes(url)`), keyed by SHA-256 digests of the driver's (types, SQL) key, and saved under `<gbrain home>/cache/pg-types/` (0600) for the next process. `db.checkPoolAndLoadSharedTypes` reads its scope (`server_version_num`, `config.version`, and the database as the server names it, so a proxy and a direct URL share a file) in each new pool's connection check and loads it; a different scope is ignored and replaced, a migration's `clearSharedTypes` deletes the file. `GBRAIN_PG_TYPE_CACHE_PERSIST=0` keeps it in-process. Pinned by `test/pg-type-cache.test.ts` and the new-process case in `test/e2e/postgres-shared-types.test.ts`.- `src/core/engine-sql/` — one SQL implementation per migrated storage domain (the domains are the `migrated` rows of `scripts/engine-sql-baseline.tsv`), run by both engines through one executor contract:diff --git a/docs/eval/managed-sync-catchup.md b/docs/eval/managed-sync-catchup.mdindex 42a7e3cd07..d79a0c69f0 100644--- a/docs/eval/managed-sync-catchup.md+++ b/docs/eval/managed-sync-catchup.md@@ -869,3 +869,43 @@ groups were large (16 pages at ~0 ms) or lanes were many (8+); the admissionwas refused and lanes ran one at a time. The sweep at `4004f1f2f` shows it:8 / 12 / 16 lanes at 88.1 / 69.2 / 56.5 pages/min. Now the batch takes only theroom left after the cursor's next group and a reserve of 10.++## Startup reads, lock scope and a held claim (follow-up wave)++Three runs per head on Ubicloud `standard-16` VMs at 57 ms, default settings,+1,500 files with 34 waived deletions first: master `b5f12b12e` (v0.60.117.0)+against this wave at `d6d9d5956`. G6 and G7 are judged on the mean of three+runs per head from here on, because single runs of the open-loop row spread by+more than the gate's margin.++| Gate | Master | This wave | Target | Result |+|---|---|---|---|---|+| G3 first commit | 19.0 / 19.3 / 19.6 s | 15.6 / 15.6 / 15.5 s | <= 15 s | missed by 0.5 s |+| G6 `put_page` p95 during catch-up, over idle | +0.52 / +0.59 / +2.28 s, 1 failed write | +0.52 / +0.52 / +0.77 s, none failed | <= idle + 1 s | met |+| G7 catch-up while a write arrives every 5 s | 65.1 / 60.9 / 63.4% | 55.4 / 64.4 / 60.1% | >= 50% of idle | met |+| Idle steady pages/min | 374 / 379 / 370 | 392 / 370 / 393 | no regression | held |++**G7 correction.** The v0.60.111.0 row above (45%, from one run) was low+against every later run of the same code: three more runs at `9d013e52d`+measured 60.6, 63.2 and 62.3%, and master has stayed between 57 and 71% since.+G7 is met.++**G3.** Three changes take 3.7 s off the first commit. Described parameter+types are saved for the next process (about 40 fewer describe round trips per+run; a statement only the catch-up runs still describes on its first run, which+is why a brain's second catch-up starts faster than the bench's first). A+waiver run's screen reuses the page snapshot and authority check its freeze+just made instead of repeating them for each entry, and each freeze reads the+page beside its origin check. The remaining 15.5 s is serial: about 4 s of+startup reads, 2.5 s of screening the 34 waived entries four at a time, 1.3 s+for their waiver transaction and about 6 s for the first group.++**G6.** Two lock waits are gone. Claiming a lane group's followers locked up+to 63 rows after the group, including the next foreground write's row, for the+claim's round trips; it now locks only the members (lock-wait samples per run+from about 190 to 84). And a foreground write the writer's own process had+claimed, but could not publish while the sync's lanes held the worktree, did+not hold back new lane heads, so groups kept starting ahead of it until it was+handed back. Master's +2.28 s run (one write not committed within its wait)+fits that case, but its bench output does not name the cause; the forced test+in `test/managed-sync-foreground-priority.test.ts` reproduces the held claim.diff --git a/vendor/README.md b/vendor/README.mdindex a4b55df0d8..d5b4763855 100644--- a/vendor/README.md+++ b/vendor/README.md@@ -47,7 +47,10 @@ parsed, described and executed in one message group. Only built-in types (oidbelow 16384) are shared, since a database's own types (pgvector) can berecreated under a new oid; a statement that fails forgets its shared types, and`PostgresEngine.initSchema` clears them after applying migrations (#5984,-`test/e2e/postgres-shared-types.test.ts`).+`test/e2e/postgres-shared-types.test.ts`). `shared_types` also accepts the Map+to share types in: GBrain passes one per database target, so every pool in a+process that reaches one database shares it, and `src/core/pg-type-cache.ts`+saves it for the next process.## Reproduce and update