Skip to content

Fix Android playground auto-connect and scrcpy preview race#2285

Merged
quanru merged 3 commits intomainfrom
codex/fix-android-playground-session-and-scrcpy-preview
Apr 7, 2026
Merged

Fix Android playground auto-connect and scrcpy preview race#2285
quanru merged 3 commits intomainfrom
codex/fix-android-playground-session-and-scrcpy-preview

Conversation

@quanru
Copy link
Copy Markdown
Collaborator

@quanru quanru commented Apr 4, 2026

Summary

  • auto-create the Android playground session when exactly one ADB device is available
  • refresh playground runtime state immediately after session create/destroy so the UI no longer waits for the polling interval
  • subscribe to the scrcpy video stream before requesting device connection to avoid dropping the initial configuration packet
  • add regression tests for single-device auto-connect and scrcpy packet buffering order

Root cause

  • the Android playground always exposed a required device selector, even when discovery found only one valid target
  • the scrcpy preview attached its video-data listener after video-metadata, so the first configuration packet could be missed and the decoder could stay stuck on the loading state until a full refresh

Impact

  • users with a single connected Android device can enter the playground directly without an unnecessary selection step
  • scrcpy preview initialization is more reliable after selecting or creating a device session
  • the new tests protect the preview stream ordering behavior from regressions

Validation

  • pnpm run lint
  • cd packages/playground-app && ../playground/node_modules/.bin/vitest run -c vitest.config.ts
  • cd packages/android-playground && ../android/node_modules/.bin/vitest run -c vitest.config.ts
  • npx nx build @midscene/playground
  • npx nx build @midscene/android-playground

Notes

  • packages/playground-app still has existing upstream build/type issues unrelated to this change, so I validated the affected app package with package-local tests instead of a full workspace build for that target.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 4, 2026

Deploying midscene with  Cloudflare Pages  Cloudflare Pages

Latest commit: 38a37b1
Status: ✅  Deploy successful!
Preview URL: https://ee3f742c.midscene.pages.dev
Branch Preview URL: https://codex-fix-android-playground.midscene.pages.dev

View logs

Produce ScrcpyMediaStreamPacket from @yume-chan/scrcpy directly so
videoStream.pipeTo(decoder.writable) type-checks during declaration
file generation.
@quanru quanru changed the title [codex] Fix Android playground auto-connect and scrcpy preview race Fix Android playground auto-connect and scrcpy preview race Apr 7, 2026
@quanru quanru marked this pull request as ready for review April 7, 2026 03:05
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 07eee6c160

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +384 to +385
if (!created) {
autoCreateSignatureRef.current = null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent infinite auto-create retries after session create failure

When createSession(autoCreateInput, { silent: true }) fails, this branch clears autoCreateSignatureRef, so the next render recomputes the same signature and immediately retries again. In a persistent failure case (e.g., stale/unauthorized device), the effect loops indefinitely, repeatedly hitting createSession and surfacing error toasts, which can flood both the backend and UI until the user refreshes or manually disables auto-create.

Useful? React with 👍 / 👎.

- Rename the keyframe field read from the raw socket payload to
  keyFrame so it matches what the android-playground server actually
  emits; the flag now reaches the decoder instead of being silently
  dropped.
- Drop the wall-clock-derived pts: BigInt(Date.now()) on data packets.
  The scrcpy decoder expects a device PTS in microseconds, so feeding
  it millisecond wall-clock values was semantically wrong. With no
  reliable source, leave pts undefined and let the decoder render in
  arrival order, matching the pre-existing behaviour.
- Remove the now-unused timestamp field from RawScrcpyVideoPacket.
- Add a vitest script and devDependency to @midscene/playground-app so
  the previously orphaned tests/ directory actually runs, and extend
  scrcpy-stream.test.ts with coverage for keyFrame propagation and the
  pts-is-undefined contract.
@quanru quanru merged commit 07c4bbe into main Apr 7, 2026
9 checks passed
@quanru quanru deleted the codex/fix-android-playground-session-and-scrcpy-preview branch April 7, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants