feat: writing filetime reads to disk to persist across process being killed
Addressing Issue https://github.com/sst/opencode/issues/4406
File read content saved to disk associated timestamp existed beyond solely in memory.
It would lead to double reads when you read a chat in a session -> kill it -> revisit the session and try to invoke write tool call
Steps to reproduce bug:
Read a file read index.ts
Exit via ctrl + c
Reinit your local -> bun dev
Go back to the session -> bun dev + /session (find session you just read index.ts in )
Ask it to write a comment on top of index.ts -> throws an error saying you didn't read it -> re-reads wastes tokens
Example:
Solution:
We are already persisting the read tool call output. However, we didn't have a way to know how when it happened. So, we write to disk when the read time was. We were already doing the in memory check but added backup to persist across releases.
Other Conditions I considered:
Changing a file between a save that you want to edit will STILL force a re-read (intended behaviour):