Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/master' into capy/fix-7172-timeline-chunk-reuse
garrytan920e6ae919b4
diff --cc CHANGELOG.mdindex 1f3d5d03db,9f6dc3e84a..a853e4c85d--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,35 -10,81 +10,110 @@@ credits are retained; no result has beeidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased]++**A timeline entry no longer rewrites the passages it didn't change, and a big passage replacement can't time out the write that carries it (#7172).** A managed write replaced its page's passages inside its publication, under the publication's 5 s statement bound. A passage whose index moved (a long entry near the top of a descending timeline adds a passage above the others) was deleted and inserted again with its vector, and on a large index each inserted row can cost about half a second, so the write ended `write_interrupted` (SQLSTATE 57014) on every attempt. Separately, a page whose stored embedding signature was missing or in an older format had every passage re-embedded after each write, which looked the same from outside: every passage got a new embedding time.++### What changed++| Situation | Before | Now |+|---|---|---|+| An entry shifts unchanged passages to new indexes | each moved passage deleted and re-inserted (vector copied) | the row keeps its id and vector and changes index in place |+| A managed put_page, edit_page, add_timeline_entry, tag write, import or sync whose passages need more than 5 vector-index writes (a passage that carries a vector, inserted or renumbered) | all of them in one statement inside the publication; on a slow index, 57014 on every attempt, then `write_interrupted` | the page commits first; its passages finish in post-commit transactions of at most 5 vector-index writes each, then the projection is sealed. Passages without a vector (new text, a new page) are still written in the publication, as before |+| Search during those steps | n/a | the page's passages are hidden until the seal (as for any pending projection); the receipt says `searchable: "pending"` and turns `true` when sealed |+| The embedding step after a write, page signature missing or older format | every passage re-embedded (paid) | passages whose recorded embedding input is current keep their vectors; the page signature is restamped |++The bound of 5 is derived in `src/core/page-state/chunk-moves.ts` (`CHUNK_VECTOR_WRITE_BUDGET`): a row version that carries a vector adds an HNSW entry, a graph search over the whole index that nothing amortizes across rows, while one without a vector adds no HNSW entry and only cheap b-tree and GIN pending-list entries (measured on pgvector: 300 passages inserted in 2.2 s with vectors and 0.06 s without; 300 renumbered in about 1 s with vectors and 0.002 s without). The slowest reported rate on a large index is about 0.5 s per vector-carrying row, and half of the 5 s statement bound is left for the rest of the write. No timeout, retry or deadline is raised, and nothing is configurable.++### What to watch for after you upgrade++- A write that was blocked by repeated `write_interrupted` (57014) on a large page can be submitted again; it commits and finishes its passages right after.+- If a page's receipt stays `searchable: "pending"` for more than a minute, no process is finishing it: run `gbrain projections drain`.+- When a top entry changes the text of every passage below it (the chunker packs about 300 words with a 50-word overlap, so a short entry can shift every boundary), those passages are new text and are embedded again; this release does not change the chunker.++### Itemized changes++- `reuseStoredChunkVectors` matches a stored row by source and text at any index (its own index first), so a kept row can move.+- New `src/core/page-state/chunk-moves.ts`: the vector-index write bound and the move planner (one UPDATE per wave; a cycle parks one row at a negative index).+- `continueDeferredProjection` runs the bounded steps after commit, holding the page's queue row under a claim it renews each step (the lease a segmented projection claim uses); the projection drain resumes a page whose steps stopped (queue reason `chunk_replacement_deferred`). A group publication now runs its members' post-commit work, as a single publication does.+- Writes that wrap a page publication in their own (takes, the facts fence, maintenance pages) still replace passages in one transaction.+- `readEmbeddingEffectProjection` accepts a vector whose recorded input hash is one the current page accepts, whatever the page-level signature says, and restamps the page.++ ## [0.60.332.0] - 2026-10-21++ **`search` and `query` stop spending result slots on copies of one page, and `--explain` shows both retrieval arms again.** The same page in two sources, a merge stub beside its target, and the summary and transcript of one document each used to take their own slot in the top 10. They now fold into the best-ranked row, which lists what it absorbed in `collapsed`.++ ### What changed++ | Situation | Before | Now |+ |---|---|---|+ | The same slug in two sources with copied bodies | two rows | one row; the other copy is listed in `collapsed` (reason `twin`) |+ | A merge or redirect stub and its target | the stub could rank above the target | the target takes the slot; a stub whose target can't be returned stays, stamped `redirect_to` and ranked ×0.5 |+ | Summary, transcript and diarized copies of one document in one directory | one slot each | one row (reason `family`) |+ | An organization question that names no person | the founder's page could outrank the company | person pages ×0.85 |+ | An image page whose text covers half the query or less | ranked like a text page | ×0.6, stamped `image_page` |+ | An undated page on a "when" question | no penalty | ×0.85 |+ | `score` down the result list | could go up | follows rank; the previous value is `fused_score` |+ | A chunk row longer than 8,000 characters | returned whole | cut at 8,000 with a marker naming the read for the rest; `snippet_chars: 0` returns it whole |+ | `gbrain search/query --explain` on a hybrid brain | printed `arms: []` and `rrf: not_run` | shows both arms, with fusion and blend applied |+ | A keyword or vector arm that timed out, on the CLI | nothing said so | a `degraded_recall` notice on stderr, `--json` included |+ | The `query` tool description | implied expansion helps | says `expand` is one LLM call and rarely helps |++ Opt-outs: `search.collapse false` and `search.rank_priors false`. Nothing is rewritten on upgrade.++ ## [0.60.331.0] - 2026-10-20++ **Writing many facts at once no longer costs one guard call per row, new pages over 4 MiB reply as soon as they commit, and a remote `append_page` links what it mentions.** The facts purge refusal and withdrawal stamp ran once per row, so a 6,000-row publish spent most of its publication deadline in triggers (#7105). A managed import of a large new page waited for its whole search index to build before replying, which on a loaded host outlasted the deadline (#7106). A remote append added text with links that never became graph edges (#7122).++ ### What changed++ | Situation | Before | Now |+ |---|---|---|+ | A publish inserts thousands of facts | the purge refusal and the withdrawal stamp ran once per row | they run once per statement over the inserted rows; `INSERT … RETURNING` still sees the stamp (migration v264) |+ | A managed `gbrain import` or `gbrain sync`, or a `put_page`, of a new page over 4 MiB stored in segments | replied after its search index was built | replies at commit with `searchable: 'pending'`; the index builds in the background, one at a time. Edits still reply when sealed |+ | A remote `append_page` to a page body with `[[wikilinks]]`, markdown links or page paths | no links were added | plain `mentions` links (`mcp-remote-mention`) to existing pages the writer can see |+ | An owner `append_page` to a page with a purged claim | (undocumented) | still not an owner edit, so it doesn't release the claim's redaction (#7123) |+ | A lane sync reaches a page whose preparation ran past its budget | another lane could claim and prepare it again, overwriting its deadline | the worktree waits for the abandoned preparation to end, and so does a foreground write to it |++ Nothing changes on upgrade beyond migration v264, which replaces the per-row facts triggers with statement-level ones.++ ### For contributors++ - `test/sync-pass-xid-arms-gbra108.test.ts` drew snapshot xmax values PostgreSQL never reports (`TransactionIdAdvance` skips low words 0–2), so it failed whenever a new migration moved `txid_current()` onto them. It now draws only reportable values.++ ## [0.60.330.0] - 2026-10-20++ **Sync no longer deletes a page just because its file is missing when Git never had that file, and the autopilot purge no longer hard-deletes what a sync deleted without review.** A large managed source lost thousands of agent-written pages: their write-through files sat in a `.gitignore`d directory, so they were never committed; when they left the disk, sync read their absence as deletions (4% of the source, under the 50% valve), and the purge phase hard-deleted them 72 hours later (#7130, reported by @liuwenyong1985).++ ### What changed++ | Situation | Before | Now |+ |---|---|---|+ | A live page's file is missing and Git never committed it (ignored, or never added) | managed sync soft-deleted the page | the page is held `file_drift` (side `deleted`, reason `never_committed` or `ignored`); a person decides with `gbrain repair file-drift --prefer file` |+ | A committed file is removed in a commit | the page is deleted | unchanged |+ | One sync run deletes many pages below the 50% valve | nothing stopped it | `sync.max_deletes` (500) and `sync.max_delete_ratio` (1%, above 50 deletes), per source too, withhold the deletes and ask the user; managed passes, classic `sync --full` and working-tree syncs |+ | Classic `sync --full` when `git log --all` fails (a dangling ref) | every stale page was deleted | every stale page is kept, with a warning |+ | The autopilot purge reaches a sync tombstone no live page duplicates | hard-deleted after 72 h | held (`sync_delete_unreviewed`); `gbrain pages purge-deleted` purges it after consent |+ | The purge window | fixed 72 h | `purge.retention_hours`, which can only lengthen it (default and minimum 72) |+ | A managed put_page or capture of a new page into an ignored directory, on a source without Git durability | wrote a file Git would never commit | the page is database-only |+ | Pages a sync already deleted this way | no way to find them | doctor `uncommitted_sync_deletions` and the preview-first `gbrain repair uncommitted-deletions --source <id>` restore them database-only |++ Pages the purge already hard-deleted come back only from a backup (`pg_dump`, or a `gbrain backup create` taken before the purge). Nothing changes on upgrade; the repair runs only when named.++ ## [0.60.329.0] - 2026-10-20++ **Five tests that failed once each on CI are fixed at their causes, and two of the causes were real bugs.** An unchanged transcript re-ingest on Postgres could admit a no-op page write (and spend a request id), and a sync that held its lock while a write admission rebuilt the database pool threw at the very end and left its lock row behind.++ ### What changed++ | Situation | Before | Now |+ |---|---|---|+ | Re-ingesting an unchanged transcript right after its page was written (Postgres) | the unchanged-page screen counted the just-committed write as still pending while its post-commit cleanup ran, so the rerun admitted a no-op put_page | only unfinished writes (queued, running, recovering) hold the screen; a finished write's page and canonical file are final |+ | A sync whose lock was held across a reconnect (a write admission that lost its connection) | the lock release ran on the ended pool: `CONNECTION_ENDED` after the work finished, lock row left until its TTL | release and exit cleanup run on the engine's live pool |+ | `worker-shutdown-error-matrix`, `persistence-memory-mutations`, belief-ledger probe 17 | each could fail on a loaded runner | each waits for the event its contract names (handler started, provider call in flight, consumer disposed) |++ No timeout, budget, retry or assertion is loosened.+## [0.60.328.0] - 2026-10-20**A Google API that's disabled in your OAuth project is now reported as itself, all at once, instead of looking like a different account.** When Gmail, Calendar or People was disabled (or a scope wasn't granted), a managed Google source could not read the account, so the sync failed or refused with `connector_account_changed`, and setup only found out one API at a time. The account now resolves through Google's sign-in identity, the services that work keep syncing, and setup, `gbrain google status` and doctor name every disabled API with its project and enable link in one report.diff --cc src/core/behavior-change-notice.tsindex 09c34b89b8,41187c672c..1364248cef--- a/src/core/behavior-change-notice.ts+++ b/src/core/behavior-change-notice.ts@@@ -1023,9 -1023,23 +1023,26 @@@ export const BEHAVIOR_CHANGES: Readonly{ since: '0.60.327.0', text: 'Fact extraction no longer rewrites the facts it stores: the prompt-injection filter used to delete words such as "System" before a parenthesis, so "Business System (ABS)" was saved as "Business [redacted](ABS)". Injection phrases are now neutralized only where stored facts are rendered into a model prompt (standing questions, turn context, proactive briefs). `gbrain doctor --only facts_redaction_marker` counts facts damaged earlier; `gbrain repair redacted-facts` previews what a source page can prove and changes nothing until you apply the printed `--apply --expect <hash>` command.' },{ since: '0.60.327.0', text: 'The embed sweep that finds chunks whose text changed after they were embedded now runs in 5,000-chunk batches, keeps its place between runs (at most 60 seconds per run) and starts a new pass once a day (`embed.content_drift.pass_interval_hours`, default 24); before, one statement covered the whole brain and a large brain cancelled it on every run. `gbrain doctor --only content_drift_sweep` shows each pass and any error.' },{ since: '0.60.328.0', id: 'google_api_access_probe', text: 'A managed Google source whose enabled services cannot name the account (an API disabled for the OAuth project, a scope not granted) now resolves it through the OAuth userinfo endpoint: the account pins, the services that work keep syncing, the run is `partial`, and the disabled API is reported as `api_not_enabled` instead of failing the whole sync. `connector_account_changed` is raised only when an account resolved and differs from the pin; when nothing can name the account (userinfo also failing), the sync fails with the underlying error, a network failure included, instead of refusing as an account change. `gbrain google setup` now probes every requested service before registering a source and stops (exit 2, `status: api_access_blocked`) naming each disabled API with its Google Cloud project and enable link, or each scope not granted, in one report. `gbrain google status` adds `accounts[].api_access` and exits 1 while a problem remains, and doctor adds `google_api_access`, read from what the last sync recorded. A Google 403 for insufficient authentication scopes is now `scope_missing` (before: `upstream`, and a calendar read named it `calendar_unreadable`).' },+ // #7130 (sync deleting pages whose file Git never committed; autopilot purge hard-deleting them). `since` is restamped at the merge slot.+ { since: '0.60.330.0', text: 'A managed sync no longer deletes a live page whose recorded file is missing when Git never committed that file (#7130): a page whose file no commit of the pinned history or the pass\'s baseline holds is held `file_drift` (side `deleted`, state `file_gone`, `meta.reason` `ignored` when `.gitignore` excludes the path, else `never_committed`) instead, in a normal pass, under `--full` and in the dry run. A file that was committed and then removed still deletes its page. When Git cannot answer (a failed or timed-out read), the page is held. `gbrain repair file-drift --prefer file` still applies the deletion after review, and committing the file again clears the hold. On a source without Git durability, a managed put_page or capture of a new page whose file would land under a path `.gitignore` excludes, now writes no file and records none: the page is database-only, so no later sync can read the missing file as a deletion.' },+ { since: '0.60.330.0', text: 'Sync now caps how many pages one run deletes (#7130): new settings `sync.max_deletes` (default 500) and `sync.max_delete_ratio` (default 0.01, applied above 50 deletes), each with a per-source override `<key>.source.<id>`, on top of the 50% valve. A managed pass over a cap withholds its deletes through the existing `deletes_withheld` record (it names the cap that tripped), the dry run lists them, and `gbrain sync status` asks the user (`ask_user`) before anything raises the cap; a classic full reconcile and a working-tree sync (on a detached HEAD too) skip the deletes with a warning naming the cap. Adds and edits still import. `GBRAIN_ALLOW_MASS_RECONCILE=1` lets a deletion through as before, and `gbrain config set` refuses a cap that is not a whole number of 0 or more (ratio: a number from 0 to 1).' },+ { since: '0.60.330.0', text: 'Classic `gbrain sync --full` no longer deletes pages it cannot prove were removed (#7130): when Git cannot list the history that shows their files were committed (a dangling ref fails `git log --all`), it keeps every stale page with a warning, where before it skipped the never-committed check and deleted them all. With readable history it deletes as before.' },+ { since: '0.60.330.0', text: 'The autopilot purge phase and the `purge` job no longer hard-delete a page that a managed sync soft-deleted unless another live page of the same source has identical content (#7130). Each sync deletion now leaves a durable record (op_checkpoints `sync-delete-tombstone`; a tombstone from before this release is recognized by its uncompacted `managed_sync_delete` receipt, and one whose receipt was compacted is not). Held pages are reported as `sync_delete_unreviewed` in the phase\'s `purged_pages_blocked` and counted in `held`, and the phase reports warn. `gbrain pages purge-deleted` still purges them after consent: its dry run reports `sync_unreviewed` and its consent text names how many of the set are sync deletions with no live twin and that a purged page can only come back from a backup. The purge phase\'s recovery window (pages and orphan clone temp dirs), and the `purge` job\'s default, now follow `purge.retention_hours` instead of a fixed 72 hours. It can only lengthen the window (default and minimum 72, so a 72-hour restore promise always holds); `gbrain config set` refuses a smaller value.' },+ { since: '0.60.330.0', text: 'New doctor check `uncommitted_sync_deletions` and explicit-only repair kind `gbrain repair uncommitted-deletions --source <id>` (#7130): on each managed source\'s owner host, doctor warns about soft-deleted pages a sync removed although Git never held their recorded file (`.gitignore` excludes it, or no commit holds it and it is not on the disk), bounded to 20,000 tombstones per source and 2,000 Git evidence reads per run. The repair previews each page (slug, recorded path, deletion time, evidence, whether a sync deleted it) with a hash; `--apply --expect <hash> --yes` restores exactly that set, each page live and database-only (detached: it forgets its recorded file and no file is written), so the next sync keeps it. Pages another writer deleted join only with `--include-ambiguous`; a sync deletion is recognized by its record or receipt for the page\'s current tombstone. A preview reads one bounded window, newest page id first, and `--after <page-id>` (named in the preview\'s `next_after` and in the doctor message) continues past it. It refuses off the owner host (`not_owner_host`) and a changed plan (`preview_changed`); without `--yes` a non-interactive run exits 3 and changes nothing. Pages already purged cannot be restored by this command; only a backup (pg_dump, or `gbrain backup create`) can bring them back. It never runs on upgrade or automatically.' },+ // Wave B follow-ups lane F2 (#7106: a managed import or sync of a new page over 4 MiB replies at commit). `since` is stamped at the merge slot.+ { since: '0.60.331.0', text: 'A managed `gbrain import` or `gbrain sync` of a new page over 4 MiB stored in segments now replies when the write commits, before its search index is built, instead of waiting for that build (which on a loaded host outlasted the 30 s import wait and replied `write_pending`). The import result and the write\'s receipt say `searchable: "pending"` and `projection: "pending"`; the import result also carries the `request_id`, `searchable_retry_after_ms` and `searchable_fix`. Read the receipt again (`gbrain write-request -- <request_id>`, `get_write_request`) at that interval until it says `searchable: true`; search finds the page from then on. The build no longer holds up the source\'s next write either. A new page up to 4 MiB, and an edit of a page stored in segments, is still searchable when its import replies (`searchable: true`). A `put_page` of a new page over 4 MiB, whose receipt already said `searchable: "pending"`, now also replies at commit instead of after the build.' },+ // Wave B follow-ups lane F3 (#7122 remote append_page mention links). `since` is stamped at the merge slot.+ { since: '0.60.331.0', text: 'A remote `append_page` to the body of a page now adds plain `mentions` links (link source `mcp-remote-mention`) for the `[[wikilinks]]`, markdown links and page paths in the appended text, to existing pages the writer can see inside its grant, as a remote `put_page` does. The post-commit pass reads only the appended text, never the rest of a large page, and never removes a link. `gbrain config set mcp.remote_auto_links off` turns it off.' },+ // Wave B follow-ups lane F4 (an abandoned lane preparation bars its worktree). `since` is stamped at the merge slot.+ { since: '0.60.331.0', text: 'During a managed sync that publishes in lanes, a page whose preparation ran past its budget is no longer claimed and prepared again by another lane while the abandoned preparation still runs; that worktree now waits for it, as a sync without lanes always did, until it settles or `persistence.preparation_ceiling_ms` passes. A foreground write to that worktree waits the same way meanwhile. The page keeps its `preparation_deadline` reason until it is claimed again.' },+ { since: '0.60.332.0', text: 'search and query fold copies of one result into the best-ranked row before reranking: the same slug in another source, a redirect stub (frontmatter `redirect_to`/`merged_into`, a `*-redirect` page or a short "merged into [[...]]" body) whose target is readable, and copies of one document (identical bodies, or a derivative `-summary`/`-transcript` slug in the same source). The kept row lists the folded pages under `collapsed` with `slug`, `source_id` and `reason`; an unresolved stub stays, stamped `redirect_to`, and ranks lower. `gbrain config set search.collapse false` turns it off.' },+ { since: '0.60.332.0', text: 'search and query apply small rank priors after reranking: a person page ranks a little lower on a question about a company or organization that names no person, an image page whose text barely covers the query ranks lower (stamped `image_page`), an undated page ranks a little lower on a when-question, and a redirect stub ranks lower. Each changed row carries `rank_prior` and `rank_score`. `gbrain config set search.rank_priors false` turns them off.' },+ { since: '0.60.332.0', text: 'The `score` that search and query return now never increases down the list: in a reranked list it is the rerank score (times any rank prior), and a pinned or unreranked row takes its neighbour\'s value. The fused score it replaced stays on the row as `fused_score`.' },+ { since: '0.60.332.0', text: 'One search or query chunk row returns at most 8,000 characters of chunk text by default, ending with the marker that names the read for the rest (an old oversized chunk could return tens of thousands). Pass `snippet_chars: 0` for the full chunk. Evidence blocks (conversations, long-page units) keep their own budget and cap.' },+ { since: '0.60.332.0', text: '`gbrain search --explain` and `gbrain query --explain` now pass explain to the search, so `score_details` reports the arms, RRF and blend that ran; before, every row said `single_arm_path` / `no_query_embedding` even when both arms ran. A CLI search or query whose keyword or vector arm failed or timed out now prints the `degraded_recall` notice on stderr (the `--json` array stays bare), as MCP already did.' },+ // #7172. `since` is restamped at the merge slot.+ { since: 'TBD', text: 'A managed put_page, edit_page, add_timeline_entry, add_tag or remove_tag, managed import or sync whose passages need more than 5 vector-index writes (a passage carrying a vector, inserted or renumbered) commits the page first and finishes its passages in post-commit transactions of at most 5 vector-index writes each, instead of writing them all inside the publication, where a slow index could end it 57014 `write_interrupted`. Search sees the page once the last step seals it; until then its receipt says `searchable: "pending"`, and `gbrain projections drain` finishes a page whose writer stopped. A passage whose text is unchanged keeps its row and vector when an entry above it moves it to another index.' },+ { since: 'TBD', text: 'The embedding step after a managed write no longer re-embeds every passage of a page whose stored embedding signature is missing or in an older format: a passage whose recorded embedding input is still current keeps its vector and the page signature is restamped, so only passages whose text changed reach the embedding provider.' },];/** The newest disclosed change's release: the notice id moves only when a release adds rows. */diff --cc src/core/persistence/import-prepare.tsindex 239a976be9,581e2f3da4..8e1ca77007--- a/src/core/persistence/import-prepare.ts+++ b/src/core/persistence/import-prepare.ts@@@ -288,12 -290,13 +290,13 @@@ export async function prepareManagedImpawait project(tx, final?.page.id);if (applied?.segmented) { if (applied.segmented.complete && live) await sealSegmentedPage(tx, Number(live.page.id)); }else if (applied?.chunkerSeal !== undefined) await sealImportedPage(tx, row.slug, row.source_id, live, applied.chunkerSeal, applied.pageId);- else if (live) await sealPageTextProjection(tx, row.slug, row.source_id, live);+ else if (live && !applied?.projectionPending) await sealPageTextProjection(tx, row.slug, row.source_id, live);}mutation.postimage = final;- } else if (!ready.noop && !image) await sealPageTextProjection(tx, row.slug, row.source_id);+ } else if (!ready.noop && !image && !applied?.projectionPending) await sealPageTextProjection(tx, row.slug, row.source_id);// #6188: the canonical file is written from the normalized page; the outcome reports what Tier 1 rewrote.- return { ...result, parsedPage: undefined, imported_file: true, source_id: row.source_id, fences_normalized: result.fences_normalized?.length+ return { ...result, parsedPage: undefined, imported_file: true, source_id: row.source_id,+ ...(ready.noop ? {} : segmentedOutcome(applied?.segmented, isQuarantined(ready.parsedPage?.frontmatter ?? {}))), fences_normalized: result.fences_normalized?.length? pageFencesNormalized({ sourceId: row.source_id, slug: row.slug, fixes: result.fences_normalized, writer: row.principal_kind, path: p.sourcePath, remote: false }) : undefined };} };return mutation;