Skip to content

fix(opencode): sort log files before cleanup to avoid deleting newest#16541

Closed
maharshi365 wants to merge 2 commits intoanomalyco:devfrom
maharshi365:fix/log-cleanup-sort
Closed

fix(opencode): sort log files before cleanup to avoid deleting newest#16541
maharshi365 wants to merge 2 commits intoanomalyco:devfrom
maharshi365:fix/log-cleanup-sort

Conversation

@maharshi365
Copy link
Contributor

Fixes #14731

cleanup() in log.ts had two bugs that caused it to delete the newest log files instead of the oldest:

  1. Glob.scan returns files in non-deterministic filesystem order. Without .sort(), slice(0, -10) could remove the newest files instead of oldest.
  2. cleanup() was called without await in init(), racing with new log file creation — the new file could appear in the glob results and get deleted.
  3. The guard threshold was <= 5 but the keep count was 10, making it inconsistent.

Verified: ran bun test test/util/log.test.ts — 4 pass. Stashed the fix and re-ran — 4 fail (Log.cleanup is not a function / wrong files deleted).

@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 8, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate PRs Found:

  1. PR fix(log): sort files before slicing to delete oldest logs first #14792 - "fix(log): sort files before slicing to delete oldest logs first"

    • This appears to directly address the same issue - sorting log files before deletion to ensure oldest files are removed first
  2. PR fix(log): await cleanup and sort files before deletion #7245 - "fix(log): await cleanup and sort files before deletion"

    • Addresses both the sorting issue AND the race condition (missing await) mentioned in your PR description
  3. PR fix: prevent log file deletion when using --log-level DEBUG #6641 - "fix: prevent log file deletion when using --log-level DEBUG"

    • Related to log file handling, though less directly related to the sorting/cleanup issue

Recommendation: PR #14792 and #7245 appear to be addressing the exact same bugs you're fixing. You should check their status (open/merged/closed) and verify if they've already been resolved or if there's an opportunity to consolidate efforts.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Mar 8, 2026
@github-actions github-actions bot closed this Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log cleanup deletes newest log files instead of oldest (path-scurry reverse ordering)

1 participant