# TiviLux 0.4.58 / Build 74 — connection diagnostic build

Purpose: determine why an old channel remains listed by XUI for roughly 55 seconds after switching. This build measures client request teardown. It is NOT a confirmed fix for immediate server-session closure.

## Run the test on your own box

1. Build with your existing builder/signing setup; install as an update.
2. Open Settings → Support → STREAM DIAGNOSTICS → START NEW CAPTURE.
3. Choose CLOSE, return to Live TV, select A&E and let it play for 10 seconds.
4. Switch to Catchy Comedy once. Wait about 60 seconds while observing XUI.
5. Return to Settings → Support → STREAM DIAGNOSTICS. Choose REFRESH, then STOP CAPTURE.
6. Photograph the summary for A&E or use COPY LOG / SHARE LOG. Share only when you choose to; no automatic report is sent.

Avoid Android HOME during the test: the existing app behavior finishes the Activity and the log exists only in process memory. Opening the share chooser may also finish the app, but its text payload is already captured. If the device has no sharing app, photograph the report. The report rows accept DPAD focus and scroll.

The report records the selected source type (HLS for .m3u8; otherwise TS/OTHER), selection time, source assignment, old-source stop/clear request, individual HTTP-resource open/close calls, byte counts returned by reads, and late reads/opens belonging to the old source. HLS TS segments are marked TS_RESOURCE within an HLS source; they are not incorrectly classified as a separate continuous TS channel.

## How to interpret it

- `latest close 15 ms after switch/stop`, `unclosed=0`, `closeErrors=0`: observed client DataSource close calls completed promptly for that source. This does not prove the XUI connection slot was released at that moment.
- `unclosed=1`: a captured resource has not completed close in the available log. A currently playing source can legitimately have an open resource. For a retired source, inspect events and refresh before drawing a conclusion.
- `late opens`: a source started another resource request after its channel was superseded/stopped. Even a delayed HLS playlist/segment open retains the old source identity.
- `read bytes after switch/stop`: data was returned from read() after selection/stop. Some bytes may already have been buffered by the HTTP implementation; this is not a packet capture or proof of when bytes arrived over the network.
- `CLOSE threw` / closeErrors: teardown reported an exception, not successful closure.
- HLS playlists/segments are distinct short HTTP requests. A server-side inactivity-based session can remain listed after requests cease. The specific XUI timeout, slot-counting behavior and cause in your server remain unverified.

For immediate old-session removal, the evidence will tell us whether the remaining work belongs in client cancellation or server HLS session accounting. Do not disable HLS, shorten buffers, or change HTTP settings merely to make a panel row disappear.

## Implementation

Existing files changed relative to Build 73:

- `AppViewModel.kt`: records the selected channel at the existing synchronous live selection entry point.
- `ui/TiviLuxApp.kt`: passes channel identity/name to diagnostic context, including restored guide previews.
- `ui/components/LivePlaybackSession.kt`: records source assignment and stop/clear requests using existing per-attempt media IDs. No tune/recovery action or timing changes.
- `ui/components/LuxComponents.kt`: uses a diagnostic-aware live media-source factory; VOD retains its original factory. Passes display-only channel context to the live session. Surface handoff code is unchanged.
- `ui/screens/SettingsScreen.kt`: adds STREAM DIAGNOSTICS under Support.
- `app/build.gradle.kts`: versionName 0.4.58 / versionCode 74 only.
- `latest.json`, `updates/latest.json`: matching version metadata.

New source:

- `data/LiveStreamTrace.java`: bounded, thread-aware in-memory capture and summary. Limits: 16 source attempts, 160 resources per source, 240 recent events; reaching a source/resource limit stops recording, not playback. No disk/network writes, polling, or extra threads. Per-read code updates counters; event formatting occurs only for the first late read and resource lifecycle events.
- `ui/components/DiagnosticMediaSourceFactory.kt`: retains the existing configured DefaultHttpDataSource factory. During an opted-in capture, wraps DataSource open/read/close and forwards calls, return values, exceptions, listeners, URI and headers unchanged. Every source gets an immutable diagnostic session, so old HLS loaders cannot be mislabeled as the newest channel. With capture off, new media sources use the original unwrapped factory path. MultiView's untagged media items also take that path.
- `ui/components/StreamDiagnosticsDialog.kt`: TV-readable local summary, manual refresh, start/stop/clear, copy and user-triggered Android share chooser.
- `diagnostic-tests/LiveStreamTraceTest.java`: deterministic JVM tests for timing and attribution.

No stream URLs, request/response headers, exception messages, usernames or passwords are written into the diagnostic. Channel display names are included. URL-like names are replaced with a generic label.

The temporary preview-handoff change considered during investigation was reverted after you reported the preview had recovered. This build does not claim to fix that transient observation.

## Verification

Passed actual JVM tests for close timing, late read/open attribution, separation of current/old sources, failed close reporting, stopped-capture freezing, stale callbacks across captures, URL-like name redaction, concurrent snapshots, and capture bounds.

Verified buffer durations, LoadControl, renderer/decoder configuration, HTTP timeouts and redirects, keep-alive behavior, recovery policy, URL selection, full-screen/guide surface handoff, and MultiView source against Build 73. They are unchanged. No switch delay, network cancellation workaround, new recovery timer or healthy-stream restart was added.

No full Android build or TV UI/device test was possible here: Android SDK, Gradle and Kotlin build toolchain are unavailable. The JVM diagnostic tests do not validate APK compilation or on-device behavior. The ZIP is source for the existing builder; no APK is included.

## Release files

APK after building: `TiviLux-Native-v0.4.58.apk`
Version code: 74
APK URL in manifest: `https://play.theappdrop.store/tivilux-updates/TiviLux-Native-v0.4.58.apk`
SHA-256 remains empty until an APK is built. The manifest is supplied for compatibility, but neither it nor an APK has been published. Test on your own box before distributing to members.
