Repository navigation
Conversation
Rect.__post_init__ returned False when the bounds were inverted, but Python discards a __post_init__ return value. The invalid rectangle was still built and reported a plausible positive area, because both deltas flip sign and the product stays positive. It then entered RectUnionPure and corrupted the paint-order occlusion result instead of failing loudly. Raise ValueError so invalid geometry surfaces at construction. Degenerate zero-area rects stay valid, since collapsed and hidden elements are normal. Closes browser-use#5987
|
|
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
This branch has not been deployed
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 this fixes
Closes #5987
Rect.__post_init__inbrowser_use/dom/serializer/paint_order.pydid:Python discards a
__post_init__return value, so this guard never rejectedanything — an inverted rectangle was constructed and kept.
The failure is quiet rather than obviously wrong: because both deltas flip sign,
area()still returns a positive number.So the rect looks plausible, gets added to
RectUnionPure, and corrupts theocclusion result instead of failing loudly.
The change
Raise
ValueErrorwhen the bounds are inverted, so invalid geometry surfaces atconstruction instead of propagating into the paint-order union.
Degenerate zero-area rects stay valid (
x1 == x2and/ory1 == y2), becausecollapsed and hidden elements are normal on real pages and are already handled
downstream. All existing
Rect(...)construction sites in_split_diffpreservethe ordering by construction, so they are unaffected.
Deliberately not included: the second half of #5987 — filtering
non-positive-dimension nodes before they reach
Rect(...)incalculate_paint_order(). That changes which elements participate in occlusion,so it deserves its own review rather than riding along here.
Validation
Baseline:
c75e8476e26d18b7617643bc2ae082fae8eae431onmain.tests/ci/test_dom_paint_order_serialization.pycoverinverted x, inverted y, both inverted, and assert degenerate/normal rects still
behave as before.
Failed: DID NOT RAISE <class 'ValueError'>, so the tests genuinely gate the fix.uv run pytest tests/ci/test_dom_paint_order_serialization.py→ 5 passeduv run pytest tests/ci/test_dom_visibility.py tests/ci/test_dom_paint_order_serialization.py tests/ci/test_ax_name_matching.py→ 24 passeduv run ruff check→ All checks passeduv run ruff format --check→ 2 files already formattedDisclosure
This patch was prepared with AI assistance. The reproduction, the before/after
regression check, the wider DOM suite and both linters were executed locally, and
the results above are the real output of those runs.
Happy to adjust the approach — in particular whether a hard
ValueErrorispreferred over skipping the node at the
calculate_paint_order()call site.Summary by cubic
Raises
ValueErrorwhenRectis constructed with inverted bounds. The previous guard (return Falsein__post_init__) was discarded by Python, so an inverted rectangle was silently built and, because both deltas flip sign, reported a plausible positive area and corrupted the paint-order occlusion result. Invalid geometry now surfaces at construction.Degenerate zero-area rects (
x1 == x2ory1 == y2) stay valid, since collapsed and hidden elements are normal and handled downstream. AllRect(...)call sites in_split_diffalready preserve bound ordering, and the branch is synced with upstreammain, keeping the change scoped topaint_order.py.Regression tests cover inverted x, inverted y, both inverted, and the degenerate/normal cases.
Written for commit 0843587. Summary will update on new commits.
Follow-up maintenance
Synced the branch with upstream
mainat3df5806a0d097a1546d92c49bcf1b28c9972c3bd. This brings in the upstream Anthropic browser-tool SDK rename that resolves the prior import/type failures while leaving this PR's change scoped tobrowser_use/dom/serializer/paint_order.pyand its regression tests.Validation after the sync:
uv run --no-sync pytest tests/ci/test_dom_paint_order_serialization.py tests/ci/integrations/test_anthropic_browser_use.py -q(16 passed, 1 skipped because the compatible SDK is installed)uv run --no-sync pre-commit run --all-files(passed)