Skip to content

perf(code_execution): cache tools in ExtensionManager#6433

Merged
alexhancock merged 1 commit intoblock:mainfrom
rabi:tool_caching
Jan 12, 2026
Merged

perf(code_execution): cache tools in ExtensionManager#6433
alexhancock merged 1 commit intoblock:mainfrom
rabi:tool_caching

Conversation

@rabi
Copy link
Contributor

@rabi rabi commented Jan 11, 2026

Summary

When code execution is enabled, every execute_code/read_module/search_modules call was fetching tools from ALL MCP servers, causing significant latency.

Changes:

  • Add tools_cache field to ExtensionManager (Arc<Vec> to avoid cloning)
  • Cache is populated on first get_prefixed_tools call
  • Cache is invalidated after extensions are modified
  • Version counter prevents stale cache from concurrent fetch/invalidate races
  • Fix CancellationToken reuse in pagination loop (pre-existing bug)

This reduces the overhead from O(N) network calls per code execution to O(1) after the initial cache population.

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

AI Assistance

  • This PR was created or reviewed with AI assistance

Testing

Unit tests added and locally tested.

…ed MCP calls

When code execution is enabled, every execute_code/read_module/search_modules
call was fetching tools from ALL MCP servers, causing significant latency.

Changes:
- Add tools_cache field to ExtensionManager (Arc<Vec<Tool>> to avoid cloning)
- Cache is populated on first get_prefixed_tools call
- Cache is invalidated after extensions are modified
- Version counter (AtomicU64) prevents stale cache from concurrent fetch/invalidate races
- Fix CancellationToken reuse in pagination loop (pre-existing bug)

This reduces the overhead from O(N) network calls per code execution
to O(1) after the initial cache population.

Signed-off-by: rabi <ramishra@redhat.com>
@rabi
Copy link
Contributor Author

rabi commented Jan 12, 2026

@alexhancock PTAL, I can see good improvement with this when using code mode.

Copy link
Collaborator

@alexhancock alexhancock left a comment

Choose a reason for hiding this comment

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

Nice improvement, thanks!

@alexhancock alexhancock merged commit 1718554 into block:main Jan 12, 2026
17 checks passed
fbalicchia pushed a commit to fbalicchia/goose that referenced this pull request Jan 13, 2026
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.

2 participants