[BUG] Filtered @before_*/@after_* hook decorators cannot be unregistered via unregister_*_hook
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 30/100
Hướng nghiên cứu
Start in lib/crewai/src/crewai/hooks/decorators.py at _create_hook_decorator, where the filtered_hook wrapper is registered but never linked back to the returned function. Compare with on and unregister in lib/crewai/src/crewai/hooks/dispatch.py, then check the four unregister_*_hook helpers in tool_hooks.py and llm_hooks.py. Done means the unregister calls return True and the registry is empty after the reproduction snippet. A linked pull request (#9683) is already open, so check it before starting.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
When registering a global hook using any of the filtered hook decorators (@before_tool_call(tools=...), @after_tool_call(tools=...), @before_llm_call(agents=...), or @after_llm_call(agents=...)), _create_hook_decorator (lib/crewai/src/crewai/hooks/decorators.py:54-75) registers the internal filtered_hook wrapper while returning the original function f.
Unlike @on(...) in lib/crewai/src/crewai/hooks/dispatch.py:406 (which stores func._registered_hook = hook and resolves it in dispatch.unregister), _create_hook_decorator does not attach _registered_hook, and all four unregister_*_hook helpers in tool_hooks.py and llm_hooks.py call .remove(hook) directly. As a result, calling unregister_before_tool_call_hook(fn) (or the other three unregister functions) always returns False and leaks the hook in the global registry.
Steps to Reproduce
- Decorate a top-level function with
@before_tool_call(tools=["delete_file"])(or@after_tool_call,@before_llm_call(agents=...),@after_llm_call(agents=...)). - Call
unregister_before_tool_call_hook(my_hook)(or the matchingunregister_*_hookhelper). - Observe that it returns
Falseandget_before_tool_call_hooks()still contains the wrapper hook.
Expected behavior
Calling unregister_before_tool_call_hook, unregister_after_tool_call_hook, unregister_before_llm_call_hook, or unregister_after_llm_call_hook with a function decorated by the corresponding filtered @before_*/@after_* decorator should remove the registered wrapper and return True, matching dispatch.unregister behavior for @on(...).
Screenshots/Code snippets
from crewai.hooks.decorators import before_tool_call
from crewai.hooks.tool_hooks import (
clear_all_tool_call_hooks,
get_before_tool_call_hooks,
unregister_before_tool_call_hook,
)
clear_all_tool_call_hooks()
@before_tool_call(tools=["delete_file"])
def guard_delete(context):
return False
removed = unregister_before_tool_call_hook(guard_delete)
print("removed:", removed, "remaining:", len(get_before_tool_call_hooks()))
Actual: removed: False remaining: 1
Expected: removed: True remaining: 0
Operating System
macOS Sonoma
Python Version
3.12
crewAI Version
1.15.44 (main 6ecb87390)
crewAI Tools Version
N/A
Virtual Environment
Venv
Evidence
lib/crewai/src/crewai/hooks/decorators.py:54-75: registersfiltered_hookand returnsfwithout storingf._registered_hook = filtered_hook.lib/crewai/src/crewai/hooks/tool_hooks.py:298-347andlib/crewai/src/crewai/hooks/llm_hooks.py:313-362:unregister_*_hookcalls.remove(hook)directly instead of delegating tocrewai.hooks.dispatch.unregister.- Running the snippet above prints
removed: False remaining: 1.
Possible Solution
Store f._registered_hook = filtered_hook in _create_hook_decorator when registering a filtered global hook (mirroring dispatch.on), and delegate unregister_before_tool_call_hook, unregister_after_tool_call_hook, unregister_before_llm_call_hook, and unregister_after_llm_call_hook to crewai.hooks.dispatch.unregister.
Additional context
I have a minimal fix with regression tests ready and will open a linked PR. AI assistance was used in preparing this report (llm-generated).
- Ngôn ngữ chính
- Python
- Star
- 61.2k
- Fork
- 9.2k
- Merge trung bình
- 1 ngày 14 giờ
- Pull request đã merge (30 ngày)
- 180
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của crewAIInc/crewAI
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[FEATURE] Add Straitly as a native OpenAI-compatible LLM providerCó thể đã có người làm @HashimSyedUBC đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Native OpenAI sync streaming with response_model returns an empty string and emits no completed event when the parse is missingCó thể đã có người làm @basil-k-aji-dev đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] Native Azure provider ignores the seed settingCó thể đã có người làm @basil-k-aji-dev đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
crewAIInc/crewAI#9787 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] LiteLLM path reports 0 cached and reasoning tokens in the usage summaryCó thể đã có người làm @basil-k-aji-dev đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của crewAIInc/crewAI
Issue tương tự
-
[BUG] SMTP listener now binds to EMAIL_PORT instead of 2525 since the gunicorn switch 5.0.3-ls373Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
linuxserver/docker-healthchecks#137 · 1 bình luận ·
-
RequirementAgent treats list -> add -> list as a tool call cycle and drops the second list call (Python)Có thể đã có người làm @chaitanya0305 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
i-am-bee/beeai-framework#2049 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fedora-infra/anitya#2272 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
unitaryfoundation/mitiq#3205 ·
Maintainer thường phản hồi trong vòng 6 ngày
-
[Bug]: Index worker test drops empty Git config values on WindowsCó thể đã có người làm @xiaoyesoso đã nhận hôm nay. Đang mởtriage/confirmed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
agentscope-ai/agentscope#4377 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày