graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Keep ACP session binding with the live turn context
justrach74666fff2b3b
diff --git a/src/acp.zig b/src/acp.zigindex 44685e12..308a5653 100644--- a/src/acp.zig+++ b/src/acp.zig@@ -96,12 +96,6 @@ fn liveAfter(ctx: *anyopaque, arena: Allocator, text: []const u8, prompt: ?std.j_ = @import("acp_images.zig").stage(live.root, prompt);}-fn liveBind(ctx: *anyopaque, session_id: []const u8) void {- const live: *LiveTurn = @ptrCast(@alignCast(ctx));- live.session_id = session_id;- live.root.last_api_reauth = null;-}-/// Per-turn context meter: the live occupancy estimate against the model's/// wall, so the client can render remaining context without reading history.fn liveMeter(ctx: *anyopaque) engine.Meter {@@ -249,7 +243,7 @@ pub fn runAcpCommand(gpa: Allocator, io: Io, environ_map: anytype, root: *agent_.seed = @bitCast(util.unixMs(io)),.slash = liveSlash,.after_user = liveAfter,- .bind_session = liveBind,+ .bind_session = LiveTurn.bindSession,.meter = liveMeter,.extra = liveModels,.mcp_servers = @import("acp_mcp_servers.zig").attach,diff --git a/src/acp_live_turn.zig b/src/acp_live_turn.zigindex e03eb4f3..e70a6820 100644--- a/src/acp_live_turn.zig+++ b/src/acp_live_turn.zig@@ -42,6 +42,12 @@ pub const LiveTurn = struct {meter.write(w, self.session_id, used, window, meter.knownCostUsd(self.root.io)) catch {};}+ pub fn bindSession(ctx: *anyopaque, session_id: []const u8) void {+ const self: *LiveTurn = @ptrCast(@alignCast(ctx));+ self.session_id = session_id;+ self.root.last_api_reauth = null;+ }+pub fn errorRecovery(ctx: *anyopaque, err: anyerror) ?@import("auth_recovery.zig").Recovery {const self: *LiveTurn = @ptrCast(@alignCast(ctx));return if (err == error.ApiError) self.root.last_api_reauth else null;diff --git a/src/acp_reauth_tests.zig b/src/acp_reauth_tests.zigindex 753d45a9..7d67d183 100644--- a/src/acp_reauth_tests.zig+++ b/src/acp_reauth_tests.zig@@ -18,7 +18,6 @@ fn root(a: std.mem.Allocator) Agent {fn parsedFailure(ctx: *anyopaque, a: std.mem.Allocator, text: []const u8) anyerror![]const u8 {const live: *LiveTurn = @ptrCast(@alignCast(ctx));- live.root.last_api_reauth = null;if (std.mem.eql(u8, text, "ok")) return "recovered";const parsed = try live.root.parseResponses(text);const failure = parsed.err;@@ -37,7 +36,7 @@ fn prompt(a: std.mem.Allocator, text: []const u8) ![]const u8 {}fn dispatch(live: *LiveTurn) engine.Dispatch {- return .{ .turn = parsedFailure, .ctx = live, .error_message = LiveTurn.errorMessage, .error_recovery = LiveTurn.errorRecovery };+ return .{ .turn = parsedFailure, .ctx = live, .bind_session = LiveTurn.bindSession, .error_message = LiveTurn.errorMessage, .error_recovery = LiveTurn.errorRecovery };}fn assertLogin(data: std.json.ObjectMap, id: []const u8, command: []const u8) !void {@@ -112,7 +111,9 @@ test "typed reauth: v1 parsed HTTP and stream auth errors carry route-specific ltry std.testing.expect(err.get("data") == null);}out.clearRetainingCapacity();+ agent.last_api_reauth = recovery.forFailure(agent.provider, "invalid_token", "Unauthorized");try engine.handleLine(&d, a, &out.writer, try prompt(a, "ok"));+ try std.testing.expect(agent.last_api_reauth == null);try std.testing.expect(std.mem.indexOf(u8, out.writer.buffered(), "end_turn") != null);try std.testing.expect(std.mem.indexOf(u8, out.writer.buffered(), "reauth_required") == null);}