Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge origin/master (v0.60.107.0, #6284) into capy/sync-feeder-fast-writes
garrytan112a3fcb2bd1
diff --cc CHANGELOG.mdindex dc7e248dc6,5d78c9cfd7..df18a61f21--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,54 -10,33 +10,81 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).- ## [0.60.107.0] - 2026-10-07++## [0.60.108.0] - 2026-10-08++**Managed Postgres sync catches up more than twice as fast, starts committing in about 20 seconds instead of 80, and a page you save during a catch-up no longer waits behind it.**++When a git source falls behind on a managed brain whose database is far away (57 ms round trips in our test), `gbrain sync` used to spend most of its time with idle connections: one process prepared the next batch of pages one statement at a time while up to six publishers waited. A 10,000-page backlog took about 75 minutes, the first page landed after about 80 seconds, and a `put_page` from your agent took 9 to 12 seconds even when nothing else was running. Now batches are prepared in bulk, publishers stay busy, a single page write takes about 2.5 seconds, and a foreground write goes ahead of queued sync batches that don't touch the same page.++### How to use it++```bash+gbrain sync --source <id> # nothing to change: the defaults pick up the new path+gbrain config set sync.lanes 12 # up to 16 publishers, clamped by the connection pool+gbrain config set sync.foreground_priority false # back to strict arrival order for page writes during a sync+GBRAIN_PG_TYPE_CACHE=0 gbrain serve # turn off the shared parameter-type cache if a driver issue appears+```++### The numbers that matter++Same 16-core machine and same Postgres, 57 ms round trips, default settings, master before vs this release.++| What you do | Before | Now |+|---|---|---|+| Catch up a 10,000-page backlog | 74.5 min | 33.5 min |+| Pages per minute once the catch-up is running | 175 | 373 |+| Time until the first page is committed | 79 s | 20 s |+| Save one page with nothing else running (typical / slow) | 8.6 s / 11.6 s | 2.5 s / 2.8 s |+| Save one page during a catch-up (typical / slow) | 11.3 s / 17.1 s | 6.9 s / 8.4 s |+| Catch-up speed while your agent saves a page every 5 s | 4.6 pages/min | 58 pages/min |+| Catch-up next to the database (about 0 ms) | 2,404 pages/min | 2,862 pages/min |++### Things to watch++- **More publishers help up to a point.** With a 20-connection pool, 8 to 16 publishers all run at about 400 to 410 pages/min against 378 at the default 6. The drain prints a `[sync] lanes:` line saying what limited it (the pool, the server's free connections or your setting).+- **Writes during a catch-up still cost something.** A page write waits for the sync batches already publishing, so during a catch-up it takes about 7 s, and a steady stream of writes slows the catch-up to about 15% of its idle speed.+- **Every new path has a switch** that accepts `0` or `false`: `persistence.single_write_group`, `persistence.preadmit_cache`, `sync.waive_batch`, `sync.foreground_priority` (environment: `GBRAIN_SINGLE_WRITE_GROUP`, `GBRAIN_PREADMIT_CACHE`, `GBRAIN_SYNC_WAIVE_BATCH`, `GBRAIN_SYNC_FOREGROUND_PRIORITY`). A running `serve` picks up a config change within 5 seconds.++### Itemized changes++- Sync feeder: a group's admission and the cursor save that records it are one transaction; window groups are admitted in batches with the request inserts and counter updates pipelined; admit-ahead never asks for more requests than the writer's outstanding limit leaves room for (it used to refuse at 8+ lanes and on a local database, serializing the lanes).+- Lanes: up to 16 (`sync.lanes`, `--lanes`), clamped by the pool and the server's free connections; groups are sized by measured apply time inside a 5 s budget (2 s while foreground writes are recent), and the first group is one or two pages. Group publication pipelines the page apply.+- Startup: runs of entries that need no write (already-deleted files, unchanged imports) are waived in one transaction instead of one each.+- Single page writes publish as a group of one on a warm reserved connection, with a per-process cache of pre-admission reads that admission rechecks under lock, and the writer's own admission claims the request directly.+- Foreground priority: a page write passes queued, unstarted sync groups that don't name its page (slug, page id or rename source); a sync group naming the page keeps its place; after each foreground commit the drain may start a group, so a stream of writes can't stall it. Every reader of request sequence order was audited for writes committed out of order; receipt health now judges a claimed write only against earlier started writes.+- Postgres: described parameter types are shared across a pool's connections (patched `[email protected]`, `GBRAIN_PG_TYPE_CACHE=0` turns it off); managed link extraction derives four pages at once with one config read per run.+- A sync group member after an uncommitted member is cancelled, never published ahead of it (#6252).+- Write receipts no longer call an ordinary publication in progress `blocked` / `recovery_required`: a request needs recovery only when it is recovering or holds a recovery record without a live claim, and the requests behind a live publication show as waiting (#6275).+- Remote `put_page` skips the similar-pages advisory while `put_page.similar_pages` is off (the default) and runs it with JIT off when on; remote `get_page` / `fetch` read the page with JIT off, so brains past about 1,000 pages stop paying JIT compile time on every call (#6276).+- Bench: `scripts/bench/managed-sync-catchup.ts` reports feeder and lane timing, steady state, per-write foreground spans, an open-loop foreground row and `--pool-size`; results in `docs/eval/managed-sync-catchup.md`.++ ## [0.60.107.0] - 2026-10-08++ **A page the quarantine gate hid stays hidden: no more planted markers, no facts mined from it, and no body handed to remote agents.**++ The content-quality gate quarantines junk and unsafe pages so search skips them. Four paths still leaked them. Any non-remote writer could plant or fake the gate's own markers; a quarantined page still fed automatic fact extraction and its facts and takes fences; `get_page` and `fetch` returned its body verbatim; and `put_page` never told the agent its page had been hidden.++ ### What you see++ | Where | What changed |+ |---|---|+ | Gate-owned frontmatter | `quarantine`, `embed_skip`, `content_flag`, `atoms_scan_hash` and `quarantine_override` are stripped from a local `put_page`, a connector, an ingest event or any other non-owner write. Sync and import of your own files, reindex, repair, reconcile, the cycle and `quarantine clear` keep them. |+ | Facts and takes | A quarantined page is not mined for facts (`facts_backstop.skipped: quarantined`) and its fences are not projected. Rows projected before it was quarantined stay. |+ | `get_page` / `fetch` | Carry `quarantined` (fetch: `metadata.quarantined`) and a `page_quarantined` notice. Remote callers get no body or text unless an admin-scoped caller passes `include_quarantined: true`; local reads keep the body. |+ | `put_page` / `put_pages` | A write the gate hid reports `quarantined: { reason, detail }` with a notice. |++ ### Things to watch++ - **Scripts that planted markers through `put_page`** (for example to force `embed_skip`) now have them stripped; use the owner paths above or `gbrain quarantine clear --force`.+ - **Remote agents reading a quarantined page** get the notice instead of its text; an admin can still ask for it.++ ### Itemized changes++ - `stripGateOwnedMarkers` (`src/core/import-screen.ts`) runs once per write; only callers passing `preserveGateMarkers: true` keep the markers. Managed `quarantine clear` submits the owner-internal `managed_quarantine_clear` intent so `quarantine_override` stays writable. `opts.remote` keeps only its fence-merge and hidden-row meaning.+ - `isFactsBackstopEligible` refuses a quarantined page; the canonical projection and the unmanaged `extract_facts` / `extract_takes` reconcilers skip it.+ - `readQuarantined` shapes `get_page` and `fetch`; `include_quarantined` is honored only for admin scope.+ - New key-files cluster `docs/architecture/key-files/quarantine.md`.+## [0.60.106.0] - 2026-10-07**Fix wave 12: one bad link no longer stops extraction, cut-off model answers stop counting as real ones, and paid loops stop paying.**diff --cc src/core/persistence/canonical-projections.tsindex 026d747a40,58b25020f0..501f903d99--- a/src/core/persistence/canonical-projections.ts+++ b/src/core/persistence/canonical-projections.ts@@@ -409,16 -413,19 +413,20 @@@ export async function prepareCanonicalP() => tx.executeRaw(`UPDATE timeline_entries t SET detail=r.next FROM jsonb_to_recordset($2::text::jsonb) AS r(id integer,detail text,next text)WHERE t.page_id=$1 AND t.event_page_id IS NULL AND t.id=r.id AND t.detail=r.detail`, [id, refreshes]),];+ if (!projectFences) {+ await pipelined(tx, timelineRows);+ return { timelineRowsRemoved: removedSummary(removedDates) };+ }+ // The timeline rows are independent of the fact and take rows, so they ride in the first pipeline.if (factRows.length) {- await pipelined(tx, [expireFacts]);+ await pipelined(tx, [expireFacts, ...timelineRows]);await tx.insertFacts(factRows, { source_id: sourceId }); // gbrain-allow-direct-insert: canonical fence projection shares the journal publication transactionawait pipelined(tx, [...factFields, checkTakes, dropTakes]);- } else await pipelined(tx, [expireFacts, checkTakes, dropTakes]);+ } else await pipelined(tx, [expireFacts, checkTakes, dropTakes, ...timelineRows]);if (takes.length) {await tx.addTakesBatch(takes.map(t => takesPreparation.toCanonicalBatchInput(id, t)));- await pipelined(tx, [...resolveTakes, ...timelineRows]);- } else await pipelined(tx, timelineRows);+ await pipelined(tx, resolveTakes);+ }return { timelineRowsRemoved: removedSummary(removedDates) };};}diff --cc src/core/persistence/page-prepare.tsindex b414aad825,54f67dfbaa..8abbdeea28--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@@ -380,12 -370,10 +380,14 @@@ export async function preparePageMutati}let prepared: PreparedContentImport | undefined;let provenance: CanonicalProvenance | undefined;+ // The apply diet: the publisher's locked read of row.slug is the import base, and one read after the+ // last page write serves the read-back check, the seal, the core notice and the receipt (as sync does).+ const lean = options.coordinated === true && !targetDeleted && row.operation !== 'restore_page' && !versionTags;const result = await importFromContent(engine, row.slug, content, {- ...source, noEmbed: true, remote: row.authority.remote, activePack, fences: projected ? 'coordinated' : 'lenient',+ ...source, noEmbed: true, remote: row.authority.remote, activePack, fences: projected ? 'coordinated' : 'lenient', coordinated: lean,+ ...(lean ? { existingSnapshot: snapshot } : {}),+ // #6259: only owner-tier intents keep gate-owned markers; an ordinary put_page, local or remote, has them stripped.+ preserveGateMarkers: !row.authority.remote && (p.kind === 'managed_maintenance_page' || p.kind === 'managed_quarantine_clear'),forceRechunk: row.operation === 'restore_page' || row.operation === 'revert_version',allowEmptyOverwrite: p.allow_empty === true || row.operation === 'restore_page' || row.operation === 'revert_version',source_kind: typeof p.source_kind === 'string' ? p.source_kind : null,diff --cc test/fixtures/goldens/exports/types.jsonindex e6ad7598fb,12e698479c..f545e8c43b--- a/test/fixtures/goldens/exports/types.json+++ b/test/fixtures/goldens/exports/types.json@@@ -4453,7 -4450,7 +4453,7 @@@"kind": "function","name": "importFromContent","signature": [- "(engine: BrainEngine, slug: string, content: string, opts?: { prepare?: (prepared: PreparedContentImport) => Promise<ImportResult>; coordinated?: boolean; existingSnapshot?: PageSnapshot | null; prepareFrontmatter?: (page: ParsedPage) => void; noEmbed?: boolean; sourceId?: string; filename?: string; sourcePath?: string; sourceRoot?: string; fileTimes?: { birthtime?: Date; mtime?: Date; firstCommit?: Date; }; forceRechunk?: boolean; activePack?: ParseOpts[\"activePack\"]; source_kind?: string | null; source_uri?: string | null; ingested_via?: string | null; remote?: boolean; allowEmptyOverwrite?: boolean; beforeCommit?: (tx: BrainEngine, slug: string) => Promise<void>; onPostCommitEmbedding?: (complete: () => Promise<ImportEmbeddingResult>) => void; } & ImportFenceOptions) => Promise<ImportResult>"- "(engine: BrainEngine, slug: string, content: string, opts?: { prepare?: (prepared: PreparedContentImport) => Promise<ImportResult>; coordinated?: boolean; prepareFrontmatter?: (page: ParsedPage) => void; noEmbed?: boolean; sourceId?: string; filename?: string; sourcePath?: string; sourceRoot?: string; fileTimes?: { birthtime?: Date; mtime?: Date; firstCommit?: Date; }; forceRechunk?: boolean; activePack?: ParseOpts[\"activePack\"]; source_kind?: string | null; source_uri?: string | null; ingested_via?: string | null; remote?: boolean; preserveGateMarkers?: boolean; allowEmptyOverwrite?: boolean; beforeCommit?: (tx: BrainEngine, slug: string) => Promise<void>; onPostCommitEmbedding?: (complete: () => Promise<ImportEmbeddingResult>) => void; } & ImportFenceOptions) => Promise<ImportResult>"++ "(engine: BrainEngine, slug: string, content: string, opts?: { prepare?: (prepared: PreparedContentImport) => Promise<ImportResult>; coordinated?: boolean; existingSnapshot?: PageSnapshot | null; prepareFrontmatter?: (page: ParsedPage) => void; noEmbed?: boolean; sourceId?: string; filename?: string; sourcePath?: string; sourceRoot?: string; fileTimes?: { birthtime?: Date; mtime?: Date; firstCommit?: Date; }; forceRechunk?: boolean; activePack?: ParseOpts[\"activePack\"]; source_kind?: string | null; source_uri?: string | null; ingested_via?: string | null; remote?: boolean; preserveGateMarkers?: boolean; allowEmptyOverwrite?: boolean; beforeCommit?: (tx: BrainEngine, slug: string) => Promise<void>; onPostCommitEmbedding?: (complete: () => Promise<ImportEmbeddingResult>) => void; } & ImportFenceOptions) => Promise<ImportResult>"]},{