fix: preserve guarded run-based tools#8790
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds support for delegating tool execution to a wrapped run method in FunctionToolManager when a call_override is not present, handling async generators, awaitables, and synchronous results. It also includes a unit test to verify this behavior. The review feedback points out a potential AttributeError when accessing context.context.event directly and suggests retrieving the event safely using getattr.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
||
| run = getattr(self._wrapped, "run", None) | ||
| if run is not None: | ||
| event = context.context.event |
There was a problem hiding this comment.
In _check_tool_permission, the retrieval of event from context is safely guarded against AttributeError in case context or context.context is missing or not fully formed. However, here event = context.context.event is accessed directly, which can lead to an unhandled AttributeError if a mock or an unexpected context object is passed.
We should retrieve event safely using nested getattr calls to match the robust behavior of _check_tool_permission.
| event = context.context.event | |
| event = getattr(getattr(context, "context", None), "event", None) |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In the
rundelegation branch, consider mirroring thecall_overridelogic (e.g., only delegating whenrunis overridden fromFunctionTool.run) to avoid accidentally calling a base/defaultrunimplementation on tools that don’t intend to support it. - The new
rundelegation assumescontext.context.eventalways exists; if there are other call sites or context types, it may be safer to access this via a helper or guard against missing attributes to avoid attribute errors in non-chat contexts.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the `run` delegation branch, consider mirroring the `call_override` logic (e.g., only delegating when `run` is overridden from `FunctionTool.run`) to avoid accidentally calling a base/default `run` implementation on tools that don’t intend to support it.
- The new `run` delegation assumes `context.context.event` always exists; if there are other call sites or context types, it may be safer to access this via a helper or guard against missing attributes to avoid attribute errors in non-chat contexts.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
CI note: the full pytest job failure is unrelated to this PR. It fails only in tests/test_fastapi_v1_dashboard.py under FastAPI 0.137 route internals, matching the compatibility issue fixed by #8783. The targeted tool permission tests and all other checks for this PR pass. |
Summary
Fixes #8788.
Verification
Summary by Sourcery
Ensure permission-guarded tools correctly delegate to underlying run-based tools when no custom call handler is defined.
Bug Fixes:
Tests: