graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Bound the live wake after graff peer send
Rach Pradhan29d594dce93c
diff --git a/docs/adr/0298-peer-send-wakes-are-bounded.md b/docs/adr/0298-peer-send-wakes-are-bounded.mdnew file mode 100644index 00000000..d080e00d--- /dev/null+++ b/docs/adr/0298-peer-send-wakes-are-bounded.md@@ -0,0 +1,31 @@+# 0298. A `graff peer send` wake is bounded; the durable post is the delivery++Status: accepted 2026-10-22++## Context++`graff peer send` appends the message to the JSONL room (ADR 0134), then wakes+each eligible live session over its Accord socket. The wake ran one+`accord.Session` per recipient, in turn, with no deadline. A recipient whose+socket the kernel accepted but that never answered blocked `Session.start`+on the preface read forever; one that answered and then stopped reading+blocked `Session.send` once the frame outgrew the socket buffer. The command+never returned, and the agent turn that ran it stayed working (#1718).++## Decision++- The CLI wake (`peer_wake.zig`) runs the client half of the Accord+ handshake itself (preface out, preface in, one `msg` frame) on nonblocking+ sockets, every recipient at once in one `poll` loop, under one shared+ deadline (`peer_wake.default_deadline_ms`, 2 s). No reader thread is+ started, so teardown is a `close` and cannot wait on a blocked read.+- A recipient that refuses, fails, or has not taken the frame by the deadline+ is counted as missed. The send still succeeds: the room post is the+ delivery, and the command prints how many were not reachable live.++## Consequences++One stalled recipient costs at most the deadline, and N of them cost the+same single deadline, not N. A healthy recipient listed after stalled ones is+still woken. The in-process `presence_accord` fan-out keeps its standing+sessions and is not changed here.diff --git a/docs/adr/README.md b/docs/adr/README.mdindex 4fa549d2..c5baffbb 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -315,6 +315,7 @@ record only when you need the evidence or the edge cases.| [0295](0295-worker-native-turns-share-the-chat-step.md) | Experimental Worker-native turns share the native chat step; JSPI supplies bounded host I/O, not a proxy or a second agent loop. || [0296](0296-worker-tasks-own-remote-sandbox-cleanup.md) | Worker/DO tasks retain the agent loop and delegate Linux execution to remote sandboxes with explicit ownership, deletion and bounded leases. || [0297](0297-sdk-managed-replay-reuses-the-relay.md) | The fetch-only managed SDK reuses account relay/device tapes; prompt retries are explicit, durability limits are stated, and content-free OTLP export remains opt-in and observational. |+| [0298](0298-peer-send-wakes-are-bounded.md) | A `graff peer send` live wake is concurrent and bounded by one shared deadline; misses are reported and the durable room post still succeeds. |## When to write onediff --git a/src/peer_cli.zig b/src/peer_cli.zigindex bad749a2..7a56eef6 100644--- a/src/peer_cli.zig+++ b/src/peer_cli.zig@@ -18,12 +18,12 @@ const std = @import("std");const builtin = @import("builtin");const Io = std.Io;const Allocator = std.mem.Allocator;-const accord = @import("accord");const presence = @import("presence.zig");const presence_chan = @import("presence_chan.zig");const presence_record = @import("presence_record.zig");const presence_accord = @import("presence_accord.zig");const peer_target = @import("peer_target.zig");+const peer_wake = @import("peer_wake.zig");const proc_identity = @import("proc_identity.zig");const worktree_lease = @import("worktree_lease.zig");const util = @import("util.zig");@@ -94,6 +94,8 @@ pub const Ctx = struct {name: []const u8,owner: proc_identity.Record,identity: []const u8,+ /// Budget for the whole live-wake fan-out after a send (#1718).+ wake_deadline_ms: u32 = peer_wake.default_deadline_ms,};pub const Room = enum { tree, device };@@ -342,33 +344,27 @@ pub fn writeHeard(w: *Io.Writer, h: Heard) !void {});}-/// Wake a live graff session over its Accord socket. The receiver only needs-/// the frame kind to start draining, so an oversize line is replaced by a-/// small marker instead of being dropped.-pub fn wake(io: Io, gpa: Allocator, dir_path: []const u8, rec: Owner, line: []const u8) void {- if (!presence_accord.enabled()) return;- var path_buf: [std.fs.max_path_bytes]u8 = undefined;- const path = std.fmt.bufPrint(&path_buf, "{s}/{d}-{x}.accord.sock", .{ dir_path, rec.pid, rec.start_id }) catch return;- if (!presence_accord.fitsUnixSocketPath(path)) return;- const addr = Io.net.UnixAddress.init(path) catch return;- const stream = addr.connect(io) catch return;- const sess = gpa.create(accord.Session) catch {- stream.close(io);- return;- };- defer gpa.destroy(sess);- sess.* = .{ .io = io, .gpa = gpa, .role = .client, .stream = stream };- sess.start() catch {- sess.shutdown();- return;- };- defer sess.shutdown();- const payload = if (line.len <= accord.max_payload) line else "{\"kind\":\"wake\"}";- sess.send(1, .msg, .{}, payload) catch {};+/// The Accord socket a live graff session with this owner binds, or null+/// when it cannot be addressed.+fn wakePath(arena: Allocator, dir_path: []const u8, rec: Owner) ?[]const u8 {+ const path = std.fmt.allocPrint(arena, "{s}/{d}-{x}.accord.sock", .{ dir_path, rec.pid, rec.start_id }) catch return null;+ return if (presence_accord.fitsUnixSocketPath(path)) path else null;+}++/// Wake one live graff session over its Accord socket, bounded by the+/// default deadline (peer_wake.zig). True when it took the frame.+pub fn wake(io: Io, gpa: Allocator, dir_path: []const u8, rec: Owner, line: []const u8) bool {+ if (!presence_accord.enabled()) return false;+ var buf: [std.fs.max_path_bytes + 64]u8 = undefined;+ var fba: std.heap.FixedBufferAllocator = .init(&buf);+ const path = wakePath(fba.allocator(), dir_path, rec) orelse return false;+ return peer_wake.wakeAll(io, gpa, &.{path}, line, peer_wake.default_deadline_ms).woke == 1;}pub const SendResult = union(enum) {- posted: struct { room: Room, target: ?Owner, woke: usize },+ /// `woke` took the live frame; `missed` were eligible but did not answer+ /// within the deadline (they still read the durable post).+ posted: struct { room: Room, target: ?Owner, woke: usize, missed: usize = 0 },held: []const Heard,no_target,ambiguous: []const Owner,@@ -406,15 +402,21 @@ pub fn send(io: Io, gpa: Allocator, arena: Allocator, dir_path: []const u8, ctx:var aw: Io.Writer.Allocating = .init(arena);var s: std.json.Stringify = .{ .writer = &aw.writer };s.write(msg) catch {};- var woke: usize = 0;- // Wake only who hears it: the DM target, or this worktree's agents.- for (peers) |p| {+ // Wake only who hears it: the DM target, or this worktree's agents. The+ // post above is the delivery; the wake is best effort under one deadline.+ var paths: std.ArrayList([]const u8) = .empty;+ var unaddressable: usize = 0;+ if (presence_accord.enabled()) for (peers) |p| {const hears = if (target) |t| p.pid == t.pid and p.start_id == t.start_id else std.mem.eql(u8, p.identity, ctx.identity);if (!hears or std.mem.eql(u8, p.activity, "external")) continue;- wake(io, gpa, dir_path, p, aw.writer.buffered());- woke += 1;- }- return .{ .posted = .{ .room = room, .target = target, .woke = woke } };+ const path = wakePath(arena, dir_path, p) orelse {+ unaddressable += 1;+ continue;+ };+ paths.append(arena, path) catch break;+ };+ const live = peer_wake.wakeAll(io, gpa, paths.items, aw.writer.buffered(), ctx.wake_deadline_ms);+ return .{ .posted = .{ .room = room, .target = target, .woke = live.woke, .missed = live.missed + unaddressable } };}fn readStdin(io: Io, arena: Allocator) []const u8 {@@ -502,10 +504,15 @@ pub fn command(gpa: Allocator, io: Io, arena: Allocator, home: []const u8, env_nconst text = if (opts.text.len > 0) opts.text else readStdin(io, arena);if (text.len == 0) std.process.fatal("graff peer send: no message (pass TEXT or pipe it on stdin)", .{});switch (send(io, gpa, arena, dir_path, ctx, &cur, opts.to, text, opts.anyway)) {- .posted => |p| if (p.target) |t|- try out.print("sent to {s} ({s} room, {d} woken)\n", .{ if (t.title.len > 0) t.title else t.session_id, @tagName(p.room), p.woke })- else- try out.print("posted to this worktree's room ({d} woken)\n", .{p.woke}),+ .posted => |p| {+ if (p.target) |t|+ try out.print("sent to {s} ({s} room, {d} woken", .{ if (t.title.len > 0) t.title else t.session_id, @tagName(p.room), p.woke })+ else+ try out.print("posted to this worktree's room ({d} woken", .{p.woke});+ // A miss is not a lost message: it is in the room either way.+ if (p.missed > 0) try out.print(", {d} not reachable live; they read it from the room", .{p.missed});+ try out.writeAll(")\n");+ },.held => |heard| {saveCursor(io, arena, ctx, cur);try out.writeAll("NOT SENT: they wrote to you after your last read. Read this, then resend (or pass --anyway):\n");@@ -524,4 +531,5 @@ pub fn command(gpa: Allocator, io: Io, arena: Allocator, home: []const u8, env_ntest {_ = @import("peer_cli_tests.zig");+ _ = @import("peer_wake_test.zig"); // #1718 bounded live wake}diff --git a/src/peer_cli_tests.zig b/src/peer_cli_tests.zigindex 7c80ec20..1cd11e57 100644--- a/src/peer_cli_tests.zig+++ b/src/peer_cli_tests.zig@@ -42,7 +42,7 @@ test "wake: an external send lands one msg frame on a graff session's Accord socdefer got.deinit(gpa);try testing.expectEqual(accord.Kind.msg, got.kind);try testing.expectEqualStrings("{\"text\":\"hi\"}", got.payload);- sender.await(io);+ try testing.expect(sender.await(io));}test "parseOpts: action, flags, and the rest joined as the message" {diff --git a/src/peer_wake.zig b/src/peer_wake.zignew file mode 100644index 00000000..2345343e--- /dev/null+++ b/src/peer_wake.zig@@ -0,0 +1,215 @@+//! Bounded live wake for `graff peer send` (#1718).+//!+//! The durable room post is the contract; the Accord wake that follows it is+//! best effort (presence_accord.zig). A wake used to run an `accord.Session`+//! per recipient, one after another, with no deadline: a recipient whose+//! socket the kernel accepted but that never answered the preface blocked+//! `Session.start` forever, and one that answered but stopped reading blocked+//! `Session.send` forever once the frame outgrew the socket buffer. Either+//! held the command, and the agent turn that ran it, open indefinitely.+//!+//! Here every recipient runs the same client half of the Accord handshake+//! (preface out, preface in, one `msg` frame on stream 1) on its own+//! nonblocking socket, all multiplexed in one `poll` loop under one shared+//! deadline. There is no reader thread to join: when the deadline passes,+//! every unfinished socket is closed and counted as missed, so N stalled+//! recipients cost one deadline, not N, and cannot keep a healthy one from+//! being attempted.++const std = @import("std");+const builtin = @import("builtin");+const posix = std.posix;+const Io = std.Io;+const accord = @import("accord");++/// Whole fan-out budget for one send: connect, handshake, frame and close+/// for every recipient together. A live graff answers in milliseconds.+pub const default_deadline_ms: u32 = 2000;++/// Sent instead of a line too big for the recipient's frame limit: the+/// receiver only needs the frame kind to start draining the durable room.+pub const marker_payload = "{\"kind\":\"wake\"}";++pub const Outcome = struct {+ /// Recipients that completed the handshake and took the frame.+ woke: usize = 0,+ /// Recipients that refused, failed, or ran out of time.+ missed: usize = 0,+};++const Phase = enum { connecting, send_preface, read_preface, send_frame, done, failed };++const Peer = struct {+ fd: posix.fd_t = -1,+ phase: Phase = .failed,+ out: []const u8 = &.{},+ sent: usize = 0,+ in: [accord.preface_size]u8 = undefined,+ got: usize = 0,+};++/// Wake every Unix socket in `paths` with `line` as one Accord `msg` frame,+/// all concurrently, giving up on whatever has not finished after+/// `deadline_ms`. Never blocks past the deadline (plus one close per socket).+pub fn wakeAll(io: Io, gpa: std.mem.Allocator, paths: []const []const u8, line: []const u8, deadline_ms: u32) Outcome {+ if (paths.len == 0) return .{};+ if (builtin.os.tag == .windows) return .{ .missed = paths.len };+ return wakeAllPosix(io, gpa, paths, line, deadline_ms);+}++fn wakeAllPosix(io: Io, gpa: std.mem.Allocator, paths: []const []const u8, line: []const u8, deadline_ms: u32) Outcome {+ const peers = gpa.alloc(Peer, paths.len) catch return .{ .missed = paths.len };+ defer gpa.free(peers);+ const fds = gpa.alloc(posix.pollfd, paths.len) catch return .{ .missed = paths.len };+ defer gpa.free(fds);+ const slots = gpa.alloc(usize, paths.len) catch return .{ .missed = paths.len };+ defer gpa.free(slots);++ var preface: [accord.preface_size]u8 = undefined;+ accord.encodePreface(&preface);+ const full_buf = gpa.alloc(u8, accord.header_size + @min(line.len, accord.max_payload)) catch return .{ .missed = paths.len };+ defer gpa.free(full_buf);+ const full_frame: ?[]const u8 = if (line.len <= accord.max_payload) frameInto(full_buf, line) else null;+ var marker_buf: [accord.header_size + marker_payload.len]u8 = undefined;+ const marker_frame = frameInto(&marker_buf, marker_payload) orelse return .{ .missed = paths.len };++ for (peers, paths) |*p, path| p.* = connect(path, &preface);+ defer for (peers) |p| if (p.fd >= 0) closeFd(p.fd);++ const start = Io.Timestamp.now(io, .awake);+ while (true) {+ var n: usize = 0;+ for (peers, 0..) |*p, i| {+ const events: i16 = switch (p.phase) {+ .connecting, .send_preface, .send_frame => posix.POLL.OUT,+ .read_preface => posix.POLL.IN,+ .done, .failed => continue,+ };+ fds[n] = .{ .fd = p.fd, .events = events, .revents = 0 };+ slots[n] = i;+ n += 1;+ }+ if (n == 0) break;+ const elapsed = @max(0, start.untilNow(io, .awake).toMilliseconds());+ if (elapsed >= deadline_ms) break;+ const left: i32 = @intCast(@as(i64, deadline_ms) - elapsed);+ const ready = posix.poll(fds[0..n], left) catch break;+ if (ready == 0) continue; // the deadline check above ends the loop+ for (fds[0..n], slots[0..n]) |pfd, i| {+ if (pfd.revents == 0) continue;+ step(&peers[i], pfd.revents, &preface, full_frame, marker_frame);+ }+ }++ var out: Outcome = .{};+ for (peers) |p| {+ if (p.phase == .done) out.woke += 1 else out.missed += 1;+ }+ return out;+}++fn frameInto(buf: []u8, payload: []const u8) ?[]const u8 {+ var w: Io.Writer = .fixed(buf);+ accord.writeFrame(&w, 1, .msg, .{}, payload) catch return null;+ return w.buffered();+}++/// Open a nonblocking socket and start connecting. A recipient that refuses+/// or whose accept queue is full fails here, without waiting.+fn connect(path: []const u8, preface: []const u8) Peer {+ var addr: posix.sockaddr.un = .{ .path = @splat(0) };+ if (path.len >= addr.path.len) return .{};+ @memcpy(addr.path[0..path.len], path);+ const rc = posix.system.socket(posix.AF.UNIX, posix.SOCK.STREAM, 0);+ if (posix.errno(rc) != .SUCCESS) return .{};+ const fd: posix.fd_t = @intCast(rc);+ var p: Peer = .{ .fd = fd };+ _ = posix.system.fcntl(fd, posix.F.SETFD, @as(usize, posix.FD_CLOEXEC));+ const fl = posix.system.fcntl(fd, posix.F.GETFL, @as(usize, 0));+ if (posix.errno(fl) != .SUCCESS) return p;+ const nonblock: usize = 1 << @bitOffsetOf(posix.O, "NONBLOCK");+ if (posix.errno(posix.system.fcntl(fd, posix.F.SETFL, @as(usize, @intCast(fl)) | nonblock)) != .SUCCESS) return p;+ while (true) switch (posix.errno(posix.system.connect(fd, @ptrCast(&addr), @sizeOf(posix.sockaddr.un)))) {+ .SUCCESS => {+ p.phase = .send_preface;+ p.out = preface;+ return p;+ },+ .INTR => continue,+ .INPROGRESS => {+ p.phase = .connecting;+ return p;+ },+ else => return p, // refused, missing, or a full accept queue (AGAIN)+ };+}++/// Advance one recipient after `poll` reported `revents` on its socket.+fn step(p: *Peer, revents: i16, preface: []const u8, full_frame: ?[]const u8, marker_frame: []const u8) void {+ switch (p.phase) {+ .connecting => {+ var err: i32 = 0;+ var len: posix.socklen_t = @sizeOf(i32);+ if (posix.errno(posix.system.getsockopt(p.fd, posix.SOL.SOCKET, posix.SO.ERROR, @ptrCast(&err), &len)) != .SUCCESS or err != 0) {+ p.phase = .failed;+ return;+ }+ p.phase = .send_preface;+ p.out = preface;+ p.sent = 0;+ },+ .send_preface, .send_frame => {+ if (revents & (posix.POLL.ERR | posix.POLL.NVAL) != 0) {+ p.phase = .failed;+ return;+ }+ while (p.sent < p.out.len) {+ const rest = p.out[p.sent..];+ const rc = posix.system.send(p.fd, rest.ptr, rest.len, posix.MSG.NOSIGNAL);+ switch (posix.errno(rc)) {+ .SUCCESS => p.sent += @intCast(rc),+ .INTR => continue,+ .AGAIN => return, // wait for POLLOUT again+ else => {+ p.phase = .failed;+ return;+ },+ }+ }+ p.phase = if (p.phase == .send_preface) .read_preface else .done;+ },+ .read_preface => {+ while (p.got < p.in.len) {+ const rc = posix.system.read(p.fd, p.in[p.got..].ptr, p.in.len - p.got);+ switch (posix.errno(rc)) {+ .SUCCESS => {+ if (rc == 0) { // closed before answering+ p.phase = .failed;+ return;+ }+ p.got += @intCast(rc);+ },+ .INTR => continue,+ .AGAIN => return,+ else => {+ p.phase = .failed;+ return;+ },+ }+ }+ const peer_max = accord.decodePreface(&p.in) catch {+ p.phase = .failed;+ return;+ };+ const frame = full_frame orelse marker_frame;+ p.out = if (frame.len - accord.header_size <= peer_max) frame else marker_frame;+ p.sent = 0;+ p.phase = .send_frame;+ },+ .done, .failed => {},+ }+}++fn closeFd(fd: posix.fd_t) void {+ _ = posix.system.close(fd);+}diff --git a/src/peer_wake_test.zig b/src/peer_wake_test.zignew file mode 100644index 00000000..2c9edb6d--- /dev/null+++ b/src/peer_wake_test.zig@@ -0,0 +1,211 @@+//! Fake-recipient tests for the bounded peer wake (#1718). Each recipient is+//! a real Unix socket in a scratch dir: one the kernel accepts but nobody+//! answers, one that answers the preface and then stops reading, one that+//! reads our preface and never replies, and a healthy Accord server. Short+//! deadlines keep them fast; the bound asserted is generous for slow CI.++const std = @import("std");+const builtin = @import("builtin");+const testing = std.testing;+const Io = std.Io;+const accord = @import("accord");+const peer_wake = @import("peer_wake.zig");+const peer_cli = @import("peer_cli.zig");++const deadline_ms: u32 = 200;+/// Wall-clock ceiling for one fan-out: the deadline plus scheduling slack.+const bound_ms: i64 = 1500;++fn elapsedMs(io: Io, t0: Io.Timestamp) i64 {+ return @max(0, t0.untilNow(io, .awake).toMilliseconds());+}++/// Accept, send a valid preface, then hold the socket open without reading.+fn answerThenStall(io: Io, listener: *Io.net.Server) !Io.net.Stream {+ const conn = try listener.accept(io);+ var pre: [accord.preface_size]u8 = undefined;+ accord.encodePreface(&pre);+ var wb: [16]u8 = undefined;+ var w = conn.writer(io, &wb);+ try w.interface.writeAll(&pre);+ try w.interface.flush();+ return conn;+}++/// Accept and read the client's preface, then never answer.+fn readThenStall(io: Io, listener: *Io.net.Server) !Io.net.Stream {+ const conn = try listener.accept(io);+ var rb: [accord.preface_size]u8 = undefined;+ var r = conn.reader(io, &rb);+ _ = try r.interface.takeArray(accord.preface_size);+ return conn;+}++/// A live graff's side: a server Session that takes one frame on stream 1.+fn healthy(io: Io, gpa: std.mem.Allocator, listener: *Io.net.Server, got: *[64]u8) !usize {+ const sess = try gpa.create(accord.Session);+ defer gpa.destroy(sess);+ sess.* = .{ .io = io, .gpa = gpa, .role = .server, .stream = try listener.accept(io) };+ try sess.start();+ defer sess.shutdown();+ const in = try sess.recv(1);+ defer in.deinit(gpa);+ const n = @min(in.payload.len, got.len);+ @memcpy(got[0..n], in.payload[0..n]);+ return n;+}++const Scratch = struct {+ name: []const u8,+ fn init(io: Io, comptime name: []const u8) !Scratch {+ Io.Dir.cwd().deleteTree(io, name) catch {};+ try Io.Dir.cwd().createDirPath(io, name);+ return .{ .name = name };+ }+ fn deinit(s: Scratch, io: Io) void {+ Io.Dir.cwd().deleteTree(io, s.name) catch {};+ }+};++test "wakeAll: stalled recipients time out together and a healthy one is still woken" {+ if (builtin.os.tag == .windows) return error.SkipZigTest;+ const io = testing.io;+ const gpa = testing.allocator;+ const scratch = try Scratch.init(io, "graff-wake-fanout");+ defer scratch.deinit(io);+ const silent_path = "graff-wake-fanout/1-a.accord.sock";+ const answer_path = "graff-wake-fanout/2-b.accord.sock";+ const read_path = "graff-wake-fanout/3-c.accord.sock";+ const ok_path = "graff-wake-fanout/4-d.accord.sock";+ // Listening but never accepted: the kernel completes the connect, nobody answers.+ var silent = try accord.listenUnix(io, silent_path);+ defer silent.deinit(io);+ var answer = try accord.listenUnix(io, answer_path);+ defer answer.deinit(io);+ var reads = try accord.listenUnix(io, read_path);+ defer reads.deinit(io);+ var ok = try accord.listenUnix(io, ok_path);+ defer ok.deinit(io);++ var answer_fut = try io.concurrent(answerThenStall, .{ io, &answer });+ var read_fut = try io.concurrent(readThenStall, .{ io, &reads });+ var got: [64]u8 = undefined;+ var ok_fut = try io.concurrent(healthy, .{ io, gpa, &ok, &got });++ const t0 = Io.Timestamp.now(io, .awake);+ // The healthy recipient comes last, behind every stalled one.+ const out = peer_wake.wakeAll(io, gpa, &.{ silent_path, answer_path, read_path, ok_path }, "{\"text\":\"hi\"}", deadline_ms);+ const took = elapsedMs(io, t0);++ const answered = try answer_fut.await(io);+ defer answered.close(io);+ const read_conn = try read_fut.await(io);+ defer read_conn.close(io);+ const n = try ok_fut.await(io);++ try testing.expect(took < bound_ms);+ // The preface-then-stall recipient takes the small frame into its socket+ // buffer unread, so it counts as woken; the silent and never-answering+ // recipients are the misses.+ try testing.expectEqual(peer_wake.Outcome{ .woke = 2, .missed = 2 }, out);+ try testing.expectEqualStrings("{\"text\":\"hi\"}", got[0..n]);+}++test "wakeAll: a recipient that stops reading mid-frame cannot hold the send" {+ if (builtin.os.tag == .windows) return error.SkipZigTest;+ const io = testing.io;+ const gpa = testing.allocator;+ const scratch = try Scratch.init(io, "graff-wake-midframe");+ defer scratch.deinit(io);+ const path = "graff-wake-midframe/5-e.accord.sock";+ var listener = try accord.listenUnix(io, path);+ defer listener.deinit(io);+ var fut = try io.concurrent(answerThenStall, .{ io, &listener });+ // A full-size frame outgrows a small socket buffer, so the write stalls+ // where the old Session.send blocked forever.+ const big = try gpa.alloc(u8, accord.max_payload);+ defer gpa.free(big);+ @memset(big, 'x');+ const t0 = Io.Timestamp.now(io, .awake);+ const out = peer_wake.wakeAll(io, gpa, &.{path}, big, deadline_ms);+ const took = elapsedMs(io, t0);+ const conn = try fut.await(io);+ defer conn.close(io);+ try testing.expect(took < bound_ms);+ try testing.expectEqual(@as(usize, 1), out.woke + out.missed);+}++test "wakeAll: silent and never-answering recipients are missed within the deadline" {+ if (builtin.os.tag == .windows) return error.SkipZigTest;+ const io = testing.io;+ const gpa = testing.allocator;+ const scratch = try Scratch.init(io, "graff-wake-silent");+ defer scratch.deinit(io);+ const silent_path = "graff-wake-silent/6-f.accord.sock";+ const read_path = "graff-wake-silent/7-a.accord.sock";+ var silent = try accord.listenUnix(io, silent_path);+ defer silent.deinit(io);+ var reads = try accord.listenUnix(io, read_path);+ defer reads.deinit(io);+ var read_fut = try io.concurrent(readThenStall, .{ io, &reads });+ const t0 = Io.Timestamp.now(io, .awake);+ const out = peer_wake.wakeAll(io, gpa, &.{ silent_path, read_path }, "{}", deadline_ms);+ const took = elapsedMs(io, t0);+ const conn = try read_fut.await(io);+ defer conn.close(io);+ try testing.expect(took >= deadline_ms - 50); // it really waited, then gave up+ try testing.expect(took < bound_ms);+ try testing.expectEqual(peer_wake.Outcome{ .woke = 0, .missed = 2 }, out);+}++test "wakeAll: a missing socket is missed at once" {+ if (builtin.os.tag == .windows) return error.SkipZigTest;+ const io = testing.io;+ const t0 = Io.Timestamp.now(io, .awake);+ const out = peer_wake.wakeAll(io, testing.allocator, &.{"graff-wake-none/8-b.accord.sock"}, "{}", 5000);+ try testing.expect(elapsedMs(io, t0) < bound_ms);+ try testing.expectEqual(peer_wake.Outcome{ .woke = 0, .missed = 1 }, out);+ try testing.expectEqual(peer_wake.Outcome{}, peer_wake.wakeAll(io, testing.allocator, &.{}, "{}", 5000));+}++test "send: a stalled recipient leaves the message posted and the command returns" {+ if (builtin.os.tag == .windows) return error.SkipZigTest;+ const io = testing.io;+ const presence_accord = @import("presence_accord.zig");+ const presence_chan = @import("presence_chan.zig");+ presence_accord.test_enabled = true;+ defer presence_accord.test_enabled = false;+ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);+ defer arena_state.deinit();+ const arena = arena_state.allocator();+ const scratch = try Scratch.init(io, "graff-wake-send");+ defer scratch.deinit(io);+ var dir = try Io.Dir.cwd().openDir(io, scratch.name, .{ .iterate = true });+ defer dir.close(io);+ const identity = "/work/repo/.git";+ // The recipient record is this test process, so the registry keeps it live.+ const self = @import("proc_identity.zig").selfRecord(io);+ const rec = try @import("presence_record.zig").formatRecord(arena, .{ .pid = self.pid, .start_id = self.start_id, .session_id = "graff-a", .identity = identity });+ try dir.writeFile(io, .{ .sub_path = "graff-a.json", .data = rec });+ // Its Accord socket accepts at the kernel and never answers.+ const sock = try std.fmt.allocPrint(arena, "{s}/{d}-{x}.accord.sock", .{ scratch.name, self.pid, self.start_id });+ var listener = try accord.listenUnix(io, sock);+ defer listener.deinit(io);++ const ctx: peer_cli.Ctx = .{ .dir = dir, .name = "claude@repo", .owner = .{ .pid = 52, .start_id = 1 }, .identity = identity, .wake_deadline_ms = deadline_ms };+ var cur = peer_cli.tailCursor(io, arena, ctx);+ const t0 = Io.Timestamp.now(io, .awake);+ const res = peer_cli.send(io, testing.allocator, arena, scratch.name, ctx, &cur, null, "verification passed", false);+ try testing.expect(elapsedMs(io, t0) < bound_ms);+ switch (res) {+ .posted => |p| {+ try testing.expectEqual(@as(usize, 0), p.woke);+ try testing.expectEqual(@as(usize, 1), p.missed);+ },+ else => return error.ExpectedPosted,+ }+ var tb: [presence_chan.chan_name_max]u8 = undefined;+ var off: u64 = 0;+ const log = presence_chan.readNewMessages(io, arena, dir, presence_chan.chanName(&tb, identity), &off);+ try testing.expectEqualStrings("verification passed", log[log.len - 1].text);+}