fix(clients): paint the Android device stream instead of looping on reset-video #14664
main fromrefs/pull/14664/head·opened View on GitHubFixes #12229.
Split out of #12237, which could not be reopened, so this replaces it. The capture-source half it also carried is now #14663 and is not part of this diff.
The client and serve-emu deadlock on the keyframe handshake#
The client configures its decoder from the SPS-carrying keyframe, drops that keyframe and sends reset-video to ask for a fresh one. serve-emu answers by restarting scrcpy's encoder, and the restart broadcasts video-session — which the client treats as a rotation and tears the decoder down. The next keyframe then finds no configured decoder, so it configures and asks again, every VIDEO_RESET_COOLDOWN_MS (1.5s), forever.
packages/client-runtime/src/device/stream.ts (shared by web, desktop, and the mobile device screen, so all three get the fix):
- Decode the SPS keyframe after
configureDecoderinstead of dropping it.reset-videois only sent when the first post-configure access unit is not a keyframe. - Only rebuild the decoder when a
video-sessionannounces a size different from the one already streaming. serve-emu sends it for every encoder restart — including the hub's own "client opened" reset and any reset we asked for — not only for rotations. A restart that announces no size still rebuilds, so the existing rotation-timeout test keeps its meaning. - Don't send
reset-videofor a delta that arrives while a configure is still in flight; that restarts the encoder underneath the handshake already running.
iOS is a different wire (AVCC over HTTP) and never sends reset-video; it is untouched.
Verification#
packages/client-runtime/src/device/stream.test.ts replays connectAndroid against a stubbed VideoDecoder:
- a
video-sessionplus a SEMU keyframe carrying an SPS must configure, paint, and send noreset-video - a same-size
video-sessionmust not close a live decoder, while a resized one must - a delta arriving mid-configure must not reset video
- a rotation that lands while
isConfigSupportedis still pending must drop the stale configure
Each one fails with its guard reverted.
Replayed the real client module against a live hub driving an Android emulator, with the hub started on scrcpy:
| statuses | frames decoded | reset-video sent | |
|---|---|---|---|
| before | connecting, connecting | 0 | 20 in 30s |
| after | connecting, connecting, streaming | 11 (1 key + 10 delta) | 0 |
Then end to end in the web client against that emulator: the panel paints and keeps painting.
vp test run packages/client-runtime/src/device → 130 passed. client-runtime typecheck clean, targeted lint clean.
No before/after image: this PR changes no UI. "Before" is an empty canvas with a status label and "after" is a live emulator screen, which the counters above describe more precisely than a screenshot would.
Model: Claude Opus 5 (1M context), harness: Claude Code in T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Approvability#
Verdict: Approved at
737fac9Macroscope's review found this PR approvable — The PR is a focused Android stream deadlock fix in one shared runtime component, with targeted tests covering decoder handshakes, restarts, rotation, and pending configuration. It does not alter defaults, schemas, infrastructure, or static-analysis configuration.
Notes:
- Diff unchanged. Approvability was decided on eligibility alone.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).d912b1d. Prior analysis still applies.Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
- Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
39fc5e2b-2a9e-4f72-a76e-4ad5ab766236
📥 Commits
Reviewing files that changed from the base of the PR and between 84f8fa00f441ee41872ff2501c335c485cbacc56 and d912b1db03565557187966b6005bb1688223febe.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
b6918b53-a20a-4781-b606-2e427276efae📥 Commits
Reviewing files that changed from the base of the PR and between a3abb5266080c15b2a675d7f92b517b567c427e2 and 737fac97d1588a2abbf061a3fc14ef669ee40345.
📒 Files selected for processing (2)
packages/client-runtime/src/device/stream.test.tspackages/client-runtime/src/device/stream.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
Walkthrough#
The Android video stream now uses announced dimensions to determine when to close the decoder. During decoder configuration, it decodes an SPS-carrying keyframe when available and avoids redundant keyframe requests.
Changes#
Android video stream
Layer / File(s) Summary Session dimensions and decoder lifecycle
packages/client-runtime/src/device/stream.ts,packages/client-runtime/src/device/stream.test.tsThe stream parses and tracks announced dimensions per connection. It closes the decoder when dimensions are unknown or change. Tests cover same-size sessions, dimension changes, and a configuration result that arrives after a resize. Decoder configuration and keyframe handling
packages/client-runtime/src/device/stream.ts,packages/client-runtime/src/device/stream.test.tsAfter successful configuration, the stream decodes an SPS-carrying keyframe. It requests a keyframe only when the retained access unit is not a keyframe, and does not request one for delta packets while configuration is pending. Tests cover these cases. Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarmingeMerge Risk: ⚪ Minimal · up to
737faThis change should fix the Android video handshake so frames paint without repeated reset requests. No concrete merge-blocking risk was found, and the new tests cover the main lifecycle paths.
Security Architecture Review#
Security architecture risk: 🔵 Low · up to
737faThe change preserves existing connection and decoder ownership checks and introduces no identified access or privilege expansion. Compatibility with the encoder’s same-size session announcements remains unverified.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
- inferred — The directly changed mutable state belongs to one stream-client instance and its selected device socket. Encoder sharing across viewers and broader tenant or deployment exposure cannot be established without producer and topology evidence.
Trust Boundaries and Controls
- observed — Remote stream messages continue to reach the browser decoder through the existing connection. Before configuration, browser codec support is checked; configuration completion requires current connection and decoder-epoch identity. These checks constrain stale work but do not establish the external producer’s protocol guarantees.
Resilience and Maintainability Implications
- observed — Unsupported Android configuration terminates through fail and stop. Stop is idempotent, clears timers, aborts active controllers, detaches and closes the socket, and invalidates the decoder. Decode errors or queue pressure enter the existing decoder-recovery path.
Hardening Proposals
- proposed — Establish the producer contract for session ordering and codec compatibility across same-size restarts. If decoder-affecting codec changes can occur without dimension changes, use an explicit generation or codec-change signal to invalidate the decoder rather than dimensions alone.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Title check ✅ Passed The title is concise, uses the conventional commit format, and clearly identifies the Android device stream fix. Description check ✅ Passed The description explains the deadlock, identifies the affected components, describes the fix, links the issue, and provides focused test and end-to-end verification results. It does not use every temp… Linked Issues check ✅ Passed The PR implements the coding requirements in [ #12229].stream.tsdecodes the SPS-carrying keyframe after decoder configuration and requests another keyframe only when the pending access unit is not …Out of Scope Changes check ✅ Passed The changed files are limited to Android stream handshake behavior and its automated tests. The changes support [ #12229] by preventing the reset loop and preserving rotation and video-session handling…✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Autopilot is currently an internal CodeRabbit preview.
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Note
Written by
claude-opus-5-5on behalf of MariaHi! We are cleaning up open PRs, and this one appears to have been created with an older model (
opus 5). If this change is really important, we recommend rebuilding the PR with a newer model if possible.maria-rcks closed this
Note
Written by
claude-opus-5-5on behalf of MariaReopening, this was closed by mistake. Sorry for the noise!
maria-rcks reopened this
Closing in favour of #17033, which makes the same change. Thanks for the work here!
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed