graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(goal): a refusal in one session must not close the next one's goal
Rach Pradhan03d0f7a827b5
diff --git a/src/goal_persist_tests.zig b/src/goal_persist_tests.zigindex aa59ad2a..289603f9 100644--- a/src/goal_persist_tests.zig+++ b/src/goal_persist_tests.zig@@ -24,6 +24,8 @@ fn resumeSession(arena: Allocator, root: *Agent, json: []const u8) !void {root.todos.clearRetainingCapacity();if (parsed.object.get("todos")) |tv| try session.appendTodosFromValue(arena, &root.todos, tv);root.todos_dirty = false;+ root.completion_gate_armed = false; // the double-check is per-process: an arm from the PREVIOUS session must not close this one's goal (#318)+ root.completion_refused = false;_ = goal_state.reconcileRestored(root);}@@ -109,6 +111,28 @@ test "resume: a finished epoch-0 leftover cannot end a bare /loop (#318)" {try std.testing.expect(goal_state.checklistFinished(&root));}+test "resume: the completion double-check does not ride in from the previous session (#318)" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const ar = arena_state.allocator();+ var root = blankRoot(ar);+ // The arm survives turns on purpose (a model emits one attempt_completion+ // per turn), so a refusal late in session A left it set. /resume B then+ // restored an active goal with open work and the FIRST attempt_completion+ // of B hit the armed short-circuit: the goal closed, the double-check the+ // user never saw refused nothing.+ root.completion_gate_armed = true;+ root.completion_refused = true;+ try resumeSession(ar, &root,+ \\{"goal":{"objective":"ship phase 2","status":"active","epoch":2,"created_ms":1,"updated_ms":2},+ \\ "todos":[{"content":"verify in the browser","status":"pending","epoch":2}]}+ );+ try std.testing.expect(!root.completion_gate_armed);+ try std.testing.expect(!root.completion_refused);+ const refusal = try goal_state.completionGate(ar, &root);+ try std.testing.expect(refusal != null and std.mem.indexOf(u8, refusal.?, "1 open") != null);+}+test "goalFromValue: epoch round-trips; legacy goals default to epoch 0 (#318)" {// Moved here from session.zig, which is at the 600-line cap.var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);diff --git a/src/session.zig b/src/session.zigindex 25f62e28..01dffb66 100644--- a/src/session.zig+++ b/src/session.zig@@ -467,6 +467,11 @@ pub fn loadSession(root: *Agent, keys: *Keys, arena: Allocator, name: []const u8root.todos.clearRetainingCapacity(); // never inherit another conversation's checklist (#318)if (obj.get("todos")) |tv| try appendTodosFromValue(arena, &root.todos, tv);root.todos_dirty = false; // restored todos are persisted state, never this-process completion evidence (#318)+ // The completion double-check is per-PROCESS state and leaked across /resume+ // (#318): an arm left by a refusal in the previous session short-circuited the+ // first attempt_completion of the resumed one, closing its goal unchecked.+ root.completion_gate_armed = false;+ root.completion_refused = false;// #318: retire a restored-active goal whose checklist is already finished.if (goal_state.reconcileRestored(root)) if (root.tracer) |t| t.note("goal", "reconciled-complete");// Steering gate state belongs to the previous conversation (#318): drop any