Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
chore: name the commit notifier migration v262 in docs and comments (master took v261)
garrytanfb5ede523255
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 113654ae51..710040ab29 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -30,7 +30,7 @@ The other changes:- **HEAD-driven autopilot.** The daemon dispatches when a checkout's HEAD moves past the last synced commit, with the wall-clock rule kept as a backstop. Its `--status` grades from a new heartbeat sidecar (#7003).- **Worker boot.** On Postgres, `gbrain jobs work` starts the persistence consumer at boot through the existing election (#7002). An idle worker wakes on a queued sync, using LISTEN on a direct session and a 1 s poll behind a pooler.- **Visibility.** `gbrain sync status` and the new doctor check `commit_notifier` name the resident that syncs each source, or say none is running and give the fix. Once a resident has run, or `sync.on_commit` is on, search and query responses carry a per-source `freshness` entry (current, behind, syncing, unknown or not_monitored).-- **Upgrade.** Migration v261 adds `sync_wanted_markers`, `sync_notifier_sources` and `sync_notifier_leases`.+- **Upgrade.** Migration v262 adds `sync_wanted_markers`, `sync_notifier_sources` and `sync_notifier_leases`.Docs: `docs/guides/on-commit-sync.md`. `GBRAIN_NOTIFIER=0` turns the notifier off for a process.diff --git a/docs/architecture/key-files/commit-notifier.md b/docs/architecture/key-files/commit-notifier.mdindex 0ea9e23cf1..2b22b7f532 100644--- a/docs/architecture/key-files/commit-notifier.md+++ b/docs/architecture/key-files/commit-notifier.md@@ -4,7 +4,7 @@Current behavior and load-bearing invariants; history belongs in Git and CHANGELOG.- `src/core/commit-notifier.ts` — the notifier core, pure over its seams (store, git reads, the runner). One loop per resident: claims the host lease every heartbeat (`GBRAIN_NOTIFIER_HEARTBEAT_MS`, default 10 s, lease two heartbeats; PGLite has no lease and the brain's holder owns), re-reads `sync.on_commit` and `sync.on_commit.sources` every 30 s (`parseOnCommit` is the one parser), lists the host's sources every 60 s, reads HEAD every poll (`GBRAIN_NOTIFIER_POLL_MS`, 3 s; a watch only nudges), and scans wanted markers every 15 s or on a nudge, with the flag off too. Starts on the leading edge of a quiet HEAD move (no rebase/merge/cherry-pick marker, no `index.lock`), then a 400 ms trailing window (`GBRAIN_NOTIFIER_QUIET_MS`). Per-source single flight under a host cap, least recently started first. Keeps a source due across refused starts, failed or blocked runs and resumable stops; retries at `RETRY_BACKOFF_MS` (5 s, 15 s, 1 min, 5 min) and reports `notifier_stalled` past the last tier without progress; `operator_blocked` waits for HEAD to move. Checks the fence before each start. Every decision is recorded (`decisions`) for tests; state and coverage rows are written on change only. Managed sources never take pull markers. Tests: `test/serve-head-watcher.test.ts` (memory store, `test/helpers/notifier-memory-store.ts`).-- `src/core/notifier/store.ts` — the durable rows (migration `v261-commit-notifier.ts`): `sync_wanted_markers` (source + intent freshness|pull|full, `generation` bumped on every upsert, `first_due_at` kept), `sync_notifier_leases` (one owner per host, fence bumped on takeover, release expires it now), `sync_notifier_sources` (state, retry schedule, last error and trace path, classic syncer host, coverage record). A drainer deletes only `WHERE generation =` the value it read (`clearMarker`, `settleMarkers`); freshness is due while `wanted_head IS DISTINCT FROM last_commit` (no ancestry assumption). `recordLocalSyncer` runs where `writeSyncAnchor` advances `last_commit`: records the syncer host and prunes satisfied markers (the CLI's re-check). `missingTable` lets callers on a pre-v261 brain read "nothing monitored".+- `src/core/notifier/store.ts` — the durable rows (migration `v262-commit-notifier.ts`): `sync_wanted_markers` (source + intent freshness|pull|full, `generation` bumped on every upsert, `first_due_at` kept), `sync_notifier_leases` (one owner per host, fence bumped on takeover, release expires it now), `sync_notifier_sources` (state, retry schedule, last error and trace path, classic syncer host, coverage record). A drainer deletes only `WHERE generation =` the value it read (`clearMarker`, `settleMarkers`); freshness is due while `wanted_head IS DISTINCT FROM last_commit` (no ancestry assumption). `recordLocalSyncer` runs where `writeSyncAnchor` advances `last_commit`: records the syncer host and prunes satisfied markers (the CLI's re-check). `missingTable` lets callers on a pre-v262 brain read "nothing monitored".- `src/core/notifier/resident.ts` + `src/core/notifier/detect.ts` — production seams and the one start path for every resident (`startResidentNotifier`: serve, serve --http through `src/core/serve-head-watcher.ts`, `gbrain jobs work`, the autopilot daemon). Never awaits: the first pass runs in the background. `GBRAIN_NOTIFIER=0` turns it off per process. Lists managed sources whose worktree this host owns and classic sources whose recorded syncer is this host (or `GBRAIN_NOTIFIER_CLASSIC_SOURCES`), skipping the rest with a reason. Starts syncs through the in-process delegated runner. Trace per source at `<gbrain home>/notifier/<source>.jsonl`. `detect.ts` resolves `--absolute-git-dir` / `--git-common-dir` (linked worktrees) and the quiet predicate. Tests: `test/pathological/s-notifier-classic-serve.test.ts`, `test/pathological/s-notifier-residents.test.ts`.- `src/core/notifier/nudge.ts` + `src/core/notifier/handoff.ts` + `src/commands/sync/trigger.ts` — submitters and drainers of wanted markers. `recordTriggerMarker` picks the intent (managed: freshness at the checkout HEAD; classic: pull) and `recordSyncNudge` answers the versioned, acknowledged `sync_nudge` IPC kind (`src/core/context/sync-ipc.ts`, `resolve-ipc.ts`, bound in `src/mcp/resolve-ipc-binding.ts`). `handoff.ts` is the post-run re-check of the `sync` job handler and the serve's delegated runner: read before the run, settle after, at most one follow-up (a queued job with `maxWaiting: 1`, or a nudge); a lock-busy skip records a marker and completes. `gbrain sync trigger` answers queued / coalesced (`maxPending: 1`) / nudged, exit 0, with the `no_resident` notice when no resident watches the source; on PGLite a live serve takes it over IPC (`maybeTriggerThroughServe` in `src/commands/sync-delegate.ts`, which also records a busy delegated sync). The GitHub push webhook (`submitGitHubPush` in `src/commands/serve-http-webhooks.ts`) records the pushed sha first; a managed source answers 409 `refresh_required`. Tests: `test/pathological/s-notifier-marker-handoff.test.ts`.- `src/core/notifier/status.ts` — what users and agents see, from rows only (no git call): `readSourceFreshness` feeds the `freshness` entry of search and query responses (`src/core/ops/search.ts` `buildRetrievalResponseMeta`; current, behind, syncing, unknown, not_monitored), and `readNotifierBlock` / `formatNotifierBlock` the notifier block for sync status and doctor (resident or none with the `gbrain sync --source <id> --no-pull` fix; remote callers get no trace path, pid or host id). An owner is live by its unexpired lease (Postgres) or a running pid on this host (PGLite). Tests: `test/pathological/s-notifier-freshness-status.test.ts`.diff --git a/src/core/notifier/status.ts b/src/core/notifier/status.tsindex 2074fae15b..22416829e3 100644--- a/src/core/notifier/status.ts+++ b/src/core/notifier/status.ts@@ -101,7 +101,7 @@ async function freshnessReported(engine: FreshnessExec): Promise<boolean> {/*** The freshness notice for search and query: one entry per source in the caller's scope, from the cached coverage- * record, or none when the brain does not report freshness (freshnessReported). A brain without the v261 tables reports+ * record, or none when the brain does not report freshness (freshnessReported). A brain without the v262 tables reports* none; another failed read answers unknown for the scope instead of failing the search.*/export async function readSourceFreshness(engine: FreshnessExec, scope: { sourceId?: string; sourceIds?: string[] }, held: ReadonlyArray<{ source_id: string; missing: number; stale: number }> = []): Promise<SourceFreshness[]> {diff --git a/src/core/notifier/store.ts b/src/core/notifier/store.tsindex 320f2cceb2..f4e3ea3818 100644--- a/src/core/notifier/store.ts+++ b/src/core/notifier/store.ts@@ -1,5 +1,5 @@/**- * GBRA-133 PR 2a: the commit notifier's durable state (migration v261).+ * GBRA-133 PR 2a: the commit notifier's durable state (migration v262).** - Wanted markers (`sync_wanted_markers`): one row per source and intent class.* `freshness` asks for the checkout's HEAD to become searchable (never pulls);@@ -16,7 +16,7 @@* verified convergence, the last error with its trace file, the classic* syncer host, and the observation the freshness notice reads.*- * Callers on a brain whose schema predates v261 catch `missingTable` and treat+ * Callers on a brain whose schema predates v262 catch `missingTable` and treat* it as "no markers, nothing monitored".*/import type { BrainEngine } from '../engine.ts';@@ -64,7 +64,7 @@ export interface NotifierSourceRow {owner_seen_at: string | null;}-/** True when the error says a v261 table does not exist yet (a brain mid-upgrade). */+/** True when the error says a v262 table does not exist yet (a brain mid-upgrade). */export function missingTable(error: unknown): boolean {const e = error as { code?: unknown; message?: unknown } | null;return e?.code === '42P01' || /relation "sync_(wanted_markers|notifier_leases|notifier_sources)" does not exist/.test(String(e?.message ?? ''));diff --git a/src/core/schema-embedded.generated.ts b/src/core/schema-embedded.generated.tsindex 80c25099fd..5d8ab18c74 100644--- a/src/core/schema-embedded.generated.ts+++ b/src/core/schema-embedded.generated.ts@@ -3328,7 +3328,7 @@ DO \$rls\$ BEGINEND \$rls\$;-- END GENERATED from src/core/belief/schema.ts (BELIEF_LEDGER_SCHEMA_SQL)--- GBRA-133 PR 2a (migration v261): commit notifier wanted markers, the+-- GBRA-133 PR 2a (migration v262): commit notifier wanted markers, the-- per-host notifier lease and per-source notifier state + coverage record-- (src/core/notifier/store.ts).CREATE TABLE IF NOT EXISTS sync_wanted_markers (diff --git a/src/schema.sql b/src/schema.sqlindex ae1c0cd2e6..ffe35742a0 100644--- a/src/schema.sql+++ b/src/schema.sql@@ -3324,7 +3324,7 @@ DO $rls$ BEGINEND $rls$;-- END GENERATED from src/core/belief/schema.ts (BELIEF_LEDGER_SCHEMA_SQL)--- GBRA-133 PR 2a (migration v261): commit notifier wanted markers, the+-- GBRA-133 PR 2a (migration v262): commit notifier wanted markers, the-- per-host notifier lease and per-source notifier state + coverage record-- (src/core/notifier/store.ts).CREATE TABLE IF NOT EXISTS sync_wanted_markers (