Skip to content

fix: prevent concurrent JSON write corruption#71

Open
charu2210 wants to merge 1 commit into
siddu-k:mainfrom
charu2210:fix-json-write-corruption
Open

fix: prevent concurrent JSON write corruption#71
charu2210 wants to merge 1 commit into
siddu-k:mainfrom
charu2210:fix-json-write-corruption

Conversation

@charu2210
Copy link
Copy Markdown

Summary

Implemented atomic JSON persistence to prevent corruption during concurrent writes and interrupted save operations.

Changes Made

  • Added atomic_json_write() helper using temporary files + os.replace()

  • Added thread locking for JSON persistence operations

  • Updated:

    • save_command_history()
    • clear_command_history()
    • save_workspace_state()
    • workspace profile persistence
  • Added safer recovery handling for corrupted workspace state files

Issue Fixed

Previously, direct concurrent writes to JSON state/history files could result in:

  • truncated JSON
  • malformed files
  • silent workspace reset
  • history corruption

The new implementation ensures writes are atomic and thread-safe.

Fixes #63

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Concurrent JSON Writes Can Corrupt command_history.json and Workspace State Files

1 participant