Skip to content

[Bug] addSession does no I/O error path for the legacy migration race #1145

Description

@akramcodez

Description

If two processes start simultaneously and both decide to migrate usage.json, the second renameSync raises EEXIST and the fallback copy-overwrites the freshly-renamed file. The user data ends up being whatever the second process wrote.

Environment

  • OS: Any
  • Node version: v22.20.0
  • Nanocoder version: 1.30.0
  • Provider: N/A
  • Model: N/A

Steps to Reproduce

  1. Trigger a legacy usage migration from two concurrent instances.

Expected Behavior

Needs a rename no-clobber or fsync-and-swap pattern to handle the migration safely.

Actual Behavior

The second process overwrites the file, potentially causing data loss.

Additional Context

  • I have searched existing issues to ensure this is not a duplicate
  • I can reproduce this issue consistently
  • This issue occurs with the latest version of nanocoder

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions