Skip to content

Diagnostics: add secret-safe WorkManager failure observation hooks #191

Description

@MrFr3di

Objective

Use the stable WorkManager 2.11.2 failure callbacks that MuxTV already depends on so background refresh/startup failures become typed, bounded and exportable without exposing secrets or changing WorkManager semantics.

Owner under modernization umbrella #179; Doctor integration must remain compatible with #30 and the user-unlocked lifecycle contract from #118.

Current gap

app/tv/src/main/kotlin/app/muxtv/MuxTvApplication.kt currently builds Configuration with only setWorkerFactory(workerFactory).

The current stable API already exposes:

  • setInitializationExceptionHandler;
  • setSchedulingExceptionHandler;
  • setWorkerInitializationExceptionHandler;
  • setWorkerExecutionExceptionHandler.

This means MuxTV currently has a blind spot when WorkManager itself cannot initialize/schedule a request or cannot initialize/execute a worker.

Architecture

Introduce a narrow WorkManager-specific diagnostic boundary rather than reusing PlaybackObservation or creating a generic raw telemetry event bus.

Suggested model:

  • WorkFailureKind: stable enum/code for the four callback families;
  • WorkFailureObservation: kind + timestamp + optional bounded safe worker identity/category only;
  • WorkFailureRecorder / WorkFailureReader: bounded process/local diagnostic owner;
  • WorkManager callbacks translate framework failures into this typed model and never propagate exceptions;
  • Doctor/export receives a coarse projection through an explicit read boundary.

Initialization failures are special: the observation path must not depend on Room/WorkManager being healthy. Do not introduce a diagnostic write path that can recursively fail during WorkManager initialization.

Security / privacy contract

Never persist or export:

  • raw Throwable.message or full stack trace;
  • playlist/source URL, path or query;
  • Authorization/Cookie/custom headers;
  • provider credentials/tokens;
  • arbitrary worker input/output Data;
  • user/channel titles.

Tests must use deliberately secret-bearing exception text and prove it cannot cross the diagnostic boundary.

Required behavior

  • all four stable callbacks are installed;
  • callback handling is non-throwing and observational only;
  • WorkManager retry/failure/scheduling semantics remain owned by WorkManager/Worker code;
  • repeated failures are bounded; no unbounded in-memory or durable list;
  • Doctor uses stable user-facing categories, not raw exception strings;
  • no custom setWorkerCoroutineContext() in this issue;
  • no WorkManager 2.12 RC upgrade solely for newer event-listener APIs.

TDD / acceptance

  1. RED pure unit tests define four typed callback categories and secret stripping;
  2. RED test proves recorder failure cannot escape into a callback;
  3. bounded retention/deduplication behavior is deterministic;
  4. wire all four Configuration.Builder callbacks after the pure boundary is GREEN;
  5. app unit tests prove the configuration contains the expected handlers where framework inspection allows it; otherwise keep wiring behind a small testable factory;
  6. Doctor/report tests prove only stable safe fields are formatted/exported;
  7. host validation GREEN on exact head;
  8. later API26 + API36 canonical-device smoke verifies startup/refresh behavior without creating any additional AVD.

Non-goals

  • generic telemetry platform;
  • remote telemetry upload;
  • storing raw WorkManager internals;
  • changing Worker retry/backoff policy;
  • changing worker dispatcher/coroutine context;
  • adding another Android TV AVD.

Official references

Dependencies / ordering

Can be implemented host-first before device runner returns. Device acceptance is deferred until the canonical API26/API36 runner is available. Keep this separate from #189 U0 UI characterization and from the combined stack staging #190.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions