Skip to content

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

Python

fix: address review findings — CI case for set_ultracode, honest pin-test scope, exact ack count, stale serve doc

Rach Pradhan24de0af49d75
diff --git a/scripts/test-json-controls.py b/scripts/test-json-controls.py
index e667f03e..9b90f9ea 100755
--- a/scripts/test-json-controls.py
+++ b/scripts/test-json-controls.py
@@ -2,10 +2,10 @@
"""Automated integration test for the graff --json live control protocol.
Spawns `graff --json`, sends each control request (set_model / compact /
-set_mode / set_agent) plus error paths, and asserts the structured ack/error
-events. Deterministic and offline: a dummy CODEGRAFF_API_KEY lets the session
-start and switch within codegraff, while switching to a keyless provider
-exercises the error path -- no real API calls.
+set_mode / set_agent / set_effort / set_fast / set_ultracode) plus error paths,
+and asserts the structured ack/error events. Deterministic and offline: a dummy
+CODEGRAFF_API_KEY lets the session start and switch within codegraff, while
+switching to a keyless provider exercises the error path -- no real API calls.
Usage: python3 scripts/test-json-controls.py [path-to-graff]
Exit 0 if all assertions pass, 1 otherwise.
@@ -73,8 +73,19 @@ CASES = [
({"type": "set_fast", "on": False},
lambda e: e.get("type") == "fast" and e.get("on") is False,
"set_fast off -> fast ack"),
+ ({"type": "set_ultracode", "on": True},
+ lambda e: e.get("type") == "ultracode" and e.get("ok") and e.get("on") is True,
+ "set_ultracode on -> ultracode ack"),
+ ({"type": "set_ultracode", "on": False},
+ lambda e: e.get("type") == "ultracode" and e.get("on") is False,
+ "set_ultracode off -> ultracode ack"),
]
-CONTROL_TYPES = {"model", "compact", "mode", "agent", "effort", "fast", "error"}
+# Every ack type a control request can answer with. The filter below keeps only
+# these, positionally against CASES, so a type missing here silently drops its
+# case's ack and shifts (or vacuously passes) every case after it. Keep in sync
+# with src/serve_events.zig's terminal_events minus "turn" (no user turns here).
+CONTROL_TYPES = {"model", "compact", "mode", "agent", "effort", "fast",
+ "ultracode", "system_prompt", "score", "error"}
def run():
env = dict(os.environ)
diff --git a/src/serve.zig b/src/serve.zig
index a1a398b8..cba832e2 100644
--- a/src/serve.zig
+++ b/src/serve.zig
@@ -255,7 +255,7 @@ pub fn freeSession(st: *ServeState, sess: *ServeSession) void {
/// POST /v1/sessions/<id>: forward one protocol request line to the child and
/// stream its stdout events back as chunked NDJSON until the terminal event
-/// for that request (turn/error for user turns; system_prompt/score acks).
+/// for that request (every type in serve_events.terminal_events).
/// `?from=N` (or `"resume_from": N` in the body) replays persisted events with
/// seq >= N first, so a reconnecting supervisor never has a hole.
fn serveMessage(st: *ServeState, req: *std.http.Server.Request, id: []const u8, from_query: ?u64) !void {
diff --git a/src/serve_events.zig b/src/serve_events.zig
index f66102c9..2fb6cc40 100644
--- a/src/serve_events.zig
+++ b/src/serve_events.zig
@@ -172,8 +172,9 @@ pub const Follower = struct {
/// An ack missing from this list wedges the session PERMANENTLY — serve.zig
/// streams it and then blocks in takeDelimiter() still holding `busy`, so every
/// later request on that session waits on a lock nobody will release. The test
-/// below pins this list against the emitter so a new control command cannot
-/// land without one.
+/// below pins this list against mainloop.zig's INLINE control block only, so a
+/// handler that emits its ack from its own module (mainloop_score.zig does)
+/// stays invisible to the scan and needs its own case there.
pub const terminal_events = [_][]const u8{
"turn",
"error",
@@ -386,7 +387,8 @@ test "terminal_events covers every control ack mainloop can emit" {
// reads; a wrapped `.emit(.{` would slip past it entirely unchecked.
const emit = ".emit(.{";
const typed_emit = emit ++ " .type = \"";
- try testing.expectEqual(std.mem.count(u8, block, emit), std.mem.count(u8, block, typed_emit));
+ const typed = std.mem.count(u8, block, typed_emit);
+ try testing.expectEqual(std.mem.count(u8, block, emit), typed);
var checked: usize = 0;
var rest = block;
@@ -395,15 +397,23 @@ test "terminal_events covers every control ack mainloop can emit" {
const stop = from + (std.mem.indexOfScalar(u8, rest[from..], '"') orelse return error.ControlBlockMoved);
const name = rest[from..stop];
rest = rest[stop..];
- var buf: [128]u8 = undefined;
- const line = try std.fmt.bufPrint(&buf, "{{\"seq\":1,\"type\":\"{s}\"}}", .{name});
+ var buf: [512]u8 = undefined;
+ const line = std.fmt.bufPrint(&buf, "{{\"seq\":1,\"type\":\"{s}\"}}", .{name}) catch {
+ std.debug.print("\nack name of {d} bytes starting \"{s}\" overflows this test's scratch buffer — enlarge buf\n", .{ name.len, name[0..@min(name.len, 48)] });
+ return error.ControlAckNameTooLong;
+ };
if (!terminalEvent(line)) {
std.debug.print("\ncontrol ack \"{s}\" is missing from serve_events.terminal_events\n", .{name});
return error.ControlAckNotTerminal;
}
checked += 1;
}
- try testing.expect(checked >= 12); // the scan read acks, not an empty slice
+ // Exact, so a scan that skips an emit (rather than finding a bad one) still
+ // fails; plus a floor, because the markers above could match a shorter
+ // region and leave both counts trivially in agreement. 17 acks today, and
+ // this only trips if acks are DELETED — adding one is fine.
+ try testing.expectEqual(typed, checked);
+ try testing.expect(checked >= 17);
// score is acked from its own module; answer/reattach never reach the
// streaming loop (serve.zig answers both before serveMessage sends).