fix(agent): track visited realpaths in iter_skill_index_files to prevent symlink loops - #69244
Closed
CarlitoDon wants to merge 1 commit into
Closed
Conversation
…ent symlink loops
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens skill-directory scanning during system-prompt construction by preventing os.walk(..., followlinks=True) from recursing indefinitely when encountering circular/self-referential symlinks, which previously could duplicate skill matches and bloat prompts.
Changes:
- Track visited directory realpaths during
iter_skill_index_files()traversal and prune recursion when a realpath repeats. - Add a unit test that creates a self-referential symlink and asserts traversal remains finite and non-duplicative.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| agent/skill_utils.py | Adds realpath-based visited directory tracking to prevent symlink-induced recursion loops while walking skill directories. |
| tests/agent/test_skill_utils.py | Adds a regression test covering circular symlink handling during skill index file iteration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
When building the system prompt and scanning skill directories,
iter_skill_index_filesusesos.walk(..., followlinks=True). If a skill directory contains a circular or self-referential symlink (e.g.dir/symlink -> dir),os.walkrecursively traverses the directory indefinitely, producing hundreds of duplicated skill matches and inflating system prompts with repeated skill descriptions.Fix
visited_dirs: set[str]initer_skill_index_filesthat tracksos.path.realpath(root).dirs[:] = []) to prevent infinite recursion.tests/agent/test_skill_utils.pyto verify symlink loop protection.