graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: print the stall ⚠ only when the reconnect budget is gone
Cursor Agent7fa82eead320
diff --git a/scripts/test-stall-drop.py b/scripts/test-stall-drop.pyindex 79103266..81a737db 100644--- a/scripts/test-stall-drop.py+++ b/scripts/test-stall-drop.py@@ -1,10 +1,11 @@#!/usr/bin/env python3-"""#134/#132/#56 end-to-end: a forced stream stall/drop first RECONNECTS on a-fresh stream (#56); only after the reconnect budget is exhausted is the turn saved-as "[response ended early: ...]" and shown as a stream notice — NEVER a user Esc-interrupt. Drives the GRAFF_FORCE_STALL_ALWAYS / GRAFF_FORCE_DROP_ALWAYS seams,-which make EVERY live attempt return error.StreamStalled / error.StreamDropped-before any network call, so the give-up path runs with no provider/key."""+"""#134/#132/#56 end-to-end: a forced stream stall/drop first reconnects on a+fresh stream (#56, silent on the transcript — ADR 0021); only after the+reconnect budget is exhausted is the turn saved as "[response ended early: ...]"+and shown as an ending-turn notice — NEVER a user Esc interrupt. Drives the+GRAFF_FORCE_STALL_ALWAYS / GRAFF_FORCE_DROP_ALWAYS seams, which make EVERY live+attempt return error.StreamStalled / error.StreamDropped before any network+call, so the give-up path runs with no provider/key."""import json, os, shutil, subprocess, sys, tempfile_arg = sys.argv[1] if len(sys.argv) > 1 else "graff"@@ -43,15 +44,18 @@ def check(name, env_flag, marker, notice):# the whole point of #134/#132: it must NOT be a user interruptionassert "interrupted by user" not in assistant, f"{name}: mislabeled [response interrupted by user]!"assert "interrupted (esc)" not in out, f"{name}: terminal showed 'interrupted (esc)'!"- assert "reconnect" in out, f"{name}: no reconnect attempt shown before giving up (#56)"- print(f"ok {name}: saved {marker!r}, notice shown, never a user Esc")+ # Reconnect stays off the transcript (ADR 0021). #56 still ran: the+ # give-up line names the exhausted budget, and mid-turn "reconnecting"+ # chatter is gone.+ assert "reconnecting" not in out, f"{name}: mid-turn reconnect leaked onto the transcript"+ print(f"ok {name}: saved {marker!r}, ending notice shown, never a user Esc")def main():check("stall (#134)", "GRAFF_FORCE_STALL_ALWAYS",- "[response ended early: stream stalled]", "stream stalled")+ "[response ended early: stream stalled]", "stream stalled — ending turn")check("drop (#132/#133)", "GRAFF_FORCE_DROP_ALWAYS",- "[response ended early: connection dropped]", "connection dropped")+ "[response ended early: connection dropped]", "connection dropped — response ended early")print("all clear: a forced stall/drop is [response ended early: ...], never a user Esc interrupt")diff --git a/src/agent_request.zig b/src/agent_request.zigindex 26753850..51e99145 100644--- a/src/agent_request.zig+++ b/src/agent_request.zig@@ -282,8 +282,6 @@ pub fn request(self: *Agent, tools_in: ?[]const u8) !std.json.ObjectMap {// the session — codex's WS→SSE fallback, and consistent// with how a WS transport error is already handled (ws_off).if (stall_retries > 1) self.ws_off = true;- // Reconnect is bookkeeping (ADR 0021). Tracer and- // telemetry keep the attempt; the transcript does not.if (self.tracer) |tr| tr.note("stream_retry", what);if (telemetry.g_telem) |t| t.errorEvent("stream_retry", what);self.partial_text.clearRetainingCapacity(); // fresh stream re-streams cleanly, no concat@@ -291,6 +289,8 @@ pub fn request(self: *Agent, tools_in: ?[]const u8) !std.json.ObjectMap {self.sleepInterruptible(stall_reconnect_backoff_ms) catch return error.Interrupted;continue :rebuild;}+ // Budget gone: the turn is ending. Mid-turn cuts stayed silent.+ @import("engine_sink.zig").forAgent(self).emit(self.io, .{ .transport_aborted = .{ .reason = if (stalled) .stalled else .dropped, .turn_ending = true } });if (stalled) {self.last_api_error = std.fmt.allocPrint(self.arena, "stream stalled: no data from the model for {d}s — ended the turn after {d} reconnect attempts (raise GRAFF_STREAM_STALL_SECS if your model needs longer)", .{ http.stream_stall_ms / 1000, max_stall_retries }) catch null;if (telemetry.g_telem) |t| t.errorEvent("stream_stall", self.last_api_error orelse "stream stalled");diff --git a/src/agent_ws.zig b/src/agent_ws.zigindex 0dfa87fc..d6898626 100644--- a/src/agent_ws.zig+++ b/src/agent_ws.zig@@ -163,8 +163,7 @@ pub fn postLive(self: *Agent, body: []const u8) ![]u8 {}/// (#422 slice 1b) A transport cut becomes a typed event; the sink decides-/// what shows. TuiSink: the old inline ⚠ lines, byte for byte. JsonSink:-/// nothing — the wire never carried these moments and must not start to.+/// what shows. Ending-turn only (ADR 0021); mid-turn reconnect is silent.fn emitAbort(self: *Agent, reason: engine_events.StreamAbort, turn_ending: bool) void {const cut: engine_events.TransportAbort = .{ .reason = reason, .turn_ending = turn_ending };engine_sink.forAgent(self).emit(self.io, .{ .transport_aborted = cut });