Skip to content

rework webdriver deserialization to avoid false-positive cycle error - #36908

Merged
jdm merged 2 commits into
servo:mainfrom
yezhizhen:fix-webdriver-deserialize
May 8, 2025
Merged

jdm merged 2 commits into
servo:mainfrom
yezhizhen:fix-webdriver-deserialize

Conversation

@yezhizhen

Copy link
Copy Markdown
Member
  1. Avoid false-positive cycle error when deserilizing
  • Only detect cycle for Objects
  • Remove last element of seen when success
  1. Cite spec

Testing: ./mach test-wpt --product servodriver -r tests\wpt\tests\webdriver\tests\classic\element_click\events.py
Fixes: #36890
cc @jdm @xiaochengh

@yezhizhen
yezhizhen requested a review from gterzian as a code owner May 8, 2025 07:08
@yezhizhen

yezhizhen commented May 8, 2025 •

Copy link
Copy Markdown
Member Author

./mach test-wpt --product servodriver -r tests\wpt\tests\webdriver\tests\classic\element_click\events.py can pass occasionally now, and never throws exception when deserializing.

To make it always pass, need to solve synchronizatoin issue.

@yezhizhen

yezhizhen commented May 8, 2025 •

Copy link
Copy Markdown
Member Author

Another thing baffling me right now is the following: sometimes the first mousemove won't occur..
image

But they are all MouseEvent and should follow the same route tho. #35685 (comment)
cc @longvatrong111

Comment thread components/script/webdriver_handlers.rs Outdated
Comment on lines +357 to +360
match jsval_to_webdriver_inner(cx, global_scope, value.handle(), seen) {
Ok(converted_item) => Ok(converted_item),
err @ Err(_) => return err,
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

https://github.com/servo/servo/actions/runs/14900760667/job/41852004184?pr=36908

error: this match expression is unnecessary
   --> components/script/webdriver_handlers.rs:357:17
    |
357 | /                 match jsval_to_webdriver_inner(cx, global_scope, value.handle(), seen) {
358 | |                     Ok(converted_item) => Ok(converted_item),
359 | |                     err @ Err(_) => return err,
360 | |                 }
    | |_________________^ help: replace it with: `jsval_to_webdriver_inner(cx, global_scope, value.handle(), seen)`

I think Clippy has bugs... The suggested way has totally different logic. With its suggestion, Step 5 would be run even with failure..
To get around it, I am thinking about

Suggested change
match jsval_to_webdriver_inner(cx, global_scope, value.handle(), seen) {
Ok(converted_item) => Ok(converted_item),
err @ Err(_) => return err,
}
Ok(jsval_to_webdriver_inner(cx, global_scope, value.handle(), seen)?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer this replacement over the match.

Comment thread components/script/webdriver_handlers.rs Outdated
Comment on lines +357 to +360
match jsval_to_webdriver_inner(cx, global_scope, value.handle(), seen) {
Ok(converted_item) => Ok(converted_item),
err @ Err(_) => return err,
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I prefer this replacement over the match.

Comment thread components/script/webdriver_handlers.rs Resolved
Comment thread components/script/webdriver_handlers.rs Resolved
Comment thread components/script/webdriver_handlers.rs Resolved
Comment thread components/script/webdriver_handlers.rs Resolved
@yezhizhen

yezhizhen commented May 8, 2025 •

Copy link
Copy Markdown
Member Author

Should I also update potentially affected wpt-test results like #36744? Even tho it is not in CI yet.

@jdm

jdm commented May 8, 2025

Copy link
Copy Markdown
Member

Yes please!

@yezhizhen
yezhizhen force-pushed the fix-webdriver-deserialize branch from b979208 to fdbfe57 Compare May 8, 2025 13:20
@yezhizhen
yezhizhen requested a review from jdm May 8, 2025 13:21
@yezhizhen
yezhizhen force-pushed the fix-webdriver-deserialize branch from fdbfe57 to 381ae60 Compare May 8, 2025 13:23
@jdm
jdm enabled auto-merge May 8, 2025 13:33
@jdm
jdm added this pull request to the merge queue May 8, 2025
Merged via the queue into servo:main with commit f58b0c6 May 8, 2025
@yezhizhen
yezhizhen deleted the fix-webdriver-deserialize branch May 8, 2025 14:34
@yezhizhen

yezhizhen commented May 9, 2025 •

Copy link
Copy Markdown
Member Author

Another thing baffling me right now is the following: sometimes the first mousemove won't occur.. image

But they are all MouseEvent and should follow the same route tho. #35685 (comment)

I think I finally know why this happens! The hit-test is unstable, and sometimes has length $0$ instead of $1$.

let results =
self.webrender_api
.hit_test(self.webrender_document, pipeline_id, world_point, flags);

And this can happen for any input event here: So there are $2^3$ possible outcomes. (Click event is determined by first 3)
E.g., image

So #36676 is due to two reasons:

  1. execute_script is executed before input events, due to shorter routes Webdriver mouse events can be processed out of order with other webdriver commands #35685 and Webdriver mouse events can be processed out of order with other webdriver commands #35685 (comment)
  2. Unstable hit test

As for why the hit test is unstable, I have not checked yet.

@yezhizhen

yezhizhen commented May 12, 2025 •

Copy link
Copy Markdown
Member Author

I think I finally know why this happens! The hit-test is unstable, and sometimes has length 0 instead of 1 .

let results =
self.webrender_api
.hit_test(self.webrender_document, pipeline_id, world_point, flags);

Correction:
Above accounts for only 90% of hit test failure. Sometimes this part is correct, but

// If the epoch in the tag does not match the current epoch of the pipeline,
// then the hit test is against an old version of the display list and we
// should ignore this hit test for now.
match details.most_recent_display_list_epoch {
Some(epoch) if epoch.as_u16() == item.tag.1 => {},
_ => return None,
}

has unmatched epoch with a low probability. This part is same as #35788 (comment)

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.

get_events (aka. allEvents.events) of WebDriver test throws exception

2 participants