fix: bound the shared closed-item history at 100 records
Closes #10352.
ClosedItemHistoryStore.shared passes a workspace capacity and leaves capacity nil, so closed panels are never trimmed. Both trim paths are guarded on totalCapacity being non-nil, and shouldTrim only returns true for .workspace records when it is nil, so a closed panel neither triggers a trim nor gets removed by one. No age-based pruning exists either.
My file after 77 days: 898 panel records against 84 workspace records, 9.5 MB total, 9.2 MB of it panels. The workspace cap is doing its job at 84 of 100. Nothing bounds the rest.
Change
static let shared = ClosedItemHistoryStore(
+ capacity: defaultTotalCapacity,
workspaceCapacity: defaultWorkspaceCapacity,
fileURL: defaultHistoryFileURL()
)
with defaultTotalCapacity = 100, plus a configuredCapacities accessor so a test can assert the shared store is configured rather than only that the policy trims when handed a bound.
The number
100 makes the history a recency window over everything closed, rather than an unbounded log. It is a product call and trivial to change, so say the word if you want more depth.
One interaction worth naming: the workspace cap is also 100, and trimTotalCapacity runs first and removes the oldest records regardless of kind. The two now compete for the same slots, so a session that has closed many workspaces keeps proportionally fewer panels. On my numbers that would be 84 workspaces leaving 16 panel slots. That reads correctly to me if Reopen Last Closed is an undo stack rather than an archive, but it is the part of this PR most worth disagreeing with.
Impact
Not CPU. menuSnapshot is already records.suffix(maxItemCount), and the comment above it says someone already considered exactly this. The cost is disk, memory, and persistRecords, which snapshots the whole array and rewrites the entire file every time anything closes. That write currently grows without bound.
Verification
Two commits, red then green. The red commit adds the constant and the accessor but leaves shared unwired, so it compiles and sharedStoreBoundsTheHistoryAsAWhole fails on total being nil against an expected 100.
I could not run cmuxTests locally, since it needs a full Xcode build with a built GhosttyKit.xcframework. The tests are in ReopenLastClosedTests.swift, which is already wired into the pbxproj, so CI is the gate.
Follow-up worth a separate decision
Panel records average 9.6 KB and the largest in my file is 491 KB. Worth asking whether a record that big should be retained whole, or trimmed to what reopening actually needs.
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Bounds the shared closed-item history to 100 total records so closed panels no longer grow the history file without bound. Previously only workspace entries were capped; panels and workspaces now share a single 100-record recency window.
- Sets
defaultTotalCapacity = 100onClosedItemHistoryStore.shared. - Adds a test proving 150 panel records are trimmed to 100 under the same constants the shared store uses.
- Total capacity trims before workspace capacity, so sessions that close many workspaces retain fewer panels.
- Persisted history trims to 100 total records on the next write; reduces disk usage without changing menu rendering cost.
Closes #10352.
Summary by CodeRabbit
-
New Features
- Closed-item history now retains up to 100 entries by default.
- Total and workspace history limits are applied consistently across the shared history.
-
Bug Fixes
- When history exceeds 100 entries, the oldest closed-item records are automatically removed.
- Closed panel history now correctly trims excess records while preserving the most recent entries.