Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(facts): drain scheduler interval returns the tick promise; serve-wiring test awaits it (#6348)

time-attackda074079e19d
diff --git a/src/core/facts/drain-scheduler.ts b/src/core/facts/drain-scheduler.ts
index 547f01e69a..18faaad550 100644
--- a/src/core/facts/drain-scheduler.ts
+++ b/src/core/facts/drain-scheduler.ts
@@ -26,7 +26,7 @@ export interface FactsDrainSchedulerOpts {
lastActivityAt?: () => number;
/** Owner veto for this tick (delegated sync running, engine degraded, shutting down). */
canRun?: () => boolean | Promise<boolean>;
- setInterval?: (fn: () => void, ms: number) => unknown;
+ setInterval?: (fn: () => unknown, ms: number) => unknown;
clearInterval?: (handle: unknown) => void;
now?: () => number;
log?: (line: string) => void;
@@ -71,9 +71,9 @@ export function startFactsDrainScheduler(engine: BrainEngine, opts: FactsDrainSc
return inflight;
};
- const set = opts.setInterval ?? ((fn: () => void, ms: number) => setInterval(fn, ms));
+ const set = opts.setInterval ?? ((fn: () => unknown, ms: number) => setInterval(fn, ms));
const clear = opts.clearInterval ?? ((h: unknown) => clearInterval(h as ReturnType<typeof setInterval>));
- const handle = engine.kind === 'pglite' ? set(() => { void tick(); }, tickMs) : null;
+ const handle = engine.kind === 'pglite' ? set(() => tick(), tickMs) : null;
(handle as { unref?: () => void } | null)?.unref?.();
return {
diff --git a/test/facts-drain-scheduler.test.ts b/test/facts-drain-scheduler.test.ts
index 81d1f52c9d..f1c5a6c2b2 100644
--- a/test/facts-drain-scheduler.test.ts
+++ b/test/facts-drain-scheduler.test.ts
@@ -30,10 +30,10 @@ const settle = () => new Promise<void>(r => setTimeout(r, 0));
const fakeResult = (owner: FactsDrainRunResult['owner']) => ({ owner, outcome: 'drained' } as FactsDrainRunResult);
function intervalStub() {
- const registered: Array<{ fn: () => void; ms: number; handle: { unrefCalled: boolean; unref(): void } }> = [];
+ const registered: Array<{ fn: () => unknown; ms: number; handle: { unrefCalled: boolean; unref(): void } }> = [];
return {
registered,
- setInterval: (fn: () => void, ms: number) => {
+ setInterval: (fn: () => unknown, ms: number) => {
const handle = { unrefCalled: false, unref() { this.unrefCalled = true; } };
registered.push({ fn, ms, handle });
return handle;
@@ -131,13 +131,12 @@ describe('stdio serve wiring', () => {
_resetStdoutRedirectForTests();
expect(h.timers.registered.map(r => r.ms)).toEqual([FACTS_DRAIN_TICK_MS]);
const tick = h.timers.registered[0].fn;
- const wait = () => new Promise(r => setTimeout(r, 100));
- tick(); await wait();
+ await tick();
expect(calls).toBe(0);
- tick(); await wait();
+ await tick();
expect(calls).toBe(1);
h.stdin.emit('data', Buffer.from('{}'));
- tick(); await wait();
+ await tick();
expect(calls).toBe(1);
h.stdin.emit('end');
expect(await h.exited).toBe(0);