Skip to content

fix(agents): exclude sanitized cache-read tool name from tool cache#6485

Open
Diwak4r wants to merge 1 commit into
crewAIInc:mainfrom
Diwak4r:fix/latent-defect
Open

fix(agents): exclude sanitized cache-read tool name from tool cache#6485
Diwak4r wants to merge 1 commit into
crewAIInc:mainfrom
Diwak4r:fix/latent-defect

Conversation

@Diwak4r

@Diwak4r Diwak4r commented Jul 8, 2026

Copy link
Copy Markdown

Summary

The guard in ToolsHandler.on_tool_use that prevents the built-in cache-read tool ("Hit Cache") from being added to the tool cache compared the raw default name "Hit Cache" against the sanitized runtime name "hit_cache". They never match, so the guard was always True and the cache tool's own output was written into the cache — polluting it with dead entries and risking stale values.

Fix

Compare against sanitize_tool_name(CacheTools().name) so the sanitized names align.

Test

Added test_cache_tool_result_is_not_cached to lib/crewai/tests/tools/test_tool_usage.py. FAILS before the fix, PASSES after. Full tests/tools/test_tool_usage.py = 24 passed + new test (5 pre-existing event-bus timing failures are unrelated to this change).

🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.6 noreply@anthropic.com

The exclusion guard compared the raw default name "Hit Cache" against the
sanitized runtime name "hit_cache", so it was always true and the cache
tool's own output was written into the cache. Compare with
sanitize_tool_name(CacheTools().name) instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 8, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c7e8867d-eeb4-4944-a8b9-e2ba0dcb7fed

📥 Commits

Reviewing files that changed from the base of the PR and between 289686a and dfce3c0.

📒 Files selected for processing (2)
  • lib/crewai/src/crewai/agents/tools_handler.py
  • lib/crewai/tests/tools/test_tool_usage.py

📝 Walkthrough

Walkthrough

The on_tool_use method in tools_handler.py now sanitizes the CacheTools name via sanitize_tool_name() before comparing it against the calling tool's name, replacing a direct comparison. A regression test was added verifying the cache tool's own result is not cached.

Changes

Cache Tool Name Sanitization

Layer / File(s) Summary
Sanitized comparison in on_tool_use
lib/crewai/src/crewai/agents/tools_handler.py
Imports sanitize_tool_name and applies it to CacheTools().name before comparing with calling.tool_name to determine caching eligibility.
Regression test for cache tool exclusion
lib/crewai/tests/tools/test_tool_usage.py
Updates imports and adds test_cache_tool_result_is_not_cached to confirm the cache tool's own output is not stored in the cache.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the cache-read tool sanitization fix and its effect on tool caching.
Description check ✅ Passed The description accurately explains the bug, the sanitize_tool_name fix, and the new regression test.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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