Closed Bug 2063328 Opened 3 months ago Closed 3 months ago

[wpt-sync] Sync PR 61915 - WebMCP: Thread execution AbortSignal to tool implementation

Categories

(Testing :: web-platform-tests, task, P4)

task

Tracking

(firefox156 fixed)

RESOLVED FIXED
156 Branch
Tracking Status
firefox156 --- fixed

People

(Reporter: wpt-sync, Unassigned)

References

()

Details

(Whiteboard: [wptsync downstream])

Sync web-platform-tests PR 61915 into mozilla-central (this bug is closed when the sync is complete).

PR: https://github.com/web-platform-tests/wpt/pull/61915
Details from upstream follow.

Dominic Farolino <dom@chromium.org> wrote:

WebMCP: Thread execution AbortSignal to tool implementation

This CL implements abortable WebMCP tools, by introducing a
ToolExecuteCallbackOptions dictionary that is always passed to the
tool execution callback, and always has an AbortSignal that the tool
can use to learn when its tool execution was cancelled.

Backing the AbortSignal that's exposed to the tool's implementation,
is an internal AbortController, and a few IPCs. The flow of aborting
a tool looks like so:

  1. The caller passes an AbortSignal to executeTool().
    • This creates an invocation ID in the caller's renderer, and hands
      it to the browser for storage in the pending executions map.
      (This all happens before this CL.)
  2. The tool owner's ModelContext document creates a new
    AbortController associated with the pending execution ID, and
    passes its signal into the tool execution callback.
  3. Mid-execution, the caller aborts the execution signal.
  4. This sends the CancelRemoteScriptTool() IPC, which requests
    cancellation from ModelContextUserData.
  5. This, and the page user data, send the CancelScriptTool() IPC to
    the owner of the tool.
  6. This enters a refactored ModelContext::CancelTool() which handles
    imperative and declarative tool execution, as well as lifetime edge
    pertaining to tool resolution and unregistration. For declarative
    tools, this just involves invoking the done_callback_ with the
    ScriptToolErrorCode::kToolCancelled code. This flow automatically
    cleans up the pending execution data, leaving nothing else to do.
  7. Finally, the tool owner's ModelContext object looks up the
    AbortController associated with the soon-cancelled execution, and
    aborts it. For imperative tools, this signals to JavaScript that the
    tool has been aborted.

Browser-side changes: The browser-side changes handle routing
cancellation IPCs, tracking target document lifetime, and managing
renderer races:

  • Target document tracking: PendingScriptToolExecution now tracks a
    WeakDocumentPtr target_document alongside document tokens, allowing
    the browser to send CancelScriptTool() IPCs to the target tool
    owner's renderer. This is to avoid having to look up the
    target document from its token.
  • Handles renderer races where, when the browser receives a
    cancellation request, the execution has already completed, or the
    tool was already unregistered, or the target document was destroyed.
  • Cancellation on document teardown
    (CancelPendingScriptToolExecutionsForDocument()):
    • When a document that is the caller of a tool is destroyed, the
      browser forwards a CancelScriptTool() IPC to the tool owner.
    • If the destructing document owns the tool itself, we can't send
      this IPC, since the RFHI's ModelContextUserData has already
      been cleared. This is fine regardless, since the document is
      being destroyed anyways.

Before this CL, there was a quirk that unregistration of a tool would
cancel pending in-flight executions of that tool, thus rejecting the
caller's Promise. The tool would keep running however, because there was
no AbortSignal to let the tool know to stop running.

After this CL, we have the AbortSignal, but we do NOT abort it in this
case. This is because a follow-up CL will fix this quirk altogether, and
NOT cancel pending executions of tools that get unregistered. This will
resolve https://github.com/webmachinelearning/webmcp/issues/218.

Bug: 481899636
Change-Id: I4971bb726e0dcf29e378d5d0bdae5f0e559aee94
Reviewed-on: https://chromium-review.googlesource.com/8025300
WPT-Export-Revision: 7e2fac27353d5bc5f5ccb9b4fe723040a5e63a43

CI Results

Ran 11 Firefox configurations based on mozilla-central, and Firefox, Chrome, and Safari on GitHub CI

Total 57 tests and 2 subtests

Status Summary

Firefox

OK : 13[GitHub] 50[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
PASS : 2[Gecko-linux2204-64-wayland-debug, Gecko-linux2204-64-wayland-opt, GitHub] 4[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
FAIL : 33[GitHub] 101[Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt]
TIMEOUT: 6
ERROR : 2
NOTRUN : 1

Chrome

OK : 12
PASS : 28
FAIL : 4
TIMEOUT: 6
ERROR : 2
NOTRUN : 3

Safari

OK : 13
PASS : 2
FAIL : 33
TIMEOUT: 6
NOTRUN : 1

Links

Gecko CI (Treeherder)
GitHub PR Head
GitHub PR Base

Details

New Tests That Don't Pass

Tests Disabled in Gecko Infrastructure

  • /webmcp/imperative/exposedTo-cross-origin-child.https.html [wpt.fyi]: SKIP [Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt], TIMEOUT [GitHub] (Chrome: OK, Safari: TIMEOUT)
  • /webmcp/imperative/exposedTo-multiple-children.https.html [wpt.fyi]: SKIP [Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt], TIMEOUT [GitHub] (Chrome: OK, Safari: TIMEOUT)
  • /webmcp/imperative/permissions-policy.https.html [wpt.fyi]: SKIP [Gecko-android-em-14-x86_64-debug-geckoview, Gecko-android-em-14-x86_64-lite-opt-geckoview, Gecko-android-em-14-x86_64-opt-geckoview, Gecko-linux2404-64-debug, Gecko-linux2404-64-opt, Gecko-windows11-32-25h2-debug, Gecko-windows11-32-25h2-opt, Gecko-windows11-64-25h2-debug, Gecko-windows11-64-25h2-opt], TIMEOUT [GitHub] (Chrome: OK, Safari: TIMEOUT)
Status: NEW → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 156 Branch
You need to log in before you can comment on or make changes to this bug.