Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: a hook runtime cap beyond the timer range no longer aborts every batch

garrytancefd1e08cbc6
diff --git a/src/core/skillopt/validate-gate.ts b/src/core/skillopt/validate-gate.ts
index 2c2b93027a..bc51d81813 100644
--- a/src/core/skillopt/validate-gate.ts
+++ b/src/core/skillopt/validate-gate.ts
@@ -76,6 +76,9 @@ interface PerTask {
rollouts: ScoredRollout[];
}
+/** setTimeout clamps longer delays to 1 ms; a cap beyond it relies on the post-call deadline check. */
+const MAX_TIMER_MS = 2 ** 31 - 1;
+
/** One hook call for the whole batch; a malformed reply is an infra error, never a score. */
async function hookBatch(opts: ValidateGateOpts, hook: RolloutBatchHook, runsPerTask: number): Promise<PerTask[]> {
const deadline = opts.deadlineMs;
@@ -87,7 +90,7 @@ async function hookBatch(opts: ValidateGateOpts, hook: RolloutBatchHook, runsPer
if (opts.abortSignal?.aborted) onAbort();
else opts.abortSignal?.addEventListener('abort', onAbort, { once: true });
let timer: ReturnType<typeof setTimeout> | undefined;
- const expired = deadline === undefined ? null : new Promise<never>((_, reject) => {
+ const expired = deadline === undefined || deadline - Date.now() > MAX_TIMER_MS ? null : new Promise<never>((_, reject) => {
timer = setTimeout(() => {
controller.abort(new Error(SKILLOPT_RUNTIME_EXCEEDED));
reject(new Error(SKILLOPT_RUNTIME_EXCEEDED));
diff --git a/test/skillopt/benchmark-hooks.test.ts b/test/skillopt/benchmark-hooks.test.ts
index 23a5963940..20ee839848 100644
--- a/test/skillopt/benchmark-hooks.test.ts
+++ b/test/skillopt/benchmark-hooks.test.ts
@@ -95,6 +95,14 @@ describe('rollout hook (B1.3)', () => {
}
});
+ test('a runtime cap beyond the timer range (or Infinity) does not abort the batch', async () => {
+ const hook: RolloutBatchHook = async (req) => { await new Promise((r) => setTimeout(r, 20)); return req.tasks.map(() => [row(1), row(1), row(1)]); };
+ for (const deadlineMs of [Date.now() + 30 * 24 * 3600 * 1000, Number.POSITIVE_INFINITY]) {
+ const res = await runValidationGate({ engine, candidateSkillText: 'S', selSet: tasks('s', 5), bestScore: 0, targetModel: 'm', rolloutHook: hook, deadlineMs });
+ expect(res.selScore).toBe(1);
+ }
+ });
+
test('a batch answered after the runtime deadline is not a score', async () => {
const hook: RolloutBatchHook = async (req) => { await new Promise((r) => setTimeout(r, 30)); return req.tasks.map(() => [row(1), row(1), row(1)]); };
const deadlineMs = Date.now() + 10;