Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript
7.7 KB
Raw Blame

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 than sources.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, or compareSegmentedExportBlob for a page stored in segments) and confirms a difference with prepareRepairPublication; direction comes from the page's sync import record (behind when its revision is the recorded one, unproven without a record, database_moved skipped). Paths sync would not import (loadSyncEligibility from sync-discovery.ts) are skipped not_eligible. A blob over SYNC_READ_BOUND is never read and reported with file_too_large. Blobs are read and compared in chunks of at most ROWS_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 is not_applicable.

  • 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.

  • src/core/persistence/sync-holds-carried.ts — the holds a source carries by design: mirrorDatabaseOnlyHold, mirrorKeepDeletedHold, carriedHolds and heldDriftPreviewArgv (re-exported from sync-holds.ts). Keep the deletion on a mirror: on a read-only mirror (sourceMirrorReadOnly), deletedPage turns --held --side deleted --state tombstone_edited --prefer database into a KeepDeletedPage (keep_deleted) bound to the same DeletedDriftPin; applyKeepDeleted re-checks the pin and records meta.keep_deleted on the hold (recordKeepDeleted in sync-holds.ts, guarded on the observed hold), writing no file or page, and a decided hold previews mirror_keep_deleted. writeGitHold carries the decision across a rewrite with the same blob_oid and state (carriedKeepDeleted; a tombstone purged to purged_differs rebinds it to the deletion marker's digest); holdBasisMoved re-checks a kept hold whose tombstone was restored, purged or rewritten, which drops it. mirrorKeepDeletedHold makes the hold carried (carriedHolds class mirror_keep_deleted, fault row mirror_keep_deleted, needs_human false), and passBanked never counts its rewrite as saved work. Test: test/mirror-keep-deleted.test.ts.