fix: text_editor stale mtime check after non-in-place patch
linuztx committed
Mar 2, 2026 at 09:38 UTC
98ee7f6341e1a560abfe5b620c4f69f40f156726
1 file changed
+9
-11
plugins/text_editor/tools/text_editor.py
+9
-11
@@ -247,21 +247,21 @@ def _all_edits_in_place(edits: list[dict]) -> bool:
247
248
249
def _apply_patch_post(agent, info: dict, new_total: int, edits: list[dict]):
250
- """Update mtime cache after a patch, using file_info from the container."""
250
+ mtimes = agent.data.setdefault(_MTIME_KEY, {})
251
+ real = info["realpath"]
252
+
253
if not _all_edits_in_place(edits):
252
- _clear_mtime(agent, info)
254
+ # Line count changed — mark stale so next patch gets
255
+ # "file changed since last read" instead of "line numbers unknown"
256
+ mtimes[real] = {"mtime": 0, "total_lines": 0}
257
return
258
255
- mtimes = agent.data.get(_MTIME_KEY)
256
- if mtimes is None:
257
- return
258
- real = info["realpath"]
259
stored = mtimes.get(real)
260
if not isinstance(stored, dict) or "total_lines" not in stored:
261
- mtimes.pop(real, None)
261
+ mtimes[real] = {"mtime": 0, "total_lines": 0}
262
return
263
if new_total != stored["total_lines"]:
264
- mtimes.pop(real, None)
264
+ mtimes[real] = {"mtime": 0, "total_lines": 0}
265
return
266
if info["mtime"] is not None:
267
mtimes[real] = {
@@ -269,11 +269,10 @@ def _apply_patch_post(agent, info: dict, new_total: int, edits: list[dict]):
269
"total_lines": new_total,
270
}
271
else:
272
- mtimes.pop(real, None)
272
+ mtimes[real] = {"mtime": 0, "total_lines": 0}
273
274
275
def _check_mtime(agent, info: dict) -> str:
276
- """Check if the file has been modified since last read, using file_info."""
276
mtimes = agent.data.get(_MTIME_KEY, {})
277
real = info["realpath"]
278
if real not in mtimes:
@@ -307,4 +306,3 @@ def _get_config(agent) -> dict:
306
"default_line_count": int(config.get("default_line_count", 100)),
307
"max_total_read_tokens": int(config.get("max_total_read_tokens", 4000)),
308
}
310
-
\ No newline at end of file