Skip to content

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

Python

Reject unsupported script output expressions with a recoverable error

Rach Pradhan18449ff5af0f
diff --git a/evals/harness_behavior.jsonl b/evals/harness_behavior.jsonl
index 4ddf4f47..a34c462e 100644
--- a/evals/harness_behavior.jsonl
+++ b/evals/harness_behavior.jsonl
@@ -131,3 +131,4 @@
{"args": [], "env": {"GRAFF_NO_CODEDB_GUARD": "1"}, "prompt": "Run the scripted RLM ordering fixture and report only observed results.", "workspace_seed": {"target.txt": "old"}, "id": "rlm-failed-edit-blocks-tail", "why": "A failed native edit aborts dependent RLM commands without marker side effects.", "script": [{"tool": "rlm", "arguments": {"code": "e = edit_file(path=\"target.txt\", old_string=\"absent\", new_string=\"new\")\nv = bash(\"printf ran > marker\")\nprint(v)"}}, {"text": "The edit failed; the later command did not run."}], "verify_command": ["python3", "-c", "from pathlib import Path; assert not Path('marker').exists()"], "assert": [{"event": {"type": "tool_call_finished", "name": "rlm", "is_error": true}}, {"file_equals": {"path": "target.txt", "content": "old"}}]}
{"args": [], "env": {"GRAFF_NO_CODEDB_GUARD": "1"}, "prompt": "Run the scripted RLM ordering fixture and report only observed results.", "workspace_seed": {"target.txt": "old"}, "id": "rlm-nested-shell-failure-status", "why": "A nested shell failure propagates error status and prevents later nested mutation.", "script": [{"tool": "rlm", "arguments": {"code": "print(bash(\"printf NESTED_FAILURE; exit 7\"), write_file(path=\"marker\", content=\"ran\"))"}}, {"text": "The nested command failed."}], "verify_command": ["python3", "-c", "from pathlib import Path; assert not Path('marker').exists()"], "assert": [{"event": {"type": "tool_call_finished", "name": "rlm", "is_error": true}}, {"request_contains": {"index": 1, "text": "NESTED_FAILURE"}}]}
{"args": [], "env": {"GRAFF_NO_CODEDB_GUARD": "1"}, "prompt": "Run the scripted RLM ordering fixture and report only observed results.", "workspace_seed": {"target.txt": "old"}, "id": "rlm-pending-host-blocks-tail-completion", "why": "Pending nested background work preserves pending status, stops later mutation and cannot satisfy same-batch completion.", "script": [{"tools": [{"tool": "rlm", "arguments": {"code": "print(bash(command=\"sleep 0.2; exit 0\", run_in_background=true), write_file(path=\"marker\", content=\"ran\"))"}}, {"tool": "attempt_completion", "arguments": {"result": "PREMATURE_COMPLETION"}}]}, {"text": "Verification is still pending."}], "verify_command": ["python3", "-c", "from pathlib import Path; assert not Path('marker').exists()"], "assert": [{"event": {"type": "tool_call_finished", "name": "rlm", "is_error": false}}, {"event": {"type": "tool_call_finished", "name": "attempt_completion", "is_error": true}}, {"no_event": {"type": "tool_call_finished", "name": "attempt_completion", "is_error": false}}, {"final_text_contains": "Verification is still pending."}]}
+{"id": "rlm-indexed-print-refuses-and-recovers", "why": "Unsupported Python-style result indexing must report an error without pretending to execute the nested host or executing later side effects; the supported text binding form recovers.", "args": ["--lean"], "prompt": "Run the scripted checks and report only observed results.", "script": [{"tool": "rlm", "arguments": {"code": "print(bash(\"printf ran > nested-marker\")[\"stdout\"])\nx = write_file(path=\"tail-marker\", content=\"ran\")"}}, {"tool": "rlm", "arguments": {"code": "r = bash(\"printf VERIFIED\")\nprint(r)"}}, {"text": "Verified using the supported text result."}], "verify_command": ["python3", "-c", "from pathlib import Path; assert not Path(\"nested-marker\").exists(); assert not Path(\"tail-marker\").exists()"], "assert": [{"event": {"type": "tool_call_finished", "name": "rlm", "is_error": true}}, {"events_at_most": {"match": {"type": "tool_call_finished", "is_error": true}, "count": 1}}, {"request_contains": {"index": 1, "text": "host results are text"}}, {"event": {"type": "tool_result", "name": "rlm", "is_error": false, "text": "VERIFIED"}}, {"final_text_contains": "Verified using the supported text result."}]}
diff --git a/scripts/eval/tier1-manifest.json b/scripts/eval/tier1-manifest.json
index 6c9a6238..0789450a 100644
--- a/scripts/eval/tier1-manifest.json
+++ b/scripts/eval/tier1-manifest.json
@@ -15,7 +15,7 @@
"src/repl.zig",
"TUI/root.zig"
],
- "test_count_baseline": 2684,
+ "test_count_baseline": 2687,
"test_count_slack": 25,
"required_invariants": [
{
diff --git a/src/rlm.zig b/src/rlm.zig
index 2f762477..7fd60bb9 100644
--- a/src/rlm.zig
+++ b/src/rlm.zig
@@ -334,7 +334,10 @@ fn renderPrintPart(ctx: ToolCtx, arena: Allocator, inner: []const u8, binds: []c
var i = binds.len;
while (i > 0) {
i -= 1;
- if (std.mem.eql(u8, binds[i].name, t)) return maybeSlim(arena, binds[i].text);
+ const name = binds[i].name;
+ if (std.mem.eql(u8, name, t)) return maybeSlim(arena, binds[i].text);
+ if (std.mem.startsWith(u8, t, name) and t.len > name.len and
+ (t[name.len] == '[' or t[name.len] == '.')) return unsupportedPrint(ctx, status);
}
if (try spec_ptc.extractCall(arena, t)) |c| {
const key = try c.key(arena);
@@ -348,9 +351,18 @@ fn renderPrintPart(ctx: ToolCtx, arena: Allocator, inner: []const u8, binds: []c
if (mcp_shapes.slim(arena, out.text)) |s| return s;
return try arena.dupe(u8, out.text);
}
+ // Preserve the historical missing-bind echo, but do not pretend an
+ // unevaluated expression is a successful tool result.
+ if (t.len == 0) return unsupportedPrint(ctx, status);
+ for (t) |c| if (!std.ascii.isAlphanumeric(c) and c != '_') return unsupportedPrint(ctx, status);
return try arena.dupe(u8, t);
}
+fn unsupportedPrint(ctx: ToolCtx, status: *?ToolOutput) ![]const u8 {
+ status.* = .{ .text = try ctx.gpa.dupe(u8, "rlm: unsupported print expression; host results are text, so assign then print(name)."), .is_error = true };
+ return "";
+}
+
fn maybeSlim(arena: Allocator, payload: []const u8) []const u8 {
return mcp_shapes.slim(arena, payload) orelse payload;
}
diff --git a/src/rlm_order_tests.zig b/src/rlm_order_tests.zig
index e46676a0..aa1bfe2a 100644
--- a/src/rlm_order_tests.zig
+++ b/src/rlm_order_tests.zig
@@ -198,3 +198,40 @@ test "rlm order unresolved print argument prevents speculative tail reads" {
try std.testing.expect(try order.leading(arena.allocator(), "print(bash(command=cmd), read_file(\"x\"))") == null);
try std.testing.expect(try order.leading(arena.allocator(), "print(read_file(\"a\"), read_file(\"b\"))") != null);
}
+
+test "rlm unsupported indexed print refuses before executing its nested command or tail" {
+ var f = try Fixture.init();
+ defer f.deinit();
+ const out = try f.run("print(bash(\"printf ran > nested-marker\")[\"stdout\"])\nx = write_file(path=\"marker\", content=\"ran\")");
+ defer gpa.free(out.text);
+ try std.testing.expect(out.is_error);
+ try std.testing.expect(std.mem.indexOf(u8, out.text, "host results are text") != null);
+ try std.testing.expectError(error.FileNotFound, f.tmp.dir.openFile(io, "nested-marker", .{}));
+ try std.testing.expectError(error.FileNotFound, f.tmp.dir.openFile(io, "marker", .{}));
+}
+
+test "rlm unsupported bound field access reports text contract without rerunning host" {
+ var f = try Fixture.init();
+ defer f.deinit();
+ for ([_][]const u8{ "r[\"stdout\"]", "r.get(\"exit_code\")" }) |expr| {
+ const code = try std.fmt.allocPrint(gpa, "r = bash(\"printf x >> target.txt\")\nprint({s})", .{expr});
+ defer gpa.free(code);
+ const out = try f.run(code);
+ defer gpa.free(out.text);
+ try std.testing.expect(out.is_error);
+ try std.testing.expect(std.mem.indexOf(u8, out.text, "assign then print(name)") != null);
+ }
+ const out = try f.run("print(read_file(\"target.txt\"))");
+ defer gpa.free(out.text);
+ try std.testing.expectEqualStrings("oldxx", out.text);
+}
+
+test "rlm print keeps literals known and missing binds and supported reducers" {
+ var f = try Fixture.init();
+ defer f.deinit();
+ try f.tmp.dir.writeFile(io, .{ .sub_path = "items.json", .data = "[{\"id\":1},{\"id\":2}]" });
+ const out = try f.run("items = read_file(\"items.json\")\ncount = len(items)\nids = project(items, \"id\")\nprint(\"literal [data]\", 'quoted', count, ids, len(items), project(items, \"id\"), missing_bind)");
+ defer gpa.free(out.text);
+ try std.testing.expect(!out.is_error);
+ try std.testing.expectEqualStrings("literal [data]\nquoted\n2\n[1,2]\n2\n[1,2]\nmissing_bind", out.text);
+}