Fix car-arrival headset playback continuity (#36) #60

Merged
alexander merged 15 commits from mcp/issue-36-car-arrival-continuity into main 2026-09-19 16:52:43 +02:00
Owner

Summary

Fixes #36.

A physical drive on 2026-09-19 supplied the evidence that had been missing from R-106 / ADR-0029:

  • 15:37:25 — Media3 logged playWhenReady=false reason=audioFocusLoss while the audiobook had been continuously advancing through the headset.
  • 15:37:27 — the first Android Auto controller bound (com.google.android.projection.gearhead).
  • 15:37:27 — merged #11 confirmed the current book generation still owned the headset: A car connected and the book was held in the headset kind=bluetooth.
  • Owner physical acceptance after #11: connecting Android Auto while wearing the headset keeps the audiobook routed to that headset.

Measured pause → first car bind interval: 2 seconds.

The same drive also recorded audioFocusLoss at 15:43:37 when stopping the car. There is no new car-arrival binding for that event, so this PR deliberately does not turn #36 into a generic resume-after-focus-loss feature.

Implementation

This PR adds a narrow CarArrivalResumeGate rather than reviving the withdrawn historical CarArrivalContinuity.

Continuity is eligible only when:

  1. Media3 reports AUDIO_FOCUS_LOSS;
  2. #11 says this exact loaded-book generation was actually heard in a connected headset;
  3. the first 0→1 car-controller binding follows within the bounded 6-second pairing window;
  4. the same generation/output is still owned when the car arrives;
  5. the #11-owned headset preference is successfully applied and settled before play() is called.

The candidate is cancelled by a newer Play, any other pause reason, a book/queue transition, or ownership being superseded by a newer explicit output choice.

This deliberately does not:

  • resume becomingNoisy or arbitrary system pauses;
  • use the phone speaker as a continuity destination;
  • migrate playback to the car merely because the car appeared;
  • resume a deliberately paused book;
  • reuse stale route evidence from another book;
  • let a second Android Auto controller binding retrigger the resume;
  • implement the separate car-stop focus-loss behavior observed at 15:43:37.

Regression coverage

CarArrivalResumeGateTest covers:

  • measured focus loss + car arrival invokes the resume action for the owned headset;
  • deliberate pause/cancel does not resume;
  • explicit phone-speaker choice blocks resume;
  • car appearance does not become the destination;
  • stale ownership from another book cannot resume;
  • a newer explicit headset choice outranks the paused route;
  • stale timing is rejected;
  • missing headset ownership is rejected;
  • one focus loss can resume only once.

Verification

Production branch head: 7f185ab895aa911b983d95d642d8c1dc4dcc1004

  • Forgejo Actions run #124: success
  • verifyDebug: BUILD SUCCESSFUL in 7m 58s
  • the previously failing playback:detektDebug and playback:ktlintMainSourceSetCheck both pass
  • playback:testDebugUnitTest passes on the production implementation

Mutation proof

Temporary mutation branch removed only the actual resume callback while leaving the car-arrival policy decision intact.

Mutation head: 621b82d73102f4ad01425b4fb8bd02fa8b5b0102
Mutation run: #126

As required, CarArrivalResumeGateTest failed when the resume action was removed:

  • measured focus loss followed by car arrival resumes the owned headset — failed at line 41;
  • one focus loss can resume only once — failed at line 192;
  • car appearing never becomes the resume destination — failed at line 98.

The temporary mutation branch was deleted after capturing this evidence.

Documentation

R-106 and ADR-0029 now record the 2026-09-19 physical evidence, the measured audio-focus-loss mechanism, the 2-second correlation, the #11 ownership prerequisite, and the intentionally separate car-stop observation.

## Summary Fixes #36. A physical drive on 2026-09-19 supplied the evidence that had been missing from R-106 / ADR-0029: - 15:37:25 — Media3 logged `playWhenReady=false reason=audioFocusLoss` while the audiobook had been continuously advancing through the headset. - 15:37:27 — the first Android Auto controller bound (`com.google.android.projection.gearhead`). - 15:37:27 — merged #11 confirmed the current book generation still owned the headset: `A car connected and the book was held in the headset kind=bluetooth`. - Owner physical acceptance after #11: connecting Android Auto while wearing the headset keeps the audiobook routed to that headset. Measured pause → first car bind interval: **2 seconds**. The same drive also recorded `audioFocusLoss` at 15:43:37 when stopping the car. There is no new car-arrival binding for that event, so this PR deliberately does **not** turn #36 into a generic resume-after-focus-loss feature. ## Implementation This PR adds a narrow `CarArrivalResumeGate` rather than reviving the withdrawn historical `CarArrivalContinuity`. Continuity is eligible only when: 1. Media3 reports **AUDIO_FOCUS_LOSS**; 2. #11 says this exact loaded-book generation was actually heard in a connected headset; 3. the **first** 0→1 car-controller binding follows within the bounded 6-second pairing window; 4. the same generation/output is still owned when the car arrives; 5. the #11-owned headset preference is successfully applied and settled before `play()` is called. The candidate is cancelled by a newer Play, any other pause reason, a book/queue transition, or ownership being superseded by a newer explicit output choice. This deliberately does not: - resume `becomingNoisy` or arbitrary system pauses; - use the phone speaker as a continuity destination; - migrate playback to the car merely because the car appeared; - resume a deliberately paused book; - reuse stale route evidence from another book; - let a second Android Auto controller binding retrigger the resume; - implement the separate car-stop focus-loss behavior observed at 15:43:37. ## Regression coverage `CarArrivalResumeGateTest` covers: - measured focus loss + car arrival invokes the resume action for the owned headset; - deliberate pause/cancel does not resume; - explicit phone-speaker choice blocks resume; - car appearance does not become the destination; - stale ownership from another book cannot resume; - a newer explicit headset choice outranks the paused route; - stale timing is rejected; - missing headset ownership is rejected; - one focus loss can resume only once. ## Verification Production branch head: `7f185ab895aa911b983d95d642d8c1dc4dcc1004` - Forgejo Actions run **#124**: **success** - `verifyDebug`: **BUILD SUCCESSFUL in 7m 58s** - the previously failing `playback:detektDebug` and `playback:ktlintMainSourceSetCheck` both pass - `playback:testDebugUnitTest` passes on the production implementation ### Mutation proof Temporary mutation branch removed only the actual resume callback while leaving the car-arrival policy decision intact. Mutation head: `621b82d73102f4ad01425b4fb8bd02fa8b5b0102` Mutation run: **#126** As required, `CarArrivalResumeGateTest` failed when the resume action was removed: - `measured focus loss followed by car arrival resumes the owned headset` — failed at line 41; - `one focus loss can resume only once` — failed at line 192; - `car appearing never becomes the resume destination` — failed at line 98. The temporary mutation branch was deleted after capturing this evidence. ## Documentation R-106 and ADR-0029 now record the 2026-09-19 physical evidence, the measured audio-focus-loss mechanism, the 2-second correlation, the #11 ownership prerequisite, and the intentionally separate car-stop observation.
alexander deleted branch mcp/issue-36-car-arrival-continuity 2026-09-19 16:52:43 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
alexander/Audiobookshelf-Manager-Claude!60
No description provided.