Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge remote-tracking branch 'origin/master' into capy/recovered-serve-sync-and-owner-remember
garrytance0e370e850a
diff --cc CHANGELOG.mdindex cb2e42290a,0a40d412e5..4c3baeaafb--- a/CHANGELOG.md+++ b/CHANGELOG.md@@@ -10,19 -10,69 +10,82 @@@ 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 recovered `gbrain serve` syncs again, and the brain owner's `remember` works on a large page++**Syncs no longer fail after a `gbrain serve` recovers from status-only mode (#9224).** When `gbrain serve` starts while another gbrain process holds a PGLite brain (a second agent session, or a cron job), it answers with only `gbrain_status` until the brain opens, then takes over as the brain's owner. From then on, every `gbrain sync` handed to that owner that had pages to write failed with `storage_error` "The persistence owner could not complete this request", and the owner's own `sync_brain` failed with "Unknown engine kind for db-lock: pglite". This lasted until the agent session restarted. An ordinary install, where serve opens the brain when it starts, was not affected.+- The cause was in the stand-in engine that status-only serve runs on. On recovery it passed the live engine's methods through, but not its getters and fields, so PGLite's `db` handle was missing and the sync lock could not be taken. It also wrapped every method as `async`, so a synchronous method such as `registerBeforeDisconnect` returned a promise instead of its value, which broke a sync that got past the lock. After recovery the stand-in now exposes exactly the live engine's properties, read through to it, and a synchronous method returns its own value. A Postgres `gbrain serve` that started while its database was unreachable runs on the same stand-in and gets the same fix; its sync lock was never affected.- - An unexpected fault inside the owner now reaches the caller as `internal_error` (detail `owner_internal`) with an incident ID. The error says the request was not at fault, and that restarting that owner and rerunning the command recovers; with no owner running, the CLI opens the brain itself. A write also names its request ID to inspect first. The fix, `gbrain sources writer status --json`, is read-only and names the owner process. The cause itself goes only to the owner's own stderr, under the same incident ID and with connection strings redacted, and never crosses the local socket. Before, the caller got `storage_error` and a `gbrain doctor` fix that could not see the fault, and the owner logged nothing.++- An unexpected fault inside the owner now reaches the caller as `internal_error` (detail `owner_internal`) with an incident ID. The error says the request was not at fault, and that restarting that owner and rerunning the command recovers; with no owner running, the CLI opens the brain itself. A write also names its request ID to inspect first. The fix, `gbrain sources writer status --json`, is read-only and names the owner process. The owner's own stderr records the error class and the gbrain code location under the same incident ID, with connection strings redacted, and nothing about the cause crosses the local socket. Before, the caller got `storage_error` and a `gbrain doctor` fix that could not see the fault, and the owner logged nothing.++**The brain owner's `remember` works on an entity page stored in segments (#9213).** With a token bound to the brain owner, `remember` onto a large entity page (one stored in segments) was refused with `page_body_segmented` before it was admitted, while the same call from an unbound token committed. The owner's visibility checks copied the whole page object, and reading a segmented page's body as one string throws on purpose. Those checks now read only the page's labels, readers and identity. The same mistake is fixed in the member scope-page check, at admission and at preparation, and in the shared-origin retention purge of a page over 24 MiB. The guard that refuses whole-body reads of a segmented page is exactly as strict as before.+- A write refused with `page_body_segmented` no longer suggests `get_page body: "auto"`, which reads the page and doesn't help a write. A `remember` gets the fix that works, which is to save the claim without an entity, filed under `memory/unattributed`. Any other write over MCP gets a fix with no step to run that names the edits that do work on such a page: `edit_page`, `append_page`, `add_tag` and `remove_tag`. Reads keep the `get_page` fix.++Reported by @thiagodalvarenga (#9224) and @andreineacsu (#9213). First fixed by @Masashi-Ono0611 (#9231, #9215).++ ## [0.60.704.0] - 2026-11-12++ ### QM can read a room's context pack, and the owner sets how a client reads named sources from another machine++ **context_pack reads a room as its audience.** A QM client that reads named sources as the scope used to be refused when it asked `context_pack` for a room's source, so QM had no session brief in shared conversations. Now a call that names `source_id` reads only that source, which covers its entities and `entity_refs`, the core block, the counterparty brief and hot facts. Nothing from the person's own member page or from pages kept to named readers comes back, and privacy is never relaxed.+ - A scope call is refused with `invalid_params` before anything is read when it sends `entity_refs` without `source_id`, names an `entity_refs` entry in another source, or sends `session_id` (a session's thread rows are the person's).+ - A client set `--attest-read person` keeps reading as the person, and its pack is narrowed to the named source the same way.+ - Contract `docs/contracts/qm-memory-provider/v5.json` marks `context_pack` `scope_read: true`. v1 to v4 stay byte for byte as published, and v4's markings are frozen in the builder.++ **`gbrain mcp admin attest <client> --attest-read person|scope|none`** sets the same `attest_read` that `gbrain auth rescope --attest-read` sets, over the owner session (`attestRead` on `/admin/api/access/attest`). It refuses what the local command refuses, previews with `--dry-run`, and logs `attest_read` in the `access_admin` row.++ ## [0.60.703.0] - 2026-11-12++ **A missing link target written while another page's links are being extracted now wakes the page that mentions it.** A `[[Name]]` reference to a page that did not exist yet was saved with the time of the save. If the target page was written during the extraction, after the extractor had looked for it but before the save, the target looked older than the saved reference, so the stale link sweep never went back to the mentioning page and the link stayed missing until one of the two pages was edited again. v0.60.679.0 named this narrow race as open. Name and basename references are now stamped with the database time taken just before the extraction reads the pages it resolves against, so a target written after that read wakes the mentioning page once on the next sweep, and a target the extractor already saw never loops.++ - `src/core/wanted-links-store.ts`: `wantedReadAt` returns the database clock; `replaceWantedLinks` stamps name rows with the `readAt` its caller took before reading, and refuses name rows that arrive without one. Slug rows keep their v0.60.679.0 behaviour.+ - Every caller that writes name rows takes the read time first: `gbrain extract` (full and `--stale`, on every run, including a page that turns stale after the pre-flight count), the wanted-link sweep, link reconciliation, and link preparation on page writes.+ - Still open: on Postgres, a writer transaction that starts before the read time and commits after the extractor's read keeps an `updated_at` older than the stamp, so its mention waits for the next edit of either page.+ - Tests: `nameRowPublishedAfterItsTargetWasWrittenWakesItsOrigin` and `basenameRowPublishedAfterItsTargetWasWrittenWakesItsOrigin` in `test/wanted-links.test.ts` and `test/e2e/wanted-links-postgres.test.ts` (both red first), and `test/wanted-links-stale-count-race.test.ts`. Idea from @akinduroifedayo's #9149.+ - Also carries the nightly shard-weight refresh: `scripts/e2e-weights.json` and its metadata file, exactly as the weight miner wrote them from a full E2E nightly.++ ## [0.60.702.0] - 2026-11-12++ **A member can now be kept to pages labelled for it.** A group chat bot or a shared assistant bound to a member read every unlabelled page its source grant opened, and every summary, atom and fact made from them. `gbrain access member labelled-only <id> on` (off by default, unchanged on upgrade) keeps every credential of that member to pages that name it: the member or one of its groups in `readable_by`, or a folder or page rule listing them. Unlabelled pages, and derived pages and facts that name nobody, are hidden on every read path; with `access.members_read_lineage` on, a derived page passes only when every origin names the member. Writes follow the same rule. Only the operator on the brain host sets it, and never on the owner. It works the same on a repo-less brain and with rules in `access.yml`.++ ### Itemized changes++ #### Labelled-only members++ - The labelled-only migration (`src/core/schema-migrations/`, numbered at merge): `access_members.labelled_only` (default false) and the SQL function `gbrain_access_origin_labelled_for()`, which passes a derived page only when it has an origin and every origin names the caller. Nothing is rewritten.+ - `src/core/access/labelled-only.ts`: `gbrain access member labelled-only <id> [on|off]`, local operator only (remote callers get `permission_denied`), never on the owner (`access_labelled_only_owner`, exit 3; `gbrain access owner` refuses a labelled-only member the same way).+ - `src/core/search/private-visibility.ts`: `CallerAccess.labelledOnly` adds one conjunct to every caller page, version and fact filter; derived pages and facts that name nobody fail closed, and under member lineage pass only when every origin names the caller. Facts on the member's own member page stay readable, lineage on or off. `src/core/access/caller.ts`, `actor.ts` and `src/cli/as-preview.ts` set it for a labelled-only member, and `labelledOnlyFor` never reports the configured owner, on any door.+ - The remote read floor: `remoteReadFloorSql` and `remoteProvenanceFloorSql` (`private-visibility.ts`) are the plain page and fact fragments plus the labelled-only conjunct, and exactly the plain fragments for every other caller. Every remote read gate that is not caller-aware uses them: recorded-time reads (`get_page` and `get_versions` with `known_as_of`), the `as_of` amendment list, fact lookups by id (`remember replaces`, `forget`), belief history, proactive briefs, entity resolution and the sources-not-readable check. `test/remote-read-floor.test.ts` lists the write-side, maintenance and classification sites that keep the plain fragment, each with its reason.+ - Attested reads: a read that names sources for a labelled-only person is refused (`permission_denied`, `src/core/access/scope-read.ts`), since the scope read drops the member identity and the grant with it.+ - Writes: `src/core/persistence/page-visibility.ts` holds a labelled-only writer to the same read rule and refuses a create that would not name it (`access_labelled_only_unnamed`, checked in page preparation, streamed uploads and capture ingest); the enforced member CLI (`src/cli/enforced-member.ts`) does the same.+ - The semantic cache key (`xlo=1`) and the per-caller key (`labelled_only`) separate a labelled-only caller.+ - `gbrain access member list`, `access check` and `who-can-read` report it; doctor `access_labelled_only_members`.+ - Docs: `docs/guides/access-designations.md` (labelled-only members), `docs/guides/error-codes.md`, key-files entry.+ - Tests: `test/access-labelled-only.test.ts` (every read path, derived pages and facts with member lineage off and on, older versions, recorded-time and `as_of` reads, a fact by id, the member's own facts, the attested scope-read refusal and owner, writes over MCP, streamed uploads, capture ingest and the enforced CLI, the owner and remote refusals, cache keys, check, who-can-read and doctor; PGLite and Postgres, rules in the database and in `access.yml`); `test/remote-read-floor.test.ts`; migration, catalog and doctor goldens.++ ## [0.60.701.0] - 2026-11-12++ ### Flaky and slow tests fixed at their cause++ **Four tests that failed at random in CI now pass reliably, one E2E file is back under its time limit, and one of the fixes is a real bug: a cycle could re-read pages it had already handled.** Each fix was proven with a forced probe that reproduces the CI failure before the fix and passes after it. No assertion, timeout or retry limit was loosened.++ - `src/core/cycle/source-window.ts`: the cycle's page-listing cursor steps back to before the oldest transaction still open on another connection, so a page written by that transaction can't be missed. That count included Postgres autovacuum workers, which never write pages. An autovacuum pass open while the cycle listed pages made the next cycle read the pages written since that pass began a second time. Autovacuum workers no longer move the cursor (`test/sync-disabled-cycle-window.test.ts`).+ - `test/facts-entity-moved-7602.test.ts`: the test created and killed the page write's facts-absorb job before the write's own background effect had queued it. When the effect ran later, it found a dead job under its key and queued a fresh one, so the preview reported a waiting job. The test now waits for the effect to finish before it touches the job.+ - `test/persistence-index-lock-reclaim-6932.test.ts`: cleanup killed a helper shell whose `rm -rf` kept running after the shell died (dash forks a script's last command instead of replacing itself with it), and then ran `chmod -R` over the tree that `rm` was still deleting. Cleanup now waits for each helper to exit.+ - `test/e2e/worktree-refresh-postgres.test.ts` ran six refresh suites in one file and took 139 to 156 s on CI against the 180 s per-file limit. Its crash-recovery, orphan and diverged-publish suites moved to `test/e2e/worktree-refresh-recovery-postgres.test.ts`; all 95 cases still run, and each file takes about 100 s on a 4-vCPU machine.+ - `scripts/postgres-arm-weights.json`: the two PostgreSQL arm weights that were estimates now hold measured medians.+ - `test/docs-repo-paths.test.ts` (the scripts/ and test/ paths named in docs must exist) runs in `bun run verify` as `check:docs-repo-paths`. Before, it ran only in the full suite and in `scripts/ci-doc-checks.sh`, so a pull request's own checks never ran it, and a doc edit could name a missing path and pass.++ ## [0.60.700.0] - 2026-11-12++ ### A gbrain commit no longer reverts someone else's commit of the same file++ **When a script, an agent or a person commits their edit of a page file while gbrain is committing the same file, their commit now stays.** If that commit landed between gbrain reading HEAD and moving the branch, gbrain's one retry used to rebuild its commit on top of it with the bytes gbrain had staged earlier. HEAD silently went back to gbrain's version, the next sync reported success with nothing imported, the index kept the other version staged, and later edits to the page could be refused as an uncoordinated local edit. The other writer's bytes survived only in their own commit.++ - A managed brain's Git effect now checks, before each commit attempt, that no commit since it staged its files changed any of them and that the index still holds what it staged. When one did, it commits nothing over it. A file whose edit the other writer committed completes `superseded` (reason `committed_by_another_writer`), the next sync imports the other version, and gbrain's write stays in the page's history. Every other file in the group is put back and retried on the new HEAD, so a file that still holds gbrain's bytes is committed on top.+ - A strict (`canonical: git`) source's write refuses `git_target_changed` in the same case instead of rebuilding over the other commit, so recovery handles it the way it handles an edit made during the write.+ - To find edits a brain already lost this way, [docs/guides/shared-checkout-git.md](docs/guides/shared-checkout-git.md#effect-reverted-edits) has a read-only loop over the history.+## [0.60.699.0] - 2026-11-12### The Ubicloud gate VMs run a current git