fix(file_tools): refresh staleness timestamp after writes#4390
Merged
Conversation
After a successful write_file or patch, update the stored read timestamp to match the file's new modification time. Without this, consecutive edits by the same task (read → write → write) would false-warn on the second write because the stored timestamp still reflected the original read, not the first write. Also renames the internal tracker key from 'file_mtimes' to 'read_timestamps' for clarity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes false staleness warnings when the agent makes consecutive edits to the same file without re-reading between them.
The problem
After PR #4345 added staleness detection, the stored timestamp only updated on
read_filecalls. So aread → write → writesequence would warn on the second write: the first write changed the file's modification time, but the stored timestamp still reflected the original read. The agent's own edit triggered a "file was modified externally" warning.The fix
_update_read_timestamp(path, task_id)is called after every successfulwrite_fileandpatch. It refreshes the stored timestamp to match the file's current state, so the next write sees a matching timestamp and doesn't warn.External edits still warn correctly — the update only fires for the task that performed the write. If a different task or external process modifies the file, the stored timestamp won't match.
Also renames the internal key from
file_mtimestoread_timestampsfor readability.Files changed
tools/file_tools.py_update_read_timestamp()helper, wired into write_file_tool and patch_tool, renamefile_mtimes→read_timestampstests/tools/test_file_staleness.pyTest plan