Skip to content

Add ToolActivatedEvent and ToolCancelEvent - #7

Merged
beaufortfrancois merged 2 commits into
mainfrom
fbeaufort/tool-lifecycle-events
Nov 12, 2026
Merged

beaufortfrancois merged 2 commits into
mainfrom
fbeaufort/tool-lifecycle-events

Conversation

@beaufortfrancois

@beaufortfrancois beaufortfrancois commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Implements webmachinelearning/webmcp#245, with the event timing from webmachinelearning/webmcp#371.

Rebased onto main (after #12). #9 is based on this branch and needs a rebase.

Changes

  • Define ToolActivatedEvent and ToolCancelEvent (src/events.ts) and install them as globals alongside ModelContext.
  • Add ontoolactivated and ontoolcancel to ModelContext, sharing the existing event handler code with ontoolchange.
  • Dispatch toolactivated at the ModelContext of the document that owns the tool, right after the execute callback is invoked (webmcp#371). If the callback detaches that document, DOM's inner invoke skips the listeners, with no extra check.
  • Dispatch toolcancel when a caller aborts a callback that has started and not settled.
  • Bump webmcp-types to ^0.1.10, which declares the new interfaces.
  • New real-browser tests:
    • constructors and Web IDL conversion;
    • handler semantics;
    • event order on cancellation (callback, toolactivated, rejection, signal abort, toolcancel);
    • no events for calls that never start or have already settled;
    • events fire in the frame that owns the tool;
    • no toolactivated after the callback detaches its document.

Revisions

  • Draft: checked against eada13b (the pin on main). Lifecycle event timing follows f2f2ae2 (webmcp#371). The other draft changes since eada13b (#345, #347, #254) are not reviewed here.
  • WPT: fe52996 (unchanged).
  • Types: [email protected].

Results

  • Browser tests: 253 passed (Playwright Chromium, Firefox, WebKit, plus native Chromium). pnpm test:package passed.

  • WPT in Chrome Canary 159.0.8153.0: 70 files, 190 subtests, zero unexpected results.

    Subtest result Count
    PASS 112
    Expected FAIL 37
    Expected TIMEOUT 25
    Expected NOTRUN 16

    Files: 44 OK, 25 expected timeouts, 1 expected error.

  • Firefox WPT could not be validated locally:

    • Nightly 162.0a1 (20261110053316) cannot load the WPT runner page (netReset);
    • Firefox 159.0.1 hits harness crashes in 7 files, none of them lifecycle-event tests.

    Firefox and Safari results come from CI.

Newly passing:

  • all 38 IDL checks (idlharness expectations deleted);
  • all of tool-activated-event (expectations deleted);
  • the ToolCancelEvent constructor and synthetic-event cases;
  • imperative/executeTool-abort: "caller abort propagates…" and "already-aborted … synchronously rejects".

Expected failures

  • imperative/executeTool-events:
    • The first case asserts isTrusted, which cannot be true for script-dispatched events.
    • The other two cases use /common/blank.html frames, which do not load the polyfill.
  • Two cases abort synchronously after executeTool(): imperative/executeTool-abort, "promise remains rejected…" (TIMEOUT), and tool-cancel-event, "ontoolcancel is invoked…" (TIMEOUT). The polyfill rejects before dispatching to the callback (the existing "Timing" limitation), so the callback never starts and no toolcancel fires.

Excluded

Declarative forms and CSS states remain unimplemented. Crashtests and non-testharness files are outside the suite.

This is not full conformance.

@beaufortfrancois
beaufortfrancois marked this pull request as draft October 1, 2026 09:21
Base automatically changed from fbeaufort/remove-origin-keyed-requirement to main October 2, 2026 06:29
@tidoust

tidoust commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

PR prepared before transition to the w3c-oss organization. Adding a comment to trigger the CLA checker...

Follow webmachinelearning/webmcp#245: define the ToolActivatedEvent and
ToolCancelEvent interfaces, add the ontoolactivated and ontoolcancel
handlers to ModelContext, and dispatch the events at the ModelContext of
the document that owns the tool. Bump webmcp-types to 0.1.10 for the
declarations.

Follow webmachinelearning/webmcp#371 (draft f2f2ae2) for timing:
toolactivated fires after the execute callback is invoked, so listeners
observe its synchronous effects. If the callback detaches its document,
DOM's inner invoke skips the listeners. toolcancel fires when a caller
aborts a callback that has started and not settled.

All pinned IDL checks, the ToolActivatedEvent tests, and executeTool-abort's
caller-abort case now pass. Record the remaining expected failures:
isTrusted is false for script-dispatched events, blank.html frames have no
polyfill, and aborting before dispatch skips the callback.

Validation: 253 browser tests and packed consumer checks pass. WPT in
Chrome Canary 159.0.8153.0: 70 files, 190 subtests, zero unexpected
results.
@beaufortfrancois
beaufortfrancois force-pushed the fbeaufort/tool-lifecycle-events branch from 3562689 to 670c319 Compare November 10, 2026 09:46
@beaufortfrancois
beaufortfrancois marked this pull request as ready for review November 10, 2026 10:18
@beaufortfrancois

Copy link
Copy Markdown
Collaborator Author

@MiguelsPizza Please review

Comment thread src/events.ts Resolved
Comment thread src/index.ts
// The draft fires toolactivated after invoking the callback, so listeners observe its
// synchronous effects. If the callback detached this document, DOM's inner invoke skips
// every listener because the context's relevant global is no longer fully active.
// Listener exceptions are reported, not thrown.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good comment thanks for explaining!

@MiguelsPizza

Copy link
Copy Markdown
Collaborator

LGTM with license fix

@beaufortfrancois
beaufortfrancois merged commit b422c5a into main Nov 12, 2026
5 checks passed
@beaufortfrancois
beaufortfrancois deleted the fbeaufort/tool-lifecycle-events branch November 12, 2026 09:08
@beaufortfrancois

Copy link
Copy Markdown
Collaborator Author

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.

3 participants