Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix: rate limit refreshes a model the sample has not seen; stranded checkout needs the current owner; CHANGELOG and behavior rows (#7083, #7089)
garrytan8a85d30a7a57
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2f3348c142..6e0f70523e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,20 @@ 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.318.0] - 2026-10-19++**On large Postgres brains, autovacuum can finish again, and a page delete's Git commit now reaches the remote.** gbrain refreshed `content_chunks` statistics after every embed drain and import. That ANALYZE waited for the table's lock, and Postgres cancels an autovacuum whenever another session waits on it for a second, so on a brain of about 10M chunks no autovacuum of the table ever finished: millions of dead rows stayed in every index, the vector index included. Separately, on a managed brain with Git durability on, a page delete whose first push failed left its removal commit local-only, while writer status and doctor reported nothing pending. Reported by @DaCal90 (#7083) and @MMichot (#7089).++### What changed++| Situation | Before | Now |+|---|---|---|+| An ANALYZE gbrain runs on Postgres (import, sync, reindex and embed refreshes, the search guard, `gbrain repair planner-stats --apply`, migrations) meets a running vacuum | waited up to 2 s (some migrations with no limit), and Postgres cancelled the autovacuum after 1 s | takes the table's lock with `NOWAIT` and defers at once with a warning; the autovacuum keeps running (the repair reports the table `deferred`) |+| An embed drain that embedded a few chunks of a large, already-sampled `content_chunks` | a 2 to 6 s ANALYZE after every drain | skipped below 50 + 10% of the table's chunks; autovacuum's own analyze covers what small drains add up to, and missing statistics still refresh |+| A hot table of at least 100,000 rows whose autovacuum keeps being cancelled | noticed only from the server log | `gbrain doctor` `planner_stats_stale` warns when its dead rows pass the vacuum threshold and no vacuum has completed in 24 h |+| A page delete on a managed brain whose first push failed | the retry found nothing to commit and completed without pushing; the branch stayed ahead | the retry pushes while the checkout is ahead of its upstream; a push that keeps failing stays queued and then parks, visible in writer status |+| A managed checkout with Git durability on that is ahead of its upstream with no Git effect pending | doctor `git_convergence` warned only after 6 h | warns at once (`stranded`), with `gbrain git commit-push --push-only --keep-checkout --path <root>` as the fix |+## [0.60.317.0] - 2026-10-19**Two CI flakes are closed at their source, and a stuck native safety suite now leaves a log instead of a silent timeout.** `test-reads-source-smell` failed with `ENOENT` when `import-file.test.ts` removed its scratch directory from `test/` mid-walk; scratch now lives in the system temp directory and a lint rule keeps it there. The native data-safety suites no longer wait inside `Bun.spawnSync`, where Bun 1.4.0 to 1.4.2 can poison a process (oven-sh/bun#34069).diff --git a/src/commands/doctor/checks/git-convergence.ts b/src/commands/doctor/checks/git-convergence.tsindex 2b878e98db..ca8500766c 100644--- a/src/commands/doctor/checks/git-convergence.ts+++ b/src/commands/doctor/checks/git-convergence.ts@@ -51,7 +51,8 @@ async function unwatchedDurableRoots(engine: BrainEngine): Promise<Set<string>>const hostId = existingLocalHostId();if (!hostId) return new Set();const bindings = await engine.executeRaw<{ local_path: string; git_durability: 'enabled' | 'disabled' | null }>(- `SELECT h.local_path,h.git_durability FROM persistence_host_bindings h WHERE h.host_id=$1::uuid AND NOT EXISTS (+ `SELECT h.local_path,h.git_durability FROM persistence_host_bindings h JOIN persistence_worktrees w ON w.id=h.worktree_id+ WHERE h.host_id=$1::uuid AND w.owner_host_id=$1::uuid AND w.state='active' AND NOT EXISTS (SELECT 1 FROM persistence_effects e WHERE e.worktree_id=h.worktree_id AND e.kind='git' AND e.state IN ('queued','running','failed'))`,[hostId]).catch(() => []);const roots = new Set<string>();diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 155b310a47..c9fb69ece7 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -974,6 +974,8 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.316.0', text: 'The autopilot daemon dispatches a freshness sync when a checkout\'s HEAD differs from the commit its source last synced, at the next tick instead of after the 5-minute wall-clock interval (which stays as the backstop), once per HEAD and never in the middle of a rebase or merge; classic and managed sources alike. With `sync.on_commit` on, the daemon also reads every checkout\'s HEAD between ticks (every 3 s, git only; `GBRAIN_AUTOPILOT_HEAD_PROBE_MS`) and queues the sync within seconds.' },{ since: '0.60.316.0', text: 'On Postgres, `gbrain jobs work` starts a persistence consumer at boot (#7002), so queued persistence effects drain after a `serve` stops even while the worker is idle. It joins the existing election: with `persistence.single_consumer` on it waits beside a live owner and takes over when that owner stops; with the switch off (the default) a worker beside a `serve` runs its own full consumer, as every resident process already does, and doctor `two_consumers_on_host` lists it. A queued sync job now wakes an idle worker at once: LISTEN on a direct session (one extra connection), a 1 s sync-queue read behind a transaction pooler; `GBRAIN_WORKER_SYNC_WAKE=0` turns it off.' },{ since: '0.60.316.0', text: '`gbrain autopilot --status` grades a running daemon from its own schedule (#7003): the daemon writes `autopilot.heartbeat.json` beside its lock with its next tick, so a healthy daemon on a long adaptive sleep no longer reads `stale` (exit 1); a missing or outdated sidecar falls back to the interval-flag rule. `--status --json` adds `stale_after_source` (`daemon` or `flag`) and `next_tick_at`.' },+ { since: '0.60.318.0', text: 'On Postgres, every ANALYZE gbrain runs on its own (the import, sync, reindex and embed-drain statistics refreshes, the search guard, `gbrain repair planner-stats --apply` and migrations) now takes its table\'s lock with NOWAIT and is deferred with a warning when another session holds the table (a vacuum, an ANALYZE or an index build), instead of waiting on it: waiting on a running autovacuum made Postgres cancel it (#7083). The repair reports such a table `deferred`; rerun it once the vacuum finishes. An embed drain now skips its `content_chunks` statistics refresh when it changed fewer than 50 + 10% of the table\'s sampled chunks and the chunk statistics exist. `gbrain doctor` `planner_stats_stale` also warns when a hot table of at least 100,000 rows holds more dead rows than autovacuum\'s vacuum threshold and no vacuum has completed on it for 24 hours (`details.vacuum_starved`).' },+ { since: '0.60.318.0', text: 'On a managed brain with Git durability on, a Git effect whose file is absent (a page delete) now pushes when the checkout is ahead of its upstream, so a removal commit whose first push failed reaches the remote on the retry instead of the effect completing `target_absent` with nothing pushed (#7089); its outcome reads `target_absent` with `push: committed`, and a push that keeps failing keeps the effect queued and then parks it. `gbrain doctor` `git_convergence` warns at once, instead of after 6 hours, when such a checkout is ahead with no Git effect queued, running or parked (`stranded: true` in `details.roots`), and its fix is `gbrain git commit-push --push-only --keep-checkout --path <root>`.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/search/projection-statistics.ts b/src/core/search/projection-statistics.tsindex 0ee9ab9d1f..6d2deb8e75 100644--- a/src/core/search/projection-statistics.ts+++ b/src/core/search/projection-statistics.ts@@ -107,16 +107,26 @@ async function analyzeChunkColumns(tx: BrainEngine): Promise<boolean> {/*** #7083: whether a drain that changed `changedRows` chunks can leave the chunk statistics alone: content_chunks was- * sampled with rows, its `SEARCH_STATISTICS_COLUMNS` statistics exist, and the drain changed fewer than 50 + 10% of- * its sampled rows (autovacuum's analyze threshold, as `statisticsStillCurrent` for pages). Such a drain barely moves- * them, and autovacuum's own analyze covers what small drains add up to. Without this, every import's embed drain on- * a 10M-chunk table ran a 2-6 s ANALYZE.+ * sampled with rows, its `SEARCH_STATISTICS_COLUMNS` statistics exist, the configured embedding model (the+ * provenance the drain writes to content_chunks.model) is among the sampled common models, and the drain changed fewer+ * than 50 + 10% of the sampled rows (autovacuum's analyze threshold, as `statisticsStillCurrent` for pages). Such a+ * drain barely moves them, and autovacuum's own analyze covers what small drains add up to. A model the sample has+ * never seen (a partial or source-scoped model switch) refreshes, or vector search would estimate one row for it and+ * sort every candidate. An unknown model refreshes too. Without this, every import's embed drain on a 10M-chunk+ * table ran a 2-6 s ANALYZE.*/async function chunkStatisticsStillCurrent(engine: BrainEngine, changedRows: number): Promise<boolean> {if (!Number.isFinite(changedRows)) return false;- const [state] = await engine.executeRaw<{ reltuples: number }>(`SELECT reltuples::float8 AS reltuples FROM pg_class WHERE oid = 'content_chunks'::regclass`);+ let model: string | null = null;+ try { model = (await import('../ai/gateway.ts')).getEmbeddingModelProvenance(); } catch { return false; } // engine-dynamic-import-ok+ if (!model) return false;+ const [state] = await engine.executeRaw<{ reltuples: number; sampled: boolean }>(+ `SELECT c.reltuples::float8 AS reltuples,+ EXISTS (SELECT 1 FROM pg_stats s WHERE s.schemaname = current_schema() AND s.tablename = 'content_chunks' AND s.attname = 'model'+ AND $1 = ANY (s.most_common_vals::text::text[])) AS sampled+ FROM pg_class c WHERE c.oid = 'content_chunks'::regclass`, [model]);const rows = Number(state?.reltuples ?? -1);- if (rows <= 0 || changedRows >= 50 + 0.1 * rows) return false;+ if (rows <= 0 || !state?.sampled || changedRows >= 50 + 0.1 * rows) return false;return !(await missingSearchStatistics(engine)).some(column => column.startsWith('content_chunks.'));}diff --git a/test/e2e/analyze-yields-to-autovacuum-postgres.test.ts b/test/e2e/analyze-yields-to-autovacuum-postgres.test.tsindex 3a0b1573de..e0689989fb 100644--- a/test/e2e/analyze-yields-to-autovacuum-postgres.test.ts+++ b/test/e2e/analyze-yields-to-autovacuum-postgres.test.ts@@ -95,6 +95,18 @@ async function vacuumingPid(): Promise<number | null> {expect(await chunkStatisticsXmin()).not.toBe(sampled);}, 60_000);+ test('a small drain under a model the sample has never seen still refreshes (a partial model switch)', async () => {+ const sampled = await chunkStatisticsXmin();+ configureGateway({ embedding_model: 'openai:text-embedding-3-large', embedding_dimensions: 1536, env: {} });+ try {+ await engine.executeRaw(`UPDATE content_chunks SET model = 'openai:text-embedding-3-large' WHERE page_id <= 10`);+ expect(await refreshChunkStatistics(engine, 10 * CHUNKS_PER_PAGE)).toBe(true);+ expect(await chunkStatisticsXmin()).not.toBe(sampled);+ } finally {+ configureGateway({ embedding_model: 'openai:text-embedding-3-small', embedding_dimensions: 1536, env: {} });+ }+ }, 60_000);+test('doctor reports a hot table whose autovacuum never completes', async () => {await engine.executeRaw(`DELETE FROM content_chunks WHERE chunk_index >= ${CHUNKS_PER_PAGE - 12}`);let starved = await readVacuumStarvation(engine);diff --git a/test/fixtures/goldens/migrations/records.json b/test/fixtures/goldens/migrations/records.jsonindex f1d9bf8ca3..1cab05d215 100644--- a/test/fixtures/goldens/migrations/records.json+++ b/test/fixtures/goldens/migrations/records.json@@ -40,7 +40,7 @@"PLANNER_REPAIR_TABLES": "008725595e099adba279d4292661eb4a59930b777c35db43c340220f7f12e093","TOKEN_TTL_MAX_SECONDS": "f4a45bec6ec0bacc859dc57732ceb76cec7eb72f242b5a6c89d47190d0525ab4","TOKEN_TTL_MIN_SECONDS": "441d8ce6bd21f753de90abd3013eaa9992a469ea60c590f1005533618199aa25",- "analyzeAfterIndexBuild": "d887a794c622b620d7543e6a36b9434d5560451634b3da02716f05c930d7f38d",+ "analyzeAfterIndexBuild": "8d627df6b496e1c197a244f8519aeaf3aebcd23e3f7cf514576d453a4270e33a","analyzeDeferred": "e627ca5e77ce0b79cf5eae7c749a0c9275f04bc186704e3f3a6e05121bb78442","analyzeYieldingToVacuum": "edba1beff1547ea5c2e9f902efe44ab24e8d7016b2253603dcbba92d4137ca9a","backfillChunkVectors": "1c8cc09a28aa3e906fe2f112b71cd3aa61f750a99984e35a029cff9458272aa1",diff --git a/test/persistence-git-removal-push-7089.test.ts b/test/persistence-git-removal-push-7089.test.tsindex 8aa62988c7..dd86391653 100644--- a/test/persistence-git-removal-push-7089.test.ts+++ b/test/persistence-git-removal-push-7089.test.ts@@ -140,6 +140,17 @@ for (const kind of testBackends()) describe(`#7089 removal commits are pushed onexpect(remoteHead(repo)).toBe(head(repo));expect((await gitConvergenceCheck(engine))?.status).toBe('ok');}), 300_000);++ test('doctor git_convergence never calls a checkout stranded on a host that no longer owns it (its binding outlives a transfer)', () => withBrain(kind, async ({ engine, home }) => {+ const repo = await managedRepo(engine, home);+ localCommit(repo);+ expect((await gitConvergenceCheck(engine))?.status).toBe('warn');+ await engine.executeRaw("UPDATE persistence_worktrees SET owner_host_id='00000000-0000-4000-8000-0000000000ff'::uuid");+ const moved = await gitConvergenceCheck(engine);+ expect(moved?.status).toBe('ok');+ expect(moved?.fix).toBeUndefined();+ expect((moved!.details as { roots: Array<{ stranded?: boolean }> }).roots[0]!.stranded).toBeUndefined();+ }), 300_000);});if (testBackends().includes('pglite')) describe('#7089 publishGitEffect on an absent target', () => {