Repository navigation
fix(reader): clear stale readAloudNextChapterProvider on external TTS stop - #281
Conversation
QA verification — PR #281 vs issue #280Acceptance criteria (bug report — issue has no explicit checklist, so the bar is "the repro no longer reproduces, with a regression test that proves it"):
What I ran
Root causeBoth Net effect: as written, this PR makes Read Aloud stop after the very first chapter, every time, which is a much worse regression than the stale-provider bug it fixes (which was explicitly "currently harmless" per the issue). Suggested direction for the dev agentThe edge-trigger needs to distinguish "engine went IDLE because AGENTS.md conventionsBranch naming and commit hygiene look fine; no hardcoded versions introduced. QA verdict: FAIL |
| QA failed its first round — routing back to the dev agent for one automated retry. |
📱 iOS Build Status: PASSED✅ iOS Simulator Build & Unit Tests - success iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those. |
… a racy IDLE edge QA on PR #281 found that watching `readAloudState` for a PLAYING/PAUSED -> IDLE edge to clear readAloudNextChapterProvider also fires on every natural chapter-to-chapter advance (both engines set state IDLE immediately before emitting completionEvent from the same call), racing the completionEvent collector and breaking Read Aloud after the first chapter. TtsEngine now exposes stopEvent, emitted only from stop() - a call natural completion never makes in either engine, so it can't collide with completionEvent. ReaderViewModel clears the provider on stopEvent instead.
|
Addressed the QA round-1 finding directly. Root cause of the regression QA found: the previous fix cleared Fix: added Added the exact repro from your report as a new test ( Full JVM suite ( |
QA verification — PR #281 vs issue #280Issue #280 is a bug report (no acceptance checklist), whose "suggested fix" was explicitly revised mid-PR after QA round 1 found a race. Checklist derived from the issue + the PR's own stated regression:
What I ran
No gaps found. QA verdict: PASS |
Principal review — PR #281Verdict: auto-merge (risk:low confirmed, no CONFIRMED findings) Risk classification sanity checkThe Same conclusion holds with the final commit included, so the label (though Correctness reviewRead the full diff plus the surrounding code (not just the hunks):
Test verification (didn't take the PR's numbers at face value)Ran the exact modules myself rather than trusting the PR body's reported Then specifically verified the AGENTS.md "prove a new test can fail" rule for Process note for a maintainer (not a code defect, not blocking)GitHub's own CI never completed on the final commit (2159c4c): Policy checks
|
|
principal-review's run crashed or exhausted its turn budget (see the workflow run) before reaching a verdict — routed to a human instead of silently leaving this on status:needs-review. Needs a human to either re-run review (re-add |
|
Automated pipeline health check: Diagnosed the crash behind the comment above. Doesn't clear this routine's self-heal bar — flagging for a human rather than requeuing. Pulled the job log for run 32157408830 (
This PR touches no sensitive path ( Recommend: raise Generated by Claude Code |
…valid verdict on crash (#298) Closes #297. --max-turns 40 was too tight — the agent's last action is writing principal-verdict.txt, so hitting the cap one turn later is common (PR #281's job log: num_turns 41 vs cap 40). At least 4 same-day crashes (PRs #257/#264/#281, plus one flagged earlier on #279) threw away a verdict the agent had already written, routing good work to status:needs-info instead of using it. Raised the cap to 65, and changed the crash-handling branch in 'Advance PR based on review verdict' to check principal-verdict.txt even when the agent step reports failure — only routes to status:needs-info when there's truly no usable verdict on disk. Sensitive path (.github/workflows/**) — opening as a direct human-authored PR for that reason.
… stop TtsAudioFocusManager can call TtsEngine.stop() directly on audio-focus loss (e.g. an audiobook resumed from the lockscreen while Read Aloud is speaking), bypassing ReaderViewModel.stopReadAloud() entirely. That left readAloudNextChapterProvider set after such a stop even though the engine had gone IDLE, so a later, unrelated completion event sharing the same singleton TtsEngineProvider engine could be misread as "advance the book". Observe readAloudState and clear the provider on any PLAYING/PAUSED -> IDLE transition, not just via stopReadAloud(). Edge-triggered rather than level-triggered so it doesn't race the provider assignment in startReadAloud against the engine's own resting IDLE state before speak() has run. Closes #280 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
… a racy IDLE edge QA on PR #281 found that watching `readAloudState` for a PLAYING/PAUSED -> IDLE edge to clear readAloudNextChapterProvider also fires on every natural chapter-to-chapter advance (both engines set state IDLE immediately before emitting completionEvent from the same call), racing the completionEvent collector and breaking Read Aloud after the first chapter. TtsEngine now exposes stopEvent, emitted only from stop() - a call natural completion never makes in either engine, so it can't collide with completionEvent. ReaderViewModel clears the provider on stopEvent instead.
2159c4c to
9f886cf
Compare
📱 iOS Build Status: PASSED✅ iOS Simulator Build & Unit Tests - success iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those. |
Principal review — PR #281Verdict: auto-merge ( What I verified directly (not just read/trusted)
Design note (not a finding)Keying the clear on No correctness, simplification, or efficiency findings. No sensitive paths, no new dependencies, tests are at the right level (pure JVM, matching AGENTS.md's test-type table) and were shown to actually catch the regression they claim to guard. |
Summary
ReaderViewModel.readAloudNextChapterProvider— the bookkeepingadvanceOnCompletion()uses to know a Read Aloud session is active — was previously cleared only byReaderViewModel.stopReadAloud(). PR #277'sTtsAudioFocusManagermakes each TTS engine callstop()on itself directly when it loses audio focus (e.g. an audiobook resumed from the lockscreen while Read Aloud is speaking), which bypassesstopReadAloud()entirely. That left the provider set (non-null) even though the engine had goneIDLE.Currently harmless (no other production caller shares the singleton
TtsEngineProviderengine yet), but the moment one does — a Settings voice-preview feature, or Markdown wiring in #276 — a stale provider left over from an externally-stopped session could hijack that unrelatedspeak()'s natural completion into "advance the book".Approach (revised after QA round 1)
The first version of this fix watched
readAloudStatefor aPLAYING/PAUSED->IDLEedge to clear the provider. QA correctly found this racesadvanceOnCompletion(): bothAndroidTtsEngine.speakNext()andPocketTtsEngine's completion callback setstatetoIDLEimmediately before emittingcompletionEvent, from the same call — so a natural chapter-to-chapter advance produces the exact sameIDLEedge as an external stop. The edge-triggered collector nulled the provider before thecompletionEventcollector read it, so Read Aloud stopped after the first chapter every time.Fixed properly this round:
TtsEnginenow exposes a newstopEvent: SharedFlow<Unit>, emitted only fromstop()in bothAndroidTtsEngineandPocketTtsEngine. Natural completion never callsstop()in either engine — it's a fundamentally distinct code path fromspeakNext()/the completion callback — sostopEventandcompletionEventare mutually exclusive at the source, with no ordering/race to reason about.ReaderViewModel.initnow clearsreadAloudNextChapterProvideronstopEventinstead of diffingstate.Testing
stop emits stopEventto bothAndroidTtsEngineTestandPocketTtsEngineTest, pluslosing audio focus while resumed emits stopEventtoPocketTtsEngineTest(mirrors the existinglosing audio focus while resumed stops the enginetest, which covers the exactTtsAudioFocusManagerpath from [enhancement] ReaderViewModel.readAloudNextChapterProvider can go stale when TtsAudioFocusManager stops the engine externally #280).external stop via audio focus loss clears the next-chapter providerinReaderViewModelTestto emitstopEventalongside theIDLEstate transition, matching what the real engines'stop()now does.natural completion driven the way production engines actually sequence it still advances— this is QA's exact repro (drivestatePLAYING->IDLEthen emitcompletionEvent, withoutstopReadAloud()), now asserting the chapter does advance. This is the regression test for QA round 1's finding../gradlew :core:tts:testDebugUnitTest :feature:reader:testDebugUnitTest :feature:settings:testFdroidDebugUnitTest—BUILD SUCCESSFUL../gradlew testDebugUnitTest testFdroidDebugUnitTest testPlayDebugUnitTest --continue(full JVM suite, both flavors) —BUILD SUCCESSFUL.Scope / risk
Touches
core/tts(interface + both engine implementations) in addition tofeature/reader, since a race-free fix needs the distinguishing signal to come from the engine, not be inferred fromstatealone in the ViewModel. Neithercore/ttsnorfeature/readeris inagent-policy.yml'ssensitive_paths— expectrisk:low, but flagging the wider blast radius explicitly per policy since it's larger than the original PR's stated scope.Closes #280