Repository navigation
Description
Summary
feature/reader/src/test/kotlin/xyz/libravault/feature/reader/epub/EpubReaderViewModelTest.kt and feature/reader/src/test/kotlin/xyz/libravault/feature/reader/ReaderViewModelTest.kt both have the exact same anti-pattern that #553 diagnosed and PR #554 just fixed only for MarkdownReaderViewModelTest: their @AfterEach tearDown() calls Dispatchers.resetMain() but never cancels the viewModelScope of any ViewModel the test created (viewModel() factory just does EpubReaderViewModel(...) / ReaderViewModel(...) directly, with no ViewModelStore to route through).
Both files create ViewModels dozens of times per class (EpubReaderViewModelTest ~10 call sites, ReaderViewModelTest ~50+), so the same class of leaked-coroutine flakiness #553 described is live in both.
Evidence (verified, not assumed)
Found while principal-reviewing PR #554 (which itself only fixes MarkdownReaderViewModelTest). PR #554's own Unit & Integration Tests (JVM) CI run hit exactly this failure mode, just manifesting differently than #553's symptom:
- Run 32774177660,
Run JVM testsstep, 2026-08-24T20:32:58Z — 9 seconds into:feature:reader:testDebugUnitTest, before any of that module's tests had printed output:This is the same underlying mechanism as Flaky test: MarkdownReaderViewModelTest > getChapterTextFromProgression returns null when no document is loaded (UncaughtExceptionsBeforeTest) #553: a##[error]Exception in thread "kotlinx.coroutines.DefaultExecutor" java.lang.IllegalStateException: Module with the Main dispatcher had failed to initialize. For tests Dispatchers.setMain from kotlinx-coroutines-test module can be used ... Caused by: java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked. See https://developer.android.com/r/studio-ui/build/not-mocked for details.viewModelScopecoroutine from one test outlives that test (because nothing cancels it intearDown()), and later resumes on the realDispatchers.Main/LooperafterDispatchers.resetMain()has already run for that test — except here it surfaces as a raw uncaught exception onkotlinx.coroutines.DefaultExecutor(a background thread with no per-test exception collector to attribute it to) rather than asUncaughtExceptionsBeforeTestagainst a specific next test. It did not fail any individual test this time, which is exactly why it's easy to miss. - The job's own overall result was green (this exception didn't fail the build), and I could not reproduce it in an immediate local re-run of the full module (
./gradlew :feature:reader:testDebugUnitTest --continue, 234/234 tests, 0 errors, noDefaultExecutorexception in the log) — consistent with Flaky test: MarkdownReaderViewModelTest > getChapterTextFromProgression returns null when no document is loaded (UncaughtExceptionsBeforeTest) #553's own finding that this class of bug is order/timing-dependent, not deterministic (Flaky test: MarkdownReaderViewModelTest > getChapterTextFromProgression returns null when no document is loaded (UncaughtExceptionsBeforeTest) #553 documented the same commit passing and failing across different runs). EpubReaderViewModelTest.ktandReaderViewModelTest.ktare the only other files underfeature/reader/src/test/that construct aViewModeland have atearDown()callingDispatchers.resetMain()without also clearing aViewModelStore(confirmed by grepping all 22 test classes in the module) —MarkdownReaderViewModelTest.ktwas the third and is now fixed by fix(reader): clear MarkdownReaderViewModel instances between tests #554.
Suggested fix
Apply the same ViewModelStore pattern PR #554 used for MarkdownReaderViewModelTest to EpubReaderViewModelTest and ReaderViewModelTest: route each test's viewModel() factory through a androidx.lifecycle.ViewModelStore field and call viewModelStore.clear() in @AfterEach, before Dispatchers.resetMain().
Impact
Same as #553: low severity on its own, but a real, reproducible, silent source of background-thread noise (and potential future UncaughtExceptionsBeforeTest flakes on unrelated tests) in CI runs touching feature:reader. Filed per the principal-review agent's mandate to give CONFIRMED findings a permanent record (see PR #554 review comment) — this doesn't block #554 itself, which is narrowly and correctly scoped to the class #553 actually named, exactly as #553 didn't block PR #541 when it was found the same way.
Activity
libravault-xyz commentedon Aug 26, 2026
Automated pipeline health check: This issue (filed by
github-actions[bot],CONTRIBUTORassociation) has received zerodev-agent.ymlruns and zero explanatory comment of any kind since it was filed.Same author-association trust-gate-skip signature already tracked on #469/#475/#479/#388/#408/#433/#437/#441/#544/#558/#582 — but unlike that earlier batch, this issue never got even the
explain-trust-gate-skipjob's own skip-reason comment, consistent with the regression confirmed on #437/#441 (that job'sgh issue commentstep has noactions/checkout/--repo, so it fails before posting:fatal: not a git repository).Not self-healing: no status label to toggle, and
.github/workflows/dev-agent.ymlis a sensitive path this routine won't edit.This now makes at least 13 open issues sitting with zero pipeline engagement: #469, #475, #479, #487, #504, #523, #534, #556, #557, #559, #561, #581, #589, #611, #626, #639. A tracked issue for the underlying
explain-trust-gate-skipcheckout/--repobug has been recommended across at least two prior automated runs (2026-08-23 on #469, 2026-08-24 on #437/#441) but doesn't appear to have been filed yet.Action needed: someone with write access can
workflow_dispatchtriage this issue manually, and/or fixexplain-trust-gate-skip'sgh issue commentstep (addactions/checkoutor--repo ${{ github.repository }}) so future instances self-report instead of going silent.Generated by Claude Code