xonecas.io
79113
Ma

mini-coding-agent / commit 3ac9136

fix: retry on failure option

xonecas2026-10-23 3ac91367e7563925e84d3ece14a8b0df6e28a4e8 parent e067595

4 files changed

AGENTS.md+3−1
@@ -24,7 +24,9 @@ by reading the code, it does not belong here; keep this file short.
2424 - Sessions are append-only JSONL, one message per line, fsynced on write. Never
2525 rewrite or delete committed lines. A persistence failure stops the turn.
2626 - The loop has no compaction, no retries, and no meta-messages between steps.
27- Provider errors surface as-is, never masked or summarized.
27+ Provider errors surface as-is, never masked or summarized. A failed request
28+ is a rolled-back transaction: it never enters the context or the log, so the
29+ user retries it by resending the turn unchanged.
2830 - `edit`, `read`, and `bash` only. Tool arguments are untrusted and validated
2931 once at the boundary. `read` returns image blocks only for models that declare
3032 image input.
README.md+5−1
@@ -52,7 +52,7 @@ tool output go to stderr, the assistant text to stdout; a failed turn exits 1.
5252
5353 | Key | Meaning |
5454 |---|---|
55-| `Enter` | submit |
55+| `Enter` | submit; on an empty draft after a failure, retry it |
5656 | `Shift+Enter` | newline (`Ctrl+J` also works) |
5757 | `Esc` | pause the turn at the next step boundary |
5858 | `Ctrl+C` | cancel the turn |
@@ -225,3 +225,7 @@ Each session is a directory under `sessionsDir` named
225225 slugified from the first user message. A header line opens the log; every
226226 message and every model request is then appended and fsynced. The log is
227227 write-only; a write failure stops the turn.
228+
229+A failed model request is never appended: the attempt stays a request line with
230+no message, so the context holds no error and the next turn resends the same
231+request instead of a `continue`.
src/agent.zig+8−4
@@ -215,6 +215,14 @@ pub fn runTurn(opts: Options, messages: *std.ArrayList(message_mod.Message), int
215215 return;
216216 };
217217
218+ // A failed request is a rolled-back transaction: the error never enters
219+ // the context or the log, so resending the turn repeats the same
220+ // request instead of appending an apology to it.
221+ if (assistant.stop_reason == .err) {
222+ listener.emit(.{ .err = assistant.error_message orelse "provider error" });
223+ return;
224+ }
225+
218226 pushMessage(opts, messages, .{ .assistant = assistant }) catch {
219227 listener.emit(.{ .err = "out of memory" });
220228 return;
@@ -229,10 +237,6 @@ pub fn runTurn(opts: Options, messages: *std.ArrayList(message_mod.Message), int
229237 listener.emit(.cancelled);
230238 return;
231239 }
232- if (assistant.stop_reason == .err) {
233- listener.emit(.{ .err = assistant.error_message orelse "provider error" });
234- return;
235- }
236240
237241 const has_calls = for (assistant.content.items) |block| {
238242 if (block == .tool_call) break true;
src/tui/tui.zig+18−2
@@ -99,6 +99,7 @@ const Tui = struct {
9999 reasoning_bytes: usize = 0,
100100 active: bool = false,
101101 paused: bool = false,
102+ retry: bool = false,
102103 pause_requested: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
103104 aborting: bool = false,
104105 turn_done: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
@@ -251,6 +252,9 @@ const Tui = struct {
251252 if (self.active and self.pause_requested.load(.seq_cst)) {
252253 return std.fmt.allocPrint(self.s, "{s} · {s}", .{ styles.comment(self.s, "pausing - waiting for the step boundary"), info }) catch info;
253254 }
255+ if (self.retry) {
256+ return std.fmt.allocPrint(self.s, "{s} · {s}", .{ styles.err(self.s, "failed - Enter to retry"), info }) catch info;
257+ }
254258 if (!self.active or self.phase == .idle) return info;
255259 const elapsed = @max(0, @divFloor(time.nowMs() - self.turn_start, 1000));
256260 return std.fmt.allocPrint(self.s, "{s} {s} · {s} · {s}", .{
@@ -437,6 +441,7 @@ const Tui = struct {
437441 .tool_result => |tr| self.commitToolResult(tr.name, tr.text, tr.is_error, tr.diffs, tr.body, tr.images),
438442 .err => |m| {
439443 self.reportStatus("error", null, m);
444+ self.retry = true;
440445 self.endTurn(styles.err(self.s, std.fmt.allocPrint(self.s, "! {s}", .{m}) catch "! error"));
441446 },
442447 .no_model => {
@@ -725,7 +730,10 @@ const Tui = struct {
725730 return;
726731 }
727732 if (self.command_active) return;
728- if (std.mem.trim(u8, text, " \t\r\n").len == 0) return;
733+ if (std.mem.trim(u8, text, " \t\r\n").len == 0) {
734+ self.retryTurn();
735+ return;
736+ }
729737 if (commands.findCommand(text)) |found| {
730738 self.editor.clear();
731739 self.runCommand(found);
@@ -750,8 +758,15 @@ const Tui = struct {
750758 self.startTurn();
751759 }
752760
761+ fn retryTurn(self: *Tui) void {
762+ if (!self.retry or self.active) return;
763+ self.note(styles.comment(self.s, "retrying"));
764+ self.startTurn();
765+ }
766+
753767 fn startTurn(self: *Tui) void {
754768 self.active = true;
769+ self.retry = false;
755770 self.abort.store(false, .seq_cst);
756771 self.pause_requested.store(false, .seq_cst);
757772 self.turn_done.store(false, .seq_cst);
@@ -794,7 +809,7 @@ const Tui = struct {
794809
795810 fn showHelp(self: *Tui) void {
796811 const keys = [_][2][]const u8{
797- .{ "Enter", "submit" },
812+ .{ "Enter", "submit; on an empty draft after a failure, retry it" },
798813 .{ "Shift+Enter", "newline (Ctrl+J also works)" },
799814 .{ "Shift+Up/Down", "walk input history (Ctrl+R to search)" },
800815 .{ "Esc", "pause the turn at the next step boundary" },
@@ -832,6 +847,7 @@ const Tui = struct {
832847 self.keepName(&self.detail, null);
833848 self.keepName(&self.writing_tool, null);
834849 self.steering_text = "";
850+ self.retry = false;
835851 self.phase = .idle;
836852 self.stream_kind = .none;
837853 _ = self.calls.reset(.retain_capacity);