graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(tui): SIGTSTP livelock and the invisible background op
Rach Pradhan2e97dd2b4b2f
diff --git a/TUI/render.zig b/TUI/render.zigindex 09df275b..6540d0fe 100644--- a/TUI/render.zig+++ b/TUI/render.zig@@ -32,7 +32,11 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,const overlay_body = self.overlay != .none and self.overlay != .image;const mid = if (overlay_body)try chrome.overlay(self, a, width)- else if (self.screen == .welcome and self.userTurnCount() == 0)+ else if (self.screen == .welcome and self.history.items.len == 0 and self.pending == null)+ // Anything in the transcript — including a live background op's+ // pending row — outranks the welcome pane: keeping it up hid a+ // running `!cmd`/@-list entirely and froze the paint loop (the+ // welcome frame is static, so the hash-diff suppressed every paint).try welcome.render(self, a, width)elsetry scrollback.render(self, a, width, now_ms);diff --git a/TUI/restore.zig b/TUI/restore.zigindex 16ef0dd3..a0598058 100644--- a/TUI/restore.zig+++ b/TUI/restore.zig@@ -141,8 +141,16 @@ fn onStop(sig: std.posix.SIG) callconv(.c) void {.flags = 0,};std.posix.sigaction(sig, &dfl, null);+ // The kernel blocks the delivered signal for the handler's duration, so a+ // bare raise() only marks it PENDING: it would deliver on handler RETURN —+ // AFTER installStopHandlers() below re-armed us — and re-enter this+ // handler forever (a measured 12 MB/s restore/enable flood at 99% CPU,+ // never reaching state T). Unblock it so the raise stops the process HERE.+ var only_stop = std.posix.sigemptyset();+ std.posix.sigaddset(&only_stop, sig);+ std.posix.sigprocmask(std.posix.SIG.UNBLOCK, &only_stop, null);std.posix.raise(sig) catch {};- // --- continued here ---+ // --- genuinely continued here (SIGCONT) ---installStopHandlers();if (!was_fullscreen) return;if (tty.enterRaw()) |_| {}diff --git a/TUI/scrollback.zig b/TUI/scrollback.zigindex 49defe21..fe22f1f6 100644--- a/TUI/scrollback.zig+++ b/TUI/scrollback.zig@@ -258,8 +258,7 @@ fn row(self: *const Model, a: std.mem.Allocator, idx: usize, e: app.Entry, widthreturn theme_mod.wrapToWidth(a, line, width);}if (e.kind == .pending) {- // Steady accent bar (no flicker); the animated dots carry the motion.- const line = try std.fmt.allocPrint(a, "{s}{s}❙{s}{s} {s}{s}", .{ sel, th.accent, theme_mod.reset, th.muted, body, theme_mod.reset });+ const line = try std.fmt.allocPrint(a, "{s}{s}{s}{s}{s} {s}{s}", .{ sel, th.accent, thinkingGlyph(now_ms), theme_mod.reset, th.muted, body, theme_mod.reset });return theme_mod.wrapToWidth(a, line, width);}const body_fg = if (e.kind == .err) th.error_fg else th.text;@@ -356,8 +355,12 @@ fn toolCard(a: std.mem.Allocator, th: theme_mod.Theme, start_text: []const u8, d}fn thinkingGlyph(now_ms: u64) []const u8 {- _ = now_ms;- return "❙";+ // A soft 1s blink on the PENDING row only. A fully static frame made+ // run.zig's hash-diff suppress every paint for a background op's whole+ // duration — 8s of literally zero terminal output read as a freeze. One+ // changing glyph on one line keeps the paints flowing while historical+ // rows stay byte-identical (the earlier full-transcript pulse bug).+ return if ((now_ms / 500) % 2 == 0) "❙" else "❘";}fn thinkingLabel(now_ms: u64) []const u8 {@@ -410,6 +413,11 @@ test "thinking animation is Grok ❙ flicker plus static Thinking" {try std.testing.expectEqualStrings("Thinking", thinkingLabel(0));try std.testing.expectEqualStrings(thinkingLabel(0), thinkingLabel(320));try std.testing.expectEqualStrings("❙", thinkingGlyph(0));+ // The glyph must actually FLICKER across a half-period, and be stable+ // within one — a fully static pending row suppressed every paint for a+ // background op's whole duration (verified live: 8s of zero output).+ try std.testing.expectEqualStrings(thinkingGlyph(0), thinkingGlyph(140));+ try std.testing.expect(!std.mem.eql(u8, thinkingGlyph(0), thinkingGlyph(500)));}test "a live turn never pulses or shifts historical rows" {@@ -446,6 +454,22 @@ test "a live turn never pulses or shifts historical rows" {}try std.testing.expect(saw_summary);try std.testing.expectEqualStrings(t0, t140);+ // Across a blink half-period exactly ONE line — the pending row — may+ // change; every historical row stays byte-identical. (Full staticness+ // went the other way into a paint freeze; full pulsing was the original+ // bug. The contract is: motion exists, and it is confined.)+ const t500 = try render(&m, arena.allocator(), 80, 500);+ var it0 = std.mem.splitScalar(u8, t0, '\n');+ var it5 = std.mem.splitScalar(u8, t500, '\n');+ var changed: usize = 0;+ while (it0.next()) |a0| {+ const a5 = it5.next() orelse "";+ if (!std.mem.eql(u8, a0, a5)) {+ changed += 1;+ try std.testing.expect(std.mem.indexOf(u8, a0, "Thinking") != null);+ }+ }+ try std.testing.expectEqual(@as(usize, 1), changed);}test "prettyTool strips mcp prefix" {