Skip to content

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

Python

docs(serve): note resumability, and derive the session path from session_index

Rach Pradhan0eeb6c469e29
diff --git a/README.md b/README.md
index ccea43d2..739644cf 100644
--- a/README.md
+++ b/README.md
@@ -1101,6 +1101,16 @@ remote clients: `@graff-new/sdk/remote` (fetch-only: Workers/Deno/Bun/browsers)
and Python's `RemoteHarness` (stdlib urllib). Endpoints are documented under the
`serve` key of `graff --schema`.
+Streams are resumable. Every event carries a monotonic `seq`, and the bridge
+persists each one to `.graff/serve/<session>.events.jsonl` while it keeps
+draining the child even after a client disconnects, so a supervisor that dies
+mid-turn does not stall the run. It reconnects with
+`GET /v1/sessions/{id}/events?from=N` (or `?from=N` on the next request) and
+gets exactly the events it missed. Sessions are durable too: the session id is
+the graff session name, the child runs as `graff --json --resume <id>`, and
+posting the same name to a replacement `graff serve` in the same workspace
+picks the run up from the last persisted turn with the sequence continuing.
+
</details>
<details>
diff --git a/src/serve_create.zig b/src/serve_create.zig
index 4c49b396..1bae96a5 100644
--- a/src/serve_create.zig
+++ b/src/serve_create.zig
@@ -15,6 +15,7 @@ const Allocator = std.mem.Allocator;
const serve = @import("serve.zig"); // back-import: shared state + HTTP helpers
const events = @import("serve_events.zig");
+const session_index = @import("session_index.zig"); // the one definition of a session file's path
const ServeState = serve.ServeState;
const ServeSession = serve.ServeSession;
@@ -150,8 +151,11 @@ fn newSessionName(io: Io, arena: Allocator) ![]const u8 {
return std.fmt.allocPrint(arena, "{x:0>16}", .{std.mem.readInt(u64, &raw, .big)});
}
+/// Does the child have a conversation to restore under this name? Asked
+/// through session_index so the path can never drift from the one saveSession
+/// and --resume use.
fn sessionOnDisk(io: Io, arena: Allocator, name: []const u8) bool {
- const path = std.fmt.allocPrint(arena, ".graff/sessions/{s}.session.json", .{name}) catch return false;
+ const path = session_index.sessionPath(arena, name) catch return false;
if (Io.Dir.cwd().statFile(io, path, .{})) |_| return true else |_| return false;
}