xonecas.io
64875
Mc

mini-coder / commit 30bf69b

fix: remove blunt step-prune fallback that caused amnesia on long turns

The STEP_PRUNE_FALLBACK_THRESHOLD (200 messages) caused applyStepPruning
to fall back to applyContextPruning on every step of long turns. That
function uses reasoning: 'before-last-message' which strips all
chain-of-thought during tool loops, causing the model to lose its plan
and repeat completed work.

Removed the threshold entirely — step pruning now always uses
reasoning: 'none' with the adjusted tool-call window, preserving the
model's chain-of-thought regardless of conversation length.

xonecas2026-03-21 30bf69b0c623edaccd115c324a20e902c04ca20a parent 09719d4

5 files changed

TODO.md+0−0
docs/KNOWN_ISSUES.md+1−0
@@ -2,6 +2,7 @@
22
33 ## Bugs
44
5+- `/model` doesn't autocomplete models provider/name pattern.
56 - CTRL+d hangs sometimes and doesn't exit.
67 - `supportsThinking()` trusts models.dev flag too broadly — sends adaptive thinking to models that reject it (e.g. `claude-haiku-4-5` via Zen returns 400).
78 - AI SDK expands `claude-3-5-haiku` → dated variant that Zen doesn't serve (404).
src/llm-api/turn-context.ts+0−9
@@ -155,20 +155,11 @@ export function applyContextPruning(messages: CoreMessage[]): CoreMessage[] {
155155 * that boundary fixed: the initial prefix stays byte-identical across
156156 * steps, so the Anthropic cache hit covers the full conversation history
157157 * up to the user's message.
158- *
159- * Falls back to full context pruning when the conversation grows past
160- * STEP_PRUNE_FALLBACK_THRESHOLD to prevent context-window overflow on
161- * very long turns.
162158 */
163-const STEP_PRUNE_FALLBACK_THRESHOLD = 200;
164-
165159 export function applyStepPruning(
166160 messages: CoreMessage[],
167161 initialMessageCount: number,
168162 ): CoreMessage[] {
169- if (messages.length > STEP_PRUNE_FALLBACK_THRESHOLD) {
170- return applyContextPruning(messages);
171- }
172163 const newMessageCount = Math.max(0, messages.length - initialMessageCount);
173164 return pruneMessages({
174165 messages,
src/llm-api/turn-request.test.ts+0−12
@@ -180,18 +180,6 @@ describe("buildStreamTextRequest", () => {
180180 expect(withCache.length).toBeGreaterThan(0);
181181 });
182182
183- test("prepareStep falls back to full pruning on very long turns", () => {
184- // Build a history that exceeds the step prune fallback threshold (200)
185- const huge = buildToolHistory(70); // 70*3 + 1 = 211 messages
186- const request = buildStreamTextRequest(makeDefaultInput(huge));
187-
188- const result = callPrepareStep(request, 1, huge);
189-
190- // Full context pruning kicks in — old tool calls removed
191- expect(result.messages).toBeDefined();
192- expect(result.messages?.length).toBeLessThan(huge.length);
193- });
194-
195183 test("prepareStep preserves messages across growing steps", () => {
196184 // Pre-prune to simulate real prepareTurnMessages flow
197185 const raw = buildToolHistory(20); // 61 messages
src/llm-api/turn.test.ts+3−3
@@ -834,10 +834,10 @@ describe("applyStepPruning", () => {
834834 expect(reasoning?.text).toBe("I should read the file first");
835835 });
836836
837- test("falls back to full pruning past threshold", () => {
838- const huge = buildHistory(70); // 211 messages > 200 threshold
837+ test("prunes stale tool calls from large histories", () => {
838+ const huge = buildHistory(70); // 211 messages
839839 const pruned = applyStepPruning(huge, huge.length);
840- // Full context pruning removes old tool calls
840+ // Tool-call window (before-last-40) removes old tool calls
841841 expect(pruned.length).toBeLessThan(huge.length);
842842 });