Skip to content

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

Python

Request evidence checkpoints during long reviews

justrachdeb01cc1f726
diff --git a/docs/adr/0124-review-checkpoints-preserve-unfinished-scope.md b/docs/adr/0124-review-checkpoints-preserve-unfinished-scope.md
new file mode 100644
index 00000000..d0ad8923
--- /dev/null
+++ b/docs/adr/0124-review-checkpoints-preserve-unfinished-scope.md
@@ -0,0 +1,33 @@
+# 0124. Review checkpoints preserve unfinished scope
+
+Status: accepted 2026-09-15
+
+## Context
+
+A long explicit review could perform many reads without an interim checkpoint
+(#306). Review mode already rejects mutation and delegation, and deliberately
+supports more than forty tool calls. Stopping after an arbitrary number would
+confuse incomplete coverage with a completed review.
+
+## Decision
+
+Every twenty model calls, an explicit root review receives an append-only,
+harness-tagged checkpoint asking for verified findings, remaining uncertainty,
+and the next inspection. When work remains, progress narration must accompany
+the next tool call rather than terminate the review. The checkpoint records an
+incomplete protocol event and trace note; it cannot mark the task complete,
+change the human request, rewrite the stable prefix, or grant capabilities.
+Short reviews, ordinary coding turns and subagents receive no review checkpoint.
+The existing opt-in call and tool limits keep their behavior.
+
+This addresses periodic call-count checkpoints only. Review wall-time controls
+and entrypoint coverage remain separate requirements; it does not close all of
+#306 or introduce a default hard review budget.
+
+## Verification
+
+Unit checks cover milestones, duplicate suppression, provenance and user-text
+preservation. The production review regression still completes a forty-six-call
+review, observes exactly two checkpoints, rejects edits/workflows, enforces
+explicit budgets and restores parent context. A Tier 2 fixture verifies the
+incomplete event and unchanged workspace.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 3ed01fbf..5d6e1773 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -135,6 +135,8 @@ record only when you need the evidence or the edge cases.
| [0123](0123-pr-check-observations-retain-the-rollup.md) | PR completion retains named current-head check observations locally; diagnostic receipts never replace fresh verification. |
+| [0124](0124-review-checkpoints-preserve-unfinished-scope.md) | Explicit reviews request a findings checkpoint every twenty calls without forcing completion or changing authority. |
+
## When to write one
Write an ADR when a decision is load-bearing and non-obvious: it was reached
diff --git a/evals/harness_behavior.jsonl b/evals/harness_behavior.jsonl
index 517ccf84..1dbc6a5c 100644
--- a/evals/harness_behavior.jsonl
+++ b/evals/harness_behavior.jsonl
@@ -105,3 +105,4 @@
{"id":"human-workflow-clarify-edit-recover-followup","why":"#106: a two-file task preserves user clarification, recovers from a failed edit, and handles a follow-up; independent checks reject a plausible but absent result.","args":["--old"],"env":{"GRAFF_NO_CODEDB_GUARD":"1"},"workspace_seed":{"normalize.py":"def normalize(text):\n return text.lower()\n","client.py":"def render(items):\n return \",\".join(items)\n","README.md":"Keep this documentation unchanged.\n"},"prompt":"Make render trim labels using the existing normalizer. Clarify whether to preserve case before editing. Keep the README unchanged, and verify the actual result.","controls_after_turn":[{"type":"answer","text":"Preserve case exactly; trim surrounding whitespace only."}],"second_prompt":"Now skip empty and whitespace-only labels too. Keep the earlier case behavior, and test that input lists stay unchanged.","script":[{"tool":"read_file","arguments":{"path":"normalize.py"}},{"tool":"read_file","arguments":{"path":"client.py"}},{"tool":"ask_user","arguments":{"question":"Should label case be preserved or normalized?","options":["Preserve case","Lowercase"]}},{"tool":"bash","arguments":{"command":"python3 -c 'from client import render; assert render([\" A \", \"B \"]) == \"A,B\"; print(\"render checks passed\")'"}},{"tool":"edit_file","arguments":{"path":"normalize.py","old_string":" return text.upper()","new_string":" return text.strip()"}},{"tool":"read_file","arguments":{"path":"normalize.py"}},{"tool":"edit_file","arguments":{"path":"normalize.py","old_string":" return text.lower()","new_string":" return text.strip()"}},{"tool":"edit_file","arguments":{"path":"client.py","old_string":"def render(items):\n return \",\".join(items)\n","new_string":"from normalize import normalize\n\ndef render(items):\n return \",\".join(normalize(item) for item in items)\n"}},{"tool":"bash","arguments":{"command":"python3 -c 'from client import render; assert render([\" A \", \"B \"]) == \"A,B\"; print(\"render checks passed\")'"}},{"text":"Both files now trim labels while preserving case. The render checks passed; README is unchanged."},{"tool":"read_file","arguments":{"path":"client.py"}},{"tool":"edit_file","arguments":{"path":"client.py","old_string":"from normalize import normalize\n\ndef render(items):\n return \",\".join(normalize(item) for item in items)\n","new_string":"from normalize import normalize\n\ndef render(items):\n return \",\".join(normalize(item) for item in items if normalize(item))\n"}},{"tool":"bash","arguments":{"command":"python3 -c 'from client import render; x=[\" A \",\" \",\"B\",\"\"]; before=x.copy(); assert render(x)==\"A,B\"; assert x==before; assert render([])==\"\"; print(\"follow-up checks passed\")'"}},{"text":"Blank labels are skipped. Case and input lists are preserved; follow-up checks passed."}],"verify_command":["python3","-c","from client import render; from normalize import normalize; x=[\" Ab \",\" \",\"cD\",\"\"]; before=x.copy(); assert render(x)==\"Ab,cD\"; assert x==before; assert render([])==\"\"; assert normalize(\" X \")==\"X\"; print(\"independent outcomes passed\")"],"assert":[{"event":{"type":"ask_user","question":"Should label case be preserved or normalized?"}},{"event":{"type":"tool_result","name":"ask_user","is_error":false,"text":"Preserve case exactly; trim surrounding whitespace only."}},{"event":{"type":"tool_call_finished","name":"edit_file","is_error":true}},{"event":{"type":"tool_call_finished","name":"bash","is_error":true}},{"events_at_least":{"match":{"type":"turn"},"count":2}},{"request_contains":{"text":"Preserve case exactly"}},{"final_text_contains":"follow-up checks passed"},{"file_equals":{"path":"normalize.py","content":"def normalize(text):\n return text.strip()\n"}},{"file_equals":{"path":"client.py","content":"from normalize import normalize\n\ndef render(items):\n return \",\".join(normalize(item) for item in items if normalize(item))\n"}},{"file_equals":{"path":"README.md","content":"Keep this documentation unchanged.\n"}},{"request_contains":{"index":3,"text":"Preserve case exactly"}},{"request_tool_calls_at_most":{"index":3,"name":"edit_file","count":0}}]}
{"id":"human-workflow-missing-config-clarify-followup","why":"#106: failed navigation cannot become an invented setting; a human supplies the actual path, then a later requested edit preserves unrelated configuration.","args":["--old"],"env":{"GRAFF_NO_CODEDB_GUARD":"1"},"workspace_seed":{"config/settings.json":"{\"retries\": 3, \"timeout\": 10}\n","README.md":"Do not change me.\n"},"prompt":"Check settings.json for the retry count. If it is missing, ask me where it lives; do not create a replacement or change anything yet.","controls_after_turn":[{"type":"answer","text":"It is config/settings.json. Read that existing file."}],"second_prompt":"Raise retries to 4 in that file, preserve timeout, and validate the JSON.","script":[{"tool":"read_file","arguments":{"path":"settings.json"}},{"tool":"ask_user","arguments":{"question":"Where is the existing settings file?"}},{"tool":"read_file","arguments":{"path":"config/settings.json"}},{"text":"The existing retry count is 3. No files were changed."},{"tool":"edit_file","arguments":{"path":"config/settings.json","old_string":"\"retries\": 3","new_string":"\"retries\": 4"}},{"tool":"bash","arguments":{"command":"python3 -c 'import json; x=json.load(open(\"config/settings.json\")); assert x=={\"retries\":4,\"timeout\":10}; print(\"configuration validated\")'"}},{"text":"Retries are 4; timeout remains 10. Configuration validated."}],"verify_command":["python3","-c","import json,pathlib; assert json.loads(pathlib.Path(\"config/settings.json\").read_text())=={\"retries\":4,\"timeout\":10}; assert not pathlib.Path(\"settings.json\").exists(); print(\"independent configuration passed\")"],"assert":[{"event":{"type":"tool_call_finished","name":"read_file","is_error":true}},{"event":{"type":"ask_user","question":"Where is the existing settings file?"}},{"events_at_least":{"match":{"type":"turn"},"count":2}},{"no_event":{"type":"tool_call","name":"write_file"}},{"request_contains":{"text":"Read that existing file"}},{"final_text_contains":"timeout remains 10"},{"file_equals":{"path":"config/settings.json","content":"{\"retries\": 4, \"timeout\": 10}\n"}},{"file_equals":{"path":"README.md","content":"Do not change me.\n"}},{"request_contains":{"index":2,"text":"config/settings.json. Read that existing file."}},{"request_tool_calls_at_most":{"index":2,"name":"edit_file","count":0}}]}
{"id":"current-head-receipt-names-actual-checks","why":"#853: preserve the actual named CI outcomes; local schema success cannot replace failing packed SDK evidence.","args":["--old","--goal","Deliver a PR with passing current-head CI"],"env":{"GRAFF_NO_CODEDB_GUARD":"1"},"github_fixture":{"runs":"none","check_rollup":[{"name":"schema drift","status":"COMPLETED","conclusion":"SUCCESS"},{"name":"packed SDK","status":"COMPLETED","conclusion":"FAILURE"},{"context":"platform contract","state":"PENDING"}]},"prompt":"Run the local publication fixture and fulfill the objective.","script":[{"tool":"todo_write","arguments":{"todos":[{"content":"inspect exact-head CI","status":"pending"}]}},{"tool":"bash","arguments":{"command":"gh pr create --title fixture --body-file notes.md"}},{"tool":"todo_write","arguments":{"todos":[{"content":"provide draft handoff","status":"completed"}]}},{"tool":"attempt_completion","arguments":{"result":"Draft handoff; the base checks also fail."}},{"tool":"attempt_completion","arguments":{"result":"Draft handoff; the base checks also fail."}},{"text":"CI is unresolved."}],"assert":[{"events_at_least":{"match":{"type":"tool_call_finished","name":"attempt_completion","is_error":true},"count":2}},{"no_event":{"type":"tool_call_finished","name":"attempt_completion","is_error":false}},{"request_contains":{"text":"failed: CI reported a failure"}},{"request_contains":{"text":"schema drift"}},{"request_contains":{"text":"packed SDK"}},{"request_contains":{"text":"platform contract"}}]}
+{"id":"review-checkpoint-preserves-unfinished-scope","why":"#306: a long read-only review requests an evidence checkpoint without forcing completion or granting edits.","args":["--old"],"prompt_options":{"type":"review"},"prompt":"Review target.txt without modifying it.","workspace_seed":{"target.txt":"original\n"},"script":[{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"tool":"read_file","arguments":{"path":"target.txt"}},{"text":"No findings. Review finished."}],"assert":[{"events_at_least":{"match":{"type":"review_checkpoint","complete":false},"count":1}},{"events_at_most":{"match":{"type":"review_checkpoint"},"count":1}},{"request_contains":{"text":"Review checkpoint:"}},{"request_contains":{"text":"next inspection tool call"}},{"file_equals":{"path":"target.txt","content":"original\n"}},{"final_text_contains":"No findings. Review finished."}]}
diff --git a/scripts/test-review-mode.py b/scripts/test-review-mode.py
index 82d4e984..84f18d7a 100644
--- a/scripts/test-review-mode.py
+++ b/scripts/test-review-mode.py
@@ -275,6 +275,17 @@ def main() -> None:
if long_events[-1].get("type") != "turn" or long_events[-1].get("text") != LONG_REPLY:
raise AssertionError(f"long review did not terminate naturally: {long_events[-1]!r}")
+ checkpoints = [event for event in long_events if event.get("type") == "review_checkpoint"]
+ if len(checkpoints) != 2 or any(event.get("complete") is not False for event in checkpoints):
+ raise AssertionError(f"long review did not emit two incomplete checkpoints: {checkpoints!r}")
+ requests = long_mock.recorded_requests()
+ for index in (20, 40):
+ body = json.dumps(requests[index].body)
+ if "Review checkpoint:" not in body or "next inspection tool call" not in body:
+ raise AssertionError(f"review request {index} lost its checkpoint instructions")
+ if any(event.get("type") == "review_checkpoint" for event in events):
+ raise AssertionError("short review received an unnecessary checkpoint")
+
global_mock = CodexMock(events_for_request=loop_events)
global_port = global_mock.start()
try:
diff --git a/src/review.zig b/src/review.zig
index d61a6ca8..7cf99875 100644
--- a/src/review.zig
+++ b/src/review.zig
@@ -141,3 +141,56 @@ test "review context hides and restores parent history" {
try std.testing.expect(root.last_usage_includes_output);
try std.testing.expect(!context.restore(&root));
}
+
+/// A milestone asks for evidence-based narration, not raw per-call counters.
+/// It cannot end the review or grant permission to modify/delegate work.
+pub const Progress = struct {
+ next_calls: u64 = 20,
+
+ pub fn beforeRequest(self: *Progress, agent: *@import("agent.zig").Agent) !void {
+ if (!agent.review_mode or agent.sub or agent.model_calls_this_turn < self.next_calls) return;
+ const text = "Review checkpoint: briefly report what you have verified, what is still uncertain, and the next inspection needed. Do not claim the review is complete from partial coverage. If work remains, put this progress update before your next inspection tool call in the same response, then continue the read-only review. Do not start fixes, delegate, or repeat already-settled validation without new evidence.";
+ var note = try @import("named_work.zig").userNudge(agent.arena, agent.provider.kind, text);
+ try note.object.put(agent.arena, @import("session_wake.zig").origin_key, .{ .string = "notification" });
+ try agent.messages.append(note);
+ self.next_calls = agent.model_calls_this_turn +| 20;
+ agent.emit(.{ .type = "review_checkpoint", .text = "Read-only review remains in progress; a findings checkpoint was requested.", .complete = false });
+ if (agent.tracer) |tr| tr.note("review_checkpoint", "requested verified findings, remaining uncertainty and next inspection; no forced completion");
+ }
+};
+
+test "review milestones preserve user authority and do not complete or repeat at the same call" {
+ var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena.deinit();
+ const a = arena.allocator();
+ const Agent = @import("agent.zig").Agent;
+ var agent: Agent = undefined;
+ agent.arena = a;
+ agent.review_mode = true;
+ agent.sub = false;
+ agent.model_calls_this_turn = 19;
+ agent.messages = .init(a);
+ agent.provider.kind = .openai;
+ agent.tracer = null;
+ agent.completed = null;
+ agent.out = null;
+ try agent.messages.append(try @import("messages.zig").textMessage(a, "user", "Review the whole diff"));
+ var progress: Progress = .{};
+ try progress.beforeRequest(&agent);
+ try std.testing.expectEqual(@as(usize, 1), agent.messages.items.len);
+ agent.model_calls_this_turn = 20;
+ try progress.beforeRequest(&agent);
+ try std.testing.expectEqual(@as(usize, 2), agent.messages.items.len);
+ try std.testing.expect(@import("session_wake.zig").isNotice(agent.messages.items[1]));
+ try std.testing.expectEqualStrings("Review the whole diff", @import("messages.zig").latestUserText(agent.messages.items));
+ try std.testing.expect(agent.completed == null);
+ try progress.beforeRequest(&agent);
+ try std.testing.expectEqual(@as(usize, 2), agent.messages.items.len);
+ agent.model_calls_this_turn = 40;
+ try progress.beforeRequest(&agent);
+ try std.testing.expectEqual(@as(usize, 3), agent.messages.items.len);
+ agent.review_mode = false;
+ agent.model_calls_this_turn = 100;
+ try progress.beforeRequest(&agent);
+ try std.testing.expectEqual(@as(usize, 3), agent.messages.items.len);
+}
diff --git a/src/task_intent.zig b/src/task_intent.zig
index 02815369..d0f4ab45 100644
--- a/src/task_intent.zig
+++ b/src/task_intent.zig
@@ -57,6 +57,7 @@ pub const checkpoint = "Summary scope checkpoint: review the map and targeted ev
pub const State = struct {
nudged: bool = false,
+ review_progress: @import("review.zig").Progress = .{},
pub fn begin(self: *Agent) State {
if (self.tracer) |tr| tr.note("task_intent", @tagName(current(self)));
@@ -64,6 +65,7 @@ pub const State = struct {
}
pub fn beforeRequest(state: *State, self: *Agent) !void {
+ try state.review_progress.beforeRequest(self);
if (state.nudged or self.sub or current(self) != .informational) return;
if (self.model_calls_this_turn < 4 and self.tool_calls_this_turn < 6) return;
var note = try @import("named_work.zig").userNudge(self.arena, self.provider.kind, checkpoint);
@@ -105,6 +107,7 @@ test "summary checkpoint is once, preserves the human request, and respects a ne
agent.arena = a;
agent.messages = .init(a);
agent.sub = false;
+ agent.review_mode = false;
agent.tracer = null;
agent.provider.kind = .openai;
agent.model_calls_this_turn = 3;