fix: improve thread safety in tool registry#1184
Merged
MervinPraison merged 1 commit intomainfrom Mar 31, 2026
Merged
Conversation
- Use thread-safe registry.unregister() in remove_tool() - Use thread-safe registry.list_tools() in list_tools() - Add double-checked locking to get_registry() singleton - Prevents race conditions in multi-agent deployments Related to #1167 and closed PR #1182 Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
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.
This PR addresses remaining thread safety issues from the original PR #1182 that were NOT covered by the merged PRs #1175 and #1176.
Issues Fixed
1. Thread-unsafe tool registry access π¨
Problem: Module-level functions
remove_tool()andlist_tools()bypassed thread-safe registry methods by directly accessingregistry._toolsandregistry._functionsdictionaries.Solution:
remove_tool()now usesregistry.unregister()(uses internal locking)list_tools()now usesregistry.list_tools()(uses internal locking)2. Missing thread safety in registry singleton
Problem:
get_registry()singleton creation lacked proper double-checked locking for concurrent initialization.Solution: Added double-checked locking pattern with
_registry_lockto prevent race conditions during singleton creation.Code Changes
Testing
Context
This addresses the remaining issues from PR #1182 that were identified by code reviewers (Qodo, CodeRabbit) but not covered by the merged thread safety fixes in PRs #1175 and #1176.
Compliance with AGENTS.md
Fixes remaining issues from #1167
Related to closed PR #1182
π€ Generated with Claude Code