Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Merge commit '2b20c6b99a2893d8aa516e75d8052685b6b8401e' into capy/sync-stops-holding-pages
garrytan264a13b76fba
diff --cc docs/architecture/key-files/canonical-reconciliation-continued.mdindex 95f4bc7b82,893ec1ebec..cdbfb9f8aa--- a/docs/architecture/key-files/canonical-reconciliation-continued.md+++ b/docs/architecture/key-files/canonical-reconciliation-continued.md@@@ -7,5 -7,6 +7,7 @@@ Current behavior and load-bearing invar- `src/commands/doctor/checks/rows-behind.ts` — doctor `sync_rows_behind_checkpoint` (BRAIN, after `sync_overwritten_db_edits`): per source counts and first slugs from `scanRowsBehind`; `warn` on `behind` rows with the read-only `gbrain repair rows-behind --source <id> --json` preview as the fix; `unknown` (info) when the `GBRAIN_DOCTOR_ROWS_BEHIND_TIMEOUT_MS` budget (default 10 s) stopped a scan or a checkout is unreadable; not applicable (ok) off the owner host and on repo-less brains.- `src/core/repair/rows-behind.ts` — `gbrain repair rows-behind --source <id>`: explicit-only, preview-bound (`--apply --expect <hash>`, `--include-ambiguous` adds rows with no import record). `reimport` submits the committed bytes through `submitManagedFileRepair`; `hold:<code>` writes the hold sync would have written (`writeGitHold`). Refused off the owner host (`not_owner_host`). Never runs on upgrade. Tests: `test/rows-behind-checkpoint-8071.test.ts` (PGLite and Postgres via `test/e2e/rows-behind-checkpoint-8071-postgres.test.ts`).- GST-2201, a file that comes back after sync deleted its page: `readShadowLevel` (`sync-pass.ts`) reads whether a tombstone is sync-made (`syncDeleteOrigin`, `sync-delete-tombstones.ts`) into `page.syncDeleted`, and `sync-classify.ts` classifies such a path `import` ahead of `deleted_same` / `deleted_edited` (uncommitted bytes take `dirty`; an old hold on it re-runs). The selection fingerprint carries `sync_deleted_restore`, so the first pass after the upgrade reads the whole level once. `originCommitted` (`sync-markers.ts`) says whether a page's file is in the tree at the source's `last_commit` or at HEAD (false off a managed checkout or for a company-brain source; an unreadable checkout counts as committed). A retention purge (`page-prepare.ts`) of a tombstone whose file is committed defers a sync-made tombstone (`revision_conflict`) and purges any other database-only (`databaseOnlyReason: committed_file`), so the file stays. Tests: `test/sync-restored-file-purge.test.ts` (PGLite and Postgres), `test/sync-classify-6712.test.ts`.+- `src/core/repair/file-drift-compare.ts` — GST-2568: `gbrain repair file-drift` with a selection and no `--prefer` (`compareSelection` in file-drift.ts) compares each page with its file through `comparePage` and writes nothing: `driftDifference` over the `reconcileCanonical` readings names what differs, `newerSide` compares the file's last commit at HEAD (`fileCommitEvidence`) with the page's `updated_at` (unknown with uncommitted bytes, a missing time or the same second), and the verdict is `release_hold`, `no_drift`, `prefer_file`, `needs_human` (a newer page, a page whose file is gone, a deleted page whose file differs) or `unknown`. A `--prefer file` preview reads `readDriftEvidence` first and lists a page newer than its file `kept_newer_page` (`newerPageParagraph`) unless `--slug` names it, which adds a warning instead. `linesNotCarried` counts the overwritten side's lines the result does not carry; `prepareDriftPage` renders both with `serializePageToMarkdown` and stores `lost_lines` on each page, which the listing, a total warning and `details.lost_lines_total` report. Test: `test/file-drift-normalisation-gst2568.test.ts`.++ - `src/core/persistence/grandfather.ts` — the retired v0.13.1 grandfather's request preparer (#7814). Upgrades no longer stamp `validate: false` into pages, so a `managed_grandfather` put_page request an older binary admitted and left queued is refused `revision_conflict` (the request ends `conflict`) and the page, its file and its revision stay unchanged. The refusal records origin `grandfather_retired` (it outlives receipt compaction), and `classifyTerminal` reads it, or an uncompacted `managed_grandfather` intent, as the always-historical `retired_operation` category, so doctor `persistence_terminal_failures` counts it as history with a "retired grandfather, nothing to do" note (#7837). Neither file holds a canonical write reference any more, so neither has a `canonical-writers.tsv` row and a new write there trips the census. `test/grandfather-managed.test.ts` covers it.- `src/core/persistence/unimported-file.ts` — GST-2579: `unimportedFile(engine, state)` reports a page file whose bytes are neither in sync's import record (`raw_sha256`/`disk_sha256`) nor a git effect gbrain wrote for a revision the page has held (live `knowledge_revision` or a `page_versions` row), with the last commit that touched it (`lastCommitOf` in `pending-import.ts`); no import record counts as newer. `discardedFilePaths` names the decided paths whose result drops the file's value. `repair/file-drift.ts` skips such pages in bulk (`kept_newer_file`; a recreate over another writer's delete is `kept_newer_delete`), names the commit for `--slug`, and `fileDriftConsentText` lists them in the consent the registry's `consent: 'destructive'` asks for. `reconcile.ts` refuses a preview, and an admitted apply (the `guard` on `admitReconcileArtifact`; keep_db passes none), whose result takes the database over such a file (`unimportedFileRefusal`, `source_changed` / `unimported_file_edit`). Test: `test/db-wins-unimported-gst2579.test.ts`.diff --cc test/postgres-unit-arms.txtindex eeb4014f6b,2276be364d..5ca64ca05e--- a/test/postgres-unit-arms.txt+++ b/test/postgres-unit-arms.txt@@@ -125,9 -126,9 +126,10 @@@ test/fence-fact-append.test.ttest/fence-first-generation-8819.test.tstest/fence-repair-receipts.test.tstest/fenced-embed-reuse-6961.test.ts+test/file-drift-normalisation-gst2568.test.tstest/file-drift-soft-delete-hold-release-gbra133.test.tstest/forecast-journal.test.ts+ test/forget-door-landed-gst2517.test.tstest/frontmatter-reserved-keys-6454.test.tstest/g4-forget-fence-edit.test.tstest/gated-hold-strict-page-gst2535.test.ts