fix: preserve app settings during key import/creation#567
Conversation
- KeyStorage.clear() now selectively removes only user-identity-related SharedPreferences keys instead of clearing all SharedPreferences - Preserves mostro_settings, first_run_complete, and community_selected so the selected Mostro instance, language, and onboarding state persist after importing or creating a new user - Previously sharedPrefs.clear() wiped everything, causing the app to fall back to the default Mostro instance on restart - Updated architecture docs to reflect the change and rationale
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughUpdated KeyStorage to provide a selective clear: secure storage is fully wiped but only specific SharedPreferences entries related to keys/identity are removed, preserving app-level preferences; docs updated to reflect this behavior. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/architecture/APP_INITIALIZATION_ANALYSIS.md`:
- Around line 225-229: There is an empty fenced code block immediately after the
`_storage.clear()` note; remove that blank triple-backtick block so the
documentation flows correctly into the subsequent heading (the stray ``` between
the paragraph describing `_storage.clear()` and the "Returning User Flow"
section should be deleted).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dff0237f-c155-4877-9022-43b176c54efe
📒 Files selected for processing (4)
docs/architecture/APP_INITIALIZATION_ANALYSIS.mddocs/architecture/SESSION_AND_KEY_MANAGEMENT.mddocs/architecture/SESSION_RECOVERY_ARCHITECTURE.mdlib/features/key_manager/key_storage.dart
There was a problem hiding this comment.
Review
Four-file change: targeted fix + three docs. Correct and well-scoped.
lib/features/key_manager/key_storage.dart
Replacing sharedPrefs.clear() with selective sharedPrefs.remove() for all key-related preferences is the right approach. App-level preferences (mostro_settings, first_run_complete, community_selected) are intentionally preserved so the selected Mostro instance, language, and onboarding state survive a key import/create. Key-related preferences (keyIndex, mostroCustomNodes, trustedNodeMetadata, backgroundFilters, fullPrivacy) are still removed — correct isolation. SecureStorage is also cleared in full — correct since it holds the cryptographic material.
docs/ (3 files)
All three docs accurately reflect the new behavior with clear notes explaining the selective clear rationale. SESSION_RECOVERY_ARCHITECTURE.md has the most complete note (mentions all 5 removed keys explicitly). SESSION_AND_KEY_MANAGEMENT.md adds the full method signature inline. APP_INITIALIZATION_ANALYSIS.md updates the comment and adds a note paragraph. Consistent across all three.
CodeRabbit (1 actionable comment)
- Empty fenced code block in APP_INITIALIZATION_ANALYSIS.md: valid. The stray ``` between the
_storage.clear()note and the "Returning User Flow" heading should be removed. Fix it in a follow-up commit or as part of this PR before merge — trivial.
CI
Flutter checks: ✅ passed (both runs).
LGTM — one minor doc issue to clean up before merge.
fix #399
Summary by CodeRabbit
Bug Fixes
Documentation