fix(agent): detect symlink cycles in iter_skill_index_files to prevent infinite recursion - #47775
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(agent): detect symlink cycles in iter_skill_index_files to prevent infinite recursion#47775liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
…t infinite recursion Add a visited set of resolved real paths to iter_skill_index_files(). When os.walk(followlinks=True) encounters a symlink cycle (e.g. skills/productivity/productivity -> productivity/), the branch is pruned instead of recursing infinitely. Without this guard, self- referencing symlinks inflate the skills prompt from ~1K to ~109K tokens, consuming most of the context window. Fixes NousResearch#47659
Collaborator
|
Duplicate of #18815 — same fix (add a |
Contributor
Author
This was referenced Jul 28, 2026
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?
Adds symlink cycle detection to
iter_skill_index_files()so that self-referencing symlinks inside skill directories (e.g.skills/productivity/productivity -> productivity/) are pruned instead of causing infinite recursion viaos.walk(followlinks=True).Without this guard, self-referencing symlinks inflate the skills prompt from ~1K tokens to ~109K tokens, consuming most of the context window before any conversation starts.
Related Issue
Fixes #47659
Type of Change
Changes Made
agent/skill_utils.py: Add avisitedset ofPath.resolve()real paths toiter_skill_index_files(). Whenos.walkrevisits an already-seen directory (via symlink cycle), prune the branch by settingdirs[:] = [].tests/agent/test_skill_utils.py: Addtest_iter_skill_index_files_prunes_self_referencing_symlinks— creates a self-referencing symlink inside a skill directory and verifies each skill appears exactly once (no duplicated entries from the cycle).How to Test
python -m pytest tests/agent/test_skill_utils.py::test_iter_skill_index_files_prunes_self_referencing_symlinks -vChecklist
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 or workflows — or N/ACode Intelligence
iter_skill_index_files(callers: 5 inagent/skill_utils.py,agent/prompt_builder.py,tools/skills_tool.py,agent/skill_commands.py)os.walk(followlinks=True)cycle detection is a well-known Python pattern; thevisitedset of resolved paths is the standard approach