Skip to content

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

Python

fix(todo): parked completed items retire at the next ask (#394)

justrach5af3d8da2939
diff --git a/evals/harness_behavior.jsonl b/evals/harness_behavior.jsonl
index a6308a74..1c2bfc25 100644
--- a/evals/harness_behavior.jsonl
+++ b/evals/harness_behavior.jsonl
@@ -37,3 +37,4 @@
{"id": "citation-free-report-not-rejected", "why": "The false-positive axis of anchorCheck: a report-slot worker that honestly cites nothing must pass in one call - no anchor rejection, no burnt phase retry. The scan once counted the harness's own appended inspect link (.graff/subagents/<id>.md) as a fabricated citation, auto-rejecting every citation-free report; this locks the fix (report_anchors.scan skips .graff/ paths).", "args": [], "prompt": "investigate whether any throttle wiring exists in this project", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "sweep the project for throttle wiring", "tasks": [{"description": "scout", "prompt": "search for throttle wiring and report what exists"}]}]}}, {"text": "No throttle wiring exists anywhere in this project; there is nothing to cite."}, {"text": "confirmed: no throttle wiring exists"}], "timeout_s": 90, "assert": [{"event": {"type": "tool_result", "name": "workflow", "is_error": false}}, {"events_at_most": {"match": {"type": "agent_usage"}, "count": 1}}, {"request_lacks": {"index": 2, "text": "Anchor every finding to real code"}}, {"request_contains": {"index": -1, "text": "1/1 ok, 0 retried"}}, {"final_text_contains": "confirmed: no throttle wiring exists"}]}
{"id": "orch-landed-turn-files-outcome-row", "why": "The landed-turn funnel: before it, flushPending fired only from the eval funnel and exhaustedFatal, so the learned rung policy never saw an ordinary success - blind to exactly the outcome it optimizes (a rung that lands within budget). A no-eval turn that admits a workflow decision must file its kind:\"orch_outcome\" row when the turn lands, so the next boot's fold has evidence from everyday runs, not just scored ones and deaths.", "env": {"GRAFF_FLEET": "on"}, "prompt": "fix the bug in stats.py", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find the defect", "tasks": [{"description": "find", "prompt": "read stats.py and locate the defect"}]}, {"title": "implement the fix", "tasks": [{"description": "fix", "prompt": "fix the defect in stats.py"}]}]}}, {"text": "declined solo - fixed it myself"}, {"tool": "bash", "arguments": {"command": "grep -h '\"kind\":\"orch_outcome\"' .graff/trajectories/*.jsonl | grep '\"arm\":\"R0\"' | grep -q '\"source\":\"bootstrap\"' && echo outcome-row-filed"}}, {"text": "the learning layer recorded the landing"}], "second_prompt": "did the learning layer record that?", "assert": [{"event": {"type": "tool_result", "name": "workflow", "is_error": false}}, {"request_contains": {"index": 1, "text": "(escalation R0):"}}, {"event": {"type": "tool_result", "name": "bash", "text": "outcome-row-filed\n"}}, {"final_text_contains": "recorded the landing"}]}
{"id": "budget-exhausted-past-the-landing-dies-fatal", "why": "#368 exhaustedFatal, the harness's own last words - and the FIRST case that can exist at all, since the runner auto-failed every nonzero exit until expected_exit landed. The #390 landing reserve buys the run ONE tools-free final call; it cannot stop a model that answers that call with a tool call anyway, and executing that tool demands a call the pool cannot admit. A one-shot (-p) run must then die LOUDLY: exit 1 with the harness naming what ran out, that the work is PARTIAL and was NOT rolled back, and where the trace is - never the bare 'turn failed: RunBudgetExhausted' that #368 replaced, and never a silent exit 0. The asserts pin the whole ordering: request 1 carries the full toolset, request 2 IS the landing call (note present, tools gone), and only PAST it does the run die. NOTE (-p): one-shot sets root.out = null, so the --json event stream is empty and no event/final_text assert is expressible here; the same exhaustion inside the stdin/mainloop shape is non-fatal by design (an error event, exit 0), which is why this case must be one-shot. GRAFF_FLEET=on plus the workflow call makes the run carry a real orchestration decision, so exhaustedFatal's other half fires too - it files the score-0 exhausted:true orch_outcome row before dying (verified by hand in the workspace: kind:\"orch_outcome\" ... \"exhausted\":true,\"landed\":false). That row is NOT asserted: it is written as the process dies, after every scripted bash step could run, and the runner keeps no post-mortem surface - it becomes assertable when the trajectory_row extension lands.", "args": ["--max-model-calls", "2", "-p", "fix the failing checks in parser.py"], "env": {"GRAFF_FLEET": "on"}, "expected_exit": 1, "timeout_s": 90, "prompt": "fix the failing checks in parser.py", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find the defect", "tasks": [{"description": "find", "prompt": "read parser.py and locate the failing check"}]}]}}, {"tool": "todo_read", "arguments": {}}, {"tool": "todo_read", "arguments": {}}, {"text": "never reached: the pool was dry two calls ago"}], "assert": [{"request_contains": {"index": 0, "text": "\"todo_write\""}}, {"request_lacks": {"index": 0, "text": "[budget landing]"}}, {"request_contains": {"index": -1, "text": "[budget landing]"}}, {"request_lacks": {"index": -1, "text": "\"todo_write\""}}, {"stderr_contains": "model-call budget exhausted"}, {"stderr_contains": "(--max-model-calls 2)"}, {"stderr_contains": "Work done so far is PARTIAL and was NOT rolled back"}, {"stderr_contains": "raise --max-model-calls or re-run to continue"}]}
+{"id": "new-ask-retires-finished-checklist", "why": "#394: completed items from PRIOR asks piled up. The omitted-completed preserve rule (2896b32) is per-ASK, but the parking never expired: five unrelated goals in one session came back from todo_read as one 13-item [x] pile, and every new prompt inherited it. A checklist that is FULLY completed retires at the next user ask, so the second ask's list holds the second ask's work only - while an unfinished list still crosses the turn untouched (compaction-keeps-completed) and an omission inside one ask still preserves (todo-preserves-completed).", "args": [], "prompt": "rename the config flag", "second_prompt": "unrelated: draft the release notes", "script": [{"tool": "todo_write", "arguments": {"todos": [{"content": "rename the flag in config.zig", "status": "completed"}]}}, {"text": "the flag is renamed"}, {"tool": "todo_write", "arguments": {"todos": [{"content": "draft the release notes", "status": "in_progress"}]}}, {"tool": "todo_read", "arguments": {}}, {"text": "the release notes are drafted"}], "assert": [{"events_at_least": {"match": {"type": "tool_call", "name": "todo_read"}, "count": 1}}, {"request_contains": {"index": -1, "text": "[~] draft the release notes"}}, {"request_lacks": {"index": -1, "text": "[x] rename the flag in config.zig\\n[~] draft the release notes"}}, {"final_text_contains": "the release notes are drafted"}]}
diff --git a/src/agent.zig b/src/agent.zig
index ac89703d..3fe221e7 100644
--- a/src/agent.zig
+++ b/src/agent.zig
@@ -35,6 +35,7 @@ pub const TodoItem = struct {
content: []const u8,
status: []const u8,
epoch: u64 = 0, // the goal epoch that authored this item (#318); 0 = no goal
+ retired: bool = false, // a LATER user ask retired this finished item (#394): kept as the session's archive, invisible to every epoch-scoped query
};
/// Governed-run status for a standing /goal (#223). Only `.active` steers turns;
diff --git a/src/doctor.zig b/src/doctor.zig
index 4802992e..ac17c8f6 100644
--- a/src/doctor.zig
+++ b/src/doctor.zig
@@ -250,7 +250,7 @@ fn armedCompletionGate(arena: Allocator, st: State) Allocator.Error!?Check {
fn countEpoch(todos: []const TodoItem, epoch: u64) usize {
var n: usize = 0;
for (todos) |t| {
- if (t.epoch == epoch) n += 1;
+ if (t.epoch == epoch and !t.retired) n += 1; // #394: retired history is not part of the live checklist this reports
}
return n;
}
diff --git a/src/goal_state.zig b/src/goal_state.zig
index 66ffcfd2..17aca1a5 100644
--- a/src/goal_state.zig
+++ b/src/goal_state.zig
@@ -9,6 +9,11 @@
//! Every query and render here is epoch-scoped instead - the old destructive
//! parkSuperseded/closeEpoch pair is gone, because a mistyped /goal must not be
//! able to erase the user's checklist.
+//! RETIREMENT (#394) is the same retention one axis over: an item a LATER user
+//! ask retired keeps its epoch and its place in root.todos and the session JSON,
+//! and is simply skipped by every query and render below - so a finished
+//! checklist stops following the session around without anything being deleted.
+//! goal_todo.retireFinishedForNewAsk owns when that happens.
//! Pure logic — no Io — so every rule here is unit-tested.
const std = @import("std");
@@ -17,6 +22,7 @@ const Allocator = std.mem.Allocator;
const agent_mod = @import("agent.zig");
const Agent = agent_mod.Agent;
const TodoItem = agent_mod.TodoItem;
+const goal_todo = @import("goal_todo.zig");
const repl_glue = @import("repl_glue.zig");
/// Epoch for a goal that replaces `old`, above every epoch already present in
@@ -44,21 +50,23 @@ pub fn currentEpoch(goal: ?agent_mod.Goal) u64 {
return if (g.status == .complete) 0 else g.epoch;
}
-/// Not-yet-completed items belonging to `epoch`.
+/// Not-yet-completed items belonging to `epoch` (retired ones never count).
pub fn openCount(todos: []const TodoItem, epoch: u64) usize {
var n: usize = 0;
for (todos) |t| {
- if (t.epoch == epoch and !std.mem.eql(u8, t.status, "completed")) n += 1;
+ if (t.epoch == epoch and !t.retired and !std.mem.eql(u8, t.status, "completed")) n += 1;
}
return n;
}
/// True only when `epoch` has a nonempty checklist and every item is completed
-/// (#226 — an empty list is "no plan yet", never "done").
+/// (#226 — an empty list is "no plan yet", never "done"). An epoch left holding
+/// only RETIRED items is empty by this rule, so retiring a finished checklist
+/// can never read as a fresh completion (#394).
pub fn allDone(todos: []const TodoItem, epoch: u64) bool {
var seen = false;
for (todos) |t| {
- if (t.epoch != epoch) continue;
+ if (t.epoch != epoch or t.retired) continue;
if (!std.mem.eql(u8, t.status, "completed")) return false;
seen = true;
}
@@ -72,7 +80,7 @@ pub fn allDone(todos: []const TodoItem, epoch: u64) bool {
pub fn parkedOpenCount(todos: []const TodoItem, keep_epoch: u64) usize {
var parked: usize = 0;
for (todos) |t| {
- if (t.epoch == keep_epoch) continue;
+ if (t.epoch == keep_epoch or t.retired) continue;
if (!std.mem.eql(u8, t.status, "completed")) parked += 1;
}
return parked;
@@ -99,8 +107,12 @@ pub fn adoptTodos(todos: []TodoItem, from_epoch: u64, to_epoch: u64) void {
/// attempt_completion per turn, so clearing the arm at the turn boundary made
/// every refusal unresolvable - refuse, turn ends, flag clears, refuse again,
/// forever, with nothing the user could type to break out.
-pub fn beginTurn(root: *Agent) void {
+/// `new_ask` marks a turn the USER started (false for a /loop continuation,
+/// which is the same ask still running): that is the boundary where a finished
+/// checklist retires instead of following the session forever (#394).
+pub fn beginTurn(root: *Agent, new_ask: bool) void {
root.completion_refused = false;
+ if (new_ask) _ = goal_todo.retireFinishedForNewAsk(root);
}
/// The caller's half of a refusal: arm the double-check so the model's promised
@@ -215,9 +227,12 @@ pub fn goalActive(agent: *Agent) bool {
return !agent.sub and !agent.review_mode and agent.goal != null and agent.goal.?.status == .active;
}
-/// True when any todo belongs to `epoch` (the goal has a checklist at all).
+/// True when any LIVE todo belongs to `epoch` (the goal has a checklist at all).
+/// Retired items do not qualify (#394): an epoch holding only retired history
+/// has no evidence of its own, so the completion gate asks for a plan instead of
+/// accepting "checklist present, 0 open" - the #318 born-done trap.
pub fn hasCurrent(todos: []const TodoItem, epoch: u64) bool {
- for (todos) |t| if (t.epoch == epoch) return true;
+ for (todos) |t| if (t.epoch == epoch and !t.retired) return true;
return false;
}
@@ -281,7 +296,7 @@ pub fn renderTodos(self: *Agent, epoch: u64) []const u8 {
var aw: Io.Writer.Allocating = .init(self.arena);
const w = &aw.writer;
for (self.todos.items) |t| {
- if (t.epoch != epoch) continue;
+ if (t.epoch != epoch or t.retired) continue; // #394: a previous ask's finished list is archive, not this ask's plan
const mark = if (std.mem.eql(u8, t.status, "completed"))
"[x]"
else if (std.mem.eql(u8, t.status, "in_progress"))
@@ -481,7 +496,7 @@ test "the completion double-check survives the turn boundary, re-arms on change
// Turn boundary: only the per-turn flag clears. A model emits one
// attempt_completion per turn, so clearing the arm here made the refusal
// unresolvable forever - the #318 fix reappearing as the #318 bug.
- beginTurn(&root);
+ beginTurn(&root, true); // a new user ask: the arm still survives it, and the open checklist is not retirable
try std.testing.expect(!root.completion_refused);
try std.testing.expect(root.completion_gate_armed);
try std.testing.expect((try completionGate(ar, &root)) == null);
diff --git a/src/goal_todo.zig b/src/goal_todo.zig
index 064677d0..6a2bf4f7 100644
--- a/src/goal_todo.zig
+++ b/src/goal_todo.zig
@@ -15,6 +15,10 @@
//! whose content matches a preserved one WINS, so "redo X, as pending" still
//! works and never leaves a duplicate behind.
//!
+//! The preserve rule is per-ASK, not per-session (#394): retireFinishedForNewAsk
+//! below expires it at the next user ask, so the record of done work survives
+//! the ask that produced it without following every later prompt around.
+//!
//! Split out of agent_tools.zig, which is at this repo's 600-line file cap.
//! Reached through the `test { _ = ... }` hook in main.zig - without that line
//! these tests silently compile to nothing and the suite still reports green.
@@ -58,6 +62,37 @@ fn mentions(contents: []const []const u8, content: []const u8) bool {
return false;
}
+/// A genuinely NEW user ask retires the checklist the PREVIOUS one finished
+/// (#394). clearEpochForReplace keeps an omitted completed item because it is
+/// the record of work done under THIS ask - but nothing ever expired that
+/// parking, so five unrelated asks in one session accumulated: todo_read came
+/// back with thirteen [x] entries spanning goals that had nothing to do with the
+/// prompt in front of the model, and every new prompt inherited the pile.
+/// The boundary is the cheapest honest one available in the loop: a user turn
+/// (goal_state.beginTurn's `new_ask` - never a /loop continuation, which is the
+/// same ask still running) whose current epoch is FULLY completed. An unfinished
+/// checklist is live work and crosses the turn untouched, which is what the
+/// compaction handoff and every cross-turn resume depend on.
+/// Retirement is retention, like parking (#318): the items keep their content,
+/// status and epoch, stay in root.todos and in the session JSON as the ask's
+/// archive, and are merely skipped by the epoch-scoped queries in goal_state.
+/// Subagents and /review turns share the Agent struct but not the user's ask,
+/// so they never retire anything. Returns how many items retired.
+pub fn retireFinishedForNewAsk(root: *Agent) usize {
+ if (root.sub or root.review_mode) return 0;
+ const epoch = goal_state.currentEpoch(root.goal);
+ // allDone is false on an empty epoch (#226) and skips already-retired items,
+ // so this is a no-op with no checklist, with open work, or run twice.
+ if (!goal_state.allDone(root.todos.items, epoch)) return 0;
+ var n: usize = 0;
+ for (root.todos.items) |*t| {
+ if (t.epoch != epoch or t.retired) continue;
+ t.retired = true;
+ n += 1;
+ }
+ return n;
+}
+
pub const WriteResult = struct { text: []const u8, rejected: bool = false, dropped_open: usize = 0 };
/// The whole todo_write handler: replace the current epoch's checklist with
@@ -268,3 +303,107 @@ test "preserved [x] items never make the NEXT goal born done (#318 guard holds)"
// A's record is still there, parked under its own epoch.
try std.testing.expectEqualStrings("[x] A1\n[x] A2", goal_state.renderTodos(&root, 1));
}
+
+test "a new user ask retires the finished checklist; the next list is that ask's own (#394)" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = todoRoot(ar); // no /goal: the plain todo_write user #394 was filed by
+
+ // Ask 1, finished.
+ _ = try applyTodoWrite(&root, try todosArg(ar,
+ \\{"todos":[{"content":"rename the flag in config.zig","status":"completed"}]}
+ ));
+ try std.testing.expect(goal_state.allDone(root.todos.items, 0));
+ try std.testing.expect(goal_state.checklistFinished(&root));
+
+ // The user asks for something else. Before this, the [x] line rode along
+ // into every later list - five asks deep it was a thirteen-item pile.
+ try std.testing.expectEqual(@as(usize, 1), retireFinishedForNewAsk(&root));
+ try std.testing.expectEqualStrings("(no todos)", goal_state.renderTodos(&root, 0));
+ try std.testing.expectEqualStrings("", goal_state.renderCurrent(&root));
+ try std.testing.expect(!goal_state.hasCurrent(root.todos.items, 0));
+ try std.testing.expect(!goal_state.allDone(root.todos.items, 0)); // retired history is not a fresh completion
+ try std.testing.expect(!goal_state.checklistFinished(&root));
+ try std.testing.expectEqual(@as(usize, 0), goal_state.openCount(root.todos.items, 0));
+ // Retirement RETAINS (#318): the archive keeps every field, it just stops being current.
+ try std.testing.expectEqual(@as(usize, 1), root.todos.items.len);
+ try std.testing.expect(root.todos.items[0].retired);
+ try std.testing.expectEqualStrings("rename the flag in config.zig", root.todos.items[0].content);
+ try std.testing.expectEqualStrings("completed", root.todos.items[0].status);
+ try std.testing.expectEqual(@as(u64, 0), root.todos.items[0].epoch);
+
+ // Ask 2's checklist is ask 2's work alone - no inherited [x] lines, and no
+ // "1 open item(s) you left out were dropped" either: nothing open was left out.
+ const rendered = (try applyTodoWrite(&root, try todosArg(ar,
+ \\{"todos":[{"content":"draft the release notes","status":"in_progress"}]}
+ ))).text;
+ try std.testing.expectEqualStrings("[~] draft the release notes", rendered);
+ // Mid-ask turns retire nothing: the list is open work.
+ try std.testing.expectEqual(@as(usize, 0), retireFinishedForNewAsk(&root));
+ try std.testing.expectEqualStrings("[~] draft the release notes", goal_state.renderCurrent(&root));
+
+ // Ask 2 finishes; ask 3 retires ITS list and leaves the older archive alone.
+ _ = try applyTodoWrite(&root, try todosArg(ar,
+ \\{"todos":[{"content":"draft the release notes","status":"completed"}]}
+ ));
+ try std.testing.expectEqual(@as(usize, 1), retireFinishedForNewAsk(&root));
+ try std.testing.expectEqual(@as(usize, 0), retireFinishedForNewAsk(&root)); // idempotent
+ try std.testing.expectEqualStrings("(no todos)", goal_state.renderTodos(&root, 0));
+ try std.testing.expectEqual(@as(usize, 2), root.todos.items.len);
+}
+
+test "retirement is per-ASK: an unfinished checklist crosses the turn whole (#394 keeps 2896b32)" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = todoRoot(ar);
+ root.goal = .{ .objective = "ship the migration", .epoch = 1 };
+ _ = try applyTodoWrite(&root, try todosArg(ar,
+ \\{"todos":[{"content":"migrate the schema","status":"completed"},
+ \\ {"content":"backfill the rows","status":"pending"}]}
+ ));
+ // The user turn (or a compaction handoff) lands mid-ask: one item done, one
+ // open. Retiring here would be the #318 bug again - the completed item is
+ // this ask's own record and compaction-keeps-completed rides on it.
+ try std.testing.expectEqual(@as(usize, 0), retireFinishedForNewAsk(&root));
+ try std.testing.expectEqualStrings("[x] migrate the schema\n[ ] backfill the rows", goal_state.renderCurrent(&root));
+ // And the omitted-completed preserve rule still holds inside the ask.
+ const rendered = (try applyTodoWrite(&root, try todosArg(ar,
+ \\{"todos":[{"content":"backfill the rows","status":"in_progress"}]}
+ ))).text;
+ try std.testing.expectEqualStrings("[x] migrate the schema\n[~] backfill the rows", rendered);
+ try std.testing.expectEqual(@as(usize, 0), retireFinishedForNewAsk(&root));
+ try std.testing.expect(!root.todos.items[0].retired);
+}
+
+test "retirement is epoch-scoped, root-only, and leaves no checklist to complete against (#394)" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = todoRoot(ar);
+ try root.todos.append(ar, .{ .content = "parked open", .status = "pending", .epoch = 1 });
+ try root.todos.append(ar, .{ .content = "parked done", .status = "completed", .epoch = 1 });
+ root.goal = .{ .objective = "phase B", .epoch = 2 };
+ _ = try applyTodoWrite(&root, try todosArg(ar,
+ \\{"todos":[{"content":"B1","status":"completed"}]}
+ ));
+
+ // Subagents and /review turns share the Agent struct but not the user's ask.
+ root.sub = true;
+ try std.testing.expectEqual(@as(usize, 0), retireFinishedForNewAsk(&root));
+ root.sub = false;
+ root.review_mode = true;
+ try std.testing.expectEqual(@as(usize, 0), retireFinishedForNewAsk(&root));
+ root.review_mode = false;
+
+ try std.testing.expectEqual(@as(usize, 1), retireFinishedForNewAsk(&root)); // B1 only
+ try std.testing.expect(!root.todos.items[0].retired and !root.todos.items[1].retired);
+ try std.testing.expectEqualStrings("[ ] parked open\n[x] parked done", goal_state.renderTodos(&root, 1));
+ try std.testing.expectEqual(@as(usize, 1), goal_state.parkedOpenCount(root.todos.items, 2));
+ // The retired epoch reads as "no checklist yet", not as a finished one: a
+ // completion claim on the new ask is deferred rather than pre-accepted off
+ // the previous ask's [x] lines (#318's born-done trap, one boundary over).
+ const refusal = try goal_state.completionGate(ar, &root);
+ try std.testing.expect(refusal != null and std.mem.indexOf(u8, refusal.?, "no checklist") != null);
+}
diff --git a/src/mainloop.zig b/src/mainloop.zig
index 2a0844b1..15038710 100644
--- a/src/mainloop.zig
+++ b/src/mainloop.zig
@@ -398,7 +398,7 @@ pub fn run(ctx: *Ctx) !void {
} else 0;
ctx.root.tools_used.clear(ctx.io); // per-turn tool log for the turn's node
ctx.root.tool_calls_this_turn = 0;
- goal_state.beginTurn(ctx.root); // per-turn gate flags; the ARMED double-check is NOT one of them (#318)
+ goal_state.beginTurn(ctx.root, !is_loop_continuation); // per-turn gate flags (the ARMED double-check is NOT one, #318) + the new-ask retirement of a finished checklist (#394)
ctx.root.seen_tool_keys.clearRetainingCapacity();
if (main_mod.json_mode) ctx.root.emit(.{ .type = "started", .provider = ctx.root.provider.id, .model = ctx.root.provider.model });
if (ctx.interactive and !main_mod.json_mode) {
diff --git a/src/schema.zig b/src/schema.zig
index ef96e9fd..4218e76a 100644
--- a/src/schema.zig
+++ b/src/schema.zig
@@ -115,14 +115,14 @@ const base_specs = [_]ToolSpec{
const meta_specs = [_]ToolSpec{
.{
.name = "todo_write",
- .desc = "Replace the task list for the current standing goal (items from a replaced, cleared or completed goal are parked - kept in the session, but not part of this list and not replaced by this call). An item you already marked completed is kept as history when you leave it out; list it again (with any status) to change or remove it that way. Omitted pending/in_progress items are dropped. Every call needs at least one item: a call with none leaves the list untouched. Use to plan and track multi-step work; skip it for trivial single-step tasks. Each item has content and status (pending|in_progress|completed). Write steps small enough to verify individually; keep exactly ONE item in_progress at a time — mark it in_progress when you start and completed as it lands, never a batch flipped at the end.",
+ .desc = "Replace the task list for the current standing goal (items from a replaced, cleared or completed goal are parked - kept in the session, but not part of this list and not replaced by this call). An item you already marked completed is kept as history when you leave it out, for as long as the current request is being worked; list it again (with any status) to change or remove it that way. Once every item is completed, the next thing the user asks starts a clean list - finished work is not carried into it. Omitted pending/in_progress items are dropped. Every call needs at least one item: a call with none leaves the list untouched. Use to plan and track multi-step work; skip it for trivial single-step tasks. Each item has content and status (pending|in_progress|completed). Write steps small enough to verify individually; keep exactly ONE item in_progress at a time — mark it in_progress when you start and completed as it lands, never a batch flipped at the end.",
.schema =
\\{"type": "object", "properties": {"todos": {"type": "array", "items": {"type": "object", "properties": {"content": {"type": "string"}, "status": {"type": "string", "enum": ["pending", "in_progress", "completed"]}}, "required": ["content", "status"]}}}, "required": ["todos"]}
,
},
.{
.name = "todo_read",
- .desc = "Read your current task list (the current goal's items; work parked by an earlier goal is not included).",
+ .desc = "Read your current task list (the current goal's items; work parked by an earlier goal, and finished lists retired by a later request, are not included).",
.schema = empty_schema,
},
.{
diff --git a/src/session.zig b/src/session.zig
index 6605d8a0..6b3e03bf 100644
--- a/src/session.zig
+++ b/src/session.zig
@@ -156,6 +156,7 @@ fn fingerprint(root: *Agent, name: []const u8) u64 {
f.text(t.content);
f.text(t.status);
f.num(t.epoch);
+ f.flag(t.retired); // #394: retiring a finished checklist is a real state change, so it must reach disk
}
f.text(root.session_title orelse sessionTitle(root));
// The persisted meter's two inputs. Its third (system prompt + tool schema
@@ -279,6 +280,12 @@ fn queueSave(root: *Agent, arena: Allocator, dir: Io.Dir, name: []const u8) !u64
try s.write(t.status);
try s.objectField("epoch");
try s.write(t.epoch);
+ // #394: only when set, so a session with no retired history is written
+ // exactly as before and older builds read it back unchanged.
+ if (t.retired) {
+ try s.objectField("retired");
+ try s.write(true);
+ }
try s.endObject();
}
try s.endArray();
@@ -354,7 +361,10 @@ pub fn appendTodosFromValue(arena: Allocator, todos: *std.ArrayList(agent_mod.To
const content = if (item.object.get("content")) |c| (if (c == .string) c.string else continue) else continue;
const status = if (item.object.get("status")) |s| (if (s == .string) s.string else "pending") else "pending";
const epoch: u64 = if (item.object.get("epoch")) |e| (if (e == .integer and e.integer >= 0) @intCast(e.integer) else 0) else 0;
- try todos.append(arena, .{ .content = content, .status = status, .epoch = epoch });
+ // Absent in sessions written before #394: those items are live, and the
+ // first new ask retires them if they turn out to be a finished list.
+ const retired = if (item.object.get("retired")) |r| (r == .bool and r.bool) else false;
+ try todos.append(arena, .{ .content = content, .status = status, .epoch = epoch, .retired = retired });
}
}
diff --git a/src/session_tests.zig b/src/session_tests.zig
index 54cc1d21..0e2574a2 100644
--- a/src/session_tests.zig
+++ b/src/session_tests.zig
@@ -34,6 +34,15 @@ test "todos round-trip: appendTodosFromValue parses content/status/epoch, skips
// Legacy sessions (no todos field / wrong type): nothing appended.
try session.appendTodosFromValue(a, &todos, .null);
try std.testing.expectEqual(@as(usize, 2), todos.items.len);
+ // #394: `retired` round-trips, and its absence means live - a pre-#394
+ // session restores an ordinary checklist, not a silently invisible one.
+ try std.testing.expect(!todos.items[0].retired);
+ const retired = try std.json.parseFromSliceLeaky(Value, a,
+ \\[{"content":"the previous ask","status":"completed","epoch":2,"retired":true}]
+ , .{});
+ try session.appendTodosFromValue(a, &todos, retired);
+ try std.testing.expectEqual(@as(usize, 3), todos.items.len);
+ try std.testing.expect(todos.items[2].retired);
}
test "goalFromValue: legacy string -> active; object round-trips; paused stays paused (#223)" {