fix: keep most recent entries in history retention#196
Merged
Conversation
The history tracker's `store()` method was using `.take(MAX_HISTORY_ENTRIES)` on unsorted HashMap values, keeping an arbitrary subset of entries instead of the most recent ones when history exceeded 35 entries. This fix: - Sorts entries by `last_opened` (most recent first) before truncation - Uses `sort_by_key` with `Reverse` for idiomatic Rust - Adds test coverage to verify the fix Before: Random 35 entries kept when history > 35 After: Most recent 35 entries consistently retained
michidk
approved these changes
May 15, 2026
Owner
|
Thanks! |
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.
Summary
last_openeddescending before truncating toMAX_HISTORY_ENTRIES, so the most recently used entries are retained.take(MAX_HISTORY_ENTRIES)was called on entries frominto_entries()which had no guaranteed order, causing arbitrary entries to be keptTest plan
cargo test test_store_keeps_most_recent_entriespasses (1/1)MAX_HISTORY_ENTRIES=35and verifies the 5 oldest are droppedcargo clippyclean, all existing tests passSummary by cubic
Fix history retention to keep the most recently opened entries by sorting by
last_openedbefore truncation. Previously, unsorted entries caused random items to be kept when exceeding the limit.Bug Fixes
last_opened(desc) and then truncate toMAX_HISTORY_ENTRIES.test_store_keeps_most_recent_entries(40 entries; oldest 5 dropped).uninlined_format_argslints.Dependencies
tempfilefor isolated file-system tests.Written for commit 54575c9. Summary will update on new commits.