Skip to content

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

Python

feat(peer): opt-in Accord Unix live path; JSONL stays durable

Rach Pradhan745e7a7dcb2a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index deb0888c..d18ce933 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,8 @@ current is part of cutting a release.
## Unreleased
+- Opt-in Accord Unix 0600 live path behind `presence_chan.postMessage` (`GRAFF_ACCORD=1`); JSONL stays the durable room (ADR 0134).
+
- Live 12-PR board on grok-4.6 SuperGrok (n=3, no SPEC.md): graff / Pi /
OpenCode 12/12, grok 11/12 (`#727`), exo 9/12 (gemini + two turbos —
no-token check-greens do not count). Honest list$ $21.48 / $18.47 /
diff --git a/build.zig b/build.zig
index 36f8933f..52a8bc3e 100644
--- a/build.zig
+++ b/build.zig
@@ -57,6 +57,9 @@ pub fn build(b: *std.Build) void {
// standalone graff-repl exe below). The repo's first dependency.
const zigzag = b.dependency("zigzag", .{ .target = target, .optimize = optimize });
exe.root_module.addImport("zigzag", zigzag.module("zigzag"));
+ const accord_dep = b.dependency("accord", .{ .target = target, .optimize = optimize });
+ const accord_mod = accord_dep.module("accord");
+ exe.root_module.addImport("accord", accord_mod);
// Shared by the line-REPL picker and the TUI overlay so they cannot
// drift: a file import from both modules is illegal in Zig 0.17.
const models_rank_mod = b.createModule(.{
@@ -103,6 +106,7 @@ pub fn build(b: *std.Build) void {
});
unit_tests.root_module.addOptions("build_options", opts);
unit_tests.root_module.addImport("zigzag", zigzag.module("zigzag"));
+ unit_tests.root_module.addImport("accord", accord_mod);
unit_tests.root_module.addImport("models_rank", models_rank_mod);
unit_tests.root_module.addImport("tui", tui_mod);
// spec/ fixtures live outside src/; importing them here makes @embedFile
diff --git a/build.zig.zon b/build.zig.zon
index 611664ae..9fefe64b 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -6,6 +6,10 @@
.zigzag = .{
.path = "vendor/zigzag",
},
+ .accord = .{
+ .url = "git+https://github.com/justrach/accord#c053e17295cb7ad8c0fb284d7d7748aad4aeeeea",
+ .hash = "accord-0.0.0-aQy1J3iBAgADDHWM0hIAXhISKtQ0zasFN7TyLhI_tkI8",
+ },
},
.paths = .{ "", "vendor/zigzag" },
.fingerprint = 0x99ab87d62eef2520,
diff --git a/docs/adr/0134-accord-live-jsonl-durable.md b/docs/adr/0134-accord-live-jsonl-durable.md
new file mode 100644
index 00000000..b03dcf6e
--- /dev/null
+++ b/docs/adr/0134-accord-live-jsonl-durable.md
@@ -0,0 +1,21 @@
+# 0134. JSONL is the durable peer room; Accord Unix is opt-in live
+
+Status: accepted 2026-09-17
+
+## Context
+
+Co-resident sessions persist speech in `presence_chan` JSONL (pid/start/goal/ts,
+resume cursor, two PIDs). Accord ACD1 is a 4-byte Unix-0600 frame. In-process
+Mailbox is a shape demo and cannot be the room.
+
+## Decision
+
+JSONL stays the durable log. `postMessage` / `readNewMessages` remain the seam.
+`GRAFF_ACCORD=1` may also send the same JSONL line over Unix 0600 (`GRAFF_ACCORD_SOCK`
+or `{chan}.sock`). Default off. A live miss never fails the durable write.
+Do not replace the room with Mailbox.
+
+## Consequences
+
+Idle sessions still only drain on the next `runTurn` (#1001). Flipping the
+flag on does not change history pull (ADR 0004).
diff --git a/docs/adr/README.md b/docs/adr/README.md
index ee666b23..0a6eb7d6 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -153,6 +153,7 @@ record only when you need the evidence or the edge cases.
| [0133](0133-clipboard-files-follow-consumer-ownership.md) | Clipboard cleanup requires file ownership and released consumers; age alone never deletes active or saved attachments. |
| [0133](0133-publication-review-binds-committed-inputs.md) | Proposed: non-draft publication reviews immutable source and observed checks; changed inputs invalidate earlier assessments. |
+| [0134](0134-accord-live-jsonl-durable.md) | JSONL is the durable peer room; Accord Unix 0600 is opt-in live behind postMessage. |
## When to write one
diff --git a/src/main.zig b/src/main.zig
index b4c06648..61522e51 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -590,7 +590,7 @@ test { // ── Unit tests (`zig build test`): pull in tests from imported modu
_ = @import("goal_flow.zig");
_ = @import("goal_todo.zig");
_ = @import("goal_pacing.zig");
- _ = .{ @import("presence_record.zig"), @import("peer_inbox_content_test.zig"), @import("peer_inbox_failure_test.zig"), @import("peer_inbox_storage_test.zig"), @import("peer_inbox_sequence_test.zig"), @import("peer_inbox_snapshot_test.zig") };
+ _ = .{ @import("presence_accord.zig"), @import("presence_chan.zig"), @import("presence_record.zig"), @import("peer_inbox_content_test.zig"), @import("peer_inbox_failure_test.zig"), @import("peer_inbox_storage_test.zig"), @import("peer_inbox_sequence_test.zig"), @import("peer_inbox_snapshot_test.zig") };
_ = @import("acp_agents.zig");
_ = @import("subagent_activity.zig");
_ = @import("subagent_recovery.zig");
diff --git a/src/presence_accord.zig b/src/presence_accord.zig
new file mode 100644
index 00000000..66c690ba
--- /dev/null
+++ b/src/presence_accord.zig
@@ -0,0 +1,155 @@
+//! Opt-in Accord Unix 0600 live path behind presence_chan.postMessage.
+//! JSONL stays the durable room (ADR 0134). Off unless GRAFF_ACCORD=1
+//! (or test_enabled). Lost live frames are never errors — the log remains.
+
+const std = @import("std");
+const builtin = @import("builtin");
+const Io = std.Io;
+const net = std.Io.net;
+const accord = @import("accord");
+
+pub const env_var = "GRAFF_ACCORD";
+pub const sock_env = "GRAFF_ACCORD_SOCK";
+
+/// Tests flip this instead of mutating process env.
+pub var test_enabled: bool = false;
+pub var test_sock: ?[]const u8 = null;
+
+pub fn enabled() bool {
+ if (builtin.is_test) return test_enabled;
+ const v = std.c.getenv(env_var) orelse return false;
+ const s = std.mem.span(v);
+ if (s.len == 0) return false;
+ return !std.mem.eql(u8, s, "0") and !std.mem.eql(u8, s, "off") and !std.mem.eql(u8, s, "false");
+}
+
+fn sockPath(buf: []u8, chan_name: []const u8) ?[]const u8 {
+ if (builtin.is_test) {
+ if (test_sock) |p| return p;
+ } else if (std.c.getenv(sock_env)) |p| {
+ const s = std.mem.span(p);
+ if (s.len > 0) return s;
+ }
+ const stem = if (std.mem.endsWith(u8, chan_name, ".jsonl"))
+ chan_name[0 .. chan_name.len - ".jsonl".len]
+ else
+ chan_name;
+ return std.fmt.bufPrint(buf, "{s}.sock", .{stem}) catch null;
+}
+
+/// Best-effort live send of the same JSONL line already appended to the room.
+/// Never fails the durable write.
+pub fn livePost(io: Io, gpa: std.mem.Allocator, chan_name: []const u8, json_line: []const u8) void {
+ if (!enabled()) return;
+ if (builtin.os.tag == .windows) return;
+ var path_buf: [std.fs.max_path_bytes]u8 = undefined;
+ const path = sockPath(&path_buf, chan_name) orelse return;
+ sendLine(io, gpa, path, json_line) catch {};
+}
+
+fn sendLine(io: Io, gpa: std.mem.Allocator, path: []const u8, json_line: []const u8) !void {
+ const addr = try net.UnixAddress.init(path);
+ const stream = addr.connect(io) catch return;
+ const sess = try gpa.create(accord.Session);
+ sess.* = .{ .io = io, .gpa = gpa, .role = .client, .stream = stream };
+ defer {
+ sess.shutdown();
+ gpa.destroy(sess);
+ }
+ try sess.start();
+ try sess.send(1, .msg, .none, json_line);
+}
+
+fn connectPath(io: Io, path: []const u8) !net.Stream {
+ const addr = try net.UnixAddress.init(path);
+ return addr.connect(io);
+}
+
+fn startSess(s: *accord.Session) !void {
+ try s.start();
+}
+
+const Pair = struct {
+ io: Io,
+ gpa: std.mem.Allocator,
+ listener: net.Server,
+ server: *accord.Session,
+ client: *accord.Session,
+ path: []const u8,
+
+ fn init(p: *Pair, io: Io, gpa: std.mem.Allocator, path: []const u8) !void {
+ Io.Dir.cwd().deleteFile(io, path) catch |err| switch (err) {
+ error.FileNotFound => {},
+ else => return err,
+ };
+ var listener = try accord.listenUnix(io, path);
+ errdefer listener.deinit(io);
+ var cfut = try Io.concurrent(io, connectPath, .{ io, path });
+ const server_sock = try listener.accept(io);
+ const client_sock = try cfut.await(io);
+ const server = try gpa.create(accord.Session);
+ errdefer gpa.destroy(server);
+ const client = try gpa.create(accord.Session);
+ errdefer gpa.destroy(client);
+ server.* = .{ .io = io, .gpa = gpa, .role = .server, .stream = server_sock };
+ client.* = .{ .io = io, .gpa = gpa, .role = .client, .stream = client_sock };
+ p.* = .{
+ .io = io,
+ .gpa = gpa,
+ .listener = listener,
+ .server = server,
+ .client = client,
+ .path = path,
+ };
+ var cstart = try Io.concurrent(io, startSess, .{p.client});
+ try p.server.start();
+ try cstart.await(io);
+ }
+
+ fn deinit(p: *Pair) void {
+ p.client.shutdown();
+ p.server.shutdown();
+ p.gpa.destroy(p.client);
+ p.gpa.destroy(p.server);
+ p.listener.deinit(p.io);
+ Io.Dir.cwd().deleteFile(p.io, p.path) catch {};
+ }
+};
+
+test "Accord live path is off by default" {
+ try std.testing.expect(!test_enabled);
+ try std.testing.expect(!enabled());
+}
+
+test "listenUnix socket is 0600" {
+ if (builtin.os.tag == .windows) return;
+ const io = std.testing.io;
+ const path = "graff-accord-mode.sock";
+ Io.Dir.cwd().deleteFile(io, path) catch {};
+ var listener = try accord.listenUnix(io, path);
+ defer {
+ listener.deinit(io);
+ Io.Dir.cwd().deleteFile(io, path) catch {};
+ }
+ var tmp: [107:0]u8 = undefined;
+ @memcpy(tmp[0..path.len], path);
+ tmp[path.len] = 0;
+ var st: std.c.Stat = undefined;
+ try std.testing.expect(std.c.stat(tmp[0..path.len :0], &st) == 0);
+ try std.testing.expectEqual(@as(std.c.mode_t, 0o600), st.mode & 0o777);
+}
+
+test "Unix 0600 round-trips the JSONL line" {
+ if (builtin.os.tag == .windows) return;
+ const io = std.testing.io;
+ const gpa = std.testing.allocator;
+ const path = "graff-accord-roundtrip.sock";
+ var pair: Pair = undefined;
+ try pair.init(io, gpa, path);
+ defer pair.deinit();
+ const line = "{\"from_pid\":1,\"text\":\"hold gui/src\"}\n";
+ try pair.client.send(1, .msg, .none, line);
+ const got = try pair.server.recv(1);
+ defer got.deinit(gpa);
+ try std.testing.expectEqualStrings(line, got.payload);
+}
diff --git a/src/presence_chan.zig b/src/presence_chan.zig
index 609e81c8..fea33872 100644
--- a/src/presence_chan.zig
+++ b/src/presence_chan.zig
@@ -19,6 +19,7 @@ const std = @import("std");
const Io = std.Io;
const Allocator = std.mem.Allocator;
+const presence_accord = @import("presence_accord.zig");
pub const chan_name_max = 96;
@@ -65,6 +66,7 @@ pub fn postMessage(io: Io, arena: Allocator, dir: Io.Dir, name: []const u8, msg:
break :blk st.size;
};
f.writePositionalAll(io, aw.writer.buffered(), end) catch return false;
+ presence_accord.livePost(io, arena, name, aw.writer.buffered());
return true;
}
@@ -159,3 +161,32 @@ test "readNewMessages: a torn trailing line waits for the next drain" {
try std.testing.expectEqual(1, second.len);
try std.testing.expectEqualStrings("rest", second[0].text);
}
+
+test "postMessage dual-writes JSONL when Accord live is on" {
+ if (@import("builtin").os.tag == .windows) return;
+ const io = std.testing.io;
+ const gpa = std.testing.allocator;
+ presence_accord.test_enabled = true;
+ defer presence_accord.test_enabled = false;
+ // No listener: live send is best-effort and must not fail the durable write.
+ presence_accord.test_sock = "graff-accord-missing.sock";
+ defer presence_accord.test_sock = null;
+ var arena_state = std.heap.ArenaAllocator.init(gpa);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ var name_buf: [chan_name_max]u8 = undefined;
+ const name = chanName(&name_buf, "/repo/.git");
+ try std.testing.expect(postMessage(io, arena, tmp.dir, name, .{
+ .from_pid = 3,
+ .from_start = 1,
+ .from_session = "s-a",
+ .ts_ms = 1,
+ .text = "durable stays",
+ }));
+ var off: u64 = 0;
+ const got = readNewMessages(io, arena, tmp.dir, name, &off);
+ try std.testing.expectEqual(@as(usize, 1), got.len);
+ try std.testing.expectEqualStrings("durable stays", got[0].text);
+}