fix(log): sort files before slicing to delete oldest logs first#14792
Open
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Open
fix(log): sort files before slicing to delete oldest logs first#14792zerone0x wants to merge 1 commit intoanomalyco:devfrom
zerone0x wants to merge 1 commit intoanomalyco:devfrom
Conversation
Glob.scan() / path-scurry may return files in reverse chronological order (newest-first), causing cleanup() to delete the newest log files instead of the oldest ones. Two bugs fixed: 1. Add files.sort() so ISO-8601 filenames are in chronological order before slicing, ensuring oldest files are deleted. 2. Align guard threshold from <= 5 to <= 10 to match the slice(0, -10) that keeps 10 files. Fixes anomalyco#14731 Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
The following comment was made by an LLM, it may be inaccurate: The search results show PR #14792 (the current PR) and two older related PRs. Let me check if those older PRs are still open and relevant:
However, PR #7245 appears to be an older PR (numbered 7245 vs current 14792), so it's likely already closed/merged. The current PR #14792 is addressing the specific issue from #14731 with a comprehensive fix including both the sort and the guard threshold alignment. No duplicate PRs found (PR #7245 is likely an older, merged version addressing similar concerns, but not an active duplicate) |
This was referenced Mar 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #14731
Type of change
What does this PR do?
The
cleanup()function inpackages/opencode/src/util/log.tswas deleting the newest log files and keeping the oldest ones — the opposite of intended behavior.Root cause:
Glob.scan()usespath-scurryinternally, which may return directory entries in reverse chronological order (newest-first). Without an explicit sort,files.slice(0, -10)was selecting the newest files for deletion.Two bugs fixed:
files.sort()before slicing — since filenames are ISO-8601 timestamps, lexicographic sort is chronological, so the oldest files end up at index 0 and get deleted correctly.<= 5to<= 10to match theslice(0, -10)that keeps 10 files (previously, 6–10 files would pass the guard but slice would return an empty array).How did you verify your code works?
Reviewed the logic: after
files.sort(), the array is oldest-first.files.slice(0, -10)selects everything except the last 10 entries, i.e., all files older than the 10 most recent — which is the correct set to delete. The guard threshold of<= 10means we skip cleanup when there are 10 or fewer files, consistent with always keeping exactly 10.Screenshots / recordings
N/A — logic change only
Checklist
🤖 Generated with Claude Code