Uh oh!
There was an error while loading. Please reload this page.
fix(log): sort files before slicing to delete oldest logs first - #14792
fix(log): sort files before slicing to delete oldest logs first#14792zerone0x wants to merge 1 commit into
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. Fixesanomalyco#14731 Co-Authored-By: Claude <noreply@anthropic.com>
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) |
Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR. |
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