Skip to content

fix: unregister agent tools through an AbortSignal, reuse the anonymous action token - #105

Merged
BatLeDev merged 4 commits into
mainfrom
webmcp-abort-signal
Nov 27, 2026
Merged

BatLeDev merged 4 commits into
mainfrom
webmcp-abort-signal

Conversation

@BatLeDev

Copy link
Copy Markdown
Member

Two issues seen in browser consoles on staging and production, plus generated files leaving git.

  • useAgentTool unregisters through an AbortSignal. Each tool is registered with registerTool(tool, { signal }) and its controller is aborted on scope dispose, instead of calling unregisterTool(), which the WebMCP draft of 2026-04-23 removed. The polyfill and BrowserMcpServer warned on every page, @mcp-b 6.x no longer has the method, and a native modelContext following the draft would throw on unmount. The live tools e2e now checks a real unmount (new close_panel dev tool) and that no deprecation warning is printed.
  • The anonymous action token is reused across page loads. The chat fetched a new token from simple-directory every time it was created, so every full page load of a portal cost one call, even with the chat closed. That endpoint shares a rate limit of 5 calls per minute and per IP with the login routes, and an anonymous visitor browsing a portal quickly got 429s. The token is valid a day and not single-use: it is now kept in localStorage and reused until an hour before its expiry (in memory when storage is unavailable). A kept token the server refuses is forgotten and the hello is retried once with a new one.
  • Generated .type/ files are no longer tracked. .type/ is gitignored, but 19 generated files had been force-added and went stale. CI and the Dockerfile build them.
  • The e2e login fixture is robust (it failed the warm-up about one run in two, the pre-push hook included). It fills the form until both fields hold their values, as the email field's late autofocus could steal the password's typing. It also clears the session cookies before a form login: a login posted over another user's admin-mode session got an exchange token carrying adminMode, and the new user's first keepalive answered 401.

Heads-up: the anonymous chat now keeps its token in the chat frame's localStorage (df-agents-anonymous-action-token), shared by the visitor's tabs.

The WebMCP draft of 2026-04-23 removed modelContext.unregisterTool() in
favor of registerTool(tool, { signal }). The polyfill and BrowserMcpServer
warn on every page that unregisters a tool, @MCP-B 6.x no longer has the
method, and a native modelContext following the draft would throw in
onScopeDispose.

useAgentTool now registers each tool with its own AbortController and
aborts it when the scope is disposed. The registration also stays bound
to the context that received it, even after useFrameServer replaces
navigator.modelContext.

The live tools dev page gets a close_panel tool, so the e2e spec checks
a real unmount: the tool leaves the aggregate and no deprecation warning
is printed.
The chat asked simple-directory for a new anonymous action token every
time it was created, so every full page load of a portal cost one call,
even with the chat closed. That endpoint shares a rate limit of 5 calls
per minute and per IP with the login routes: an anonymous visitor
browsing a portal quickly got 429s.

The token is valid a day and not single-use. It is now kept in
localStorage and reused by later page loads and tabs until an hour
before its expiry, with an in-memory fallback when storage is
unavailable. A kept token the server refuses (a rotated key) is
forgotten and the hello is retried once with a new one.
.type/ is gitignored, but 19 files generated by df-build-types had been
force-added over time. They went stale against their schemas, so every
build-types left a diff to sort out before a commit. CI builds them and
shares them as an artifact, and the Dockerfile runs build-types, so
nothing needs them in git.
Two flakes of the login fixture failed the e2e warm-up about one run in
two, in the pre-push hook too:

- Both fields of simple-directory's login form carry autofocus, and the
  email field's can land late: it took the focus back between the
  password fill's focus and its typing, "passwd" was appended to the
  email and the login waited out the timeout. The fixture now fills
  until both fields hold the expected values.
- A login posted while the context still held another user's admin-mode
  session got an exchange token carrying adminMode: the first keepalive
  of the new, non-admin user answered 401 and the session was deleted
  (the warm-up visits as the superadmin in admin mode, then as another
  user). The fixture now clears the session cookies before a form login.
@github-actions github-actions Bot added the fix label Nov 27, 2026
@BatLeDev
BatLeDev merged commit b6f77c6 into main Nov 27, 2026
7 checks passed
@BatLeDev
BatLeDev deleted the webmcp-abort-signal branch November 27, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant