Fix projected car lifecycle headset continuity (#36) #89

Merged
alexander merged 20 commits from mcp/issue-36-projection-continuity into main 2026-09-24 06:30:16 +02:00
Owner

Summary

Repairs issue #36 using the physical evidence from the September 22–23 drives.

Arrival

  • Retains the last positively heard exact playing headset across the measured pre-focus route omission / AUDIO_BECOMING_NOISY ordering.
  • Positive non-headset playback still clears that evidence.
  • AUDIO_BECOMING_NOISY remains non-authoritative: it never issues Play by itself.
  • A positive Android Auto projection-connect edge may satisfy an already-armed Arrival candidate before Gearhead binds; the first 0→1 car controller bind remains a secondary/compatibility boundary.
  • Final recovery still requires the exact captured headset, same book generation and same explicit-output-selection sequence.

Departure

  • Separates physical projected-car lifetime from legacy MediaSession controller lifetime.
  • Observes Android Auto projection state through the connection update/provider contract without adding a new dependency or weakening Gradle dependency verification.
  • A positive projection session owns the physical departure boundary; Projection -> NotConnected completes the existing Departure focus candidate without waiting for Gearhead onDisconnected().
  • Supports either strong physical ordering inside the existing bounded window:
    • focus loss -> projection exit
    • projection exit -> focus loss
  • Legacy controller disconnect remains a conservative focus-first fallback only when no positive projection signal was observed.
  • Physical projection exit clears stale controller counts so delayed controller callbacks cannot poison the next drive or issue duplicate Play.

Physical evidence driving this repair

  • 2026-09-22 arrival: becomingNoisy + route omission occurred before audioFocusLoss, causing the old gate to reject the focus candidate.
  • 2026-09-23 07:43 arrival: automatic recovery succeeded after first Gearhead bind.
  • 2026-09-23 12:00 arrival: automatic recovery succeeded but with about three seconds of audible interruption.
  • 2026-09-23 departure: Departure / FocusLossWaitingForBoundary armed correctly, but no useful final MediaSession disconnect arrived for at least 108 seconds in one drive and at least 29 seconds in another.

Safety invariants

  • Media3 continues to own audio focus and becoming-noisy behavior.
  • No generic focus-loss auto-resume.
  • No speaker/car/other-headset substitution.
  • Explicit Play/Pause, book/session changes and newer output selection remain authoritative.
  • Unknown/inaccessible projection state never manufactures a departure.
  • A focus loss while the car remains projected does not complete Departure.

Automated coverage

Adds/updates regression coverage for:

  • pre-focus headset route disappearance;
  • positive non-headset evidence clearing retained headset authority;
  • projection-owned departure without MediaSession disconnect;
  • projection-exit-before-focus reverse ordering;
  • bounded reverse-order correlation;
  • delayed legacy disconnect after recovery;
  • stale multi-controller count reset; and
  • projection connection-state mapping.

Physical acceptance after CI

Retest:

  1. headset playing -> start car: no route substitution; automatic recovery if Android pauses;
  2. headset playing + car established -> stop car: exact headset resumes without manual Play;
  3. repeat with delayed Gearhead disconnect;
  4. ordinary headset unplug with no car stays paused;
  5. deliberate Pause during transition stays paused;
  6. call/navigation/other focus loss while projection remains connected does not trigger departure recovery.

Closes #36 only after those device checks pass.

## Summary Repairs issue #36 using the physical evidence from the September 22–23 drives. ### Arrival - Retains the last positively heard exact playing headset across the measured pre-focus route omission / `AUDIO_BECOMING_NOISY` ordering. - Positive non-headset playback still clears that evidence. - `AUDIO_BECOMING_NOISY` remains non-authoritative: it never issues Play by itself. - A positive Android Auto projection-connect edge may satisfy an already-armed Arrival candidate before Gearhead binds; the first 0→1 car controller bind remains a secondary/compatibility boundary. - Final recovery still requires the exact captured headset, same book generation and same explicit-output-selection sequence. ### Departure - Separates physical projected-car lifetime from legacy MediaSession controller lifetime. - Observes Android Auto projection state through the connection update/provider contract without adding a new dependency or weakening Gradle dependency verification. - A positive projection session owns the physical departure boundary; `Projection -> NotConnected` completes the existing Departure focus candidate without waiting for Gearhead `onDisconnected()`. - Supports either strong physical ordering inside the existing bounded window: - focus loss -> projection exit - projection exit -> focus loss - Legacy controller disconnect remains a conservative focus-first fallback only when no positive projection signal was observed. - Physical projection exit clears stale controller counts so delayed controller callbacks cannot poison the next drive or issue duplicate Play. ## Physical evidence driving this repair - 2026-09-22 arrival: `becomingNoisy` + route omission occurred before `audioFocusLoss`, causing the old gate to reject the focus candidate. - 2026-09-23 07:43 arrival: automatic recovery succeeded after first Gearhead bind. - 2026-09-23 12:00 arrival: automatic recovery succeeded but with about three seconds of audible interruption. - 2026-09-23 departure: `Departure / FocusLossWaitingForBoundary` armed correctly, but no useful final MediaSession disconnect arrived for at least 108 seconds in one drive and at least 29 seconds in another. ## Safety invariants - Media3 continues to own audio focus and becoming-noisy behavior. - No generic focus-loss auto-resume. - No speaker/car/other-headset substitution. - Explicit Play/Pause, book/session changes and newer output selection remain authoritative. - Unknown/inaccessible projection state never manufactures a departure. - A focus loss while the car remains projected does not complete Departure. ## Automated coverage Adds/updates regression coverage for: - pre-focus headset route disappearance; - positive non-headset evidence clearing retained headset authority; - projection-owned departure without MediaSession disconnect; - projection-exit-before-focus reverse ordering; - bounded reverse-order correlation; - delayed legacy disconnect after recovery; - stale multi-controller count reset; and - projection connection-state mapping. ## Physical acceptance after CI Retest: 1. headset playing -> start car: no route substitution; automatic recovery if Android pauses; 2. headset playing + car established -> stop car: exact headset resumes without manual Play; 3. repeat with delayed Gearhead disconnect; 4. ordinary headset unplug with no car stays paused; 5. deliberate Pause during transition stays paused; 6. call/navigation/other focus loss while projection remains connected does not trigger departure recovery. Closes #36 only after those device checks pass.
Fix departure integration test compilation
All checks were successful
BookWave / PR verification BookWave PR verification passed
200b3d9e2a
alexander deleted branch mcp/issue-36-projection-continuity 2026-09-24 06:30:16 +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!89
No description provided.