xonecas.io
64875
Mc

mini-coder / commit b90fd10

Revert "fix: keep GPT commentary out of session history"

This reverts commit 36d6d4307a418450ade344e425c311de840cf188.

xonecas2026-03-14 b90fd105e08ba2bfb905a4109500f8ed91f4cec0 parent 36d6d43

3 files changed

src/agent/agent-helpers.ts+1−18
@@ -1,20 +1,5 @@
11 import type { CoreMessage } from "../llm-api/turn.ts";
22
3-function isRecord(value: unknown): value is Record<string, unknown> {
4- return value !== null && typeof value === "object";
5-}
6-
7-function isCommentaryTextPart(part: unknown): boolean {
8- if (!isRecord(part) || part.type !== "text") return false;
9- const providerData = isRecord(part.providerOptions)
10- ? part.providerOptions
11- : isRecord(part.providerMetadata)
12- ? part.providerMetadata
13- : null;
14- if (!providerData || !isRecord(providerData.openai)) return false;
15- return providerData.openai.phase === "commentary";
16-}
17-
183 export function makeInterruptMessage(reason: "user" | "error"): CoreMessage {
194 const text =
205 reason === "user"
@@ -51,9 +36,7 @@ export function extractAssistantText(newMessages: CoreMessage[]): string {
5136 parts.push(content);
5237 } else if (Array.isArray(content)) {
5338 for (const part of content as Array<{ type?: string; text?: string }>) {
54- if (part?.type === "text" && part.text && !isCommentaryTextPart(part)) {
55- parts.push(part.text);
56- }
39+ if (part?.type === "text" && part.text) parts.push(part.text);
5740 }
5841 }
5942 }
src/agent/agent.test.ts+0−22
@@ -66,28 +66,6 @@ describe("extractAssistantText", () => {
6666 ];
6767 expect(extractAssistantText(msgs)).toBe("Tests pass.");
6868 });
69-
70- test("ignores GPT commentary text parts", () => {
71- const msgs: CoreMessage[] = [
72- {
73- role: "assistant",
74- content: [
75- {
76- type: "text",
77- text: "to=functions.shell json{...}",
78- providerOptions: { openai: { phase: "commentary" } },
79- },
80- {
81- type: "text",
82- text: "Committed the fix.",
83- providerOptions: { openai: { phase: "final_answer" } },
84- },
85- ],
86- },
87- ] as unknown as CoreMessage[];
88-
89- expect(extractAssistantText(msgs)).toBe("Committed the fix.");
90- });
9169 });
9270
9371 // ─── makeInterruptMessage ─────────────────────────────────────────────────────
src/agent/session-runner.ts+9−14
@@ -1,7 +1,6 @@
11 import * as c from "yoctocolors";
22 import type { ImageAttachment } from "../cli/image-types.ts";
33 import { watchForCancel } from "../cli/input.ts";
4-import { stripGPTCommentaryFromHistory } from "../llm-api/history-transforms.ts";
54 import type { ThinkingEffort } from "../llm-api/providers.ts";
65 import { resolveModel } from "../llm-api/providers.ts";
76 import type { ContextPruningMode, CoreMessage } from "../llm-api/turn.ts";
@@ -291,22 +290,18 @@ export class SessionRunner {
291290 await this.reporter.renderTurn(events, {
292291 showReasoning: this.showReasoning,
293292 });
294- const sanitizedNewMessages = stripGPTCommentaryFromHistory(
295- newMessages,
296- this.currentModel,
297- );
298293
299- if (sanitizedNewMessages.length > 0) {
300- this.coreHistory.push(...sanitizedNewMessages);
301- this.session.messages.push(...sanitizedNewMessages);
302- // Persistence invariant: save model-authored messages with stable,
303- // replay-safe JSON. Provider commentary/tool-call scratchpad text is
304- // intentionally stripped because persisting it pollutes future turns
305- // and can reintroduce malformed raw tool-call text into history.
306- saveMessages(this.session.id, sanitizedNewMessages, thisTurn);
294+ if (newMessages.length > 0) {
295+ this.coreHistory.push(...newMessages);
296+ this.session.messages.push(...newMessages);
297+ // Persistence invariant: save model-authored messages with lossless JSON
298+ // serialization and preserve exact shape/ordering (including
299+ // providerOptions/providerMetadata thought-signature fields). Never
300+ // reconstruct tool-call history during save/load.
301+ saveMessages(this.session.id, newMessages, thisTurn);
307302 }
308303
309- lastAssistantText = extractAssistantText(sanitizedNewMessages);
304+ lastAssistantText = extractAssistantText(newMessages);
310305 this.totalIn += inputTokens;
311306 this.totalOut += outputTokens;
312307 this.lastContextTokens = contextTokens;