Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(skillopt): a remote run_skillopt caller can no longer ask for uncapped spend with max_cost_usd 0

time-attack5a5103eebb9b
diff --git a/src/core/ops/skillopt.ts b/src/core/ops/skillopt.ts
index bd82ffc218..313a9cace3 100644
--- a/src/core/ops/skillopt.ts
+++ b/src/core/ops/skillopt.ts
@@ -138,7 +138,7 @@ const run_skillopt: Operation = {
epochs: { type: 'number', description: 'Default 4' },
batch_size: { type: 'number', description: 'Default 8' },
lr: { type: 'number', description: 'Default 4' },
- max_cost_usd: { type: 'number', description: 'Default 5.00 (an unpriced model then warns and runs). When set, an unpriced model is refused with no_pricing.' },
+ max_cost_usd: { type: 'number', description: 'Default 5.00 (an unpriced model then warns and runs). When set, an unpriced model is refused with no_pricing. Remote callers must pass a positive value; 0 (uncapped) is host-only.' },
reflect_max_tokens: { type: 'number', description: 'Optimizer output cap (positive integer, clamped to 256..32000). Default: skillopt.reflect_max_tokens config, else 32000 for thinking optimizers and 4096 otherwise.' },
no_mutate: { type: 'boolean', description: 'Write proposed.md without replacing SKILL.md' },
allow_mutate_bundled: { type: 'boolean', description: 'Required to mutate bundled skills' },
@@ -181,6 +181,12 @@ const run_skillopt: Operation = {
{ fix: hostFix(ctx, ['gbrain', 'skillopt', skillName], 'Runs the optimizer on the brain host, where no remote allowlist applies.', { consent: ['paid'] }) });
}
}
+ const maxCostUsd = p.max_cost_usd;
+ if (ctx.remote !== false && maxCostUsd !== undefined && !(typeof maxCostUsd === 'number' && Number.isFinite(maxCostUsd) && maxCostUsd > 0)) {
+ throw invalidParam(ctx, 'run_skillopt', 'max_cost_usd',
+ 'run_skillopt: max_cost_usd must be a positive number of USD for remote callers; 0 (uncapped) is a host-only setting',
+ { example: 5 });
+ }
const { clampRemoteReflectMaxTokens } = await import('../skillopt/output-cap.ts');
let reflectMaxTokens: number | undefined;
try {
@@ -269,8 +275,8 @@ const run_skillopt: Operation = {
bootstrapReviewed: false,
...(heldOutPath ? { heldOutPath } : {}),
json: true,
- maxCostUsd: (p.max_cost_usd as number) ?? 5.0,
- maxCostSource: p.max_cost_usd === undefined ? 'default' : 'user',
+ maxCostUsd: (maxCostUsd as number | undefined) ?? 5.0,
+ maxCostSource: maxCostUsd === undefined ? 'default' : 'user',
maxRuntimeMin: 30,
force: false,
});
diff --git a/test/fixtures/goldens/cli/tools-json.json b/test/fixtures/goldens/cli/tools-json.json
index 1b7d89af04..a7dbe801f3 100644
--- a/test/fixtures/goldens/cli/tools-json.json
+++ b/test/fixtures/goldens/cli/tools-json.json
@@ -2,8 +2,8 @@
"golden": {
"exitCode": 0,
"stderr": "",
- "stdoutBytes": 204468,
- "stdoutSha256": "97c5e339227556a50c8efb05f6740d793148ad1bb18e67172af71788595a563f",
+ "stdoutBytes": 204538,
+ "stdoutSha256": "14baa283cc6c3428ec4ab5205ee7a23660cb9c516c8bea96dbb84f8e421d5f3c",
"toolNames": [
"remember",
"entity",
@@ -6254,7 +6254,7 @@
"type": "number"
},
"max_cost_usd": {
- "description": "Default 5.00 (an unpriced model then warns and runs). When set, an unpriced model is refused with no_pricing.",
+ "description": "Default 5.00 (an unpriced model then warns and runs). When set, an unpriced model is refused with no_pricing. Remote callers must pass a positive value; 0 (uncapped) is host-only.",
"type": "number"
},
"no_mutate": {
diff --git a/test/skillopt/run-skillopt-op.serial.test.ts b/test/skillopt/run-skillopt-op.serial.test.ts
index 27da8a4614..f30dd410c9 100644
--- a/test/skillopt/run-skillopt-op.serial.test.ts
+++ b/test/skillopt/run-skillopt-op.serial.test.ts
@@ -208,3 +208,30 @@ describe('run_skillopt reflect_max_tokens (#5584)', () => {
expect(runSkillOptCalls.length).toBe(1);
});
});
+
+describe('run_skillopt max_cost_usd for remote callers', () => {
+ beforeEach(async () => {
+ await engine.setConfig('skillopt.allowed_skills', JSON.stringify(['test-skill']));
+ });
+
+ test('remote 0, negative, non-finite or non-number → invalid_params, no run (never uncapped spend)', async () => {
+ for (const bad of [0, -1, Number.POSITIVE_INFINITY, Number.NaN, '0']) {
+ await expectCode(run_skillopt.handler(ctxOf({ remote: true }), { skill_name: 'test-skill', max_cost_usd: bad }), 'invalid_params');
+ }
+ expect(runSkillOptCalls.length).toBe(0);
+ });
+
+ test('remote positive cap passes through as a user cap; absent stays the $5 default cap', async () => {
+ await run_skillopt.handler(ctxOf({ remote: true }), { skill_name: 'test-skill', max_cost_usd: 2.5 });
+ await run_skillopt.handler(ctxOf({ remote: true }), { skill_name: 'test-skill' });
+ expect(runSkillOptCalls.map((c) => {
+ const o = c as { maxCostUsd?: number; maxCostSource?: string };
+ return [o.maxCostUsd, o.maxCostSource];
+ })).toEqual([[2.5, 'user'], [5, 'default']]);
+ });
+
+ test('local CLI caller keeps 0 = uncapped semantics', async () => {
+ await run_skillopt.handler(ctxOf({ remote: false }), { skill_name: 'test-skill', max_cost_usd: 0 });
+ expect((runSkillOptCalls[0] as { maxCostUsd?: number }).maxCostUsd).toBe(0);
+ });
+});