Skip to content

Use atomic flushed writes for small persistent state files #2828

Description

@Widthdom

Evidence

src/CodeIndex/Cli/ActiveWorkspace.cs writes active workspace state directly:

File.WriteAllText(StatePath, JsonSerializer.Serialize(payload, ProgramRunner.CreateDefaultJsonOptions()));

Other small persistent files also use direct File.WriteAllText, while SuggestionStore.SaveUnlocked already has a temp-file, flush-to-disk, rename pattern.

Impact

Interrupted writes can leave persistent state files truncated or partially written. Some readers recover by returning null, but that still loses state and makes behavior harder to explain.

Requested behavior

Introduce or reuse a small atomic JSON write helper for user-visible persistent state: write to a temp file in the same directory, flush, then rename over the target. Keep best-effort cleanup for orphaned temp files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions