Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
Key files: Engines (1/2, 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/pglite-legacy-lock.ts— core ofgbrain pglite-repair --legacy-lock(C-3): read-onlyinspectLegacyLock(verdict, plan hash over the legacy dir, advisory this-host-only evidence: kill -0, /proc fd scan, statfs; refuseslive_holder/network_filesystem/filesystem_unverified, the last when locality is unknown: neither Linux statfs nor macOSdf -P+mount(localflag and a known-local type) confirms a local disk, or a probe failed) andapplyLegacyLockRemoval(moves the dir aside with a receipt, backs up the prior ownership marker bytes, writes the kernel-v1 marker; the restore command puts the marker back). Test:test/pathological/c3-pglite-legacy-lock.test.ts.src/core/pglite-repair.ts— WAL-repair orchestrator wrapping the resetWal port with the safety layers that make it runnable automatically fromconnect():validateWalRepairTarget(read-only, fail-closed; refuses symlinked dataDir/pg_wal/global/pg_control — lstat follows INTERMEDIATE symlinks, soglobal/itself must be checked or surgery would write pg_control through it into a foreign dir; tolerates the in-dir.gbrain-lock), rename-based backup (the ENTIREpg_wal/dir + postmaster.pid renamed into a sibling<dataDir>.wal-repair-backup-<ts>/, only the 8KB pg_control copied — zero transient disk cost),restoreWalBackup(overwrite order: control first via atomic tmp+rename, then a pg_wal dir swap with the reset dir set ASIDE inside the backup — nothing is ever deleted during restore; mtime guard refuses when a foreign segment is newer than the backup; a missing/empty backup NEVER reportsrestored:true),WalRepairError(thrown when resetWal fails AFTER the backup — carries the receipt + the best-effort restore's REAL result so the seam'srestoredflag and thefailed-restored/failed-not-restoredmessage arms never lie), a cooldown sidecar<dataDir>.wal-repair-attempt.json(skip'recently-failed'insideGBRAIN_PGLITE_WAL_REPAIR_COOLDOWN_SECONDS, default 3600 — bounds the autopilot/supervisor reconnect loops) with episode-scoped backups (attempts within one corruption episode REUSE the episode's first backup — the pre-damage forensic state, honored only when the sidecar's path is a real non-symlink<dataDir>.wal-repair-backup-*sibling since the sidecar is user-writable JSON; retention keeps the newest 3 episodes, never pruning the open episode's), andattemptWalRepairAndRetry— the engine seam that NEVER throws (gates: kill-switch → reaped-lock'possibly-live-writer'→ 10-minute reap-marker quarantine (msSinceLastReap, cross-process) → validation → cooldown; then repair → retry create once → restore-and-record on failure; prints a repair-start stderr line so a timeout-killed attempt is self-explaining).inspectPgliteDataDiris the read-only diagnosis forgbrain doctor+pglite-repair --dry-run. Imports runtime values only frompglite-lock.ts/pglite-resetwal.ts/node:fs — never frompglite-engine.ts(no cycle; the engine statically imports THIS file per the engine-live rule). Pinned bytest/pglite-repair.test.ts+test/pglite-wal-repair.serial.test.ts.src/core/pglite-repair-consent.ts+ the repair-failed marker insrc/core/pglite-repair.ts— when automatic WAL repair fails (or a recent failure put it on cooldown)recordFailedAutoRepairwrites the sibling<dataDir>.repair-failed.json; while it existsPGLiteEngine.connect()refuses beforeacquireLock(zero writes to the data dir) withrepairFailedRefusal: the exit-3 consent payload (effectsdestructive, fixgbrain pglite-repair [--path] --yes --expect <plan_hash>from the samewalRepairPlanthe command binds, preview--dry-run --json, and the hands-off textHANDS_OFF_BRAIN_FILES). The CLI'sexitOnRepairFailed(src/cli/cli-error.ts) exits 3 on it fromconnectEngine; stdio serve maps it to status reasonrepair_failed. Cleared by a completedpglite-repairorreinit-pglite. Pinned bytest/agent-operator-gate-fixes.{,serial.}test.ts.