Description
The application performs direct JSON writes to state/history files without atomic write protection or file locking.
Affected areas include:
save_command_history()
save_workspace_state()
- workspace profile saves
Current implementation writes directly using:
with open(path, 'w', encoding='utf-8') as f:
json.dump(data, f)
Because the application uses threaded execution flows and supports multiple simultaneous actions, concurrent writes can corrupt JSON files.
Possible Impact
command_history.json becomes malformed/truncated
- workspace state resets unexpectedly
- profile JSON files become unreadable
- silent data loss after concurrent actions
- inconsistent UI state after reload
Steps to Reproduce
- Open multiple terminals/tabs
- Execute commands rapidly in parallel
- Simultaneously clear command history or save workspace state
- Interrupt execution during write operations
- Restart/reload application
Observed Behavior
Under concurrent write conditions, JSON state files may become partially written, truncated, or malformed. On reload, the application may fail to restore history/workspace state correctly and can fall back to empty defaults.
Suggested Fix
- Use atomic file writes via temporary files +
os.replace()
- Add threading/file locks around write operations
- Validate JSON integrity before replacing original files
- Add recovery handling for partially written state files
Expected Outcome
State/history files remain consistent and recoverable even under concurrent operations or interrupted writes.
Description
The application performs direct JSON writes to state/history files without atomic write protection or file locking.
Affected areas include:
save_command_history()save_workspace_state()Current implementation writes directly using:
Because the application uses threaded execution flows and supports multiple simultaneous actions, concurrent writes can corrupt JSON files.
Possible Impact
command_history.jsonbecomes malformed/truncatedSteps to Reproduce
Observed Behavior
Under concurrent write conditions, JSON state files may become partially written, truncated, or malformed. On reload, the application may fail to restore history/workspace state correctly and can fall back to empty defaults.
Suggested Fix
os.replace()Expected Outcome
State/history files remain consistent and recoverable even under concurrent operations or interrupted writes.