Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
chore(notifier): verify green after d2 (test isolation, function size)
garrytan86bd0374a958
diff --git a/src/core/commit-notifier.ts b/src/core/commit-notifier.tsindex 3a0dc4057e..e30627b26d 100644--- a/src/core/commit-notifier.ts+++ b/src/core/commit-notifier.ts@@ -285,6 +285,18 @@ function snapshotSource(rt: Rt, now: number): NotifierSourceSnapshot {markers: rt.markers.map(m => ({ intent: m.intent, generation: m.generation })) };}+/** Each source's wanted markers that no live queued job already covers; an unreadable marker table keeps the last read. */+async function readOwedMarkers(opts: CommitNotifierOptions, guard: ReturnType<typeof notifierKit>['guard'], sources: Map<string, Rt>): Promise<void> {+ const ids = [...sources.keys()];+ const markers = ids.length ? await guard('reading wanted markers', () => opts.store.dueMarkers(ids), null) : [];+ if (!markers) return;+ const jobIds = markers.flatMap(m => m.job_id === null ? [] : [m.job_id]);+ const live = jobIds.length ? await guard('reading queued sync jobs', () => opts.store.liveJobs(jobIds), new Set<number>()) : new Set<number>();+ // A managed source never pulls: its pull markers (a push webhook) wait for gbrain sources refresh, not for this loop.+ for (const rt of sources.values()) rt.markers = markers.filter(m => m.source_id === rt.sourceId && (m.job_id === null || !live.has(m.job_id))+ && !(m.intent === 'pull' && rt.kind === 'managed'));+}+export function startCommitNotifier(opts: CommitNotifierOptions): CommitNotifier {const { pollMs, quietMs, heartbeatMs, leaseMs, cap, now, pid, ownerId, forcePoll, setTimer, clearTimer, log, logOnce, guard, decisions, decide } = notifierKit(opts);@@ -532,15 +544,7 @@ export function startCommitNotifier(opts: CommitNotifierOptions): CommitNotifierif (wasNudged || firstPass || t - markersAt >= MARKER_SCAN_MS) {markersAt = t;firstPass = false;- const ids = [...sources.keys()];- const markers = ids.length ? await guard('reading wanted markers', () => opts.store.dueMarkers(ids), null) : [];- if (markers) {- const jobIds = markers.flatMap(m => m.job_id === null ? [] : [m.job_id]);- const live = jobIds.length ? await guard('reading queued sync jobs', () => opts.store.liveJobs(jobIds), new Set<number>()) : new Set<number>();- // A managed source never pulls: its pull markers (a push webhook) wait for gbrain sources refresh, not for this loop.- for (const rt of sources.values()) rt.markers = markers.filter(m => m.source_id === rt.sourceId && (m.job_id === null || !live.has(m.job_id))- && !(m.intent === 'pull' && rt.kind === 'managed'));- }+ await readOwedMarkers(opts, guard, sources);}for (const job of [...running.values()]) {const st = opts.jobStatus(job.id);diff --git a/test/pathological/s-notifier-sigterm-lease.test.ts b/test/pathological/s-notifier-sigterm-lease.test.tsindex 95dc93068e..6726253b63 100644--- a/test/pathological/s-notifier-sigterm-lease.test.ts+++ b/test/pathological/s-notifier-sigterm-lease.test.ts@@ -17,8 +17,8 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { join, resolve } from 'node:path';import type { BrainEngine } from '../../src/core/engine.ts';-import { PGLiteEngine } from '../../src/core/pglite-engine.ts';-import { PostgresEngine } from '../../src/core/postgres-engine.ts';+import type { EngineConfig } from '../../src/core/types.ts';+import { createEngine } from '../../src/core/engine-factory.ts';import { performSync } from '../../src/commands/sync.ts';import { isolatedPersistencePostgres } from '../helpers/persistence-postgres.ts';import { withEnv } from '../helpers/with-env.ts';@@ -64,10 +64,11 @@ describe('GBRA-133 2b-d2: SIGTERM releases the commit notifier lease', () => {const repo = join(home, 'repo');const git = (...args: string[]) => execFileSync('git', ['-C', repo, '-c', 'user.name=Example', '-c', '[email protected]', ...args], { encoding: 'utf8' }).trim();const pg = databaseUrl ? await isolatedPersistencePostgres(databaseUrl) : null;- const dbConfig = pg ? { engine: 'postgres', database_url: pg.databaseUrl } : { engine: 'pglite', database_path: join(home, 'brain.pglite') };+ const dbConfig: EngineConfig = pg ? { engine: 'postgres', database_url: pg.databaseUrl } : { engine: 'pglite', database_path: join(home, 'brain.pglite') };+ // The residents' own config, through the production factory; each handle is disconnected where it is opened.const open = async (): Promise<BrainEngine> => {- const engine = pg ? new PostgresEngine() : new PGLiteEngine();- await engine.connect(pg ? { database_url: pg.databaseUrl } : { database_path: join(home, 'brain.pglite') });+ const engine = await createEngine(dbConfig);+ await engine.connect(dbConfig);return engine;};const residents: Resident[] = [];