AltimateAI / AltimateAI/altimate-code

`edit` tool: "Could not find oldString" failure — model context drift

Abierto
#470 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
811
Forks
134
Merge medio
3 d 2 h
PR fusionados (30 d)
50

Descripción

## Problem

The `edit` tool fails with:

```
Could not find oldString in the file. It must match exactly, including whitespace, indentation, and line endings.
```

236 occurrences in a single day. This is the second most common tool failure after `webfetch`.

## Root cause

The model's in-context representation of a file drifts from the actual file content. This happens when:

1. **External processes** (formatters, linters) modify files after the model reads them — partially addressed by #450
2. **Multiple edits** to the same file where the model uses stale oldString from before previous edits
3. **Context compaction** drops or summarizes file content, leaving the model with an outdated view
4. **Model hallucination** — generating oldString that was never in the file

## Impact

- Each failed edit wastes a tool call
- Model often retries with the same incorrect oldString, creating short failure bursts
- The existing doom loop detector (threshold=3) catches identical inputs but not semantically similar ones

## Suggested investigation

1. Analyze whether failures correlate with files that were recently edited (context drift) vs. files never read (hallucination)
2. Consider including a snippet of the actual file content in the error response so the model can self-correct (similar approach to #450 for stale files)
3. Evaluate whether the fuzzy matchers (LineTrimmedReplacer, WhitespaceNormalizedReplacer, etc.) are catching enough cases or if thresholds need tuning

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.