graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: keep Responses SSE open until the data payload
Cursor Agent8b2f401a81a5
diff --git a/src/agent_stream.zig b/src/agent_stream.zigindex 722aacc5..b224e525 100644--- a/src/agent_stream.zig+++ b/src/agent_stream.zig@@ -351,10 +351,10 @@ pub fn isStreamEnd(arena: std.mem.Allocator, kind: anytype, raw_line: []const u8if (std.mem.eql(u8, line, "data: [DONE]") or std.mem.eql(u8, line, "data:[DONE]")) return true;if (std.mem.startsWith(u8, line, "event:")) return switch (kind) {.anthropic => std.mem.indexOf(u8, line, "message_stop") != null,- .responses => std.mem.indexOf(u8, line, "response.completed") != null or- std.mem.indexOf(u8, line, "response.incomplete") != null or- std.mem.indexOf(u8, line, "response.failed") != null,- .openai => false,+ // xAI/OpenAI Responses: `event: response.completed` is the SSE name;+ // usage rides the following `data:` line. Ending here made -p+ // `[usage]` print 0 calls (live stream never saw the payload).+ .responses, .openai => false,};const payload = ssePayload(raw_line) orelse return false;const candidate = switch (kind) {diff --git a/src/agent_stream_tests.zig b/src/agent_stream_tests.zigindex 772e7596..efea935e 100644--- a/src/agent_stream_tests.zig+++ b/src/agent_stream_tests.zig@@ -14,8 +14,8 @@ pub fn streamEnd(is_stream_end: anytype) !void {try std.testing.expect(is_stream_end(arena, Kind.anthropic, "event: message_stop"));try std.testing.expect(is_stream_end(arena, Kind.anthropic, "data: {\"type\":\"message_stop\"}"));try std.testing.expect(!is_stream_end(arena, Kind.anthropic, "data: {\"type\":\"content_block_delta\",\"delta\":{\"text\":\"message_stop\"}}"));- // Responses completion/incompletion terminate; output deltas do not.- try std.testing.expect(is_stream_end(arena, Kind.responses, "event: response.completed"));+ // Responses: the event: name is not the end — usage is on the data line.+ try std.testing.expect(!is_stream_end(arena, Kind.responses, "event: response.completed"));try std.testing.expect(is_stream_end(arena, Kind.responses, "data: {\"type\":\"response.completed\"}"));try std.testing.expect(is_stream_end(arena, Kind.responses, "data: {\"type\":\"response.incomplete\"}"));try std.testing.expect(!is_stream_end(arena, Kind.responses, "data: {\"type\":\"response.output_text.delta\",\"delta\":\"hi\"}"));