Skip to content

fix(file_tools): refresh staleness timestamp after writes#4390

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-abdd86e5
Apr 1, 2026
Merged

fix(file_tools): refresh staleness timestamp after writes#4390
teknium1 merged 1 commit intomainfrom
hermes/hermes-abdd86e5

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

@teknium1 teknium1 commented Apr 1, 2026

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_file calls. So a read → write → write sequence 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 successful write_file and patch. 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_mtimes to read_timestamps for readability.

Files changed

File Change
tools/file_tools.py _update_read_timestamp() helper, wired into write_file_tool and patch_tool, rename file_mtimesread_timestamps
tests/tools/test_file_staleness.py Updated key name in helper unit tests

Test plan

  • 64 existing file-tool tests pass
  • E2E: 3 consecutive writes after one read → no warnings
  • E2E: 2 consecutive patches after one read → no warnings
  • E2E: external edit between writes → still warns correctly
  • E2E: write → external edit → write → warns correctly
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.
@teknium1 teknium1 merged commit ef2ae3e into main Apr 1, 2026
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant