Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(eval): a RED repair grant respects the run budget

justrach93ffc096ccea
diff --git a/src/agent_steps.zig b/src/agent_steps.zig
index 1e7c2156..262325e3 100644
--- a/src/agent_steps.zig
+++ b/src/agent_steps.zig
@@ -46,6 +46,12 @@ const sseIndex = Agent.sseIndex;
/// spent the caller falls back to the old end-the-turn behavior.
fn grantRepairTurn(self: *Agent) !bool {
if (self.eval_repair_grants >= eval_control.max_repair_grants) return false;
+ // A repair turn costs at least a repair call plus a concluding call.
+ // Without that headroom in the run budget, granting one just converts
+ // the orderly repair-pending turn end into RunBudgetExhausted mid-repair
+ // (caught by scripts/test-review-mode.py's max_model_calls=2 gate) —
+ // surface the hard stop instead, exactly the pre-grant contract.
+ if (self.run_budget) |b| if (!b.canAfford(2)) return false;
self.eval_repair_grants += 1;
try self.messages.append(try messages_mod.textMessage(self.arena, "user", eval_control.verifier_hard_stop));
return true;
diff --git a/src/run_budget.zig b/src/run_budget.zig
index b7f36aaa..ed56a4cd 100644
--- a/src/run_budget.zig
+++ b/src/run_budget.zig
@@ -98,6 +98,15 @@ pub const RunBudget = struct {
return self.model_calls.load(.acquire);
}
+ /// True when at least `calls` more model calls fit under the ceiling.
+ /// Advisory (racy against concurrent children) — for skipping OPTIONAL
+ /// spending (e.g. a RED repair continuation), never for admission;
+ /// acquire() remains the only authority.
+ pub fn canAfford(self: *const RunBudget, calls: u64) bool {
+ if (self.max_model_calls == 0) return true;
+ return self.model_calls.load(.acquire) + calls <= self.max_model_calls;
+ }
+
pub fn remaining(self: *const RunBudget) u64 {
if (self.max_model_calls == 0) return std.math.maxInt(u64); // 0 = unlimited
return self.max_model_calls -| self.used();