Skip to content

fix(mobile): abort abandoned video thumbnail extractions and deduplicate in-flight loads - #40889

Open
aihehye wants to merge 1 commit into
pingdotgg:mainfrom
aihehye:fix/mobile-abort-abandoned-video-thumbnail
Open

aihehye wants to merge 1 commit into
pingdotgg:mainfrom
aihehye:fix/mobile-abort-abandoned-video-thumbnail

Conversation

@aihehye

@aihehye aihehye commented Nov 22, 2026

Copy link
Copy Markdown

Problem

When a mobile user taps Play on a chat video or leaves a thread while VideoThumbnailImage is still extracting frame 0 over a slow T3 Connect relay link (#40878), loadVideoThumbnail lets the hidden expo-video player keep running for up to 15 seconds:

  1. extractFrame(uri) did not accept an AbortSignal, so unmounting VideoThumbnailImage (e.g. tapping Play or switching threads) left the thumbnail player open and competing for relay bandwidth with the main playback player — and blocking all other queued posters behind the 15 s timeout.
  2. Concurrent calls for the same thumbnail key (such as MediaVideoPlayer's fitToVideo sizing effect and VideoThumbnailImage) were not deduplicated in flight, so a failed or timed-out extraction could trigger a second full 15 s extraction.
  3. When timedOut won Promise.race([frame, timedOut]), releasing the native player in finally could cause the in-flight frame IIFE to reject without a .catch() handler.

Change

  • Track active readers per in-flight thumbnail key in apps/mobile/src/lib/videoThumbnails.ts and deduplicate concurrent calls for the same key.
  • Pass an AbortSignal into extractFrame(uri, signal) and race frame extraction against abort and the 15 s timeout, releasing the native player and disposing the source immediately when no reader remains.
  • Defer abort by a single microtask (queueMicrotask) when the last reader aborts so a re-signed URL mounting for the same key in the same render/tick still reuses the in-flight extraction without restarting it.
  • Attach .catch(() => null) to the internal frame promise so late native rejections after player.release() never surface as unhandled rejections.
  • Add unit tests in apps/mobile/src/lib/videoThumbnails.test.ts covering aborting abandoned extractions, deduplicating failed concurrent loads, and swallowing late post-release rejections.

Related: #40878

Verification

  • vp test run apps/mobile/src/lib/videoThumbnails.test.ts apps/mobile/src/lib/useMediaVideoPlayback.test.tsx: 18/18 passed (7 in videoThumbnails.test.ts including the 3 new cases and the existing re-signed URL handoff case; 11 in useMediaVideoPlayback.test.tsx).
  • vp run check:changed: format, lint (0 warnings/errors), knip (1/2 and 2/2), typecheck (2 packages), tests (2 files), and React Compiler coverage all passed.
  • Not checked on a physical iOS/Android device or simulator (Windows host); verified via the mobile unit and React test suites.

Model: Gemini 4 Neon (via T3 Code)

@github-actions github-actions Bot added vouch:unvouched Author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The video thumbnail loader now shares active extractions for the same key and tracks each caller as a reader. When no readers remain, it aborts the extraction. Tests cover cancellation, shared failures, and native rejection after player release.

Changes: Thumbnail extraction lifecycle

Layer / File(s) Summary
Abortable frame extraction
apps/mobile/src/lib/videoThumbnails.ts, apps/mobile/src/lib/videoThumbnails.test.ts
Frame extraction checks for abort, races extraction against abort and timeout, and cleans up after failures. A test covers native rejection after an aborted player is released.
Shared requests and reader cleanup
apps/mobile/src/lib/videoThumbnails.ts, apps/mobile/src/lib/videoThumbnails.test.ts
Requests with the same key share an active extraction. The loader aborts the extraction when its final reader leaves and removes the in-flight entry. Tests cover reader cancellation and shared extraction failure.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant loadVideoThumbnail
  participant InFlightEntry
  participant extractFrame
  participant NativePlayer
  Caller->>loadVideoThumbnail: request thumbnail
  loadVideoThumbnail->>InFlightEntry: register reader
  loadVideoThumbnail->>extractFrame: start shared extraction
  Caller->>InFlightEntry: abort reader
  InFlightEntry->>extractFrame: abort controller when no readers remain
  extractFrame->>NativePlayer: release player
  extractFrame-->>loadVideoThumbnail: resolve null
Loading

Possibly related issues

Possibly related PRs

  • pingdotgg/t3code#32196 — Both changes reuse in-flight thumbnail extractions for the same video.
  • pingdotgg/t3code#40597 — Both changes handle abandoned thumbnail loads by releasing the player and discarding late extraction results.
  • pingdotgg/t3code#37172 — The PR’s inline sizing reuses cached video preview extraction, which this change modifies with reader tracking and cancellation.

Suggested reviewers: bartlomiejbloniarz, macroscopeapp

Merge Risk: Minimal · up to 9bc64

Abandoned video thumbnail extractions are now aborted and concurrent loads for the same key share one extraction, which frees the player for queued posters. No concrete merge-blocking issue was found; the remaining gap is that physical iOS and Android devices were not exercised.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes: aborting abandoned video thumbnail extractions and deduplicating in-flight loads. Both match the summary and objectives. It follows conventional commit format and…
Description check Passed The description follows the template. It has Problem, Change, Scope (links #40878 as related and explains the bug), and Verification sections. Verification lists the exact test commands, pass counts, …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main changes: aborting abandoned video thumbnail extractions and deduplicating in-flight loads. Both match the summary and objectives. It follows conventional commit format and is specific to the mobile app.

Full details: Description check

Explanation

The description follows the template. It has Problem, Change, Scope (links #40878 as related and explains the bug), and Verification sections. Verification lists the exact test commands, pass counts, and states what was not checked (physical devices, simulators). The model line is included as the template asks. The Scope section does not clearly say why the fix needs no separate issue, and it links #40878 only as 'Related'. The template asks for a linked issue that shows the bug, so this is a minor gap. The description also does not state that no UI change was made, so the screenshot requirement is not addressed.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between ad2bdc7 and 9bc64d1.

Files selected for processing: 2

  • apps/mobile/src/lib/videoThumbnails.test.ts
  • apps/mobile/src/lib/videoThumbnails.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants