Skip to content

fix: clear stale client-side tools on page navigation#43

Merged
masudahiroto merged 2 commits intomainfrom
masudahiroto/fix-tool-leak-on-navigation
Mar 19, 2026
Merged

fix: clear stale client-side tools on page navigation#43
masudahiroto merged 2 commits intomainfrom
masudahiroto/fix-tool-leak-on-navigation

Conversation

@masudahiroto
Copy link
Copy Markdown
Contributor

This is a bug fix PR. When a user visits a page that registers client-side tools and then navigates to another page that has no tools, useAI does not process the unregister call, so the tools from the previous page remain in the agent's tool list. When the agent invokes one of those stale tools, the client-side browser cannot resolve it, causing the AI process to hang indefinitely.

🤖 Generated with Claude Code

When components registering tools unmount during navigation, the tools
were removed from the local registry but not cleared from UseAIClient.
This caused the AI to call stale tools whose handlers no longer exist,
resulting in an infinite "thinking" hang.

Handle the hasTools=false transition by calling client.registerTools([])
to clear stale tools from the client instance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@masudahiroto masudahiroto marked this pull request as ready for review March 17, 2026 04:41
@masudahiroto masudahiroto merged commit 648f0bc into main Mar 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants