graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
lean -p: bounce a text-only first answer only for an action request (#1518)
justrach25f0775a94db
diff --git a/docs/adr/0052-lean-oneshot-bounces-prose.md b/docs/adr/0052-lean-oneshot-bounces-prose.mdindex 61b970e1..f8be7330 100644--- a/docs/adr/0052-lean-oneshot-bounces-prose.md+++ b/docs/adr/0052-lean-oneshot-bounces-prose.md@@ -78,3 +78,12 @@ are data. This recognition is local to the fake-done guard: it does not changeintent classification, tool permissions, empty-response retries, or open-workcompletion gates. Translation and ambiguous multiword requests remain outsidethis narrow exemption.++## Action-request and budget refinement (#1518)++The bounce now needs an action word in the latest request (fix, edit, make,+create, run, ...; `task_intent.requestsAction`). A question with no action+verb is answered by its first text reply, so `graff -p "what is 2+2"` no+longer pays a second call. The bounce is also skipped when the run's+model-call budget or the per-turn call cap cannot pay for the retry: a valid+answer must not become a budget-exhaustion failure.diff --git a/src/agent_empty_completion.zig b/src/agent_empty_completion.zigindex f15233e4..45a10f6a 100644--- a/src/agent_empty_completion.zig+++ b/src/agent_empty_completion.zig@@ -147,6 +147,10 @@ pub fn handle(self: *Agent, final_text: []const u8, hist_len: usize) !bool {if (@import("task_intent.zig").current(self) == .informational) return false;if (@import("exact_reply.zig").requested(messages.latestUserText(self.messages.items))) return false;if (no_local_tools.enabled) return false;+ // #1518: a question answered in text is done, and a retry the model-call+ // budget cannot pay for turns a valid answer into a budget failure.+ if (!@import("task_intent.zig").requestsAction(messages.latestUserText(self.messages.items))) return false;+ if (!PendingWork.canRequest(self)) return false;if (!shouldBounce(main_mod.unattended, no_local_tools.lean, self.text_only, self.review_mode, self.sub, self.tool_calls_this_turn, self.model_calls_this_turn, final_text))return false;try self.messages.append(try messages.userNote(self.arena, self.provider.kind, bounce_note));@@ -423,3 +427,37 @@ test "exact reply bypasses only fake done while mixed requests and empty repliestry std.testing.expectEqual(@as(u8, if (empty) 1 else 0), self.empty_completion_retries);}}++test "#1518 lean bounce skips questions and a spent model-call budget" {+ var state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer state.deinit();+ const old_unattended = main_mod.unattended;+ const old_lean = no_local_tools.lean;+ const old_enabled = no_local_tools.enabled;+ main_mod.unattended = true;+ no_local_tools.lean = true;+ no_local_tools.enabled = false;+ defer {+ main_mod.unattended = old_unattended;+ no_local_tools.lean = old_lean;+ no_local_tools.enabled = old_enabled;+ }+ var budget: @import("run_budget.zig").RunBudget = .{ .max_model_calls = 1 };+ budget.model_calls.store(1, .release);+ const cases = .{+ .{ "What does parse() return for an empty string?", false, false },+ .{ "Fix the off-by-one in fib.py", true, false },+ .{ "Fix the off-by-one in fib.py", false, true },+ };+ inline for (cases) |case| {+ var self = pendingFixture(state.allocator());+ self.empty_completion_retries = 0;+ self.call_kind = .title; // suppress fixture notices without initializing a writer+ self.tool_calls_this_turn = 0;+ self.model_calls_this_turn = 1;+ if (case[1]) self.run_budget = &budget;+ try self.messages.append(try messages.textMessage(self.arena, "user", case[0]));+ const before = self.messages.items.len;+ try std.testing.expectEqual(case[2], try handle(&self, "It returns an empty list.", before));+ }+}diff --git a/src/task_intent.zig b/src/task_intent.zigindex 6bee0c9e..32c1ec03 100644--- a/src/task_intent.zig+++ b/src/task_intent.zig@@ -41,13 +41,28 @@ pub fn classify(text: []const u8) Intent {var words = std.mem.tokenizeAny(u8, text, " \t\r\n,;:!?()[]{}\"`");while (words.next()) |raw| {const word = std.mem.trim(u8, raw, ".");- if (oneOf(word, &.{ "fix", "edit", "implement", "add", "remove", "delete", "rename", "refactor", "write", "create", "update", "patch", "build", "test", "lint", "run", "merge", "push", "deploy", "commit" })) return .general;+ if (actionWord(word)) return .general;if (oneOf(word, &.{ "summarize", "summarise", "summary", "explain", "describe", "overview", "map", "research", "investigate", "lookup" })) informational = true;if (std.ascii.eqlIgnoreCase(word, "read-only")) informational = true;}return if (informational) .informational else .general;}+const action_words = [_][]const u8{ "fix", "edit", "implement", "add", "remove", "delete", "rename", "refactor", "write", "create", "update", "patch", "build", "test", "lint", "run", "merge", "push", "deploy", "commit", "change", "modify", "make", "resolve", "apply", "replace", "rewrite" };++fn actionWord(word: []const u8) bool {+ return oneOf(word, &action_words);+}++/// True when the request names something to change or execute. A text-only+/// first answer is unfinished only for such a request (#1518); a question+/// with no action verb is answered by its text.+pub fn requestsAction(text: []const u8) bool {+ var words = std.mem.tokenizeAny(u8, text, " \t\r\n,;:!?()[]{}\"`");+ while (words.next()) |raw| if (actionWord(std.mem.trim(u8, raw, "."))) return true;+ return false;+}+pub fn current(self: *const Agent) Intent {return classify(@import("messages.zig").latestUserText(self.messages.items));}@@ -139,3 +154,10 @@ test "summary checkpoint is once, preserves the human request, and respects a netry std.testing.expect(state.nudged);try std.testing.expectEqual(@as(usize, 5), agent.messages.items.len);}++test "only a request naming an action counts as one (#1518)" {+ for ([_][]const u8{ "Fix src/parser.zig", "Make `python3 test.py` print OK. Do not edit the tests.", "Reply with exactly: pong; then create target.txt" }) |text|+ try std.testing.expect(requestsAction(text));+ for ([_][]const u8{ "What does parse() return for an empty string?", "Which module owns retries?", "what is 2+2" }) |text|+ try std.testing.expect(!requestsAction(text));+}