Repository navigation
Fix inactive document unregistration's notification algorithm - #345
Merged
Merged
Conversation
beckysiegel
pushed a commit
to chromium/chromium
that referenced
this pull request
Oct 14, 2026
`ModelContext::UnregisterTool()` always sends `UnregisterScriptTool()`
to the browser. But once a document is inactive, e.g., after its iframe
is removed, its `model_context_host_remote_` (a `HeapMojoRemote`) has
been reset as part of its execution context being destroyed, and calling
a method on an unbound remote crashes the renderer.
This is reachable from script, by aborting an imperative tool's
`AbortSignal` after the registering document has become inactive, e.g.,
after its iframe is removed:
const controller = new AbortController();
await iframe.contentDocument.modelContext.registerTool(
{...}, {signal: controller.signal});
iframe.remove();
controller.abort(); // Crash.
This CL still removes the tool from `ModelContext`'s own state, but only
notifies the browser when the document is active. An inactive document
has no browser host to notify: frameless documents never bind one, and
the document of a removed frame becomes inactive before its execution
context is destroyed. This matches the `IsActive()` checks that
`registerTool()` and `executeTool()` already perform.
See webmachinelearning/webmcp#345.
R=beaufort.francois@gmail.com
Bug: 573454028
Change-Id: If36db9f87aaa750561c1368b9b20e0a5a974b423
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8578418
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1718966}
khushalsagar
approved these changes
Oct 14, 2026
Collaborator
Author
|
Welcome back @khushalsagar! |
github-actions Bot
added a commit
that referenced
this pull request
Oct 14, 2026
SHA: 1636b33 Reason: push, by domfarolino Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
chromium-wpt-export-bot
pushed a commit
to web-platform-tests/wpt
that referenced
this pull request
Oct 14, 2026
`ModelContext::UnregisterTool()` always sends `UnregisterScriptTool()`
to the browser. But once a document is inactive, e.g., after its iframe
is removed, its `model_context_host_remote_` (a `HeapMojoRemote`) has
been reset as part of its execution context being destroyed, and calling
a method on an unbound remote crashes the renderer.
This is reachable from script, by aborting an imperative tool's
`AbortSignal` after the registering document has become inactive, e.g.,
after its iframe is removed:
const controller = new AbortController();
await iframe.contentDocument.modelContext.registerTool(
{...}, {signal: controller.signal});
iframe.remove();
controller.abort(); // Crash.
This CL still removes the tool from `ModelContext`'s own state, but only
notifies the browser when the document is active. An inactive document
has no browser host to notify: frameless documents never bind one, and
the document of a removed frame becomes inactive before its execution
context is destroyed. This matches the `IsActive()` checks that
`registerTool()` and `executeTool()` already perform.
See webmachinelearning/webmcp#345.
R=beaufort.francois@gmail.com
Bug: 573454028
Change-Id: If36db9f87aaa750561c1368b9b20e0a5a974b423
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8578418
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1718966}
beckysiegel
pushed a commit
to chromium/chromium
that referenced
this pull request
Oct 15, 2026
`ModelContext::registerTool()` checks that its document is active up
front, but then serializes `inputSchema`, which can run script via a
`toJSON()` method. If that script makes the document inactive, e.g., by
removing its iframe, `registerTool()` carries on and dereferences the
document's now-null frame (and would then call into its reset
`ModelContextHost` remote), crashing the renderer:
iframe.contentDocument.modelContext.registerTool({
name: 'tool',
description: 'desc',
inputSchema: {toJSON() { iframe.remove(); return {}; }},
execute: () => {},
}); // Crash.
This CL checks again after serialization, and rejects with the same
`InvalidStateError` as the up-front check. This matches the re-check
added to the spec in
webmachinelearning/webmcp#345.
R=khushalsagar
Bug: 573671121
Change-Id: I9afb20dfa0d23d6aa54d34b568e17461b88d39db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8582224
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1719223}
chromium-wpt-export-bot
pushed a commit
to web-platform-tests/wpt
that referenced
this pull request
Oct 15, 2026
`ModelContext::registerTool()` checks that its document is active up
front, but then serializes `inputSchema`, which can run script via a
`toJSON()` method. If that script makes the document inactive, e.g., by
removing its iframe, `registerTool()` carries on and dereferences the
document's now-null frame (and would then call into its reset
`ModelContextHost` remote), crashing the renderer:
iframe.contentDocument.modelContext.registerTool({
name: 'tool',
description: 'desc',
inputSchema: {toJSON() { iframe.remove(); return {}; }},
execute: () => {},
}); // Crash.
This CL checks again after serialization, and rejects with the same
`InvalidStateError` as the up-front check. This matches the re-check
added to the spec in
webmachinelearning/webmcp#345.
R=khushalsagar
Bug: 573671121
Change-Id: I9afb20dfa0d23d6aa54d34b568e17461b88d39db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8582224
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1719223}
chromium-wpt-export-bot
pushed a commit
to web-platform-tests/wpt
that referenced
this pull request
Oct 15, 2026
`ModelContext::registerTool()` checks that its document is active up
front, but then serializes `inputSchema`, which can run script via a
`toJSON()` method. If that script makes the document inactive, e.g., by
removing its iframe, `registerTool()` carries on and dereferences the
document's now-null frame (and would then call into its reset
`ModelContextHost` remote), crashing the renderer:
iframe.contentDocument.modelContext.registerTool({
name: 'tool',
description: 'desc',
inputSchema: {toJSON() { iframe.remove(); return {}; }},
execute: () => {},
}); // Crash.
This CL checks again after serialization, and rejects with the same
`InvalidStateError` as the up-front check. This matches the re-check
added to the spec in
webmachinelearning/webmcp#345.
R=khushalsagar
Bug: 573671121
Change-Id: I9afb20dfa0d23d6aa54d34b568e17461b88d39db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/8582224
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Commit-Queue: Dominic Farolino <dom@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1719223}
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.
See https://crrev.com/c/8578418 and https://crrev.com/c/8582224 for tests. After this CL, unregistration of an individual tool in an inactive document no longer attempts to notify all other documents in the frame that the tool has been unregistered.
Note that we may want to consider notifying all other documents that the set of tools have changed, when a tool-owning document gets removed and becomes inactive. That's besides this CL, and is being explored in https://crbug.com/508285989, but I'll hold off on filing a spec issue for that specifically, since the story/need for that may change given the changes that we'll make to satisfy #236.
Preview | Diff