File/Line
internal/agent/unread_edit_guard.go L172-180 (checkStaleRead warn gate), L91-103 (recordRead)
Problem
Comment contract: "allow re-warning if the file changes again after a stale warning... only skip if the stale warning was already issued for this exact mtime". Implementation keys warnedFiles[n+"\x00stale"] — mtime is not part of the key, and no code path ever clears it (recordRead updates readMtime but not warnedFiles; only reset() per run clears it).
Trigger scenario (false negative, data-loss direction)
| Step |
Event |
State |
Warning |
| T1 |
agent reads file (mtime=T1) |
readMtime=T1 |
— |
| T2 |
external edit (mtime=T2); agent edit_file |
stale key set |
fired |
| T2' |
agent re-reads (mtime=T2) |
readMtime=T2, stale key still set |
— |
| T3 |
second external edit (mtime=T3); agent edit_file |
gate returns "" |
silent |
Agent now edits T3 content with old_text from T2 — edit fails (wasted iterations) or, with write_file/other whole-file paths, silently clobbers external changes.
Expected vs actual
- Expected (per comment): re-warn when mtime advances past the newly-read mtime
- Actual: one stale warning per file per run regardless of subsequent changes
Fix
Include mtime generation in the key (e.g. n+"\x00stale\x00"+readAt.String()) or clear the stale key in recordRead.
Severity
High in shared-workspace / concurrent-edit scenarios (the product's core multi-agent collab mode); single-user impact is medium (edit_file mismatch usually fails loudly).
Verified by independent review subagent (sa-14: all warnedFiles write sites enumerated — no clearing path exists; interleaving table constructed).
File/Line
internal/agent/unread_edit_guard.goL172-180 (checkStaleReadwarn gate), L91-103 (recordRead)Problem
Comment contract: "allow re-warning if the file changes again after a stale warning... only skip if the stale warning was already issued for this exact mtime". Implementation keys
warnedFiles[n+"\x00stale"]— mtime is not part of the key, and no code path ever clears it (recordReadupdatesreadMtimebut notwarnedFiles; onlyreset()per run clears it).Trigger scenario (false negative, data-loss direction)
Agent now edits T3 content with old_text from T2 — edit fails (wasted iterations) or, with write_file/other whole-file paths, silently clobbers external changes.
Expected vs actual
Fix
Include mtime generation in the key (e.g.
n+"\x00stale\x00"+readAt.String()) or clear the stale key inrecordRead.Severity
High in shared-workspace / concurrent-edit scenarios (the product's core multi-agent collab mode); single-user impact is medium (edit_file mismatch usually fails loudly).
Verified by independent review subagent (sa-14: all warnedFiles write sites enumerated — no clearing path exists; interleaving table constructed).