graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(gui): restore canonical saved task state
justrachf8367a9cc36f
diff --git a/apps/native/app/api/sessions/route.ts b/apps/native/app/api/sessions/route.tsindex 09ae4a13..7ca6cb91 100644--- a/apps/native/app/api/sessions/route.ts+++ b/apps/native/app/api/sessions/route.ts@@ -59,6 +59,7 @@ export async function GET(req: NextRequest) {provider?: unknown;workspace?: unknown;messages?: unknown;+ todos?: unknown;};const header = peekHeader(found.file, st.size);return Response.json({@@ -74,10 +75,11 @@ export async function GET(req: NextRequest) {// payload as a snapshot with unknown execution (#839).view: "snapshot",execution: "unknown",+ ...(Array.isArray(parsed.todos) ? { todos: parsed.todos } : {}),// The desktop never displayed raw provider history. Avoid allocating// its tool bodies and image payloads again in Chromium just to drop them....(req.nextUrl.searchParams.get("view") === "transcript"- ? { presentation: "transcript-v1", transcript: transcriptFromMessages(Array.isArray(parsed.messages) ? parsed.messages : [], str(parsed.model) ?? undefined) }+ ? { presentation: "transcript-v1", transcript: transcriptFromMessages(Array.isArray(parsed.messages) ? parsed.messages : [], str(parsed.model) ?? undefined, parsed.todos) }: { messages: Array.isArray(parsed.messages) ? parsed.messages : [] }),});} catch (err) {diff --git a/apps/native/lib/session-projection.test.ts b/apps/native/lib/session-projection.test.tsindex 9faf2143..d1905b96 100644--- a/apps/native/lib/session-projection.test.ts+++ b/apps/native/lib/session-projection.test.ts@@ -142,3 +142,26 @@ test("#839: intermediate and final-looking saved prose cannot establish live com}}});++test('#912: snapshot uses saved todos over stale historical writes, and honors clearing', async () => {+ const file = fixture();+ try {+ const messages = [{ role: 'assistant', content: 'Earlier work', tool_calls: [+ { id: 'old-todo', function: { name: 'todo_write', arguments: JSON.stringify({ todos: [{ content: 'Review', status: 'in_progress' }] }) } },+ ] }];+ for (const todos of [[{ content: 'Review', status: 'completed', epoch: 1 }], []]) {+ writeFileSync(path.join(file.root, '.graff/sessions/example.session.json'), JSON.stringify({ messages, todos }));+ for (const view of [undefined, 'transcript']) {+ const loaded = sessionFromResponse(await (await GET(new NextRequest(file.url(view)))).json());+ const last = loaded.messages.at(-1);+ expect(last?.role).toBe('assistant');+ if (last?.role === 'assistant') {+ expect(last.turn.todos).toEqual(todos.map(({content, status}, i) => ({id: `todo-${i}`, content, status})));+ expect(last.turn.status).toBe('snapshot');+ }+ }+ }+ const legacy = transcriptFromMessages(messages).at(-1);+ if (legacy?.role === 'assistant') expect(legacy.turn.todos[0].status).toBe('in_progress');+ } finally { file.cleanup(); }+});diff --git a/apps/native/lib/sessions.ts b/apps/native/lib/sessions.tsindex 94304d2d..03466c79 100644--- a/apps/native/lib/sessions.ts+++ b/apps/native/lib/sessions.ts@@ -41,6 +41,8 @@ export type TranscriptMsg =export type SessionResponse = StoredSession & {messages?: unknown[];+ /** Canonical checklist from the same saved file, including an explicit clear. */+ todos?: unknown;presentation?: "transcript-v1";transcript?: TranscriptMsg[];/** Saved file only — not a live REPL attach (#839). */@@ -51,17 +53,27 @@ export type SessionResponse = StoredSession & {/** New servers project the existing GUI transcript before crossing into the* renderer. Keep raw responses readable for older servers and local fixtures. */export function sessionFromResponse(body: SessionResponse): { meta: StoredSession; messages: TranscriptMsg[]; snapshot: boolean } {- const { messages, presentation, transcript, view: _view, execution: _execution, ...meta } = body;+ const { messages, presentation, transcript, todos, view: _view, execution: _execution, ...meta } = body;return {meta,// A saved file is never a live REPL attach. The GUI must not infer// that commentary or a successful load means the other surface finished (#839).snapshot: true,- messages: presentation === "transcript-v1" && Array.isArray(transcript)- ? transcript.map(message => message.role === "assistant" ? { ...message, turn: { ...message.turn, status: "snapshot" } } : message) : transcriptFromMessages(messages ?? [], meta.model ?? undefined),+ messages: withSavedTodos(presentation === "transcript-v1" && Array.isArray(transcript)+ ? transcript.map(message => message.role === "assistant" ? { ...message, turn: { ...message.turn, status: "snapshot" } } : message) : transcriptFromMessages(messages ?? [], meta.model ?? undefined), todos),};}+/** Tool arguments are historical proposals; the saved checklist is authoritative. */+function withSavedTodos(messages: TranscriptMsg[], saved: unknown): TranscriptMsg[] {+ if (!Array.isArray(saved)) return messages;+ const todos = todosOf({ todos: saved });+ const last = messages.findLastIndex(message => message.role === "assistant");+ if (last < 0) return todos.length ? [...messages, { role: "assistant", turn: { ...emptyTurn(), status: "snapshot", todos } }] : messages;+ return messages.map((message, index) => index === last && message.role === "assistant"+ ? { ...message, turn: { ...message.turn, todos } } : message);+}+const BASE = "/api/sessions";function withRoot(params: Record<string, string | undefined>): string {@@ -234,7 +246,7 @@ function appendText(turn: AssistantTurn, text: string): void {* the live ACP stream renders a turn; `attempt_completion` is the engine's* final-answer tool, so its `result` becomes prose instead of a tool row.*/-export function transcriptFromMessages(raw: unknown[], model?: string): TranscriptMsg[] {+export function transcriptFromMessages(raw: unknown[], model?: string, savedTodos?: unknown): TranscriptMsg[] {const out: TranscriptMsg[] = [];let turn: AssistantTurn | null = null;const flush = () => {@@ -312,5 +324,5 @@ export function transcriptFromMessages(raw: unknown[], model?: string): Transcri}}flush();- return out;+ return withSavedTodos(out, savedTodos);}diff --git a/docs/adr/0099-gui-saved-sessions-are-snapshots.md b/docs/adr/0099-gui-saved-sessions-are-snapshots.mdindex fc981dad..a34a13af 100644--- a/docs/adr/0099-gui-saved-sessions-are-snapshots.md+++ b/docs/adr/0099-gui-saved-sessions-are-snapshots.md@@ -23,6 +23,12 @@ claim the REPL turn.Unmatched tool calls in the last restored turn stay running so the snapshotcan still show in-progress work. That is display state, not a live attach.+The checklist comes from the saved session’s top-level `todos` field when+present, including an empty list. Historical `todo_write` arguments may be+stale or rejected proposals and must not override that saved state. Older+files without the field retain history-based reconstruction. This does not+turn a saved checklist into live execution status.+## ConsequencesOpening and refreshing history never bootstrap an ACP session. The composer