Skip to content

[bug] Log cleanup race condition deletes newest log file on repeated launches #16540

Closed as not planned

Description

@maharshi365

Description

Two bugs in packages/opencode/src/util/log.ts cleanup() that together cause the latest log file to be deleted when OpenCode is launched multiple times:

  1. Race condition: cleanup() was called without await in init(), so it ran concurrently with new log file creation. The newly created file could appear in the glob results mid-cleanup and get deleted.

  2. Non-deterministic sort: Glob.scan returns files in filesystem order (non-deterministic on Windows NTFS). Without .sort() before .slice(0, -10), the newest files could be deleted instead of the oldest.

Fix:

- cleanup(Global.Path.log)
+ await cleanup(Global.Path.log)

- const filesToDelete = files.slice(0, -10)
+ const filesToDelete = files.sort().slice(0, -10)

Plugins

No response

OpenCode version

latest dev

Steps to reproduce

  1. Launch OpenCode TUI and close it
  2. Repeat 10+ times
  3. Check the log directory — the most recent log file may be missing

Screenshot and/or share link

No response

Operating System

Windows (most reproducible due to NTFS non-deterministic directory ordering)

Terminal

Windows Terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 8, 2026
  2. github-actions commented on Mar 8, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Please review #14731 to see if it covers your report, and consider closing this issue if it does.

  3. maharshi365 commented on Mar 8, 2026

    @maharshi365
    ContributorAuthor

    Duplicate of #14731 which covers the same root cause in more detail.

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

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions