Skip to content

Fix ExPlat crash#5196

Open
sztomek wants to merge 4 commits intorelease/8.9from
fix/track-crash-on-stale-cache
Open

Fix ExPlat crash#5196
sztomek wants to merge 4 commits intorelease/8.9from
fix/track-crash-on-stale-cache

Conversation

@sztomek
Copy link
Copy Markdown
Contributor

@sztomek sztomek commented Apr 6, 2026

Description

This PR addresses a crash reported by one of our users via ZenDesk. It stemmed from ExPlat, happened when a cached experiment's json schema was no longer recognised by the library.
This was a known issue and was fixed with ExPlat v 6.0.8, so I updated our library to this version.
On top of that I've added safeguards so this should never happen again:

  • the dispatcher of ExPlat calls is now a SupervisorJob that logs errors instead of crashing + clears cache on issue
  • the init call is guarded with try-catch

Fixes PCDROID-523

Testing Instructions

As I found no easy way to replicate the OG issue, just review the code pls.

Checklist

  • If this is a user-facing change, I have added an entry in CHANGELOG.md
  • Ensure the linter passes (./gradlew spotlessApply to automatically apply formatting/linting)
  • I have considered whether it makes sense to add tests for my changes
  • All strings that need to be localized are in modules/services/localization/src/main/res/values/strings.xml
  • Any jetpack compose components I added or changed are covered by compose previews
  • I have updated (or requested that someone edit) the spreadsheet to reflect any new or changed analytics.

@sztomek sztomek added this to the 8.9 ❄️ milestone Apr 6, 2026
@sztomek sztomek added the [Type] Bug Not functioning as intended. label Apr 6, 2026
@sztomek sztomek requested a review from a team as a code owner April 6, 2026 14:32
@sztomek sztomek added the [Area] Analytics Analytics related issues label Apr 6, 2026
@sztomek sztomek requested review from a team, Copilot and geekygecko and removed request for a team April 6, 2026 14:32
@dangermattic
Copy link
Copy Markdown
Collaborator

dangermattic commented Apr 6, 2026

1 Warning
⚠️ This PR is assigned to the milestone 8.9 ❄️. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the ExPlat (Automattic experimentation) integration to prevent user-facing crashes caused by unreadable/corrupted cached experiment data, primarily by bumping the library version and hardening initialization/execution error handling.

Changes:

  • Bump Automattic Tracks/ExPlat dependency from 6.0.7 to 6.0.8 (upstream fix for the known cache/schema crash).
  • Guard ExperimentProvider.initialize(...) with runCatching to avoid crashing on initialization failures.
  • Provide ExPlat with a SupervisorJob-backed coroutine scope plus a CoroutineExceptionHandler that logs and clears the experiments cache directory on uncaught coroutine errors.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
modules/services/analytics/src/main/java/au/com/shiftyjelly/pocketcasts/analytics/experiments/ExperimentProvider.kt Wraps repository initialization in runCatching to prevent crashes during ExPlat init.
modules/services/analytics/src/main/java/au/com/shiftyjelly/pocketcasts/analytics/di/AnalyticsModule.kt Switches ExPlat scope to SupervisorJob + CoroutineExceptionHandler and clears cache on uncaught exceptions.
gradle/libs.versions.toml Bumps Tracks/ExPlat version to 6.0.8.

Copilot AI review requested due to automatic review settings April 6, 2026 14:40
@sztomek sztomek force-pushed the fix/track-crash-on-stale-cache branch from ba90379 to 96d67f8 Compare April 6, 2026 14:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment on lines +32 to +37
runCatching {
repository.initialize(anonymousId = uuid, oAuthToken = null)
}.onFailure { throwable ->
LogBuffer.e(TAG, throwable, "Failed to initialize experiments")
runCatching { repository.clear() }
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

The new runCatching/onFailure behavior in initialize(uuid) (swallowing init exceptions and clearing the repository) isn’t covered by unit tests. Please add a test that stubs repository.initialize(...) to throw and asserts initialize(uuid) does not rethrow and triggers repository.clear().

Copilot generated this review using guidance from repository custom instructions.
Comment on lines +109 to +114
val deleted = runCatching { directory.deleteRecursively() }.getOrDefault(false)
if (deleted) {
LogBuffer.i(ExperimentProvider.TAG, "Cleared corrupted experiment cache")
} else {
LogBuffer.e(ExperimentProvider.TAG, "Failed to clear corrupted experiment cache")
}
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

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

File.deleteRecursively() returns false when the directory doesn’t exist, which would log "Failed to clear corrupted experiment cache" even though there may be nothing to clear (or it was already deleted). Consider treating a missing directory as a successful clear (e.g., !exists() || deleteRecursively()), to avoid noisy/misleading error logs.

Copilot uses AI. Check for mistakes.
@wpmobilebot
Copy link
Copy Markdown
Collaborator

Project dependencies changes

list
! Upgraded Dependencies
com.automattic.tracks:crashlogging:6.0.8, (changed from 6.0.7)
com.automattic.tracks:experimentation:6.0.8, (changed from 6.0.7)
com.automattic:Automattic-Tracks-Android:6.0.8, (changed from 6.0.7)
tree
-+--- com.automattic.tracks:crashlogging:6.0.7
++--- com.automattic.tracks:crashlogging:6.0.8
 +--- project :modules:features:account
 |    +--- project :modules:features:search
 |    |    +--- project :modules:services:analytics
 |    |    |    +--- project :modules:services:servers
-|    |    |    |    \--- com.automattic.tracks:crashlogging:6.0.7 (*)
+|    |    |    |    \--- com.automattic.tracks:crashlogging:6.0.8 (*)
-|    |    |    +--- com.automattic.tracks:experimentation:6.0.7
+|    |    |    +--- com.automattic.tracks:experimentation:6.0.8
-|    |    |    \--- com.automattic:Automattic-Tracks-Android:6.0.7
+|    |    |    \--- com.automattic:Automattic-Tracks-Android:6.0.8
 |    |    +--- project :modules:services:repositories
 |    |    |    \--- project :modules:services:crashlogging
-|    |    |         \--- com.automattic.tracks:crashlogging:6.0.7 (*)
+|    |    |         \--- com.automattic.tracks:crashlogging:6.0.8 (*)
 |    |    \--- project :modules:services:views
-|    |         \--- com.automattic.tracks:crashlogging:6.0.7 (*)
+|    |         \--- com.automattic.tracks:crashlogging:6.0.8 (*)
 |    \--- project :modules:features:settings
-|         \--- com.automattic.tracks:crashlogging:6.0.7 (*)
+|         \--- com.automattic.tracks:crashlogging:6.0.8 (*)
 +--- project :modules:features:discover
-|    \--- com.automattic.tracks:crashlogging:6.0.7 (*)
+|    \--- com.automattic.tracks:crashlogging:6.0.8 (*)
 +--- project :modules:features:endofyear
-|    \--- com.automattic.tracks:crashlogging:6.0.7 (*)
+|    \--- com.automattic.tracks:crashlogging:6.0.8 (*)
 \--- project :modules:features:profile
-     \--- com.automattic.tracks:crashlogging:6.0.7 (*)
+     \--- com.automattic.tracks:crashlogging:6.0.8 (*)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Analytics Analytics related issues [Type] Bug Not functioning as intended.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants