fix: skip dependency dirs in skill rglob fallback to prevent context injection#18724
Open
liuhao1024 wants to merge 1 commit into
Open
fix: skip dependency dirs in skill rglob fallback to prevent context injection#18724liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
Collaborator
1 similar comment
Collaborator
…injection
_build_skill_message() and skill_view() use rglob('*') to discover
supporting files when linked_files is empty. This traverses into
node_modules/, .venv/, __pycache__/ and similar directories, injecting
thousands of file paths into the agent context.
- Add _SKIP_DIRS set (node_modules, .venv, venv, __pycache__, .tox,
.pytest_cache, .mypy_cache, .ruff_cache, .git, .hg, .svn)
- Add _MAX_SUPPORTING_FILES = 200 hard cap
- Skip empty files
- Apply same filters to skills_tool.py assets/ and skill_dir rglob
Fixes NousResearch#18675
2518a5d to
7b2a496
Compare
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.
What does this PR do?
_build_skill_message()andskill_view()userglob('*')to discover supporting files whenlinked_filesis empty. This traverses intonode_modules/,.venv/,__pycache__/and similar directories, injecting thousands of file paths into the agent context — silently inflating token usage and potentially causing context overflow.Changes
agent/skill_commands.py —
_build_skill_message()fallback scan:_SKIP_DIRSfrozenset:.git,.hg,.svn,node_modules,.venv,venv,.tox,__pycache__,.pytest_cache,.mypy_cache,.ruff_cache_MAX_SUPPORTING_FILES = 200hard cap with truncation messagef.stat().st_size > 0)tools/skills_tool.py —
skill_view()file scan:_SKIP_DIRSfilter onskill_dir.rglob("*")(line 1111)assets_dir.rglob("*")(line 1210)Root Cause
skill_viewuses non-recursiveglob(ext)forscripts/andreferences/, but the fallback in_build_skill_messageuses recursiverglob("*")with no exclusions. Whenskill_viewreturnslinked_files: null(e.g. scripts/ only containsnode_modules/with no top-level.py/.sh/.js), the unfiltered fallback kicks in and scans everything.Root Cause
skill_viewuses non-recursiveglob(ext)forscripts/andreferences/, but the fallback in_build_skill_messageuses recursiverglob("*")with no exclusions. Whenskill_viewreturnslinked_files: null(e.g. scripts/ only containsnode_modules/with no top-level.py/.sh/.js), the unfiltered fallback kicks in and scans everything.Related Issue
Fixes #18675
Type of Change
Changes Made
agent/skill_commands.py —
_build_skill_message()fallback scan:_SKIP_DIRSfrozenset:.git,.hg,.svn,node_modules,.venv,venv,.tox,__pycache__,.pytest_cache,.mypy_cache,.ruff_cache_MAX_SUPPORTING_FILES = 200hard cap with truncation messagef.stat().st_size > 0)tools/skills_tool.py —
skill_view()file scan:_SKIP_DIRSfilter onskill_dir.rglob("*")(line 1111)assets_dir.rglob("*")(line 1210)Root Cause
skill_viewuses non-recursiveglob(ext)forscripts/andreferences/, but the fallback in_build_skill_messageuses recursiverglob("*")with no exclusions. Whenskill_viewreturnslinked_files: null(e.g. scripts/ only containsnode_modules/with no top-level.py/.sh/.js), the unfiltered fallback kicks in and scans everything.Fixes #18675
How to Test
pytest tests/ -q— all tests should passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture and workflows — or N/A