fix: store history in an app-namespaced SwiftData store - #36
Merged
Conversation
A non-sandboxed app's bare ModelContainer(for:) resolves to the shared ~/Library/Application Support/default.store. Any other non-sandboxed app using the same default writes to that file too; when one opens it with a different schema, Core Data recreates the store and silently drops our HistoryItem table — the user's whole history vanishes. Pin the store to Application Support/<bundle-id>/Lumo.store so it can't collide with another app (and keeps Debug "Lumo Dev" history separate from Release). On first launch with the new path, importLegacyHistory(from:into:) does a one-time, non-destructive rescue of any history still in the old shared store: it confirms via read-only Core Data metadata that the file holds our HistoryItem entity before opening it read-only, so another app's data is never touched. Add LegacyStoreRescueTests covering the matching-store import, the foreign-schema skip, and the missing-file no-op. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Merged
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.
Problem
Translation history could silently disappear.
HistoryStorecreated its SwiftData database with a bareModelContainer(for: HistoryItem.self)and no URL. For a non-sandboxed app that resolves to the shared~/Library/Application Support/default.store— a path every other non-sandboxed app using a bareModelContaineralso writes to. When another app opens that file with its own schema, Core Data recreates the store and drops ourHistoryItemtable, wiping the user's whole history. (Observed in the wild: the shared file ended up holding another app'sAPIRequestModelentity, with noHistoryItemtable left anywhere on disk.)Fix
Application Support/<bundle-id>/Lumo.store. A bundle-id-scoped path can't collide with another app, and also keeps the Debug "Lumo Dev" history separate from Release.importLegacyHistory(from:into:)does a one-time, non-destructive rescue of any history still in the old shared store:HistoryItementity. If it holds another app's schema, nothing is touched.allowsSave: falseand never deleted.Tests
New
LegacyStoreRescueTestssuite (3 tests):Full suite:
Test run with 100 tests in 15 suites passed.Note
History already lost before this fix is unrecoverable (the shared store was overwritten). The rescue only helps installs where the old history still survives. API-key storage is unchanged.
🤖 Generated with Claude Code