Offline backlog blocks crash collection in other profiles

Open
#23,770 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
android, kotlin
Domain
mobile

Research direction

The reproduction is a new test, ProfileCrashReportQueueTest.kt, which fills the approved folder of one profile via ReportLocator and then asserts that another profile can still collect, using the plugins' shouldStartCollecting. Run it first to confirm the failure. Done means the other profile collects while the offending profile stays limited, but the fix is unresolved: a per-profile cap may exceed the shared sender's batch limit, so the design needs maintainer input first.

Written by the indexing model from the issue text.

Description

code-scan Multi Profile Needs Triage

Assisted-by: GPT-6.1-Terra xhigh & GPT-6.2-Sol high & GPT-6.2-Sol xhigh & GPT-6.2-Astra xhigh

Offline backlog blocks crash collection in other profiles [P2]
Subject: Offline backlog blocks crash collection in other profiles

Five unsent reports from one profile can prevent ACRA from collecting a new crash in another profile.

---
diff --git a/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileCrashReportQueueTest.kt b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileCrashReportQueueTest.kt
new file mode 100644
index 0000000000..6b2ae1cb86
--- /dev/null
+++ b/AnkiDroid/src/test/java/com/ichi2/anki/multiprofile/ProfileCrashReportQueueTest.kt
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+package com.ichi2.anki.multiprofile
+
+import android.app.Application
+import android.content.Context
+import androidx.core.content.pm.PackageInfoCompat
+import androidx.test.core.app.ApplicationProvider
+import com.ichi2.anki.acraCoreConfigBuilder
+import com.ichi2.anki.common.crashreporting.CrashReportService
+import com.ichi2.anki.initializeAcraCrashReporter
+import com.ichi2.testutils.EmptyApplication
+import com.ichi2.testutils.common.OS
+import io.mockk.every
+import io.mockk.mockkStatic
+import io.mockk.unmockkAll
+import org.acra.ACRA
+import org.acra.ACRAConstants
+import org.acra.ReportField
+import org.acra.builder.ReportBuilder
+import org.acra.config.CoreConfiguration
+import org.acra.config.CoreConfigurationBuilder
+import org.acra.config.LimiterConfiguration
+import org.acra.config.ReportingAdministrator
+import org.acra.data.CrashReportData
+import org.acra.file.CrashReportPersister
+import org.acra.file.ReportLocator
+import org.junit.After
+import org.junit.Assume.assumeFalse
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.robolectric.RobolectricTestRunner
+import org.robolectric.annotation.Config
+import java.io.File
+import java.text.SimpleDateFormat
+import java.util.Date
+import java.util.Locale
+import kotlin.test.assertFalse
+import kotlin.test.assertTrue
+
+@RunWith(RobolectricTestRunner::class)
+@Config(application = EmptyApplication::class)
+class ProfileCrashReportQueueTest {
+    @After
+    fun tearDown() {
+        unmockkAll()
+    }
+
+    @Test
+    fun `an offline backlog only limits the profile that collected it`() {
+        assumeFalse("ACRA's report file names contain ':', which Windows doesn't allow", OS.WINDOWS.isRunning())
+        val application = ApplicationProvider.getApplicationContext<Application>()
+        mockkStatic(ACRA::class)
+        every { ACRA.init(any<Application>(), any<CoreConfigurationBuilder>(), any()) } returns Unit
+        with(application) { initializeAcraCrashReporter() }
+        val config = CrashReportService.acraCoreConfigBuilder.build()
+        val offlineProfile =
+            ProfileContextWrapper.create(application, ProfileId("p_offline"), File(application.dataDir, "p_offline"))
+        val otherProfile =
+            ProfileContextWrapper.create(application, ProfileId("p_other"), File(application.dataDir, "p_other"))
+        val version = PackageInfoCompat.getLongVersionCode(application.packageManager.getPackageInfo(application.packageName, 0))
+        val timestamps = SimpleDateFormat(ACRAConstants.DATE_TIME_FORMAT_STRING, Locale.ENGLISH)
+        val approved = ReportLocator(offlineProfile).approvedFolder
+
+        // Reports that have been approved but could not be uploaded.
+        repeat(LimiterConfiguration().failedReportLimit) { index ->
+            val timestamp = timestamps.format(Date(index.toLong()))
+            val report =
+                CrashReportData().apply {
+                    put(ReportField.APP_VERSION_CODE, version)
+                    put(ReportField.FILE_PATH, offlineProfile.filesDir.absolutePath)
+                    put(ReportField.USER_CRASH_DATE, timestamp)
+                }
+            CrashReportPersister().store(report, File(approved, timestamp + ACRAConstants.REPORTFILE_EXTENSION))
+        }
+
+        assertFalse(shouldCollect(offlineProfile, config), "A full queue must keep limiting its own profile")
+        assertTrue(shouldCollect(otherProfile, config), "Another profile's approved reports must not fill this profile's queue")
+    }
+
+    private fun shouldCollect(
+        profile: Context,
+        config: CoreConfiguration,
+    ): Boolean {
+        val report = ReportBuilder().exception(IllegalStateException("new crash"))
+        return config.pluginLoader.loadEnabled(config, ReportingAdministrator::class.java).all {
+            it.shouldStartCollecting(profile, config, report)
+        }
+    }
+}

Fix unresolved: no compatible temporary fix verified. A per-profile cap can exceed the shared sender’s batch limit and leave reports queued.

Originally posted by @david-allison in https://github.com/ankidroid/Anki-Android/pull/23337#pullrequestreview-6047733103, with a per-profile queue proposed in https://github.com/ankidroid/Anki-Android/pull/23337#issuecomment-7170891275

Dominant language
Kotlin
Stars
12.3k
Forks
3.1k
Avg merge
2d 1h
Merged PRs (30d)
311

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ankidroid/Anki-Android

All issues in ankidroid/Anki-Android

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.