Skip to content

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

Python

fix(codex): stall watchdog waits through encrypted thinking; honest reconnect notice

justrach24c872c624f2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 175f9a92..7f7349ee 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,10 @@ current is part of cutting a release.
${arch}` / `macOS ${product} ${arch}`, kernel `os.release()` (#617)
- Codex `session_id` header is the same value as `prompt_cache_key` (openai/codex
ModelClient default), not a per-process random UUID
+- Codex high-effort thinking no longer trips the 45s stall watchdog after
+ `in_progress` (encrypted reasoning is silent). A stall notice no longer says
+ "ending turn" while reconnect still has retries. Interactive sessions print a
+ dim `graff update` line when GitHub has a newer release.
## v0.0.275 (2026-08-24)
diff --git a/src/agent_stream.zig b/src/agent_stream.zig
index 5530b621..aa80e8aa 100644
--- a/src/agent_stream.zig
+++ b/src/agent_stream.zig
@@ -30,8 +30,9 @@ const WatchdogFired = http.WatchdogFired;
const sendHeadTask = http.sendHeadTask;
const headStallTask = http.headStallTask;
const streamLineTask = http.streamLineTask;
-const streamStallWatch = http.streamStallWatch;
+const deadlineStallTask = http.deadlineStallTask;
const watchdogError = http.watchdogError;
+const http_stall = @import("http_stall.zig");
// escPressed/drainSteerStdin/rawNonblockStdin/restoreStdin/ssePayload live in
// agent_interrupt.zig; reached through the Agent struct's member aliases.
@@ -234,11 +235,12 @@ pub fn postStreamWithClient(self: *Agent, client: *std.http.Client, body: []cons
// flush the partial, poison, and end the turn as StreamStalled (never a
// hang, never a mislabeled StreamDropped or user Esc).
if (saw_done) break :stream;
- sink.emit(self.io, .{ .stream_aborted = .stalled });
+ sink.emit(self.io, .{ .transport_aborted = .{ .reason = .stalled, .turn_ending = false } });
if (req.connection) |conn| conn.closing = true;
return error.StreamStalled;
};
- rsel.concurrent(.stall, streamStallWatch, .{ self.io, orig_tio != null, self.partial_text.items.len != 0 }) catch {
+ const stall_budget = http_stall.interFrameBudgetMs(http.stream_stall_ms, got_body, self.partial_text.items.len != 0);
+ rsel.concurrent(.stall, deadlineStallTask, .{ self.io, orig_tio != null, stall_budget }) catch {
const r = rsel.await() catch |e| {
rsel.cancelDiscard();
return e;
@@ -273,7 +275,7 @@ pub fn postStreamWithClient(self: *Agent, client: *std.http.Client, body: []cons
// idle stream (silent past this read's budget) — end the turn as
// error.StreamStalled so it is never recorded as "[response
// interrupted by user]" (#134). Only the deadline gets a notice.
- sink.emit(self.io, .{ .stream_aborted = if (w == .deadline) .stalled else .interrupted });
+ if (w == .deadline) sink.emit(self.io, .{ .transport_aborted = .{ .reason = .stalled, .turn_ending = false } }) else sink.emit(self.io, .{ .stream_aborted = .interrupted });
if (req.connection) |conn| conn.closing = true;
return watchdogError(w, error.StreamStalled);
},
diff --git a/src/agent_ws.zig b/src/agent_ws.zig
index a8ed3baa..5a88e594 100644
--- a/src/agent_ws.zig
+++ b/src/agent_ws.zig
@@ -505,14 +505,14 @@ pub fn postResponsesWs(self: *Agent, body: []const u8) ![]u8 {
// 2-slot stall budget — the SSE head guard's contract for "sent,
// nothing came back". A FRESH connect skips this: its handshake just
// proved liveness, so it keeps the full pre-first-token budget.
- // * otherwise → the inter-frame budget: full while only protocol /
- // reasoning frames have landed, a quarter once prose has flowed.
+ // * otherwise → the inter-frame budget: full stream_stall_ms after
+ // protocol frames (encrypted thinking), a quarter once prose flowed.
// http_stall.budgetMs is what streamStallWatch asks the SSE reader's
// budget of on every tick; it cannot change mid-wait, so deciding it
// here is equivalent and lets both regimes share one watchdog arm.
read: {
const head_wait = reused and frames_seen == 0;
- const budget = if (head_wait) http.head_stall_ms else http_stall.budgetMs(http.stream_stall_ms, text_seen);
+ const budget = if (head_wait) http.head_stall_ms else http_stall.interFrameBudgetMs(http.stream_stall_ms, frames_seen > 0, text_seen);
const ReadDone = union(enum) { msg: ws.Error!ws.Opcode, stall: WatchdogFired };
var rd_buf: [2]ReadDone = undefined;
var rsel: Io.Select(ReadDone) = .init(self.io, &rd_buf);
@@ -521,7 +521,7 @@ pub fn postResponsesWs(self: *Agent, body: []const u8) ![]u8 {
// blocking readMessage can hang forever on a half-open ws with no
// watchdog; end the turn as StreamStalled (never a hang, never a user
// Esc), exactly as the .deadline arm below does.
- emitAbort(self, .stalled, true);
+ emitAbort(self, .stalled, false);
if (self.tracer) |tr| tr.note("ws", "stall");
return error.StreamStalled;
};
@@ -550,7 +550,7 @@ pub fn postResponsesWs(self: *Agent, body: []const u8) ![]u8 {
return watchdogError(w, error.HungRequest);
} else {
// Only the deadline gets a notice; a user Esc stays silent.
- if (w == .deadline) emitAbort(self, .stalled, true);
+ if (w == .deadline) emitAbort(self, .stalled, false);
if (self.tracer) |tr| tr.note("ws", if (w == .esc) "esc" else "stall");
return watchdogError(w, error.StreamStalled);
},
diff --git a/src/cli.zig b/src/cli.zig
index 073b0ed4..8dc7cdd9 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -25,6 +25,8 @@ pub const changelog_text =
\\ • foreground bash auto-backgrounds after 120s instead of waiting forever (#620)
\\ • Kimi identity: graff/<version> User-Agent; device headers match kimi-code (#617)
\\ • Codex session_id header matches prompt_cache_key (openai/codex)
+ \\ • Codex thinking silence uses the full stall budget; stall notice is honest
+ \\ • REPL/TUI prints a dim line when a newer graff release is available
\\
\\0.0.275
\\ • OpenRouter requests carry app attribution (categories: cli-agent, programming-app)
@@ -334,6 +336,41 @@ fn isCleanReleaseVersion(s: []const u8) bool {
return dots == 2;
}
+fn fetchLatestReleaseTag(io: Io, gpa: Allocator, arena: Allocator, repo_api: []const u8) ?[]const u8 {
+ var client: std.http.Client = .{ .allocator = gpa, .io = io };
+ defer client.deinit();
+ var aw: Io.Writer.Allocating = .init(arena);
+ defer aw.deinit();
+ const extra = [_]std.http.Header{.{ .name = "Accept", .value = "application/vnd.github+json" }};
+ const res = client.fetch(.{
+ .location = .{ .url = repo_api },
+ .method = .GET,
+ .response_writer = &aw.writer,
+ .headers = .{ .user_agent = .{ .override = "simple-harness/" ++ harness_version } },
+ .extra_headers = &extra,
+ }) catch return null;
+ if (@intFromEnum(res.status) != 200) return null;
+ if (aw.writer.buffered().len > 64 * 1024) return null;
+ const v = std.json.parseFromSliceLeaky(Value, arena, aw.writer.buffered(), .{ .allocate = .alloc_always }) catch return null;
+ if (v != .object) return null;
+ const t = v.object.get("tag_name") orelse return null;
+ return if (t == .string) t.string else null;
+}
+
+/// Dim REPL/TUI line when GitHub has a newer release. Null if current, newer,
+/// offline, or GRAFF_NO_UPDATE_CHECK is set.
+pub fn updateAvailableLine(io: Io, gpa: Allocator, arena: Allocator, skip: bool) ?[]const u8 {
+ if (skip) return null;
+ const repo_api = "https://api.github.com/repos/justrach/codegraff/releases/latest";
+ const latest_tag = fetchLatestReleaseTag(io, gpa, arena, repo_api) orelse return null;
+ const cur_raw = if (std.mem.startsWith(u8, harness_version, "v")) harness_version[1..] else harness_version;
+ const latest_raw = if (std.mem.startsWith(u8, latest_tag, "v")) latest_tag[1..] else latest_tag;
+ const cur = parseVersion(cur_raw) orelse return null;
+ const latest = parseVersion(latest_raw) orelse return null;
+ if (cur.order(latest) != .lt) return null;
+ return std.fmt.allocPrint(arena, "graff v{s} is available (you have {s}) — graff update", .{ latest_raw, cur_raw }) catch null;
+}
+
/// `graff update [--force|--check]` — bring the installed binary up to the
/// latest GitHub release. Checks the release tag first and skips when already
/// current (unless --force); --check only reports, never installs. The actual
@@ -371,32 +408,7 @@ pub fn updateCommand(
const cur = parseVersion(cur_raw);
const cur_is_release = cur != null and isCleanReleaseVersion(cur_raw);
- // Query the latest release tag. GitHub's API requires a User-Agent; the
- // Accept header pins the v3 JSON response. Any failure → null, handled below.
- const latest_tag: ?[]const u8 = blk: {
- var client: std.http.Client = .{ .allocator = gpa, .io = io };
- defer client.deinit();
- var aw: Io.Writer.Allocating = .init(arena);
- defer aw.deinit();
- const extra = [_]std.http.Header{.{ .name = "Accept", .value = "application/vnd.github+json" }};
- const res = client.fetch(.{
- .location = .{ .url = repo_api },
- .method = .GET,
- .response_writer = &aw.writer,
- .headers = .{ .user_agent = .{ .override = "simple-harness/" ++ harness_version } },
- .extra_headers = &extra,
- }) catch break :blk null;
- if (@intFromEnum(res.status) != 200) break :blk null;
- // Cap the response before parsing: the endpoint is pinned to GitHub's
- // API (normally a small JSON blob), but a captive-portal redirect or a
- // TLS MITM could stream an unbounded body and exhaust memory. 64 KiB is
- // far above any legitimate /releases/latest payload.
- if (aw.writer.buffered().len > 64 * 1024) break :blk null;
- const v = std.json.parseFromSliceLeaky(Value, arena, aw.writer.buffered(), .{ .allocate = .alloc_always }) catch break :blk null;
- if (v != .object) break :blk null;
- const t = v.object.get("tag_name") orelse break :blk null;
- break :blk if (t == .string) t.string else null;
- };
+ const latest_tag = fetchLatestReleaseTag(io, gpa, arena, repo_api);
// `latest` is a release tag from GitHub, so it parses to a clean triple.
const latest_raw = if (latest_tag) |tag| (if (std.mem.startsWith(u8, tag, "v")) tag[1..] else tag) else null;
diff --git a/src/http_stall.zig b/src/http_stall.zig
index 54aeaa9a..136589ac 100644
--- a/src/http_stall.zig
+++ b/src/http_stall.zig
@@ -40,6 +40,16 @@ pub fn budgetMs(base_ms: u64, tokens_flowing: bool) u64 {
return @min(base_ms, @max(idle_floor_ms, base_ms / idle_divisor));
}
+/// Inter-frame wait. No bytes yet is a dead socket (head ceiling). Protocol
+/// frames without prose is a reasoning model (full `base_ms` — gpt-5.6-sol
+/// high/max often encrypts thinking and emits nothing for well over 45s).
+/// Visible prose tightens to the between-lines budget.
+pub fn interFrameBudgetMs(base_ms: u64, saw_protocol: bool, tokens_flowing: bool) u64 {
+ if (tokens_flowing) return budgetMs(base_ms, true);
+ if (saw_protocol) return base_ms;
+ return budgetMs(base_ms, false);
+}
+
/// True once a silent read has outlasted its budget — the watchdog loop's only
/// decision, split out so it can be exercised at the boundary in a unit test.
pub fn expired(waited_ms: u64, base_ms: u64, tokens_flowing: bool) bool {
@@ -79,3 +89,10 @@ test "stall budget (#56): between-lines silence trips sooner than a pre-first-to
try std.testing.expectEqual(@as(u64, 5 * 1000), budgetMs(5 * 1000, true));
try std.testing.expect(expired(5 * 1000, 5 * 1000, true));
}
+
+test "stall budget: protocol-seen thinking keeps the full wait, not the 45s ceiling" {
+ const base: u64 = 120 * 1000;
+ try std.testing.expectEqual(head_ceiling_ms, interFrameBudgetMs(base, false, false));
+ try std.testing.expectEqual(base, interFrameBudgetMs(base, true, false));
+ try std.testing.expectEqual(@as(u64, 30 * 1000), interFrameBudgetMs(base, true, true));
+}
diff --git a/src/session_start.zig b/src/session_start.zig
index eef52db4..cbaa3d3a 100644
--- a/src/session_start.zig
+++ b/src/session_start.zig
@@ -59,6 +59,7 @@ const repl = @import("repl.zig");
const repl_glue = @import("repl_glue.zig");
const messages_mod = @import("messages.zig");
const session = @import("session.zig");
+const cli = @import("cli.zig");
/// `graff title <prompt>` — print the tab-title the model would generate for
/// that prompt (one title call, no session). For A/B-ing title prompts/styles.
@@ -179,6 +180,10 @@ pub fn setupWorktreeAndBanner(
}),
.tone = .dim,
} });
+ if (cli.updateAvailableLine(io, gpa, arena, environ_map.get("GRAFF_NO_UPDATE_CHECK") != null)) |line| sink.emit(io, .{ .session_notice = .{
+ .text = line,
+ .tone = .dim,
+ } });
}
}