Skip to content

[business-logic] unread_edit_guard.go: stale-read warning is once-per-run forever — second external modification after re-read never re-warns (contradicts 'exact mtime' comment) #162

Description

@topcheer

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions