Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Fix the train review findings: purge keeps emptied pages healable, safe maintenance holds embedding repair lanes, unlink hints put slugs after --
garrytanf60886f95950
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 81d08ea818..8b91bb9f47 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -26,7 +26,7 @@ identifiers and attribution are available in the pre-removal Git revision**Doctor checks that misreported their findings now report them accurately.** A community bug wave: each fix below was reported by a contributor, reproduced on master with a failing test first, and rewritten here.-**`gbrain maintain --safe` no longer deletes pages or calls a paid provider.** It used to run the whole dream cycle on the default source, so pages soft-deleted more than 72 hours earlier were purged for good, and the embedding, synthesis and other model phases ran too. The source cycle now runs only free phases that never purge: lint, backlinks, sync, the fence and content repair lanes, unindexed files, extract, extract_facts, symbol edges, emotional weight, consolidate, orphans and schema suggestions. It also holds back `extract_facts` when an embedding provider is set up or the decide conflict slot is on (its conflict sweep calls the decision provider), and the fence and content repair lanes when `fences.repair.llm` has a repair model. The JSON report lists the phases that ran and the ones held back. Old soft-deleted pages are still purged by `gbrain pages purge-deleted` (preview it with `--dry-run`), `gbrain dream` and an installed autopilot, and the paid phases still run from `gbrain dream`.+**`gbrain maintain --safe` no longer deletes pages or calls a paid provider.** It used to run the whole dream cycle on the default source, so pages soft-deleted more than 72 hours earlier were purged for good, and the embedding, synthesis and other model phases ran too. The source cycle now runs only free phases that never purge: lint, backlinks, sync, the fence and content repair lanes, unindexed files, extract, extract_facts, symbol edges, emotional weight, consolidate, orphans and schema suggestions. It also holds back `extract_facts` when an embedding provider is set up or the decide conflict slot is on (its conflict sweep calls the decision provider), and the fence and content repair lanes when an embedding provider is set up (their publications embed) or `fences.repair.llm` has a repair model. The JSON report lists the phases that ran and the ones held back. Old soft-deleted pages are still purged by `gbrain pages purge-deleted` (preview it with `--dry-run`), `gbrain dream` and an installed autopilot, and the paid phases still run from `gbrain dream`.**Enrich write-ups from thinking models are no longer cut off.** Enrich capped every write-up at 2048 output tokens, which thinking-by-default models such as Claude 5 spend on reasoning, so write-ups came back truncated or failed. Thinking models now get the gateway's thinking headroom; other models keep 2048.@@ -50,11 +50,11 @@ identifiers and attribution are available in the pre-removal Git revision- `timeline_history`: on a brain with more than 10,000 pages carrying database-only timeline rows, a pass keeps only the first 10,000 for its final recount. It used to report that recount as exact, and a pass whose kept pages had been repaired was recorded as clean while the rest still held database-only rows. Such a pass now reports its counts as a lower bound ("at least"), keeps warning, and is never trusted as clean. A pass saved by an earlier release, which did not record whether it dropped pages, is treated the same way when its kept list is full. Reported by @Masashi-Ono0611 (#8511).- `conversation_format_coverage`: the sample now includes pages stored under the granular conversation types the extractor already reads (`slack-thread`, `slack-dm-day`, `email-digest`), so unparseable transcripts on a brain that never ran the type-consolidation pack are reported instead of silently skipped. Reported by @Masashi-Ono0611 (#8519).- `minions_migration` under `gbrain doctor --fast`: a migration the brain's config can decline (v0.53.0, `shared_skills.migration.enabled`) is no longer listed as not run. Without a database connection the check cannot read that setting, and `gbrain apply-migrations --yes` skips a declined migration, so the warning could never clear. The full `gbrain doctor` still reports it when it is not declined. Reported by @Masashi-Ono0611 (#8721).-- `stale_mentions`: each stale example now carries its own `gbrain unlink` command with the link type the row is stored under, shell-quoted so a slug or link type with quotes or `$(...)` pastes as plain words. The hint used to say `--link-type mentions` for every row, which removes nothing for a typed link stored under a verb such as `founded`. Reported by @Masashi-Ono0611 (#8817).+- `stale_mentions`: each stale example now carries its own `gbrain unlink` command with the link type the row is stored under, shell-quoted so a slug or link type with quotes or `$(...)` pastes as plain words, with the options first and `--` before the two slugs, so a slug that starts with `--` is never read as a flag. The hint used to say `--link-type mentions` for every row, which removes nothing for a typed link stored under a verb such as `founded`. Reported by @Masashi-Ono0611 (#8817).- `schema_pack_consistency`: pages gbrain itself wrote (extract receipts under `extracts/`, and pages from the code importer) no longer count as undeclared on a custom schema pack copied before the base pack declared their types. The exemption follows how the page was written, not its type name: a page of yours that uses one of those types, such as a Markdown note with `type: code`, still warns, as do your own undeclared types. Reported by @Masashi-Ono0611 (#8818).-- `embedding_state` and `gbrain embed --stale`: a page whose body holds only a protected takes fence (which never reaches search chunks) is now counted `empty` instead of `chunkless_healable`. Doctor no longer warns about it, and `embed --stale` no longer plans a heal that can never produce a chunk. A page is treated this way only when the writer already chunked its current revision to nothing; a chunkless page that was never chunked, a page whose chunks were deleted after it was chunked, or an `embed_skip` page an older release stored without chunks, is still healed. Reported by @akinduroifedayo (#8502).+- `embedding_state` and `gbrain embed --stale`: a page whose body holds only a protected takes fence (which never reaches search chunks) is now counted `empty` instead of `chunkless_healable`. Doctor no longer warns about it, and `embed --stale` no longer plans a heal that can never produce a chunk. A page is treated this way only when the writer already chunked its current revision to nothing; a chunkless page that was never chunked, a page whose chunks were deleted after it was chunked, or an `embed_skip` page an older release stored without chunks, is still healed. Deleting a page's chunks clears that seal, in `deleteChunks`, an empty chunk replacement and `purge_fact`'s chunk delete (which also empties pages whose body held no purged row), so such a page stays healable. Reported by @akinduroifedayo (#8502).- `managed_sync_backlog`: removing a source in the middle of a managed sync now removes its sync cursor too, whether the brain is managed or not. The cursor used to stay behind, and doctor warned about a stalled backlog forever with a resume command that failed `unknown_source`. A cursor an earlier removal already left behind is no longer reported, including after the source is added back under the same id. Reported by @omni-nordaware (#8741).-- `src/commands/maintain.ts`: `MAINTAIN_SAFE_PHASES` is the allowlist of free, non-purging phases; `maintainSafePhases` intersects it with the source's own phase list and holds back provider-gated phases (`extract_facts` on an embedding provider or an enabled decide conflict slot, `fence_repair` and `content_repair` on a resolved repair model); the dry-run and applied actions report `phases` and `held_phases`; the help text names `gbrain pages purge-deleted` and `gbrain dream`.+- `src/commands/maintain.ts`: `MAINTAIN_SAFE_PHASES` is the allowlist of free, non-purging phases; `maintainSafePhases` intersects it with the source's own phase list and holds back provider-gated phases (`extract_facts` on an embedding provider or an enabled decide conflict slot, `fence_repair` and `content_repair` on an embedding provider or a resolved repair model); the dry-run and applied actions report `phases` and `held_phases`; the help text names `gbrain pages purge-deleted` and `gbrain dream`.- `src/core/behavior-change-notice.ts`: one row for the changed `maintain --safe` behavior.- `scripts/module-size-limits.tsv`: the notice file's ceiling grows by one for that row.- Docs: the `maintain.ts` row in `docs/architecture/key-files/commands-4.md`.diff --git a/docs/architecture/canonical-writers.tsv b/docs/architecture/canonical-writers.tsvindex 50b8fecfd9..082139412f 100644--- a/docs/architecture/canonical-writers.tsv+++ b/docs/architecture/canonical-writers.tsv@@ -75,7 +75,7 @@ src/core/embedding-invalidation.ts 2 projection Derived vector invalidation; sigsrc/core/embedding-migration.ts 1 projection Derived indexing, retrieval telemetry, or source settings; canonical fields remain guarded by SQL triggers.src/core/engine-constants.ts 1 contract Engine contract or explanatory SQL references; execution is in guarded engine implementations.src/core/engine-sql/bootstrap.ts 1 schema Schema installation and forward-reference DDL; coordinated activation quiesces canonical writers.-src/core/engine-sql/chunks.ts 2 projection Derived indexing: setPageEmbeddingSignature stamps pages.embedding_signature, and a complete chunk replacement (upsertChunks sealChunkerVersion, #5984) stamps pages.chunker_version in the caller's transaction; chunk rows are derived index state and canonical fields remain guarded by SQL triggers.+src/core/engine-sql/chunks.ts 4 projection Derived indexing: setPageEmbeddingSignature stamps pages.embedding_signature, and a complete chunk replacement (upsertChunks sealChunkerVersion, #5984) stamps pages.chunker_version in the caller's transaction; chunk rows are derived index state and canonical fields remain guarded by SQL triggers. deleteChunks and an empty upsertChunks replacement clear pages.text_projection_revision, the derived seal certifying the deleted chunks, in the same statement as the chunk delete (#8502).src/core/engine-sql/facts.ts 11 engine_guard Canonical table SQL trigger requires coordinator capability; legacy calls fail before canonical DB publication.src/core/engine-sql/page-body.ts 2 engine_guard Wave B segmented storage: createSegmentedPageShell inserts the page row and flipBodyGeneration moves its body identity (body_generation, size and lead columns); both run in the caller's publication transaction, and the pages SQL trigger requires coordinator capability on managed brains (body_generation is guarded content).src/core/engine-sql/pages.ts 18 engine_guard Canonical table SQL trigger requires coordinator capability; legacy calls fail before canonical DB publication. #5761: markPagesAttendanceBlocked writes only derived attendance-marker columns. The additional UPDATE pages in updatePageContextualRetrievalState changes only contextual projection state and clears active vectors in the same statement, under the caller's page lock; canonical body fields remain guarded. #6454: stripStaleFrontmatterKeys removes only the four parser-reserved keys from pages.frontmatter (keys no canonical file can carry, so the file is unchanged) inside the repair sweep's coordinated write; it touches no body, title, type or tag column.@@ -268,7 +268,7 @@ src/core/repair/take-supersession.ts 1 coordinator gbrain repair take-supersessisrc/core/repair/timeline-comments.ts 2 coordinator `gbrain repair timeline-comments` (#6184) deletes or rewrites timeline rows carrying HTML comment markup under the page lock: `withCoordinatedWrite` with maintenance attribution on managed brains, `maintenanceTransaction` otherwise; the page body changes go through a revision-bound put_page first.src/core/repair/take-supersession.ts 1 coordinator gbrain repair take-supersession reprojects superseded_by for a page whose fence is already right: a managed_maintenance_take_reproject request replanned under the page key on a managed brain, maintenanceTransaction (revision-checked) on an unmanaged one. Fence edits go through a revision-bound put_page request.src/core/facts/derivation-inputs.ts 3 coordinator hideDerivedRows expires derived facts, deactivates derived takes and soft-deletes derived pages only inside the purge_fact transaction, after write admission and under withCoordinatedWrite on the purge source with the affected page keys locked.-src/core/facts/purge.ts 3 coordinator purge_fact deletes the purged fact and take rows and rewrites affected page bodies inside one admitted write transaction under withCoordinatedWrite, after the pending-publication check and page-key locks; the request journal records the terminal receipt.+src/core/facts/purge.ts 4 coordinator purge_fact deletes the purged fact and take rows and rewrites affected page bodies inside one admitted write transaction under withCoordinatedWrite, after the pending-publication check and page-key locks; the request journal records the terminal receipt. The plan-wide chunk delete clears the same pages' text_projection_revision seal in that statement, so an unrewritten page it emptied stays healable (#8502).src/core/persistence/page-purge.ts 4 coordinator purgePageInTransaction deletes the page's filed facts and hard-deletes the page only from the prepared delete_page purge publication callback in page-prepare.ts, under the same source/page identity, revision and durable authority guards as receipt completion. #6619: in the same callback it deletes the purged page's page_aliases and the slug_aliases redirects that resolve to it.src/core/trust/fence-append.ts 1 coordinator withPageTierKept restores the page's prior trust_tier and write_origin in the same coordinated fence-append transaction that wrote the page (fence-write, facts-prepare and memory-prepare callers); it changes no content column.src/commands/sources-trust.ts 1 engine_guard gbrain sources set-trust rewrites only the source's config jsonb (its default trust tier for future writes); the managed writer guard exempts sources rows whose id, incarnation, local_path, archived and checkpoint columns are unchanged, and no knowledge row changes.diff --git a/docs/architecture/key-files/commands-4.md b/docs/architecture/key-files/commands-4.mdindex b3a61591f7..33bf2a013b 100644--- a/docs/architecture/key-files/commands-4.md+++ b/docs/architecture/key-files/commands-4.md@@ -22,7 +22,7 @@ Current behavior and load-bearing invariants; history belongs in Git and CHANGEL- `src/commands/lint.ts` — Page quality linter (catches LLM artifacts, placeholder dates). `runLintCore(opts)` walks the tree ONCE; `--fix` applies fixes during that same scan and reports per-page results through the `onPageIssues(relPath, issues, fixedCount)` callback (issues = what remains after this run's fix attempt for the page; `fixedCount` = fixes actually applied), so the summary's auto-fixed count is the true count — a second scan run after fixing would see already-fixed files and report zero. `onScanStart` fires once with the collected page count for progress wiring. Pinned by `test/lint-fix-single-pass.test.ts`. On a durability-hardened brain (`isDurabilityHardened` on the target dir, or the page's directory for a single-file target) every non-dry-run `--fix` repair is committed path-limited via `commitWriteThroughFile` right after the `writeFileSync` — the same contract as put_page write-through, so the cycle, the `lint`/`lint-fix` minion handlers and the CLI never leave hardened repairs as uncommitted drift for the sync phase to flag (pinned by `test/cycle-lint-durability.test.ts`). Lint rules `huge-page` (flags pages exceeding `content_sanity.bytes_warn`) and `scraper-junk` (flags pages matching any junk pattern). Both reuse `assessContent()` from `src/core/content-sanity.ts` so lint, doctor, and ingest share one assessor. `lint.ts` lifts DB config when `~/.gbrain/` is reachable; falls back to file/env on CI. Pinned by `test/lint-content-sanity.test.ts`. Rule `type-undeclared` flags an explicit frontmatter `type` the active schema pack neither declares nor aliases (resolved once per run from the shared/probed engine's DB-plane `schema_pack`, else file/env config; no resolvable pack skips it; `LintOpts.typePack` injects it), pinned by `test/lint-page-type-vocabulary.test.ts`. with `src/commands/sources.ts`: `gbrain lint` has a `markup-heavy` rule (flags pages whose prose-vs-markup ratio exceeds `content_sanity.max_markup_ratio`, reusing `assessContentSanity` so lint/gate/scan share one assessor); pinned by `test/lint-content-sanity.test.ts`. `gbrain sources audit <id>` is disposition-aware: its dry-run disk scan reports would-quarantine / would-reject / would-flag counts driven by the effective `content_sanity.junk_disposition` + markup config, so an operator previews the gate's verdict before sync. The `content-sanity-audit` JSONL (`src/core/audit/content-sanity-audit.ts`) records the quarantine/flag dispositions. On a managed brain (persistence enabled) `runLintCore` skips the legacy filesystem lock and publishes each repair through the persistence coordinator (`maintenancePreflight` + `publishMaintenancePage`: DB row and worktree file in one guarded write) instead of writing the file. It reads the page revision before the bytes it repairs, checks them with the coordinator's canonical predicate (`fileMatchesSnapshot`, so formatting differences are not divergence) and submits against that revision. A repair that must wait (no indexed page, a file that diverged from the database, a held or removed file, a publication mid-scan) is a non-fixable `managed-write-pending` issue with `code: 'managed_write_pending'`, a `reason` (the coordinator refusal's detail, `held_file`, `canonical_file_missing`, `revision_changed`, `not_indexed`), the refusal's own rendered `fix` (never a sync) and the guide link; the run continues (`LintResult.write_path` / `fix_pending` / `pending_issues`, first 50; #5180, `test/managed-lint.test.ts` on both engines). A file the scan listed that is gone by its scan read (ENOENT only; other read errors still fail the run) is reported instead of aborting: a managed `--fix` run asks the coordinator (pending `canonical_file_missing`), otherwise a non-fixable `file-removed-during-scan` issue with code `file_removed_during_scan` and a `gbrain lint <target>` fix; the CLI prints each issue's `Fix:` command and `Docs:` link (`test/lint-file-removed-during-scan.test.ts`). `llm-preamble` matches only a leading run at a body start (file top, after leading frontmatter, or after a whole-page ```markdown wrapper), and repair removes only that run, so a later line that begins like a preamble is never flagged or deleted. A filesystem fix write refused with EACCES/EPERM/EROFS leaves the file unchanged and becomes a non-fixable `fix-not-writable` issue (`code: 'fix_not_writable'`, the errno as `reason`, a user `fix` naming the permission change or `--exclude`) counted in `fix_pending`; the run continues (`test/lint-preamble-anchor.test.ts`). `placeholder-date` and `empty-section` read code-masked text (`stripCodeBlocks`, offset-preserving): a placeholder or a `## ` line inside a fence or inline code is code, an unclosed fence masks to the end of the file, and `empty-section` reads each section's body from the original text, so a section holding only a code block is not empty (`test/lint-3958.test.ts`). #5433: `missing-created` fires only when none of `created`, `event_date`, `date`, `published`, `captured_at`, `ingested_at` parses (`parseDateLoose` on the parsed frontmatter, never a regex; a block YAML could not read is already `frontmatter-yaml-parse`) and is never fixable: `fixContent` no longer promotes a capture timestamp into `created` (ingest time is not creation time, and the cycle's `fix: true` lint phase rewrote every native page), so a page `serializePageToMarkdown` emits stays byte-identical across repeated `--fix` runs; `promoteCreatedFromCapture` stays exported, deprecated, for explicit callers.-- `src/commands/maintain.ts` — `gbrain maintain [--safe] [--dry-run] [--json]`: stale extraction, then one source-scoped `runCycle` per source doctor's `cycle_freshness` names, limited to `MAINTAIN_SAFE_PHASES` (free and never hard-deleting: no `purge`, no paid phase); `maintainSafePhases` also holds back `extract_facts` when an embedding provider is available or the decide conflict slot is on and the repair lanes when `fences.repair.llm` has a model (GST-2246). A source whose cycle throws an item-scoped error is a `blocked` action with `details.code` and `fix` (`gbrain dream --source <id>`) and later sources still cycle (ItemRun site `maintain.cycle_sources`); run-scoped errors and `item_failures_systemic` stop maintain; any blocked action sets exit 1. Tests: `test/maintain.test.ts`, `test/pathological/a41-maintain-sources.test.ts`.+- `src/commands/maintain.ts` — `gbrain maintain [--safe] [--dry-run] [--json]`: stale extraction, then one source-scoped `runCycle` per source doctor's `cycle_freshness` names, limited to `MAINTAIN_SAFE_PHASES` (free and never hard-deleting: no `purge`, no paid phase); `maintainSafePhases` also holds back `extract_facts` when an embedding provider is available or the decide conflict slot is on and the repair lanes when an embedding provider is available or `fences.repair.llm` has a model (GST-2246). A source whose cycle throws an item-scoped error is a `blocked` action with `details.code` and `fix` (`gbrain dream --source <id>`) and later sources still cycle (ItemRun site `maintain.cycle_sources`); run-scoped errors and `item_failures_systemic` stop maintain; any blocked action sets exit 1. Tests: `test/maintain.test.ts`, `test/pathological/a41-maintain-sources.test.ts`.- `src/commands/migrate-embeddings.ts` — `gbrain migrate embeddings --to <provider:model> [--dim N] [--dry-run] [--yes] [--json] [--no-embed] [--status] [--reranker auto|off|keep|<model>] [--retarget] [--batch-size N] [--pace[=mode]] [--ignore-env-override]` (alias: `gbrain retrieval-upgrade`). ONE shared orchestrator for CLI and the `migrate_embeddings` op: `planMigrationFlow` (plan + `verifyMigrationComplete` + env presence + un-merged file plane + brain/DB identity via `redactPgUrl` + concurrent-writer census + reranker plan + in-flight-other marker) and `executeMigrationFlow` (global `gbrain-embedding-migration` DbLock → retarget gate under it → all-source embed locks sorted with `includeArchived` → worst-case authorization under the locks (a cap below it returns `refused_budget` / op `refused` with `embedding_budget_below_worst_case` before any provider call or invalidation) → live embed probe → apply → reranker probe + switch → drain via `runEmbedCore({heldLocks, …})` so the migration never lock_skips itself, with a 5-min heartbeat whose refresh-false/3-errors ABORTS as `lock_lost` → reconcile → completion smoke check stamped into the marker → transactional complete; locks released in finally). The skip path exits 0 ONLY on `verify.complete` with no pending retarget decision and no pending reranker action (a resolved switch/disable runs as a config-only completion). `--status` is read-only/spend-free and never refuses on env (it REPORTS planes, key PRESENCE booleans only, censuses, markers verbatim incl. corrupt, the exact resume command, and the last completion + smoke-check outcome). `persistEmbeddingFileConfig` writes through `loadConfigFileOnly` (never persists env-sourced keys) and supports env-canonical no-file deployments (env pins target ⇒ proceed with notice). Exit codes: 0 completed/verified-no-work, 1 locked/refused/failed/incomplete (message names which; lock_skipped and lock_lost get their own copy), 3 consent required (agent operator wave C2: `requireConsent` with effects `paid` + `destructive`; `spend.posture=tokenmax` covers only the paid part, `--json` never implies consent, the payload's fix repeats the caller's argv plus `--yes`; the TTY prompt is interaction.readLine, and the `confirm`/`isTTY` test seams map onto ConsentEnv). Spend stays bounded by the durable `--max-cost-usd` authorization, not the consent cap. Pinned by `test/migrate-embeddings-flow.serial.test.ts`, `test/migrate-embeddings-boundary.serial.test.ts`, `test/migrate-embeddings-hardening.serial.test.ts`. Migration guidance uses `renderCanonicalMigrationCommands` (`src/core/ai/defaults.ts`) to keep supported targets and dimensions consistent.- `src/commands/migrate-engine.ts` — Legacy engine copier (`gbrain migrate --to pglite`, and PGLite → Postgres when `migrate.graduation` is `false`). A PGLite → Postgres move routes to `src/commands/migrate-graduation.ts` (engine graduation) before connect and never reaches this file. Copies the complete source catalog FIRST (`copyMigrationSources` — every `sources` row incl. archived rows and sync/routing metadata, `ON CONFLICT (id) DO UPDATE`, `default` ordered first) so every page write has a valid `pages.source_id` FK parent and the target preserves per-source behavior; pages copy afterward: `listAllPageRefs` lists every live page's `(source_id, slug)` in one uncapped query, `copyMigrationPages` reads each body with `getPage(slug, { sourceId })` (a page soft-deleted after the listing reads null and is skipped, reported, and kept out of the link copy; it is not a failure), and each page is tracked in the resume manifest by composite `(source_id, slug)` key. Link copy preserves each row's `to_source_id` (falling back to the origin source only for legacy rows without it), and failed-target filtering uses that same target composite key, so cross-source links migrate without being rebound to the origin source. The resume manifest is target-aware: `migrationTargetId(config)` hashes `(engine, locator)` (`database_url` for Postgres, resolved `database_path` for PGLite) and `manifestMatchesTarget` requires `schema_version === 2` plus a matching `target_id` — a legacy engine-only manifest, or one from a DIFFERENT target of the same engine kind, starts fresh instead of skipping "completed" pages the new target never received. After links, `copyMigrationFacts` carries the facts table verbatim (conversation facts have no markdown fence to re-sync from): source∩target column intersection via information_schema (older source schemas still copy), delete-and-recopy so every re-run converges to source truth, two-pass `superseded_by` restore (the self-FK points old→newer id, so id-ordered single-pass inserts would violate it), embeddings round-tripped as text into whichever physical type (`vector`/`halfvec`) the target column has with a NULL-embedding retry on per-row cast failure, and a `setval` bump so post-migration inserts don't collide with copied ids; fact-row failures block the config flip and force a non-zero exit, same contract as page failures. Takes are deliberately NOT copied (fence-canonical, keyed on target-reassigned `page_id`; the next extract cycle rebuilds them). `copyMigrationConfig` then copies EVERY DB-plane config row except the explicit engine-local denylist `MIGRATE_CONFIG_ENGINE_LOCAL_KEYS` (`engine`, `version` = target-owned schema ledger, `embedding_columns` + `search_embedding_column` = physical-column registry the copy doesn't materialize); skipped keys print in the end-of-run per-table copied-count summary, so nothing is dropped silently. Pinned by `test/migrate-engine-resume.test.ts` (manifest identity) + `test/e2e/migrate-engine-sources-postgres.test.ts` (source catalog lands before overlapping-slug pages, PGLite → real Postgres) + `test/e2e/multi-source-bug-class.test.ts` (cross-source links) + `test/migrate-engine-completeness.serial.test.ts` (facts chains/embeddings/sequence, config copy-all + denylist, summary) + `test/migrate-engine-pagination.serial.test.ts` (no listing cap; a page deleted mid-copy). Legacy engine copies explicitly include stored unverified chunks and queue sanitized text rebuilding under the target revision; retrieval stays gated until rebuilt. #6286: `copyPageToTarget` forwards the full page row (`page_kind`, `source_path`, effective date and its source, `import_filename`, `source_kind`/`source_uri`/`ingested_via`, `ingested_at` restored in the timestamp UPDATE), the frontmatter aliases (`setPageAliases`) and each chunk's code metadata (`carryChunkMetadata`). A page sealed on the source is queued `engine_migration`; one the source had not sealed is queued `engine_migration_source_unsealed` and keeps its verbatim chunks and vectors. Before the config flip, while autopilot is paused, `runMigrateEngine` runs `drainProjections` (moved to `src/core/page-state/projections.ts`; `commands/projections.ts` re-exports it) on the target for the `engine_migration` and `rebuild_failed` reasons, keyless; the rebuild keeps chunk ids and vectors whose identity and embedding input match, so the first sync after the flip skips unchanged pages. A failed rebuild blocks the flip with exit 1, like a page that failed to copy. Pinned by `test/migrate-full-row-projections.serial.test.ts`, `test/e2e/migrate-full-row-projections-postgres.test.ts` and a D2 case in `test/e2e/migrate-engine-pglite-to-postgres.test.ts`. Open-loop and loop-suppression rows the target refuses (`copyMigrationSimpleTable`, per-row `ItemRun` site `migrate_engine.loop_rows`) are printed with their id and reason, block the config flip and set exit 1; a run-scoped failure stops the copy (`test/pathological/a31-migrate-loop-rows.serial.test.ts`). Both source and target refuse any durable request history, withdrawal ledger, or ownership record before copying/clearing because this copier cannot preserve those identities.diff --git a/src/commands/doctor/checks/stale-mentions.ts b/src/commands/doctor/checks/stale-mentions.tsindex 0dbfdc35b3..47db98fc3c 100644--- a/src/commands/doctor/checks/stale-mentions.ts+++ b/src/commands/doctor/checks/stale-mentions.ts@@ -53,7 +53,7 @@ export async function staleMentionsCheck(engine: BrainEngine): Promise<Check> {.map(([k, n]) => `${n} ${k}`).join(', ');const unlink = res.examples.map(e => {- const argv = ['gbrain', 'unlink', e.from, e.to, '--link-type', e.link_type, '--link-source', 'mentions'];+ const argv = ['gbrain', 'unlink', '--link-type', e.link_type, '--link-source', 'mentions', '--', e.from, e.to];return { argv, command: shellQuote(argv) };});const eg = unlink.map((u, i) => `${res.examples[i]!.from} -> ${res.examples[i]!.to}: ${u.command}`).join('; ');diff --git a/src/commands/maintain.ts b/src/commands/maintain.tsindex ddfc153000..6d7203164c 100644--- a/src/commands/maintain.ts+++ b/src/commands/maintain.ts@@ -102,8 +102,8 @@ export interface SafePhaseProviders {export function maintainSafePhases(sourceId: string, providers: SafePhaseProviders): { phases: CyclePhase[]; held: CyclePhase[] } {const held: CyclePhase[] = [];if (providers.embedding || providers.decideConflict) held.push('extract_facts');- if (providers.fenceRepairModel) held.push('fence_repair');- if (providers.contentRepairModel) held.push('content_repair');+ if (providers.fenceRepairModel || providers.embedding) held.push('fence_repair');+ if (providers.contentRepairModel || providers.embedding) held.push('content_repair');const phases = resolveCyclePhases(undefined, sourceId).filter((phase) => MAINTAIN_SAFE_PHASES.includes(phase) && !held.includes(phase));return { phases, held };diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.tsindex 108ed2082f..f006bb79a1 100644--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@ -1515,7 +1515,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText;{ since: '0.60.655.0', id: 'memory_propose_held_writes_gst1158', text: 'New attested operation `memory_propose` (add it to `--attest-ops`): QM proposes one timeline entry or link on a shared page for the person it serves, and nothing is written until the brain owner runs `gbrain memory-proposals approve <request_id>` (`list`, `show`, `deny --reason`). `get_write_request` and `cancel_write_request` read and withdraw the proposal; an approved one becomes an ordinary write under the same request id. Held text stays in the `memory_proposals` table, out of git, export, search and recall. Proposals expire after `proposals.ttl_hours` (168), at most 10 wait per person and 50 per credential, and closed ones are deleted after `proposals.retention_days` (30). `gbrain doctor` (`memory_proposals_pending`) and `gbrain status` show the queue.' },{ since: '0.60.655.0', id: 'member_email_link_gst1158', text: 'A member can carry an operator-declared email: `gbrain access member add <id> --email <addr>` or `gbrain access member set <id> --email <addr>|none`, shown by `member list`, stored lower-case and unique per brain, and cleared when the member is removed. `gbrain access member link --email <addr> --qm <id>` (and `gbrain mcp admin link --email`, `member-add --email`, `member-set` over the owner session) links the one member that declares it, exactly as linking by member id does; an unknown email is `not_found` and creates nothing. No OAuth token, attested call or MCP tool can set an email or make a link.' },{ since: '0.60.655.0', id: 'qm_admin_http_gst1094', text: 'The brain owner can now manage the attest right, members and canonical-id links over the running server: `gbrain mcp admin attest <client> --attest-actor qm|none [--attest-ops <list>]`, `member-add`, `member-disable`, `member-enable`, `members`, `link <member> --qm <id>`, `unlink --qm <id>` and `links`, backed by `/admin/api/access/attest`, `/admin/api/access/members` and `/admin/api/access/member-links`. These routes take the owner session only (never an OAuth token or an MCP tool), refuse what the local `gbrain auth rescope` and `gbrain access member` commands refuse, preview with `--dry-run` where those do, and log each applied change as `access_admin`. Removing a member stays a brain-host command.' },- { since: 'TBD', id: 'maintain_safe_free_phases_gst2246', text: '`gbrain maintain --safe` no longer hard-deletes pages or runs paid phases. Its source cycle now runs only free phases that never purge (lint, backlinks, sync, the fence and content repair lanes, unindexed files, extract, extract_facts, symbol edges, emotional weight, consolidate, orphans and schema suggestions), and it holds back `extract_facts` when an embedding provider is set up or the decide conflict slot is on (its sweep calls the decision provider), and the repair lanes when `fences.repair.llm` has a repair model, because those would call a provider. Pages soft-deleted more than 72 hours ago are still purged by `gbrain pages purge-deleted` (preview it with `--dry-run`), `gbrain dream` and an installed autopilot; paid phases run from `gbrain dream`.' },+ { since: 'TBD', id: 'maintain_safe_free_phases_gst2246', text: '`gbrain maintain --safe` no longer hard-deletes pages or runs paid phases. Its source cycle now runs only free phases that never purge (lint, backlinks, sync, the fence and content repair lanes, unindexed files, extract, extract_facts, symbol edges, emotional weight, consolidate, orphans and schema suggestions), and it holds back `extract_facts` when an embedding provider is set up or the decide conflict slot is on (its sweep calls the decision provider), and the repair lanes when an embedding provider is set up (their publications embed) or `fences.repair.llm` has a repair model, because those would call a provider. Pages soft-deleted more than 72 hours ago are still purged by `gbrain pages purge-deleted` (preview it with `--dry-run`), `gbrain dream` and an installed autopilot; paid phases run from `gbrain dream`.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --git a/src/core/facts/purge.ts b/src/core/facts/purge.tsindex cfa3147724..ffd827c542 100644--- a/src/core/facts/purge.ts+++ b/src/core/facts/purge.ts@@ -558,7 +558,10 @@ export async function submitPurgeFactMutation(ctx: OperationContext, params: Rec.then(() => recordDerivationPurge(tx, admitted.id, p.sourceId, pageIds, [current.fact, escapeFenceCell(current.fact)])), current.id, p.sourceId);// 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;+ // Deleting a page's chunks voids the seal that certified them (#8502), also on a page whose body held no purged row.+ const chunks = inline.length ? (await tx.executeRaw(`WITH gone AS (DELETE FROM content_chunks WHERE page_id=ANY($1::integer[]) RETURNING page_id),+ unsealed AS (UPDATE pages SET text_projection_revision=NULL WHERE id IN (SELECT page_id FROM gone) AND text_projection_revision IS NOT NULL)+ SELECT 1 FROM gone`, [inline])).length : 0;const versions = await redactPageVersions(tx, p.sourceId, current.fact, pageIds);const ledger = await (await import('../generations/ledger-scrub.ts')).scrubGenerationLedger(tx, p.sourceId, { needles: [current.fact] });prose = versions.prose;diff --git a/test/doctor-stale-mentions-link-type-8814.test.ts b/test/doctor-stale-mentions-link-type-8814.test.tsindex 837a1745e5..ac3167a0aa 100644--- a/test/doctor-stale-mentions-link-type-8814.test.ts+++ b/test/doctor-stale-mentions-link-type-8814.test.ts@@ -5,6 +5,7 @@* (e.g. `founded`), so that command removed nothing. Each example now* carries its exact unlink command with the stored link_type.*/+import { parseOpArgs } from '../src/cli/main.ts';import { afterAll, beforeAll, expect, test } from 'bun:test';import { PGLiteEngine } from '../src/core/pglite-engine.ts';import { staleMentionsCheck } from '../src/commands/doctor/checks/stale-mentions.ts';@@ -34,7 +35,7 @@ test('the suggested unlink removes a stale typed_ner link', async () => {const ctx = { engine, remote: false, config: {}, logger: console, dryRun: false } as unknown as OperationContext;const removed = await operationsByName.remove_link!.handler(ctx, { from: 'notes/meeting', to: 'companies/acme-example', link_type: suggested![1], link_source: suggested![2] });expect(removed).toMatchObject({ removed: 1 });- expect(check.message).toContain('gbrain unlink notes/meeting companies/acme-example --link-type founded --link-source mentions');+ expect(check.message).toContain('gbrain unlink --link-type founded --link-source mentions -- notes/meeting companies/acme-example');expect(await engine.executeRaw("SELECT 1 FROM links WHERE link_source = 'mentions'")).toHaveLength(0);});@@ -47,7 +48,7 @@ test('the suggested unlink is shell-quoted: metacharacters reach gbrain as plainconst check = await staleMentionsCheck(engine);expect(check.status).toBe('warn');- const argv = ['gbrain', 'unlink', from, 'companies/acme-example', '--link-type', linkType, '--link-source', 'mentions'];+ const argv = ['gbrain', 'unlink', '--link-type', linkType, '--link-source', 'mentions', '--', from, 'companies/acme-example'];const command = shellQuote(argv);const run = Bun.spawnSync(['bash', '-c', `gbrain() { printf '%s\\0' "$@"; }; ${command}`]);expect(run.exitCode).toBe(0);@@ -55,3 +56,15 @@ test('the suggested unlink is shell-quoted: metacharacters reach gbrain as plainexpect(check.message).toContain(command);expect(check.details?.unlink).toEqual([{ argv, command }]);});++test('a slug that looks like a flag stays a positional in the suggested unlink', async () => {+ await engine.executeRaw("DELETE FROM links");+ const from = '--to=companies/beta-example';+ await engine.putPage(from, { type: 'note', title: 'Dashed', compiled_truth: 'Quiet day.', timeline: '', frontmatter: {} });+ await engine.addLinksBatch([{ from_slug: from, to_slug: 'companies/acme-example', link_type: 'mentions', link_source: 'mentions', link_kind: 'typed_ner' }]);++ const check = await staleMentionsCheck(engine);+ const [suggestion] = check.details?.unlink as { argv: string[] }[];+ const params = parseOpArgs(operationsByName.remove_link!, suggestion!.argv.slice(2));+ expect(params).toMatchObject({ from, to: 'companies/acme-example', link_type: 'mentions', link_source: 'mentions' });+});diff --git a/test/fact-purge-unrewritten-seal.test.ts b/test/fact-purge-unrewritten-seal.test.tsnew file mode 100644index 0000000000..7afa385399--- /dev/null+++ b/test/fact-purge-unrewritten-seal.test.ts@@ -0,0 +1,66 @@+/**+ * A fact purge deletes the chunks of every page its plan names, including a+ * page whose body did not hold the purged row and so was not rewritten. Such+ * a page loses its chunks, so its text projection seal must go with them, or+ * the embedding state reads it as sealed-empty and nothing ever re-chunks it+ * (R51 review of the doctor/dream/enrich train, #8502). Real PGLite.+ */+import { afterAll, beforeAll, expect, test } from 'bun:test';+import { randomUUID } from 'node:crypto';+import { mkdtempSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import type { OperationContext } from '../src/core/ops/contract.ts';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import { importFromContent } from '../src/core/import-file.ts';+import { runExtractFacts } from '../src/core/cycle/extract-facts.ts';+import { registerLocalWriter } from '../src/core/persistence/identity.ts';+import { operations } from '../src/core/operations.ts';+import { withEnv } from './helpers/with-env.ts';++const CLAIM = 'Gate code is 7731';+const home = mkdtempSync(join(tmpdir(), 'gbrain-purge-seal-'));+let engine: PGLiteEngine;++const fence = (rows: string[]) => `<!--- gbrain:facts:begin -->+| # | claim | kind | confidence | visibility | notability | valid_from | valid_until | source | context |+|---|-------|------|------------|------------|------------|------------|-------------|--------|---------|+${rows.join('\n')}+<!--- gbrain:facts:end -->`;+const ROW_TEA = '| 1 | Likes green tea | preference | 1.0 | world | medium | 2026-01-01 | | chat | |';+const ROW_CLAIM = `| 2 | ${CLAIM} | fact | 1.0 | world | medium | 2026-01-01 | | chat | |`;+const body = (rows: string[]) => `---\ntitle: Bob\ntype: person\n---\n# Bob\n\nProse about bob-example and the garden.\n\n## Facts\n\n${fence(rows)}\n`;++let ctx: OperationContext;+const purge = operations.find(o => o.name === 'purge_fact')!;++beforeAll(async () => withEnv({ GBRAIN_HOME: home }, async () => {+ engine = new PGLiteEngine(); await engine.connect({}); await engine.initSchema();+ await registerLocalWriter(engine, 'cli');+ ctx = { engine, sourceId: 'default', remote: false, dryRun: false,+ config: { engine: engine.kind }, logger: { info() {}, warn() {}, error() {} } } as unknown as OperationContext;+}), 120_000);+afterAll(async () => { await engine.disconnect(); rmSync(home, { recursive: true, force: true }); });++test('an unrewritten page whose chunks a purge deletes stays healable', async () => withEnv({ GBRAIN_HOME: home }, async () => {+ const slug = 'people/bob-example';+ await importFromContent(engine, slug, body([ROW_TEA, ROW_CLAIM]), { noEmbed: true, sourceId: 'default' });+ await runExtractFacts(engine, { slugs: [slug] });+ const [fact] = await engine.executeRaw<{ id: number }>('SELECT id FROM facts WHERE fact=$1 AND entity_slug=$2', [CLAIM, slug]);+ expect(fact).toBeDefined();+ await importFromContent(engine, slug, body([ROW_TEA]), { noEmbed: true, sourceId: 'default' });+ const [before] = await engine.executeRaw<{ sealed: boolean; chunks: number }>(+ `SELECT p.text_projection_revision IS NOT DISTINCT FROM p.knowledge_revision AS sealed,+ (SELECT count(*)::int FROM content_chunks c WHERE c.page_id = p.id) AS chunks FROM pages p WHERE p.slug = $1`, [slug]);+ expect(before).toEqual({ sealed: true, chunks: expect.any(Number) });+ expect(before!.chunks).toBeGreaterThan(0);+ const healableBefore = await engine.countChunklessPagesWithContent();+ const id = Number(fact!.id);+ const dry = await purge.handler(ctx, { id, dry_run: true }) as Record<string, unknown>;+ await purge.handler(ctx, { id, confirm: dry.confirm_token, expected_revision: dry.expected_revision, request_id: randomUUID() });+ const [after] = await engine.executeRaw<{ sealed: boolean; chunks: number }>(+ `SELECT p.text_projection_revision IS NOT DISTINCT FROM p.knowledge_revision AS sealed,+ (SELECT count(*)::int FROM content_chunks c WHERE c.page_id = p.id) AS chunks FROM pages p WHERE p.slug = $1`, [slug]);+ expect(after).toEqual({ sealed: false, chunks: 0 });+ expect(await engine.countChunklessPagesWithContent()).toBe(healableBefore + 1);+}), 60_000);diff --git a/test/fixtures/goldens/exports/runtime.json b/test/fixtures/goldens/exports/runtime.jsonindex 85601969e9..18bb5f18a3 100644--- a/test/fixtures/goldens/exports/runtime.json+++ b/test/fixtures/goldens/exports/runtime.json@@ -796,6 +796,7 @@"isFrontmatterHoldMessage","isRelativeFileUri","isTimelineHeadingAfterDash",+ "needsEmptyTimelineSentinel","nullBytesError","parseMarkdown","parseMarkdownHead",diff --git a/test/fixtures/goldens/exports/types.json b/test/fixtures/goldens/exports/types.jsonindex 120d64f811..7625834a13 100644--- a/test/fixtures/goldens/exports/types.json+++ b/test/fixtures/goldens/exports/types.json@@ -6161,6 +6161,13 @@"(trimmed: string) => boolean"]},+ {+ "kind": "variable",+ "name": "needsEmptyTimelineSentinel",+ "signature": [+ "(body: string) => boolean"+ ]+ },{"kind": "function","name": "nullBytesError",diff --git a/test/maintain.test.ts b/test/maintain.test.tsindex 946ee3cb62..0ed741b8cd 100644--- a/test/maintain.test.ts+++ b/test/maintain.test.ts@@ -134,6 +134,11 @@ describe('maintainSafePhases', () => {expect(phases).toContain('extract');});+ test('an embedding provider alone holds the repair lanes too, whose publications embed', () => {+ const { held } = maintainSafePhases('default', { ...NO_PROVIDERS, embedding: true });+ expect(held).toEqual(['extract_facts', 'fence_repair', 'content_repair']);+ });+test('a non-default source keeps its source-freshness subset', () => {expect(maintainSafePhases('wiki', NO_PROVIDERS).phases).toEqual(['lint', 'backlinks', 'sync', 'extract', 'extract_facts', 'recompute_emotional_weight']);});