fix(apps): ghost installs — re-sync on activity restart (E3 R3)#539
Conversation
WalkthroughMainActivity now syncs installed apps on activity restart via an injected ChangesApp Sync on Activity Restart & Release Notes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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.
🧹 Nitpick comments (1)
composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/MainActivity.kt (1)
112-114: ⚡ Quick winAvoid swallowing coroutine cancellation in restart sync.
runCatchingcapturesCancellationExceptionalong with other exceptions, which interferes with structured concurrency. RethrowCancellationExceptionexplicitly and only log non-cancellation failures:♻️ Proposed refactor
+import kotlinx.coroutines.CancellationException @@ override fun onRestart() { super.onRestart() appScope.launch { - runCatching { syncInstalledAppsUseCase() } - .onFailure { Logger.w(it) { "onRestart sync failed" } } + try { + syncInstalledAppsUseCase() + } catch (e: CancellationException) { + throw e + } catch (t: Throwable) { + Logger.w(t) { "onRestart sync failed" } + } } }🤖 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 `@composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/MainActivity.kt` around lines 112 - 114, The current appScope.launch block uses runCatching { syncInstalledAppsUseCase() } which will catch CancellationException and swallow coroutine cancellations; change it to call syncInstalledAppsUseCase() inside a try/catch: catch CancellationException and rethrow it immediately, and in a separate catch (e: Throwable) call Logger.w(e) { "onRestart sync failed" } so only non-cancellation failures are logged. Reference the appScope.launch block, the syncInstalledAppsUseCase() call, and Logger.w usage when making the change.
🤖 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 `@composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/MainActivity.kt`:
- Around line 112-114: The current appScope.launch block uses runCatching {
syncInstalledAppsUseCase() } which will catch CancellationException and swallow
coroutine cancellations; change it to call syncInstalledAppsUseCase() inside a
try/catch: catch CancellationException and rethrow it immediately, and in a
separate catch (e: Throwable) call Logger.w(e) { "onRestart sync failed" } so
only non-cancellation failures are logged. Reference the appScope.launch block,
the syncInstalledAppsUseCase() call, and Logger.w usage when making the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8bff02bf-1fbe-4d30-952b-ee958d8fc3d5
📒 Files selected for processing (14)
composeApp/src/androidMain/kotlin/zed/rainxch/githubstore/MainActivity.ktcore/presentation/src/commonMain/composeResources/files/whatsnew/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/ar/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/bn/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/es/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/fr/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/hi/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/it/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/ja/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/ko/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/pl/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/ru/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/tr/17.jsoncore/presentation/src/commonMain/composeResources/files/whatsnew/zh-CN/17.json
Fixes E3 R3 from
roadmap/FREE_FEATURES.md. Survey #21: "Sometimes deleted apps are still shown as installed."Problem
Three paths already remove orphaned rows:
PackageEventReceiver.onPackageRemoved— broadcast handlerSyncInstalledAppsUseCase— cold-start reconciler called fromMainViewModel.initUpdateCheckWorker— periodic syncGap: when GitHub Store is foregrounded, the user leaves to system Settings, uninstalls an app, returns. The broadcast may be dropped (OEM background restrictions, Doze, manifest receiver instantiation race). MainViewModel.init does not re-fire on resume. Periodic worker may be hours away. Result: ghost row persists until next pull-to-refresh or cold start.
Fix
MainActivity.onRestart()firesSyncInstalledAppsUseCaseon the app-scopedCoroutineScope.onRestartruns only on stop→start transitions, so it does not duplicate the cold-start sync fromMainViewModel.init. The use case is idempotent (runs inwithContext(IO), deletes orphaned rows in a transaction), safe under the rare race with concurrent broadcast handlers.Acceptance criteria
adb shell pm uninstall <pkg>→ broadcast handler removes row in foreground (already worked, no regression)onRestartre-synconPackageInstalledflow handles correctly (no change)MainViewModel.initstill primary sync pathTest plan
adb shell pm uninstall com.example.appwhile GHS in foreground → row gone within 5s (broadcast path)adb shell pm uninstall <pkg>, foreground GHS → row gone on resume (onRestartpath):composeApp:compileDebugKotlinAndroid✅GithubStoreApp.ktare pre-existing, unrelated to this fixNotes
SyncInstalledAppsUseCasereconciler logic deferred — repo currently has no test scaffolding (*Test.ktabsent across all modules). When test infra lands, add coverage for "row in DB without matching package" branch.What's-new
whatsnew/17.jsonacross 13 locales.Summary by CodeRabbit
New Features
Bug Fixes