Skip to content

fix: preserve app settings during key import/creation#567

Merged
grunch merged 2 commits into
mainfrom
persist-preferences-mostro
Apr 9, 2026
Merged

fix: preserve app settings during key import/creation#567
grunch merged 2 commits into
mainfrom
persist-preferences-mostro

Conversation

@Catrya

@Catrya Catrya commented Apr 8, 2026

Copy link
Copy Markdown
Member

fix #399

  • 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

Summary by CodeRabbit

  • Bug Fixes

    • Improved key/session recovery so importing a mnemonic or clearing keys no longer resets app preferences—identity/key data is cleared while user settings persist.
  • Documentation

    • Updated key management and session recovery docs to describe the selective clearing behavior and preservation of app preferences.

  - 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
@coderabbitai

coderabbitai Bot commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e4ad510e-22ad-491c-a5cd-807709881bb4

📥 Commits

Reviewing files that changed from the base of the PR and between 5b0c13a and 4fdc0d0.

📒 Files selected for processing (1)
  • docs/architecture/APP_INITIALIZATION_ANALYSIS.md
✅ Files skipped from review due to trivial changes (1)
  • docs/architecture/APP_INITIALIZATION_ANALYSIS.md

Walkthrough

Updated 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

Cohort / File(s) Summary
Documentation Updates
docs/architecture/APP_INITIALIZATION_ANALYSIS.md, docs/architecture/SESSION_AND_KEY_MANAGEMENT.md, docs/architecture/SESSION_RECOVERY_ARCHITECTURE.md
Clarified that _storage.clear()/KeyStorage.clear() performs a selective wipe: secureStorage.deleteAll() plus targeted removal of SharedPreferences keys, while preserving mostro_settings, first_run_complete, and community_selected.
Implementation
lib/features/key_manager/key_storage.dart
Added Future<void> clear() in KeyStorage that calls secureStorage.deleteAll() and removes specific SharedPreferences keys: keyIndex, mostroCustomNodes, trustedNodeMetadata, backgroundFilters, fullPrivacy (no full sharedPrefs.clear()).

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Caller
participant KeyStorage
participant SecureStorage
participant SharedPrefs
Caller->>KeyStorage: invoke clear()
KeyStorage->>SecureStorage: deleteAll()
SecureStorage-->>KeyStorage: success
KeyStorage->>SharedPrefs: remove(keyIndex, mostroCustomNodes, trustedNodeMetadata, backgroundFilters, fullPrivacy)
SharedPrefs-->>KeyStorage: success
KeyStorage-->>Caller: complete

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~18 minutes

Suggested reviewers

  • grunch

Poem

🐰 Hopped in with care through storage and keys,

Cleared only what mattered, left comforts and ease,
Instances steady, no default surprise—
A rabbit's small fix beneath digital skies.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: modifying key storage behavior to preserve app settings during user import/creation operations.
Linked Issues check ✅ Passed The PR successfully addresses issue #399 by implementing selective SharedPreferences clearing that preserves community_selected, ensuring the selected Mostro instance persists after user import.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objective: modifying KeyStorage.clear() to preserve specific SharedPreferences keys and updating related documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch persist-preferences-mostro

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between a1fbf60 and 5b0c13a.

📒 Files selected for processing (4)
  • docs/architecture/APP_INITIALIZATION_ANALYSIS.md
  • docs/architecture/SESSION_AND_KEY_MANAGEMENT.md
  • docs/architecture/SESSION_RECOVERY_ARCHITECTURE.md
  • lib/features/key_manager/key_storage.dart

Comment thread docs/architecture/APP_INITIALIZATION_ANALYSIS.md Outdated

@mostronatorcoder mostronatorcoder Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tACK

@grunch grunch merged commit bb24575 into main Apr 9, 2026
2 checks passed
@grunch grunch deleted the persist-preferences-mostro branch April 9, 2026 14:27
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.

Instance selection resets to default after importing a user

2 participants