fix: retry vault read on resume-window IPC failure to prevent false sign-out#1085
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesVault read resilience
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed: dependency version conflict. Check your lock file or package.json. 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.
🧹 Nitpick comments (2)
infrastructure/eid-wallet/src/lib/global/controllers/evault.ts (2)
607-632: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winNo test coverage for the new retry logic.
This is the core fix for a production false-sign-out bug, but there's no accompanying unit test verifying that: a resolved
undefinedreturns immediately without retrying, a thrown error retries up tomaxAttempts, and exhausted retries resolve toundefinedwithout throwing. Worth covering with fake timers given how easy it would be to silently regress this behavior.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@infrastructure/eid-wallet/src/lib/global/controllers/evault.ts` around lines 607 - 632, The new `#readVaultResilient` retry behavior lacks unit coverage. Add tests using fake timers to verify a resolved undefined returns immediately without retrying, thrown store errors retry up to maxAttempts, and exhausted retries return undefined without throwing; exercise the existing `#store.get` behavior through the VaultController test setup.
583-632: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winConcurrent
vaultreads during the resume window each run their own independent 10x retry cycle.The docstring itself notes that multiple call sites (deep-link handler, scan-qr, app guard) read
vaultaround app resume — exactly when the IPC failures this fix targets occur. Since#readVaultResilient()is invoked fresh on everyget vault()access with no shared/cached in-flight promise, concurrent callers during that window each independently retry up to 10 times (~1.8s worst case), multiplying IPC calls and log noise instead of sharing one outcome.Caching the in-flight promise (cleared once it settles) lets concurrent callers share a single retry cycle while still hitting the store fresh on the next independent access.
♻️ Proposed dedup for concurrent reads
+ `#pendingVaultRead`: Promise<Record<string, string> | undefined> | null = + null; + get vault() { - return this.#readVaultResilient(); + if (!this.#pendingVaultRead) { + this.#pendingVaultRead = this.#readVaultResilient().finally( + () => { + this.#pendingVaultRead = null; + }, + ); + } + return this.#pendingVaultRead; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@infrastructure/eid-wallet/src/lib/global/controllers/evault.ts` around lines 583 - 632, Deduplicate concurrent vault reads by caching the in-flight promise used by the vault getter and returning it to all callers while it is pending. Clear the cached promise after it settles so later independent accesses perform a fresh store read, while preserving the existing retry behavior and Record-or-undefined result of `#readVaultResilient`().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@infrastructure/eid-wallet/src/lib/global/controllers/evault.ts`:
- Around line 607-632: The new `#readVaultResilient` retry behavior lacks unit
coverage. Add tests using fake timers to verify a resolved undefined returns
immediately without retrying, thrown store errors retry up to maxAttempts, and
exhausted retries return undefined without throwing; exercise the existing
`#store.get` behavior through the VaultController test setup.
- Around line 583-632: Deduplicate concurrent vault reads by caching the
in-flight promise used by the vault getter and returning it to all callers while
it is pending. Clear the cached promise after it settles so later independent
accesses perform a fresh store read, while preserving the existing retry
behavior and Record-or-undefined result of `#readVaultResilient`().
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 6e6f7a2d-7e13-492b-bf0c-e6c443d58403
📒 Files selected for processing (1)
infrastructure/eid-wallet/src/lib/global/controllers/evault.ts
Description of change
Fix an intermittent, unexpected sign-out in the eID Wallet: on iOS the
ipc://localhostcustom protocol is briefly torn down when the app resumes from background, soplugin:store|getthrows — the vault getter swallowed that intoundefined(looks like "logged out") and route guards redirected the user to/login. The getter now retries the read across the resume window instead of reporting a false logout.No env/config/infra changes.
Issue Number
Closes #1084
Type of change
How the change has been tested
IPC custom protocol failed, Tauri will now use the postMessage interface instead – TypeError: Load failedandFetch API cannot load ipc://localhost/plugin%3Astore%7Cget due to access control checks— with the storegetthrowing inside thevaultgetter.#readVaultResilientasserts the three invariants — genuine logout →undefinedimmediately (no retry penalty); one transient resume-window throw → recovers the vault (stays logged in); persistent failure →undefined, never throws or hangs.biome checkpasses on the changed file.tauri ios dev— dev-mode resume reloads the WebView (Vite reconnect), which independently masks the sign-out and preempts the retry loop. Real-runtime confirmation requires a release build (no Vite reload).Design decisions
get vault()), not per-guard: one change covers the app guard, the deep-link handler and scan-qr, and leaves all ~15 callers untouched.undefined(no throw) and returns immediately, so real logouts stay instant; the ~2s retry budget (10 × 200ms) is spent only during an actual IPC-dead window.Record | undefinedand never throws, so no caller changes were needed.Change checklist
Summary by CodeRabbit