Skip to content

fix: prevent concurrent JSON write corruption#71

Open
charu2210 wants to merge 3 commits into
siddu-k:mainfrom
charu2210:fix-json-write-corruption
Open

fix: prevent concurrent JSON write corruption#71
charu2210 wants to merge 3 commits 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

@siddu-k
Copy link
Copy Markdown
Owner

siddu-k commented May 27, 2026

@charu2210 conflicts

@charu2210
Copy link
Copy Markdown
Author

Hi @siddu-k , I’ve resolved the merge conflicts and updated the PR with the fixes.

@siddu-k
Copy link
Copy Markdown
Owner

siddu-k commented May 31, 2026

@charu2210 conflicts that must be resolved

@charu2210
Copy link
Copy Markdown
Author

@siddu-k, I've resolved the conflicts and updated the PR.

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

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

2 participants