Skip to content

fix(agent): track visited realpaths in iter_skill_index_files to prevent symlink loops - #69244

Closed
CarlitoDon wants to merge 1 commit into
NousResearch:mainfrom
CarlitoDon:fix/prevent-symlink-loop-in-skill-scanning
Closed

fix(agent): track visited realpaths in iter_skill_index_files to prevent symlink loops#69244
CarlitoDon wants to merge 1 commit into
NousResearch:mainfrom
CarlitoDon:fix/prevent-symlink-loop-in-skill-scanning

Conversation

@CarlitoDon

Copy link
Copy Markdown

Summary

When building the system prompt and scanning skill directories, iter_skill_index_files uses os.walk(..., followlinks=True). If a skill directory contains a circular or self-referential symlink (e.g. dir/symlink -> dir), os.walk recursively traverses the directory indefinitely, producing hundreds of duplicated skill matches and inflating system prompts with repeated skill descriptions.

Fix

  • Added visited_dirs: set[str] in iter_skill_index_files that tracks os.path.realpath(root).
  • If an ancestor or symlink destination realpath has already been visited during traversal, subdirectories are pruned (dirs[:] = []) to prevent infinite recursion.
  • Added comprehensive unit test in tests/agent/test_skill_utils.py to verify symlink loop protection.

Copilot AI review requested due to automatic review settings July 22, 2026 10:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@CarlitoDon CarlitoDon closed this by deleting the head repository Jul 22, 2026
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint tool/skills Skills system (list, view, manage) P3 Low — cosmetic, nice to have duplicate This issue or pull request already exists labels Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P3 Low — cosmetic, nice to have tool/skills Skills system (list, view, manage) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants