Skip to content

fix: keep most recent entries in history retention#196

Merged
michidk merged 2 commits into
michidk:mainfrom
kimjune01:fix-history-retention-bug
May 15, 2026
Merged

fix: keep most recent entries in history retention#196
michidk merged 2 commits into
michidk:mainfrom
kimjune01:fix-history-retention-bug

Conversation

@kimjune01
Copy link
Copy Markdown
Contributor

@kimjune01 kimjune01 commented May 12, 2026

Summary

  • Fixed history tracker to sort entries by last_opened descending before truncating to MAX_HISTORY_ENTRIES, so the most recently used entries are retained
  • Previously, .take(MAX_HISTORY_ENTRIES) was called on entries from into_entries() which had no guaranteed order, causing arbitrary entries to be kept

Test plan

  • cargo test test_store_keeps_most_recent_entries passes (1/1)
  • Test creates 40 entries exceeding MAX_HISTORY_ENTRIES=35 and verifies the 5 oldest are dropped
  • cargo clippy clean, all existing tests pass

Summary by cubic

Fix history retention to keep the most recently opened entries by sorting by last_opened before truncation. Previously, unsorted entries caused random items to be kept when exceeding the limit.

  • Bug Fixes

    • Sort entries by last_opened (desc) and then truncate to MAX_HISTORY_ENTRIES.
    • Add test test_store_keeps_most_recent_entries (40 entries; oldest 5 dropped).
    • Resolve clippy uninlined_format_args lints.
  • Dependencies

    • Add dev-dependency tempfile for isolated file-system tests.

Written for commit 54575c9. Summary will update on new commits.

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
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@kimjune01 kimjune01 changed the title Fix history retention to keep most recent entries fix: keep most recent entries in history retention May 12, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

@michidk
Copy link
Copy Markdown
Owner

michidk commented May 15, 2026

Thanks!

@michidk michidk merged commit 5fce752 into michidk:main May 15, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants