Refactor tool availability checks into registration#376
Merged
Conversation
cd48289 to
f15854c
Compare
Member
Author
Contributor
Greptile SummaryThis PR refactors tool availability gating from conditional block-imports in Key observations:
Confidence Score: 3/5
Important Files Changed
Prompt To Fix All With AIThis is a comment left during a code review.
Path: strix/tools/registry.py
Line: 197-204
Comment:
**Redundant `_is_sandbox_mode()` call**
`sandbox_mode = _is_sandbox_mode()` is evaluated at line 198, but `_should_register_tool` (called immediately after on line 199) also invokes `_is_sandbox_mode()` internally. This means `os.getenv` is read twice on every decorated function — once wastefully before the early-exit check.
The cleaner fix is to move `sandbox_mode = _is_sandbox_mode()` to *after* the `_should_register_tool` guard, or pass it into `_should_register_tool` as a parameter and return it alongside the bool result:
```python
def decorator(f: Callable[..., Any]) -> Callable[..., Any]:
if not _should_register_tool(
sandbox_execution=sandbox_execution,
requires_browser_mode=requires_browser_mode,
requires_web_search_mode=requires_web_search_mode,
):
return f
sandbox_mode = _is_sandbox_mode() # only computed when we'll actually use it
...
```
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: tests/tools/test_tool_registration_modes.py
Line: 61-80
Comment:
**Test doesn't actually test "direct import" isolation**
The test is named `test_load_skill_does_not_register_agents_graph_when_imported_directly`, and the PR description states "direct imports do not back-register agent-graph tools." However, the test first evicts **all** `strix.tools.*` entries from `sys.modules` before importing `strix.tools.load_skill.load_skill_actions`. Because `strix.tools` itself was evicted, Python must re-execute `strix/tools/__init__.py` as part of resolving the parent package — which unconditionally imports *all* submodules including `from .agents_graph import *` and `from .python import *`.
The `assert "python_action" in names_before` at line 78 only holds because of this full `__init__.py` re-execution, not because `load_skill_actions` itself registers it. Similarly, `create_agent` is absent from the registry solely due to sandbox-mode filtering (`sandbox_execution=False`), not because of import isolation.
If `strix.tools` were already present in `sys.modules` (which is the "direct import" scenario the test claims to cover), importing `strix.tools.load_skill.load_skill_actions` would **not** re-run `__init__.py`, meaning `python_action` would be absent from `names_before`. The test would then fail on line 78.
To genuinely test direct-import isolation, either (a) avoid evicting `strix.tools` from `sys.modules`, or (b) remove the misleading assertion on `python_action` and update the test name/comment to accurately describe what is being tested (sandbox-mode filtering).
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: "refactor: move tool ..." |
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.
Summary
strix.tools.__init__intoregister_tool(...)