Skip to content

json file saves wipe out other-instance and manual changes #53

@smemsh

Description

@smemsh

I noticed that json file saves (for example of a history) don't take into account changes to the gemini_cli_config.json that happened since the file was loaded. I didn't look at the code, but based on an incident where a long-running session save completely wiped out all my saved history from other sessions, I'm guessing each process is assuming it's the only one accessing the file, and just serializes its own data, overwriting the file completely.

It also seems to have wiped out other settings I had made by hand and saved into the file (such as safety category thresholds, system prompts).

One solution might be, upon any action that saves the serialized data structure:

  1. make a second (mutable) copy of the working set, to edit what you're about to serialize
  2. lock the file on disk (ie, fcntl(F_SETLK))
  3. re-read the file's current contents into a third (read-only) copy
  4. compute a delta between the mutable and read-only copy (json diff library)?
  5. in the mutable copy, append to nodes where possible (such as history)
  6. replace nodes with disk version for items that can't be edited within the program
  7. serialize the mutated copy and replace the file
  8. unlock

without trying to merge anything into the working set, that would be too hard (better to just restart), but at least this will keep changes without racing between simultaneous sessions. I typically have many of these open in different terminals.

Just thinking out loud. I might take a stab at some point but not any time soon...

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