Skip to content

[Bug]: Windows: "Your chats could not be saved to disk" — EPERM renaming app-state.json at startup #194

Backlog

Description

@magicprinc

GUI version

0.1.64

Operating system

Windows 10 Home, build 19045

Reproduction steps

Intermittent (~2 of ~8 launches on this machine), not deterministic:

  1. Open Command Code desktop normally and let startup finish.
  2. Shortly after startup — about 11.8 s after the main log prints [thread-index] ready — a toast appears: "Your chats could not be saved to disk. Recent changes may be lost if the app closes."
  3. %APPDATA%\Command Code\logs\main.log then contains a [store] setAppState failed ... EPERM ... rename ... error.

Expected behavior

app-state.json is saved atomically at startup with no error and no toast.

Actual behavior

The atomic write (temp file + rename) of app-state.json fails on Windows with EPERM. The toast is shown. On-disk session transcripts are unaffected and a later write succeeds, so the failure is transient.

Screenshots, recordings, or sanitized logs

Occurrences (2):

  • 2026-11-27 01:50:52.385 — app started 01:50:36.304 (16.1 s), 11.72 s after [thread-index] ready
  • 2026-12-01 12:20:50.008 — app started 12:20:30.160 (19.8 s), 11.85 s after [thread-index] ready

Full stack from main.log:

[error] [store] setAppState failed Error: EPERM: operation not permitted,
rename 'C:\Users\<user>\AppData\Roaming\Command Code\app-state.json.tmp-XXXX'
   -> 'C:\Users\<user>\AppData\Roaming\Command Code\app-state.json'
    at renameSync (node:fs:1073:11)
    at attempt (...\stubborn-utils\dist\retryify_sync.js:11:31)
    at writeFileSync (...\atomically\dist\index.js:189:46)
    at ElectronStore._write (...\conf\dist\source\index.js:367:17)
    at set store (...\conf\dist\source\index.js:251:14)

Environment / evidence:

  • app-state.json is valid JSON, writable, and not locked afterwards (exclusive open succeeds).
  • Ample free disk; the user has FullControl ACL; Controlled Folder Access is disabled.
  • Windows Defender real-time protection is on (a quick scan ran ~4 min before one of the launches).
  • At inspection: one running instance (main + 3 Electron helpers); no third-party sync/backup tools.
  • Backups exist under app-state-backups/ but are not written per save (one is ~1 s before the 2026-12-01 failure; the 2026-11-27 failure has none nearby), so a backup-vs-rename race is possible but not conclusive.

Hypothesis: an intermittent race on the atomic write of app-state.json during startup. Windows returns EPERM while the target is briefly held (AV scan / indexer / concurrent internal read or backup), and the atomically -> stubborn-utils retry wrapper still ultimately throws.

Suggested improvement: retry the rename on EPERM/EBUSY with backoff, and/or avoid holding a handle on app-state.json across the rename; optionally keep large caches (skillsCatalogCache, ~130 KB) out of the hot app-state file.

Safety check

  • I removed credentials and private project information from this report.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions