Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test(decide): S6 firing cases run on widened recall deadlines (turn-context-s6 flake)
garrytanb6139f3e6cde
diff --git a/src/core/context/recall-needed.ts b/src/core/context/recall-needed.tsindex 136b93dd53..e0f9210ef6 100644--- a/src/core/context/recall-needed.ts+++ b/src/core/context/recall-needed.ts@@ -45,6 +45,19 @@ import type { VolunteeredPage } from './volunteer.ts';export const RECALL_NEEDED_DEADLINE_MS = 250;/** The fired search starts only when this much of the IPC server budget is left. */export const RECALL_FIRE_MIN_REMAINING_MS = 150;++/**+ * The two wall-clock windows S6 runs inside: its own decision deadline and the+ * IPC server budget a fire must leave room in. Production uses the constants;+ * `__setRecallDeadlinesForTests` widens them so a loaded test runner cannot+ * turn a decision into `late`, and returns the restore.+ */+let deadlines = { decisionMs: RECALL_NEEDED_DEADLINE_MS, serverBudgetMs: TURN_CONTEXT_SERVER_BUDGET_MS };+export function __setRecallDeadlinesForTests(next: { decisionMs: number; serverBudgetMs: number }): () => void {+ const prev = deadlines;+ deadlines = next;+ return () => { deadlines = prev; };+}export const RECALL_FIRE_LIMIT = 3;/** The fired search must finish this long before the server budget ends (response write headroom). */export const RECALL_RESPONSE_MARGIN_MS = 40;@@ -94,7 +107,7 @@ export async function startRecallNeeded(const base = { cfg, policy, state, sessionRef, sourceId: opts.sourceId };if (policy.effective === 'off') return { ...base, skipped: policy.inactive };if (policy.effective === 'shadow' && !sampled(policy.shadowSample)) return null;- const deadlineMs = stageDeadlineMs(createQueryBudget(RECALL_NEEDED_DEADLINE_MS, opts.startedAt), cfg.timeoutMs);+ const deadlineMs = stageDeadlineMs(createQueryBudget(deadlines.decisionMs, opts.startedAt), cfg.timeoutMs);if (deadlineMs === null) return { ...base, skipped: 'late' };const call = runDecide({ slot: 'recall_needed', callSite: 'turn_context', state, questions: [recallNeededQuestion()], deadlineMs, provider: policy.provider, lane: 'hot' },@@ -172,7 +185,7 @@ async function decideRecall(pending: Promise<RecallNeededPrepared | null>,ctx: RecallApplyContext,): Promise<RecallNeededApplied | null> {- const s6End = ctx.startedAt + RECALL_NEEDED_DEADLINE_MS;+ const s6End = ctx.startedAt + deadlines.decisionMs;const safePending = pending.catch(() => null);const prepared = await settleBy(safePending, s6End);const reflex = recallReflex([...ctx.pointers, ...ctx.volunteered]);@@ -237,7 +250,7 @@ async function decideRecall(let reason: string | undefined;if (j.outcome === 'suppress') window = { pointers: [], volunteered: [] };if (j.outcome === 'fire') {- const budgetEnd = ctx.startedAt + TURN_CONTEXT_SERVER_BUDGET_MS;+ const budgetEnd = ctx.startedAt + deadlines.serverBudgetMs;const fired = budgetEnd - Date.now() < RECALL_FIRE_MIN_REMAINING_MS ? LATE : await fireRetrieval(engine, prepared, ctx, budgetEnd - RECALL_RESPONSE_MARGIN_MS);if (fired === LATE) reason = 'late';else if (fired.length === 0) reason = 'no_candidates';diff --git a/test/decide/turn-context-s6.serial.test.ts b/test/decide/turn-context-s6.serial.test.tsindex 3cb61a37d0..fea839a764 100644--- a/test/decide/turn-context-s6.serial.test.ts+++ b/test/decide/turn-context-s6.serial.test.ts@@ -24,7 +24,7 @@ import { drainShadow } from '../../src/core/ai/decide/runtime.ts';import { packShape } from '../../src/core/ai/decide/pack.ts';import { resetDecideSearchCache } from '../../src/core/search/decide-stage.ts';import { assembleTurnContext, type TurnContextResult } from '../../src/core/context/turn-context.ts';-import { applyRecallNeeded, startRecallNeeded, RECALL_NEEDED_DEADLINE_MS } from '../../src/core/context/recall-needed.ts';+import { applyRecallNeeded, startRecallNeeded, RECALL_NEEDED_DEADLINE_MS, __setRecallDeadlinesForTests } from '../../src/core/context/recall-needed.ts';import {ensureIpcSecret, requestTurnContext, resolveSocketPath, startResolveIpcServer, TURN_CONTEXT_SERVER_BUDGET_MS, type TurnContextResponse,} from '../../src/core/context/resolve-ipc.ts';@@ -150,6 +150,13 @@ describe('all slots off', () => {});describe('S6 on', () => {+ // These cases pin what S6 decides, not how fast: wide windows keep a loaded+ // runner from turning a decision into `late`. The fail directions (timeout,+ // the late fire) run on the production deadlines.+ let restoreDeadlines = () => {};+ beforeEach(() => { restoreDeadlines = __setRecallDeadlinesForTests({ decisionMs: 5_000, serverBudgetMs: 5_150 }); });+ afterEach(() => restoreDeadlines());+test('fires one keyword-only search when the reflex was silent; world pages only; receipt fire', async () => {transport({ p: 0.9 });await setConfig(S6_ON);