Skip to content

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

Python

fix(eval): whole-line score parsing + exit-code fallback (#367)

justrachde4948105429
diff --git a/src/agent_eval.zig b/src/agent_eval.zig
index ae1868af..d406612d 100644
--- a/src/agent_eval.zig
+++ b/src/agent_eval.zig
@@ -69,7 +69,14 @@ pub fn runEval(self: *Agent, note: []const u8) !ExecResult {
.exited => |c| @intCast(c),
else => -1,
};
- const det = parseEvalScore(run.stdout) orelse parseEvalScore(run.stderr);
+ // #367: a command that prints no parseable score falls back to exit-code
+ // semantics — 0 is a pass, anything else a fail — so pointing --eval at a
+ // plain test runner (`pytest -q`, `zig build test`, `false`) works out of
+ // the box instead of scraping nonsense off its summary line. An explicit
+ // `score: N` line always wins; judges (runJudge) keep parse-only.
+ const parsed = parseEvalScore(run.stdout) orelse parseEvalScore(run.stderr);
+ const exit_derived = parsed == null;
+ const det: ?f64 = parsed orelse if (exit_code == 0) @as(f64, 100) else @as(f64, 0);
// LLM-as-judge (--judge): an independent subagent inspects the actual
// artifacts against the rubric and returns its own 0-100 score. Both
@@ -209,6 +216,7 @@ pub fn runEval(self: *Agent, note: []const u8) !ExecResult {
} else {
try w.print("eval #{d}: score {d:.1}/100 (best {d:.1}, target {d}). ", .{ self.eval_iter, s, self.eval_best, self.eval_target });
}
+ if (exit_derived) try w.writeAll("(Score derived from the command's exit code — its output had no score line; make it print `score: N` for finer grading.) ");
if (met)
try w.writeAll("TARGET MET - verifier gate is green; finish only if no workspace-changing tool runs after this eval.")
else if (improved)
diff --git a/src/repl_glue.zig b/src/repl_glue.zig
index 5ddc8711..3515c3ef 100644
--- a/src/repl_glue.zig
+++ b/src/repl_glue.zig
@@ -110,9 +110,11 @@ pub fn goalSteeringNote(arena: Allocator, goal: ?agent_mod.Goal) ![]const u8 {
return std.fmt.allocPrint(arena, "[standing goal: {s} - track this as a live todo_write checklist and work through it (todo_read shows the current one; todo_write REPLACES it - completed items you omit are kept, open items you omit are dropped), marking each item in_progress when you start and completed when done. When the objective is verifiably done, call attempt_completion - that completes the goal and ends this steering.]", .{g.objective});
}
-/// Extract a 0-100 score from an eval command's output: a `score` key (JSON or
-/// key=val) if present, else the last numeric line. Values in [0,1] are read as
-/// fractions and scaled to 0-100.
+/// Extract a 0-100 score from eval output ([0,1] scales up): a `score` key
+/// (JSON or key=val) if present, else a last line that IS a number — whole
+/// line, never a leading prefix (#367: pytest's "4 passed in 0.01s" scored a
+/// green suite 4/100, and "1 failed" → 1 → the fraction rule → a false 100;
+/// prose is not a score — plain runners ride runEval's exit-code fallback).
pub fn parseEvalScore(out: []const u8) ?f64 {
if (std.mem.indexOf(u8, out, "score")) |i| {
var j = i + 5;
@@ -125,8 +127,7 @@ pub fn parseEvalScore(out: []const u8) ?f64 {
}
const trimmed = std.mem.trimEnd(u8, out, " \t\r\n");
const last = if (std.mem.lastIndexOfScalar(u8, trimmed, '\n')) |k| trimmed[k + 1 ..] else trimmed;
- if (parseLeadingNumber(std.mem.trim(u8, last, " \t\r\n"))) |v| return normalizeScore(v);
- return null;
+ return normalizeScore(std.fmt.parseFloat(f64, std.mem.trim(u8, last, " \t\r\n")) catch return null);
}
fn parseLeadingNumber(s: []const u8) ?f64 {
diff --git a/src/subagent_tests.zig b/src/subagent_tests.zig
index 9913b0be..9253189d 100644
--- a/src/subagent_tests.zig
+++ b/src/subagent_tests.zig
@@ -29,6 +29,15 @@ test "variantJudgePrompt: bounded, names the phase, keeps the score contract" {
try std.testing.expect(std.mem.indexOf(u8, p, "score: <N>") != null);
// …and it round-trips: a judge tail like this parses back to the score.
try std.testing.expectEqual(@as(?f64, 87), repl_glue.parseEvalScore("ok\nscore: 87"));
+ // #367: a prose line is not a score. pytest's summary used to parse as a
+ // leading number — 4/100 for a green suite, and "1 failed" → 1 → the
+ // [0,1] fraction rule → 100/100 on a FAILING suite.
+ try std.testing.expectEqual(@as(?f64, null), repl_glue.parseEvalScore("4 passed in 0.01s"));
+ try std.testing.expectEqual(@as(?f64, null), repl_glue.parseEvalScore("2 failed, 2 passed in 0.02s"));
+ try std.testing.expectEqual(@as(?f64, null), repl_glue.parseEvalScore("1 failed in 0.01s"));
+ // A last line that IS a number still works, as does an explicit fraction.
+ try std.testing.expectEqual(@as(?f64, 85), repl_glue.parseEvalScore("all checks done\n85"));
+ try std.testing.expectEqual(@as(?f64, 90), repl_glue.parseEvalScore("{\"score\": 0.9}"));
}
test "classifyFailure: maps the child's api-error detail to a category + retry-safety" {