graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(goal): any accepted claim spends the double-check arm; trim restates state
Rach Pradhan28c9fcee131d
diff --git a/src/agent_compact.zig b/src/agent_compact.zigindex 071b4705..e77e0e30 100644--- a/src/agent_compact.zig+++ b/src/agent_compact.zig@@ -425,6 +425,8 @@ pub fn emergencyTrim(self: *Agent) usize {// suppressed /loop note points the model at (#318).if (trimOldestToolOutputs(self) > 0) {self.history_rewrites +%= 1;+ if (self.pending_goal_note == null)+ self.pending_goal_note = goal_flow.compactionSnapshot(self.arena, self) catch null;return 1;}return 0;diff --git a/src/goal_flow.zig b/src/goal_flow.zigindex ba9b861e..713afbfa 100644--- a/src/goal_flow.zig+++ b/src/goal_flow.zig@@ -49,6 +49,7 @@ pub fn reapplyFlagGoal(arena: Allocator, root: *Agent, objective: []const u8, no// steering and no completion gate at all, silently (#318).g.status = .active;g.updated_ms = now_ms;+ root.goal_note_fp = 0; // a revived goal re-states its note, not by caller-ordering luckreturn null;}}diff --git a/src/goal_persist_tests.zig b/src/goal_persist_tests.zigindex f422c811..2ed7a683 100644--- a/src/goal_persist_tests.zig+++ b/src/goal_persist_tests.zig@@ -397,3 +397,24 @@ test "a fresh /loop cannot stop accepted off a checklist finished before it (#31goal_state.noteTodoWrite(&root); // the model re-plans and finishes in-runtry std.testing.expectEqual(repl_glue.ContinuationOutcome.accepted, goal_flow.loopTurnDecision(&root, 25).stop);}++test "an accepted claim while paused still consumes the double-check arm (#318)" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const ar = arena_state.allocator();+ var root = blankRoot(ar);+ root.goal = .{ .objective = "ship", .epoch = 1, .status = .active };+ try root.todos.append(ar, .{ .content = "open", .status = "pending", .epoch = 1 });+ try std.testing.expect((try goal_state.completionGate(ar, &root)) != null);+ goal_state.noteCompletionRefused(&root);+ // The user pauses between the refusal and the promised second call. The+ // gate stands down for a paused goal, the claim is recorded, nothing+ // retires - but the arm must be SPENT, or /goal resume hands the revived+ // goal a free pass on its next claim with the items still open.+ root.goal.?.status = .paused;+ try std.testing.expect((try goal_state.completionGate(ar, &root)) == null);+ try std.testing.expect(!goal_state.retireOnCompletion(&root, 9));+ try std.testing.expect(!root.completion_gate_armed);+ root.goal.?.status = .active; // /goal resume+ try std.testing.expect((try goal_state.completionGate(ar, &root)) != null); // fresh double-check+}diff --git a/src/goal_state.zig b/src/goal_state.zigindex b238122d..f202ae6e 100644--- a/src/goal_state.zig+++ b/src/goal_state.zig@@ -169,15 +169,13 @@ pub fn reconcileRestored(root: *Agent) bool {/// can (#318). Pure (no Io) so the rule is unit-tested; the caller passes the/// clock reading.pub fn retireOnCompletion(root: *Agent, now_ms: i64) bool {- if (!goalActive(root)) return false;- if (root.goal.?.standing) {- // The accepted claim consumed this double-check cycle. A /goal objective- // retires here, making its arm moot; a standing goal lives on, so without- // this reset the arm stayed stuck and every LATER claim passed unchecked -- // the unearned accepted, displaced by one cycle (#318).- resetCompletionGate(root);- return false;- }+ // ANY accepted claim consumes the double-check arm: the refusal it answered+ // is spent whether the goal retires, stands, or sits paused. A goal that+ // lives on (standing, or paused-then-resumed) must not ride one refusal+ // forever, or every later claim passes unchecked - the unearned accepted,+ // displaced by one cycle (#318).+ resetCompletionGate(root);+ if (!goalActive(root) or root.goal.?.standing) return false;root.goal.?.status = .complete;root.goal.?.updated_ms = now_ms;return true;