Skip to content

fix(harmony): align observation size with the captured viewport - #3408

Merged
quanru merged 2 commits into
web-infra-dev:mainfrom
jiezhnust:fix/harmony-foldable-observation-size
Nov 26, 2026
Merged

quanru merged 2 commits into
web-infra-dev:mainfrom
jiezhnust:fix/harmony-foldable-observation-size

Conversation

@jiezhnust

Copy link
Copy Markdown
Contributor

Problem

On HarmonyOS foldables, RenderService can report the physical panel size while snapshot_display captures the active viewport. commonContextParser calls size() before screenshotBase64(), so updating the size cache during screenshot capture happens too late for the current observation. The first observation, or the first one after folding/rotation, can therefore use an incorrect screenshot-to-device coordinate ratio.

For example, a cached panel size of 2232 x 3184 with an active screenshot of 1008 x 2232 gives an incorrect horizontal ratio of 1008 / 2232; a screenshot x-coordinate of 934 maps to approximately 2068 instead of 934.

Change

  • Capture the active viewport in size(), derive dimensions from the image, and reuse that exact capture for the following screenshotBase64() call.
  • Refresh each observation and invalidate a pending frame when a subsequent HDC interaction occurs or the device is destroyed.
  • Keep internal gesture calculations on getScreenSize() so repeated flings do not introduce a screenshot per iteration.
  • Add regression coverage for the first folded observation, folding/rotation transitions, repeated size requests, intervening actions, standalone captures, and invalid image dimensions.

No public signatures change. A normal size/screenshot observation still captures only once.

Validation

  • pnpm run lint — passed.
  • pnpm exec nx build @midscene/harmony --output-style=static — passed.
  • pnpm --filter @midscene/harmony exec rstest tests/unit-test/device.test.ts — 133 passed.
  • pnpm exec nx test @midscene/harmony --output-style=static — 308 passed (after building the report template required by existing agent tests).
  • Running the four key new size regression tests against the original device implementation reproduces all four failures; they pass with this change.

Validation uses mocked device data; no real-device operations or model requests were run for this PR.

@CLAassistant

CLAassistant commented Nov 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@quanruzhuoxiu

quanruzhuoxiu commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @jiezhnust — thanks for the well-scoped HarmonyOS foldable fix and for adding the regression coverage! Before we can run CI and review it, could you please sign the Contributor License Agreement via the link the CLA assistant posted above? Once it shows as signed, we'll trigger the workflows and take a closer look. The rest looks good from our side (lint/build/tests pass, no public API change).

@quanru quanru left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reading dimensions from the captured JPEG fixes the first-observation viewport mismatch. I found a regression in the standalone Playground preview that needs a change before merge.

  1. Playground requests /interface-info, which calls device.size() and saves frame A.
  2. The user unfolds the device or the app redraws without an HDC command.
  3. Playground requests /screenshot. It receives frame A with a fresh timestamp.

I simulated two distinguishable frames. The same test returned the expanded frame on the base commit and the folded frame on this head. All 133 tests in device.test.ts passed separately.

Could you scope frame reuse to a single observation, keep standalone screenshots fresh, and add this sequence as a regression test? The separate size and screenshot HTTP requests have no shared observation lifetime.

@quanru quanru left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Verified that the expanded viewport and its screenshot are paired in one observation. The separate Playground screenshot request now returns the expanded frame on the HarmonyOS foldable emulator. The previous stale-frame finding is resolved.

@quanru
quanru merged commit 4f77fd1 into web-infra-dev:main Nov 26, 2026
1 check passed
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.

4 participants