Garry's Opinionated OpenClaw/Hermes Agent Brain
Canonical reconciliation (continued)
Subsystem index · Previous entries. Read only the entries relevant to your change. Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.
src/core/persistence/rows-behind.ts— #8071:scanRowsBehind(engine, sourceId, { deadlineAt })finds live Markdown pages of a managed source whose row holds an older version of its file thansources.last_commit, with no hold. It reads the checkpoint tree from Git (readHeadTree(root, commit)), compares each page in id batches of 256 with the committed blob (compareInlineExportFile, orcompareSegmentedExportBlobfor a page stored in segments) and confirms a difference withprepareRepairPublication; direction comes from the page's sync import record (behindwhen its revision is the recorded one,unprovenwithout a record,database_movedskipped). Paths sync would not import (loadSyncEligibilityfromsync-discovery.ts) are skippednot_eligible. A blob overSYNC_READ_BOUNDis never read and reported withfile_too_large. Blobs are read and compared in chunks of at mostROWS_BEHIND_BATCH_BYTES(64 MiB) and dropped after the comparison, and the deadline is checked before each tree read and each chunk, so one batch of large files neither holds every blob in memory nor runs past the budget. Owner host only; a repo-less brain isnot_applicable.src/commands/doctor/checks/rows-behind.ts— doctorsync_rows_behind_checkpoint(BRAIN, aftersync_overwritten_db_edits): per source counts and first slugs fromscanRowsBehind;warnonbehindrows with the read-onlygbrain repair rows-behind --source <id> --jsonpreview as the fix;unknown(info) when theGBRAIN_DOCTOR_ROWS_BEHIND_TIMEOUT_MSbudget (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-ambiguousadds rows with no import record).reimportsubmits the committed bytes throughsubmitManagedFileRepair;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 viatest/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) intopage.syncDeleted, andsync-classify.tsclassifies such a pathimportahead ofdeleted_same/deleted_edited(uncommitted bytes takedirty; an old hold on it re-runs). The selection fingerprint carriessync_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'slast_commitor 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-driftwith a selection and no--prefer(compareSelectionin file-drift.ts) compares each page with its file throughcomparePageand writes nothing:driftDifferenceover thereconcileCanonicalreadings names what differs,newerSidecompares the file's last commit at HEAD (fileCommitEvidence) with the page'supdated_at(unknown with uncommitted bytes, a missing time or the same second), and the verdict isrelease_hold,no_drift,prefer_file,needs_human(a newer page, a page whose file is gone, a deleted page whose file differs) orunknown. A--prefer filepreview readsreadDriftEvidencefirst and lists a page newer than its filekept_newer_page(newerPageParagraph) unless--slugnames it, which adds a warning instead.linesNotCarriedcounts the overwritten side's lines the result does not carry;prepareDriftPagerenders both withserializePageToMarkdownand storeslost_lineson each page, which the listing, a total warning anddetails.lost_lines_totalreport. 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 stampvalidate: falseinto pages, so amanaged_grandfatherput_page request an older binary admitted and left queued is refusedrevision_conflict(the request endsconflict) and the page, its file and its revision stay unchanged. The refusal records origingrandfather_retired(it outlives receipt compaction), andclassifyTerminalreads it, or an uncompactedmanaged_grandfatherintent, as the always-historicalretired_operationcategory, so doctorpersistence_terminal_failurescounts it as history with a "retired grandfather, nothing to do" note (#7837). Neither file holds a canonical write reference any more, so neither has acanonical-writers.tsvrow and a new write there trips the census.test/grandfather-managed.test.tscovers 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 (liveknowledge_revisionor apage_versionsrow), with the last commit that touched it (lastCommitOfinpending-import.ts); no import record counts as newer.discardedFilePathsnames the decided paths whose result drops the file's value.repair/file-drift.tsskips such pages in bulk (kept_newer_file; a recreate over another writer's delete iskept_newer_delete), names the commit for--slug, andfileDriftConsentTextlists them in the consent the registry'sconsent: 'destructive'asks for.reconcile.tsrefuses a preview, and an admitted apply (theguardonadmitReconcileArtifact; 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.src/core/persistence/sync-holds-carried.ts— the holds a source carries by design:mirrorDatabaseOnlyHold,mirrorKeepDeletedHold,carriedHoldsandheldDriftPreviewArgv(re-exported fromsync-holds.ts). Keep the deletion on a mirror: on a read-only mirror (sourceMirrorReadOnly),deletedPageturns--held --side deleted --state tombstone_edited --prefer databaseinto aKeepDeletedPage(keep_deleted) bound to the sameDeletedDriftPin;applyKeepDeletedre-checks the pin and recordsmeta.keep_deletedon the hold (recordKeepDeletedinsync-holds.ts, guarded on the observed hold), writing no file or page, and a decided hold previewsmirror_keep_deleted.writeGitHoldcarries the decision across a rewrite with the sameblob_oidand state (carriedKeepDeleted; a tombstone purged topurged_differsrebinds it to the deletion marker's digest);holdBasisMovedre-checks a kept hold whose tombstone was restored, purged or rewritten, which drops it.mirrorKeepDeletedHoldmakes the hold carried (carriedHoldsclassmirror_keep_deleted, fault rowmirror_keep_deleted, needs_human false), andpassBankednever counts its rewrite as saved work. Test:test/mirror-keep-deleted.test.ts.