Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(eval-run-all): reject NaN and out-of-range numeric flags so the cost guard cannot be bypassed (#5933)

garrytan786f8bf6aa97
diff --git a/src/commands/eval-run-all.ts b/src/commands/eval-run-all.ts
index a90bebf23f..78af3bbeb3 100644
--- a/src/commands/eval-run-all.ts
+++ b/src/commands/eval-run-all.ts
@@ -26,6 +26,9 @@ import { dirname, join } from 'path';
import type { BrainEngine } from '../core/engine.ts';
import { SEARCH_MODES, type SearchMode } from '../core/search/mode.ts';
import { redactSecrets } from '../eval/longmemeval/run-config.ts';
+import { OperationError } from '../core/ops/contract.ts';
+import { usageError } from '../cli/cli-error.ts';
+import { intFlagValue, numberFlagValue } from '../cli/flag-values.ts';
export interface RunAllOpts {
help: boolean;
@@ -88,16 +91,17 @@ export function parseRunAllArgs(args: string[]): RunAllOpts {
opts.suites = list;
continue;
}
- if (a === '--limit') { opts.limit = Number(args[++i]); continue; }
- if (a === '--seed') { opts.seed = Number(args[++i]); continue; }
+ // #5933 (D4): NaN/out-of-range values would bypass the cost guard; reject them (usage error, exit 2).
+ if (a === '--limit') { opts.limit = intFlagValue(args[++i], '--limit', { min: 1, example: 50 }); continue; }
+ if (a === '--seed') { opts.seed = intFlagValue(args[++i], '--seed', { example: 42 }); continue; }
if (a === '--parallel') {
const n = Number(args[++i]);
if (!Number.isFinite(n) || n < 1) throw new Error('--parallel must be >= 1');
opts.parallel = Math.min(n, SEARCH_MODES.length);
continue;
}
- if (a === '--budget-usd-retrieval') { opts.budgetUsdRetrieval = Number(args[++i]); continue; }
- if (a === '--budget-usd-answer') { opts.budgetUsdAnswer = Number(args[++i]); continue; }
+ if (a === '--budget-usd-retrieval') { opts.budgetUsdRetrieval = numberFlagValue(args[++i], a, { min: 0, example: 5 }); continue; }
+ if (a === '--budget-usd-answer') { opts.budgetUsdAnswer = numberFlagValue(args[++i], a, { min: 0, example: 5 }); continue; }
if (a === '--yes' || a === '-y') { opts.yes = true; continue; }
if (a === '--output' || a === '--output-dir') { opts.outputDir = args[++i]; continue; }
if (a === '--json') { opts.jsonOutput = true; continue; }
@@ -286,8 +290,7 @@ export async function runEvalRunAll(_engine: BrainEngine | null, args: string[])
try {
opts = parseRunAllArgs(args);
} catch (e) {
- process.stderr.write(`Error: ${(e as Error).message}\n`);
- process.exit(1);
+ throw e instanceof OperationError ? e : usageError((e as Error).message, 'Run `gbrain eval run-all --help` for the accepted flags and examples.');
}
if (opts.help) {
printHelp();
diff --git a/test/eval-run-all.test.ts b/test/eval-run-all.test.ts
index 6b7df0ee59..ce3449f3a2 100644
--- a/test/eval-run-all.test.ts
+++ b/test/eval-run-all.test.ts
@@ -71,6 +71,32 @@ describe('parseRunAllArgs', () => {
expect(parseRunAllArgs(['--yes']).yes).toBe(true);
expect(parseRunAllArgs(['-y']).yes).toBe(true);
});
+
+ // #5933 (absorbed in agent contract v1 D4): NaN/out-of-range numeric flags
+ // are invalid_params usage errors, so the cost guard can't be bypassed.
+ test('--limit requires a positive safe integer', () => {
+ for (const value of ['NaN', 'Infinity', '1.5', '0', '-1', '9007199254740992']) {
+ expect(() => parseRunAllArgs(['--limit', value]), `--limit ${value}`).toThrow(/--limit/);
+ }
+ expect(() => parseRunAllArgs(['--limit', 'NaN'])).toThrow(expect.objectContaining({ code: 'invalid_params' }));
+ });
+
+ test('--seed requires a safe integer and allows zero', () => {
+ expect(parseRunAllArgs(['--seed', '0']).seed).toBe(0);
+ for (const value of ['NaN', 'Infinity', '1.5', '9007199254740992']) {
+ expect(() => parseRunAllArgs(['--seed', value]), `--seed ${value}`).toThrow(/--seed/);
+ }
+ });
+
+ test('budget caps require finite non-negative amounts', () => {
+ expect(parseRunAllArgs(['--budget-usd-answer', '0']).budgetUsdAnswer).toBe(0);
+ expect(parseRunAllArgs(['--budget-usd-retrieval', '0.25']).budgetUsdRetrieval).toBe(0.25);
+ for (const flag of ['--budget-usd-retrieval', '--budget-usd-answer']) {
+ for (const value of ['NaN', 'Infinity', '-Infinity', '-1']) {
+ expect(() => parseRunAllArgs([flag, value]), `${flag} ${value}`).toThrow(new RegExp(flag));
+ }
+ }
+ });
});
describe('estimateRunCost', () => {