Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Merge commit '520df8a6d6b8be5eef2d69509397149824d45261' into gate-ahead/6923

garrytan5210d783bfca
diff --cc CHANGELOG.md
index 0311e864cc,8b8e8cd25c..e791ec2488
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -10,29 -10,31 +10,54 @@@ credits are retained; no result has bee
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased] - 2026-10-17
+
+**A brain that lost its `query_cache` table can finish its nightly purge again.** On a brain where `query_cache` was missing although the schema was at head, every coordinated page purge failed with `42P01`, so the dream cycle's purge phase failed every night with `managed_purge_failed` and the tombstone was never purged (#6911). `apply-migrations` and `db-repair` both reported healthy, because the schema version said the table's migration had run.
+
+### What changed
+
+| Situation | Before | Now |
+|---|---|---|
+| Page purge with `query_cache` missing | failed with `42P01` every time (`managed_purge_failed`) | commits; the receipt lists `purge.missing_caches` and shows `query_cache` as `not_present` with reason `table_missing` |
+| Fact purge with `query_cache` missing | failed with `42P01` | commits; the store report shows `query_cache` as `not_present` with reason `table_missing` |
+| Purge with a missing table that holds user data | failed | still fails, because the purge cannot say it removed rows it could not reach |
+| `gbrain doctor` with a missing table | nothing flagged it | `schema_missing_tables`: warn for a rebuildable cache or a table without user data, fail for a user-data table; below head it checks the rebuildable caches, whose absence would wedge `apply-migrations` |
+| Getting the cache back | run the old migration handler by hand | `gbrain repair missing-tables` previews, then `--apply --expect <hash>` recreates it empty in the shape a fully migrated brain has |
+| `gbrain forget --purge --vacuum` on PGLite with the cache missing | the VACUUM failed silently, so nothing was vacuumed | the other tables are vacuumed, and the receipt says whether VACUUM ran or failed |
+
+### What you need to do
+
+Nothing, unless doctor reports `schema_missing_tables`. Then ask your agent: *"Doctor says query_cache is missing. Fix it."* It runs `gbrain repair missing-tables`, shows you the preview, and applies it after you agree. The repair runs only when named; nothing changes on upgrade.
+
+If your nightly purge failed on the missing cache for a while, some deleted pages were parked after five failures and stay unpurged. Doctor `purge_parked_pages` lists them; preview with `gbrain pages purge-deleted --retry-parked --dry-run`, then run it without `--dry-run` after you agree.
+
+If doctor fails `schema_missing_tables` on a table that holds user data, restore that table's rows from a backup **before** you run `gbrain upgrade`, `apply-migrations` or `init --migrate-only`: they recreate a base-schema table empty, which clears the check while the rows stay lost.
+
+ ## [0.60.290.0] - 2026-10-17
+
+ **Every part of gbrain can now read, protect, forget and export pages stored in segments, so large-page storage is ready to turn on in a later release.** Segmented storage (`pages.segmented_storage`) stays off by default, and with it off nothing changes for your brain: pages over 1 MiB are still stored inline up to 24 MiB. This release adds the read side and the safety work that has to exist before the switch can be turned on: reads, row-level security, forget and purge, delete and restore, export and backup, and the derived passes all handle segmented pages. A writer gate keeps the switch off while any recent writer can't read segments.
+
+ ### What changed
+
+ | Area | With segmented storage on | With it off (the default) |
+ |---|---|---|
+ | Reads (`get_page`, `fetch`, `entity`, evidence, `gbrain get`) | read segmented pages in windows, with withdrawn facts, fences and credentials applied; `body: 'full'` refuses and points at `body: 'auto'` | unchanged |
+ | Privacy | row-level security on the six segment tables; `docs/ENGINES.md` has a source-scoped policy recipe | search, `get_page`, `put_page`, `remember`, sync and embedding need no segment-table grant |
+ | `forget` and `purge_fact` | work at any page size and never delete text an in-flight write still holds | unchanged |
+ | Delete and restore | lossless up to `pages.max_bytes` on file-backed sources | unchanged |
+ | Export and backup | segmented pages export byte-identical to inline pages; PGLite backups restore them | unchanged |
+ | Derived passes (links, timeline, takes, facts, tags, dedup, sweep, stale extraction) | read segmented pages in blocks; a page the sweep can't fit in its budget is deferred | unchanged |
+ | Search | a new page up to 4 MiB is searchable when the write returns; a larger one reports `searchable: "pending"` | unchanged |
+ | Tag, timeline, takes and facts writes | `add_tag`/`remove_tag` work at any size; the others work up to 24 MiB and refuse above it, naming the limit | unchanged |
+ | `gbrain doctor` | seven whole-body checks report `skipped_segmented: N`; `segmented_storage` reports the writer gate | `segmented_storage` reports the switch as off |
+ | Ceilings | 256 MiB on Postgres, 128 MiB on PGLite | 24 MiB |
+
+ Migrations v252–v256 add a segment-text GC index, `page_view_digests`, segment-reader marks on write requests, consumers and `ingest_log`, `page_body_staging_texts`, and a chunk retirement index. On Postgres the indexes build `CONCURRENTLY`.
+
+ ### What you need to do
+
+ Nothing. Leave `pages.segmented_storage` unset. `gbrain doctor` shows the switch's state, and the release that turns it on will say so in its notes.
+
## [0.60.289.0] - 2026-10-17
**The unit test matrix runs 10 shards instead of 8, so one slow CI runner no longer turns master red.** Master run 39030803745 lost `test (2)` to the 22-minute job timeout. The tests were fine: CPU steal on that runner was 2–3x the usual and every file ran about 1.5x slower. At 8 shards each shard carried about 908s of measured test time, so a normal job took about 16.5 minutes and a 1.5x slower runner overran the timeout. At 10 shards each carries about 727s.
diff --cc src/core/facts/purge-verify.ts
index 03d132c304,7ac228863d..5c96ef2bc1
--- a/src/core/facts/purge-verify.ts
+++ b/src/core/facts/purge-verify.ts
@@@ -26,9 -26,10 +26,11 @@@ import type { WriteRequest } from '../p
import { DELETION_INVENTORY, OUT_OF_REACH_RESIDUALS, type InventoryEntry } from '../deletion-inventory.ts';
import type { PurgePlan, PurgeTarget } from './purge.ts';
import { gitChildEnv } from '../git-env.ts';
+ import { segmentedBodyContains } from '../page-body/segment-rewrite.ts';
+ import { stagingNeedsTextSql } from '../page-body/schema.ts';
import { claimForms, quotes, type LedgerPurgeReport } from '../belief/purge.ts';
import { CARRYING_FIELDS } from '../belief/keys.ts';
+import { relationExists } from '../persistence/rebuildable-cache.ts';
export type StoreCount = Record<string, number>;
export type StoreStatus = 'deleted' | 'would_remove' | 'retained_inactive' | 'unverified' | 'out_of_reach' | 'out_of_scope' | 'not_present' | 'incomplete';
@@@ -475,8 -509,13 +519,14 @@@ export async function verifyPagePurge(e
await keyed('slug_aliases', 'SELECT 1 FROM slug_aliases WHERE source_id=$1 AND canonical_slug=$2', [src, slug]);
await keyed('files', 'SELECT 1 FROM files WHERE page_slug=$2 AND (source_id=$1 OR source_id IS NULL)', [src, slug]);
await keyed('write_gate_holds', 'SELECT 1 FROM write_gate_holds WHERE source_id=$1 AND slug=$2', [src, slug]);
- await keyed('query_cache', 'SELECT 1 FROM query_cache WHERE $1::text IS NOT NULL', [src]);
+ if (!await relationExists(engine, 'query_cache')) stores.push(missingCache('query_cache'));
+ else await keyed('query_cache', 'SELECT 1 FROM query_cache WHERE $1::text IS NOT NULL', [src]);
+ // The page's own segment texts only: a text of another page holding the same words is that page's body, never a
+ // residue of this purge (an inline page referenced none, so the inventory sweep below must not probe the table).
+ if (context && !context.segmentShas.length) stores.push({ store: 'page_segment_texts', status: 'not_present', removed: removed.page_segment_texts ?? 0 });
+ if (context?.segmentShas.length) await keyed('page_segment_texts', `SELECT 1 FROM page_segment_texts t WHERE t.source_id=$1
+ AND t.sha256=ANY(SELECT decode(h,'hex') FROM unnest($2::text[]) AS h)
+ AND NOT EXISTS (SELECT 1 FROM page_body_manifest m WHERE m.source_id=t.source_id AND m.sha256=t.sha256) AND NOT ${stagingNeedsTextSql('t')}`, [src, context.segmentShas]);
if (context) {
const refs = context.factIds.map(String);
for (const table of ['decide_review_queue', 'decide_review_proposals']) await keyed(table, `SELECT 1 FROM ${table} WHERE source_id=$1 AND (a_ref=ANY($2::text[]) OR b_ref=ANY($2::text[]))`, [src, refs]);
diff --cc src/core/facts/purge.ts
index 3d38f59877,c7fe239973..287821f841
--- a/src/core/facts/purge.ts
+++ b/src/core/facts/purge.ts
@@@ -375,12 -516,17 +517,17 @@@ export async function submitPurgeFactMu
const notices = (await tx.executeRaw(`UPDATE core_edit_notices SET base_text=NULL WHERE source_id=$1 AND strpos(lower(base_text),$2)>0 RETURNING 1`,
[p.sourceId, current.fact.toLowerCase()])).length;
const facts = (await tx.executeRaw('DELETE FROM facts WHERE id=ANY($1::bigint[]) AND source_id=$2 RETURNING id', [ids, p.sourceId])).length;
- rewritten = await rewritePageBodies(tx, p.sourceId, plan.pages);
+ const bodies = await rewritePageBodies(tx, p.sourceId, plan.pages);
+ ({ rewritten, unsealed } = bodies);
const pageIds = plan.pages.map(page => page.page_id);
- const chunks = pageIds.length ? (await tx.executeRaw('DELETE FROM content_chunks WHERE page_id=ANY($1::integer[]) RETURNING 1', [pageIds])).length : 0;
+ // A segmented page's flip already retired only the chunks of the occurrences it rewrote.
+ const inline = pageIds.filter(id => !bodies.segmented.includes(id));
+ const chunks = inline.length ? (await tx.executeRaw('DELETE FROM content_chunks WHERE page_id=ANY($1::integer[]) RETURNING 1', [inline])).length : 0;
const versions = await redactPageVersions(tx, p.sourceId, current.fact, pageIds);
prose = versions.prose;
+ const segments = await purgeSegmentStorage(tx, p.sourceId, current.fact, plan, [...new Set([...bodies.segmented, ...versions.segmentedPages])],
+ [...bodies.replaced, ...versions.replaced], admitted.id);
- const cache = (await tx.executeRaw('DELETE FROM query_cache RETURNING 1')).length;
+ const cache = (await clearRebuildableCache(tx, 'query_cache')) ?? 0;
const pages = pageIds.length ? await tx.executeRaw<{ id: number; slug: string; knowledge_revision: string }>(
'SELECT id,slug,knowledge_revision::text AS knowledge_revision FROM pages WHERE source_id=$1 AND id=ANY($2::int[]) ORDER BY slug', [p.sourceId, pageIds]) : [];
await tx.executeRaw(`INSERT INTO persistence_effects(request_id,kind,data,source_id,source_incarnation,worktree_id)
diff --cc test/postgres-unit-arms.txt
index 6eafacdf0d,5a7bc953e8..400fae0f6f
--- a/test/postgres-unit-arms.txt
+++ b/test/postgres-unit-arms.txt
@@@ -191,8 -269,8 +270,9 @@@ test/repair-frontmatter-keys-sweep-6454
test/repair-frontmatter.test.ts
test/repair-receipt-compaction.test.ts
test/repair-rename-identity-6729.test.ts
+test/schema-missing-tables.test.ts
test/scripts/test-stress-postgres.test.ts
+ test/search-read-keyword-bound.test.ts
test/search/page-rank-cut.test.ts
test/search/rerank-gate-hybrid.test.ts
test/search/rerank-gate-telemetry.test.ts