Repository navigation
fix(window): tolerate DIP rounding in bsk window resize - #775
Merged
Merged
Conversation
Why: At a fractional display scale (Windows 10 22H2 at 125%), `chrome.windows.get` reports the outer window one DIP larger than requested on each axis because Windows round-trips `chrome.windows.update`'s DIP request through device pixels (1100x700 -> 1101x701). `handleWindowResize` verified the result with exact equality in two places, so that rounding was indistinguishable from a real window-manager constraint: every resize first burned the full 21 x 50 ms settling budget and then reported `protocol_error` / `window_resize_constrained` / exit code 2 even though `effect_state` was `committed` (Tencent#771). What: - Add `WINDOW_ROUNDING_TOLERANCE_DIP = 2` and a `withinRounding(actual, requested)` helper for window bounds. - Accept the resize when both axes land within that tolerance, both in the settling loop (a rounding-only resize returns immediately instead of dead-waiting ~1 s) and in the constrained branch (a DPI-rounded window is no longer mislabelled as constrained; it falls through to the accurate `window_resize_viewport_unchanged` diagnosis). - Reuse the constant as the floor of `viewportFollowed`'s window-bounds epsilon, which already encoded "2 px of DIP rounding". 2 px fixed rather than scaled: the DIP round-trip error is bounded by half a device pixel, i.e. <= ~1.5 DIP at any scale >= 100%, so it does not grow with the DPI factor, while a percentage tolerance would grow with the window (1% of 1400 px = 14 px) and swallow real work-area constraints. The extension cannot read the OS scale factor either (no `system.display` permission). Unchanged on purpose: `effect_state: "committed"` still accompanies a genuine `window_resize_constrained` (same message, same exit code), the `unconfirmed` retry guard still compares exact sizes, and the Tencent#559 `window_resize_viewport_unchanged` guard is untouched. Tests: - `apps/extension/src/tools/__tests__/window.test.ts`: +9 cases covering exact / +1,+1 / -1,-1 / +2,-2 acceptance (asserting the settling budget is not spent), +40,+40 / -40,0 / 0,+12 still constrained, rounding-with-frozen-viewport reporting `window_resize_viewport_unchanged`, and a rejected `windows.update` never becoming success. 46/46 pass (4 were red before the fix). - Full extension unit suite: 4110 passed / 1 failed / 8 skipped, versus 4101 passed / 1 failed / 8 skipped on the untouched baseline (+9 tests, same failure); the failure is the sandbox's `spawnSync ... EPERM` in `human-loop.test.ts`. - `tsc --noEmit` clean; `biome check` clean on the changed files. Docs: bilingual CHANGELOG entries and the agent-facing resize paragraph in `crates/bsk-cli/skill/references/interaction-details.md`. Fixes Tencent#771
Why: After accepting 2 px DIP rounding in handleWindowResize, keeping exact sameSize() comparisons in the unconfirmed-retry guard allowed a second identical resize request on a frozen viewport under fractional scaling (e.g. requesting 1100x710 while the browser reports 1101x711) to bypass the guard, clear unconfirmed via viewportFollowed(), and return false success. The same mismatch occurred when a post-resize read failed after windows.update committed DPI-rounded bounds (previousFailure.window held the exact requested size while beforeWindow on retry held the rounded bounds). What: - Compare beforeWindow against both requested and previousFailure.window with withinRounding() in the unconfirmed retry guard while keeping exact sameSize() for viewport comparison. - Add regression tests in window.test.ts covering repeated identical resizes and failed post-resize reads with DPI-rounded bounds and a frozen viewport. - Align CHANGELOG.zh-CN.md with the 2 px DIP rounding tolerance.
NianJiuZst
reviewed
Nov 19, 2026
NianJiuZst
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the thorough investigation and clean fix for #771 — using a fixed 2 DIP tolerance (WINDOW_ROUNDING_TOLERANCE_DIP) shared with viewportFollowed is the right rule here, avoiding the 1s settling penalty on fractional scaling without hiding genuine window-manager constraints.
During review, I caught one subtle interaction with the unconfirmed retry guard and pushed a small follow-up commit (f866dec3) directly to this branch:
- Preserve the
unconfirmedretry guard under DIP rounding (apps/extension/src/tools/window.ts): Previously, thepreviousFailurecheck still used exactsameSize(beforeWindow, requested)andsameSize(previousFailure.window, beforeWindow). When a viewport is frozen under fractional scaling (e.g. requesting1100x710while Windows commits1101x711), the first call accurately returnedwindow_resize_viewport_unchanged, but an immediate retry of1100x710bypassed the guard, clearedunconfirmedviaviewportFollowed(), and reported a false success. The same mismatch also occurred when a post-resize read failed (window_resize_unconfirmed) afterwindows.updatecommitted rounded bounds. Switched both window-bounds checks in that guard towithinRounding()while keeping exactsameSize()for the viewport comparison. - Regression coverage (
apps/extension/src/tools/__tests__/window.test.ts): Added tests covering repeated identical resizes and failed post-resize reads with DPI-rounded bounds and a frozen viewport (plus recovery once the viewport updates). - Changelog wording (
CHANGELOG.zh-CN.md): Aligned the Chinese entry to reflect the 2 px DIP rounding tolerance to match the code andCHANGELOG.md.
Verified locally with window.test.ts (47/47), real-Chrome window.browser.test.ts (1/1), tsc --noEmit, pnpm lint, and scripts/check-changelog-sync.py. Ready to merge once CI finishes green!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
bsk window resizenow accepts a committed resize whose reported bounds are within 2 DIP of the request on each axis, instead of requiring exact equality.Fixes #771.
Why it failed
apps/extension/src/tools/window.ts(handleWindowResize) verified the resize with exact DIP equality in two places: the success condition of the 21 × 50 ms settling loop, and thewindow_resize_constrainedbranch that producesWindow resize requested … but the browser reports ….Windows stores a window rect in device pixels while
chrome.windows.updatetakes DIP, so at a fractional display scale the DIP → physical → DIP round-trip lands 1 DIP off per axis (Windows 10 at 125%:1100x700→1101x701). Exact equality cannot tell that rounding apart from a real window-manager constraint, so every such resize burned the full settling budget (~1 s, 21 reads) and then reportedprotocol_error/window_resize_constrained/ exit 2 for a resize the browser had already committed.The rule
Fixed 2 DIP per axis (
WINDOW_ROUNDING_TOLERANCE_DIP), deliberately not a percentage:viewportFollowed(Math.max(2, zoom)), so the constant now has a single home and the two comparisons agree.Page zoom stays out of this comparison — it moves CSS viewports, not DIP bounds.
effect_state: "committed", the error message, theunconfirmedsettling guard and thewindow_resize_viewport_unchangedcheck are unchanged; a genuinely constrained window still reports the same reason.Verification
window.test.ts: 37 passing before → 4 failing / 42 passing with the new tests against the unpatched code → 46/46 passing after the fix.human-loop"bounds dangerous URL regex checks in a child process",spawnSync … EPERM) reproduces on the baseline and is environmental.tsc --noEmitclean;biome checkclean on both changed files.New cases cover: exact match, ±1 and ±2 DIP (accepted, without spending the settling budget), and 12/40 px deltas (still
window_resize_constrained, message and payload unchanged), plus a rounding-sized resize with a stale viewport still reportingwindow_resize_viewport_unchanged.Second observation in the issue (not fixed here)
The reporter also noted
data.actual_viewportstaying at1178x702across resizes. That value is geometrically impossible for a 1101×701 window — it matches the session-start viewport — so it is stale by at least one generation, below this handler (it re-readsPage.getLayoutMetricsevery poll). In-extension candidates are a pinnedemulatedevice-metrics override (resize deliberately does not clear it), a throttled/occluded unfocused Agent Window, or a wedged renderer.Worth flagging plainly: if the reporter's viewport really is frozen, this change moves their error from
window_resize_constrained(wrong) towindow_resize_viewport_unchanged(accurate) rather than to success. Weakening that guard would hide the second bug and drop the existing browser regression, so it is out of scope here — happy to follow up separately if you want the staleness chased down.Scope
apps/extension/src/tools/window.ts, its test file, both changelogs (the repo requires them updated in the same PR), and thewindow resizeparagraph incrates/bsk-cli/skill/references/interaction-details.md. No protocol, CLI surface or message-shape changes.