Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(decide): time the budgeted span, not the runner, in two decide timing tests (#6483)
time-attack4237b2979bb9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 163e38368b..1c1df98f4e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,15 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased]++**Two decide timing tests stop failing on slow runners.** Each one measured wall-clock time that included work outside the budget under test. Both budgets are unchanged.++### Itemized changes++- `test/decide/turn-context-s6.serial.test.ts`: "a provider slower than the server budget never nulls the reflex block" times the server's budgeted assembly (the handler the 400 ms `TURN_CONTEXT_SERVER_BUDGET_MS` races) instead of the client's round trip, which also counts connection setup and runner scheduling. The test now holds the event loop for 200 ms before the request reaches the server. The old round-trip check fails on every run with that stall; the server-span check passes.+- `test/decide/search-slots.serial.test.ts` (#6483): "S3 evidence gate > fails open on timeout" holds decide's clock through the new `__setDecideClockForTests` seam in `src/core/ai/decide/index.ts`, so only the transport's abort ends the stage. The test stalls the egress page check by 150 ms; without the held clock that stall reproduces `skipped: 'late'` on every run. `runDecide` counting pre-send work such as the egress check against `decide.timeout_ms` is intended behaviour, not a product bug.+## [0.60.170.0] - 2026-10-11**Fixes the OpenClaw native startup lane that failed master three times; no product change.**diff --git a/src/core/ai/decide/index.ts b/src/core/ai/decide/index.tsindex 0cfdcc3ff4..f6646b439e 100644--- a/src/core/ai/decide/index.ts+++ b/src/core/ai/decide/index.ts@@ -48,6 +48,14 @@ export interface DecideContext {const BACKGROUND_DEFAULT_MS = 60_000;+let testClock: (() => number) | undefined;+/** Drive runDecide's deadline arithmetic from `clock` when the caller passes no `now`; returns the restore. */+export function __setDecideClockForTests(clock: (() => number) | undefined): () => void {+ const prev = testClock;+ testClock = clock;+ return () => { testClock = prev; };+}+export async function loadDecideConfig(engine: BrainEngine | null, opts: { evalSlots?: string } = {}): Promise<DecideConfig> {return readDecideConfig(engine ? await loadConfigSnapshot(engine) : null, { ...opts, typesafeKey: hasTypesafeKey() });}@@ -69,7 +77,7 @@ function emptyResult(provider: string, lane: DecideLane, refused: Record<string,}export async function runDecide(req: DecideRequest, ctx: DecideContext): Promise<DecideResult> {- const now = ctx.now ?? Date.now;+ const now = ctx.now ?? testClock ?? Date.now;const started = now();const cfg = ctx.config ?? await loadDecideConfig(ctx.engine);const provider = req.provider ?? cfg.slots[req.slot].provider;diff --git a/test/decide/search-slots.serial.test.ts b/test/decide/search-slots.serial.test.tsindex 7ba57017ff..f8cb3373f5 100644--- a/test/decide/search-slots.serial.test.ts+++ b/test/decide/search-slots.serial.test.ts@@ -25,6 +25,7 @@ import { flushDecideWrites, __resetDecideStoreForTests, insertCalibration } fromimport { resetDecideSearchCache } from '../../src/core/search/decide-stage.ts';import { gradeRetrievalConfidence } from '../../src/core/search/crag.ts';import { packShape } from '../../src/core/ai/decide/pack.ts';+import { __setDecideClockForTests } from '../../src/core/ai/decide/index.ts';import type { HybridSearchMeta, SearchResult } from '../../src/core/types.ts';let engine: PGLiteEngine;@@ -191,7 +192,24 @@ describe('S3 evidence gate', () => {const baseline = await search();await setConfig({ ...S3_ON, 'decide.timeout_ms': '100' });setup();- const { results, meta } = await search();+ // Timeout: only the transport's abort may end the stage. The clock is held, so a slow runner spending the+ // 100 ms before the request is sent (here a stalled egress page check) cannot turn it into `late`.+ const restoreClock = name === 'timeout' ? __setDecideClockForTests(() => 1_000_000) : () => {};+ const executeRaw = engine.executeRaw.bind(engine);+ if (name === 'timeout') {+ engine.executeRaw = (async (sql: string, params?: unknown[]) => {+ if (sql.includes('AS want(source_id, slug)')) await new Promise((r) => setTimeout(r, 150));+ return executeRaw(sql, params as never);+ }) as typeof engine.executeRaw;+ }+ let out: Awaited<ReturnType<typeof search>>;+ try {+ out = await search();+ } finally {+ engine.executeRaw = executeRaw;+ restoreClock();+ }+ const { results, meta } = out;expect(results.map((r) => r.slug)).toEqual(baseline.results.map((r) => r.slug));expect(meta?.decide?.evidence).toMatchObject({ effective: 'off', skipped: reason });const rows = await receipts();diff --git a/test/decide/turn-context-s6.serial.test.ts b/test/decide/turn-context-s6.serial.test.tsindex fea839a764..0f7790f24c 100644--- a/test/decide/turn-context-s6.serial.test.ts+++ b/test/decide/turn-context-s6.serial.test.ts@@ -326,6 +326,8 @@ describe('through the IPC server (the serve handler shape the hook talks to)', (for (const d of dirs) rmSync(d, { recursive: true, force: true });});+ /** Server-side spans of the budgeted assembly (the handler the server's budget races), in ms. */+ const spans: number[] = [];async function serve(): Promise<{ sock: string; secret: string }> {const dir = mkdtempSync(join(tmpdir(), 'gbrain-s6-ipc-'));dirs.push(dir);@@ -333,7 +335,14 @@ describe('through the IPC server (the serve handler shape the hook talks to)', (const sock = resolveSocketPath(dir);const server = await startResolveIpcServer(sock, {resolve: async () => null,- turn_context: (req) => assembleTurnContext(engine, { sourceId: 'default', window: req.window ?? [], priorContextText: req.priorContextText, sessionId: req.sessionId, maxBytes: req.maxBytes }),+ turn_context: async (req) => {+ const started = performance.now();+ try {+ return await assembleTurnContext(engine, { sourceId: 'default', window: req.window ?? [], priorContextText: req.priorContextText, sessionId: req.sessionId, maxBytes: req.maxBytes });+ } finally {+ spans.push(performance.now() - started);+ }+ },}, { secret, boundSourceId: 'default' });servers.push(server!);return { sock, secret };@@ -343,9 +352,14 @@ describe('through the IPC server (the serve handler shape the hook talks to)', (transport({ p: 0.01, delayMs: 5000 });await setConfig(S6_ON);const { sock, secret } = await serve();- const t0 = Date.now();- const res = await requestTurnContext(sock, { secret, window: [{ role: 'user', text: SURNAME }], sessionId: 's6-ipc' }) as TurnContextResponse;- expect(Date.now() - t0).toBeLessThan(TURN_CONTEXT_SERVER_BUDGET_MS);+ spans.length = 0;+ const pending = requestTurnContext(sock, { secret, window: [{ role: 'user', text: SURNAME }], sessionId: 's6-ipc' });+ // The client and the runner can stall before the server has the request; that time is not the server's budget.+ const stallUntil = performance.now() + 200;+ while (performance.now() < stallUntil) { /* hold the event loop before the request reaches the server */ }+ const res = await pending as TurnContextResponse;+ expect(spans).toHaveLength(1);+ expect(spans[0]!).toBeLessThan(TURN_CONTEXT_SERVER_BUDGET_MS);expect(res.ok).toBe(true);expect(res.degradedReason).toBeUndefined();expect(res.block?.pointers.map((p) => p.slug)).toEqual(['people/mateo-glimmerton']);