Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(probe): the run-budget tracker returns its reservation id, so each probe call settles its own hold

time-attack4a1f2c9b7c7f
diff --git a/src/core/cycle/nightly-quality-probe.ts b/src/core/cycle/nightly-quality-probe.ts
index 16dcc3319a..15dc8329ce 100644
--- a/src/core/cycle/nightly-quality-probe.ts
+++ b/src/core/cycle/nightly-quality-probe.ts
@@ -42,6 +42,7 @@ import {
BudgetTracker,
type BudgetActualUsage,
type BudgetEstimate,
+ type BudgetReservation,
type PricingOverrides,
} from '../budget/budget-tracker.ts';
import { resolveAuditDir } from '../minions/handlers/shell-audit.ts';
@@ -178,9 +179,9 @@ export function resolveProbeCap(
class ProbeBudgetTracker extends BudgetTracker {
exhausted: BudgetExhausted | null = null;
- override reserve(estimate: BudgetEstimate): void {
+ override reserve(estimate: BudgetEstimate): BudgetReservation | undefined {
try {
- super.reserve(estimate);
+ return super.reserve(estimate);
} catch (err) {
if (err instanceof BudgetExhausted) this.exhausted ??= err;
throw err;
diff --git a/test/nightly-probe-run-budget.test.ts b/test/nightly-probe-run-budget.test.ts
index 2c77a82f66..baba293adc 100644
--- a/test/nightly-probe-run-budget.test.ts
+++ b/test/nightly-probe-run-budget.test.ts
@@ -161,6 +161,19 @@ describe('one budget across LongMemEval and the judges (CEO B4)', () => {
expect(event!.cap_usd).toBe(5);
});
});
+
+ test('each call settles its own reservation, so the cap counts actual spend, not held worst cases', async () => {
+ await withEnv({ GBRAIN_AUDIT_DIR: auditTmp }, async () => {
+ let refused = -1;
+ const r = await runNightlyQualityProbe(deps({
+ resolveMaxUsd: () => 0.02,
+ runLongMemEval: async () => { refused = await chatCalls(PRICED, 8); },
+ }));
+ expect(refused).toBe(0);
+ expect(r.outcome).toBe('pass');
+ expect(providerCalls).toHaveLength(8);
+ });
+ });
});
describe('pricing policy for the run cap', () => {