graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
acp: explain an exhausted empty-reply retry instead of naming the error (#1802)
justrach82037968fb08
diff --git a/src/acp_live_turn.zig b/src/acp_live_turn.zigindex 3af3b240..a6dd89cc 100644--- a/src/acp_live_turn.zig+++ b/src/acp_live_turn.zig@@ -59,10 +59,7 @@ pub const LiveTurn = struct {pub fn errorMessage(ctx: *anyopaque, err: anyerror) []const u8 {const self: *LiveTurn = @ptrCast(@alignCast(ctx));- return switch (err) {- error.ApiError, error.ProviderAuthenticationFailed => self.root.last_api_error orelse "Provider request failed",- else => @errorName(err),- };+ return describeError(err, self.root.last_api_error);}pub fn signalCancel() void {@@ -251,6 +248,25 @@ pub const LiveTurn = struct {}};+/// What an ACP client shows for a failed turn. An exhausted empty-reply retry+/// carries its own explanation (#1802); a bare error name told the user nothing.+pub fn describeError(err: anyerror, last_api_error: ?[]const u8) []const u8 {+ return switch (err) {+ error.ApiError, error.ProviderAuthenticationFailed => last_api_error orelse "Provider request failed",+ error.EmptyCompletion => last_api_error orelse @import("agent_empty_completion.zig").exhausted_text,+ else => @errorName(err),+ };+}++test "#1802: an exhausted empty-reply retry is explained, not named" {+ const exhausted = @import("agent_empty_completion.zig").exhausted_text;+ try std.testing.expectEqualStrings(exhausted, describeError(error.EmptyCompletion, exhausted));+ try std.testing.expectEqualStrings(exhausted, describeError(error.EmptyCompletion, null));+ try std.testing.expect(std.mem.indexOf(u8, exhausted, "6 times") != null);+ try std.testing.expectEqualStrings("Provider request failed", describeError(error.ApiError, null));+ try std.testing.expectEqualStrings("Interrupted", describeError(error.Interrupted, "stale"));+}+test "session/prompt receipt is traced even when dedup skips the turn" {const dedup = @import("turn_dedup.zig");dedup.resetForTest();diff --git a/src/agent_empty_completion.zig b/src/agent_empty_completion.zigindex a108237a..690bad47 100644--- a/src/agent_empty_completion.zig+++ b/src/agent_empty_completion.zig@@ -134,6 +134,11 @@ test "#1013 without a bounce note the follow-up is the answer" {try std.testing.expectEqualStrings("Current answer", current.finish(&self, "Current answer"));}+/// Why the turn ended, for the user (#1802): nothing earlier is lost, and+/// sending again is the retry.+pub const exhausted_text = "The provider returned an empty reply " ++ std.fmt.comptimePrint("{d}", .{max_consecutive + 1}) +++ " times in a row, so this turn stopped. The conversation is kept; send a message to try again.";+/// Handle a degenerate completion inside runTurn. Returns true when the/// caller should `continue` the loop.pub fn handle(self: *Agent, final_text: []const u8, hist_len: usize) !bool {@@ -144,7 +149,7 @@ fn handleWithWait(self: *Agent, final_text: []const u8, hist_len: usize, comptimif (std.mem.trim(u8, final_text, " \t\r\n").len == 0) {if (Agent.esc_cancel.load(.acquire) or @import("acp_engine.zig").cancel_flag.load(.acquire)) return error.Interrupted;if (!shouldRetry(final_text, self.empty_completion_retries)) {- self.last_api_error = "provider returned empty completions after 5 retries";+ self.last_api_error = exhausted_text;return error.EmptyCompletion;}try checkBudget(self);