fix(agent): scope subdirectory hint discovery to workspace - closes #14471#14510
Open
vominh1919 wants to merge 1 commit into
Open
fix(agent): scope subdirectory hint discovery to workspace - closes #14471#14510vominh1919 wants to merge 1 commit into
vominh1919 wants to merge 1 commit into
Conversation
SubdirectoryHintTracker._is_valid_subdir() did not check whether the candidate directory is inside the configured working_dir. This allowed tool calls that touch files in unrelated directories to inject AGENTS.md, CLAUDE.md, or .cursorrules content from completely different projects into the agent context, causing instruction contamination. Add a workspace boundary check using Path.relative_to() so only directories inside working_dir are scanned for hint files. Fixes NousResearch#14471
1 task
19 tasks
2 tasks
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.
Fix: Scope subdirectory hint discovery to workspace directory
Bug
Closes #14471
Hermes has a second project-context injection path beyond the normal startup cwd-based prompt assembly. Post-tool-call path discovery can append context from nearby AGENTS.md, CLAUDE.md, or .cursorrules files based on tool arguments — even from directories completely outside the intended workspace.
This breaks workspace isolation expectations and can cause:
Root Cause
In
agent/subdirectory_hints.py,SubdirectoryHintTracker._is_valid_subdir()only checks:It does not check whether the directory is inside the configured
working_dir. This means any tool call that touches a file in an unrelated directory can trigger hint discovery there.Fix
Add a workspace boundary check in
_is_valid_subdir()usingPath.relative_to(). Only directories insideworking_dirare scanned for hint files:Impact