Commit 78d2d71
fix: [AI-450] auto-re-read stale files in agent loop so model sees current content
When `edit` or `write` tools fail with "modified since it was last read", the
agent loop now auto-re-reads the file and includes its current content in the
error response. This gives the model the fresh file state so it can adjust its
next edit accordingly, preventing infinite retry loops.
This approach preserves the original safety check in `FileTime.assert()` (the
tool still throws on stale files) but recovers at the agent level by:
1. Detecting stale file errors via regex match on the error message
2. Re-reading the file and updating `FileTime` read timestamp
3. Appending fresh file content to the error so the model sees current state
Also handles "must read file before overwriting" errors the same way.
Closes #450
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 6688a43 commit 78d2d71
1 file changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| |||
211 | 215 | | |
212 | 216 | | |
213 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
214 | 235 | | |
215 | 236 | | |
216 | 237 | | |
217 | 238 | | |
218 | 239 | | |
219 | | - | |
| 240 | + | |
220 | 241 | | |
221 | 242 | | |
222 | 243 | | |
| |||
0 commit comments