Skip to content

[BUG] Config File Save is Not Atomic #134

@olddev94

Description

@olddev94

Project

vgrep

Description

The Config::save() function in src/config.rs line 227 writes directly to the config file using std::fs::write(). This is not an atomic operation - if the process crashes or is interrupted during the write, the config file can be left in a corrupted (partially written) state.

Error Message

Error: Failed to parse config file
Caused by: expected value at line 15 column 1

or similar JSON parsing errors after interrupted write.

Debug Logs

System Information

- Bounty Version: 0.1.0
- OS: Ubuntu 24.04 LTS
- Rust: 1.75+

Screenshots

No response

Steps to Reproduce

  1. Run any config-changing command: vgrep config set mode server
  2. Kill the process (SIGKILL) at exactly the right moment during write
  3. Run any vgrep command
  4. Observe config file parsing error

Expected Behavior

Config saves should be atomic:

  1. Write to temporary file
  2. Sync to disk
  3. Rename temp file to final name (atomic on most filesystems)

Actual Behavior

Direct write to config file can leave it corrupted on interruption.

Additional Context

This is a common issue with config file handling. The race window is small but real.

The same pattern exists in src/cli/install.rs for writing various config files:

  • Line 64: Claude instructions
  • Line 147: OpenCode tool config
  • Line 231: Codex agents
  • Line 287: Skills
  • Line 347-348: Factory hooks
  • Line 415: Factory settings

All these writes should ideally be atomic to prevent corruption.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingvalidValid issuevgrep

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions