aws / aws/aws-toolkit-visual-studio

Duplicate Workspace Folder Context Loading

Open
#550 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
No language data
Stars
135
Forks
37
PR merge metrics
No merged PRs in 30d

Description

# Amazon Q Bug Report: Duplicate Workspace Folder Context Loading

## Summary
Amazon Q loads `.amazonq\rules\` files multiple times when duplicate workspace folders exist, causing significant token waste and reduced available context.

## Environment
- **IDE**: Visual Studio (with Amazon Q extension)
- **Operating System**: Windows
- **Amazon Q Version**: 1.81.0.0

## Issue Description
When the same directory is added to the workspace multiple times (with minor path variations like trailing slashes), Amazon Q treats them as separate workspaces and loads all `.amazonq\rules\` files from each instance.

## Observed Behavior
**Workspace Folders Detected:**
```
D:\Path\To\Project\
D:\Path\To\Project
```

**Files Loaded Multiple Times:**
- `Project\.amazonq\rules\00-CRITICAL.md` - loaded 2 times
- `Project\README.md` - loaded 3 times (appears in pinned context)

**Token Impact:**
- Project README.md (3 copies): ~15,000-18,000 tokens
- 00-CRITICAL.md (2 copies): ~1,000-1,200 tokens
- **Total waste**: ~10,000-12,500 tokens per conversation
- **Percentage of budget**: ~5-6% of 200K token budget wasted

## Expected Behavior
Amazon Q should:
1. Normalize workspace folder paths before loading rules
2. Detect and deduplicate identical physical directories
3. Load each unique `.amazonq\rules\` file only once

## Path Normalization Issues
On Windows, the following should be treated as identical:
- Trailing slash variations: `path\` vs `path`
- Case variations: `Path\` vs `path\`
- Path separator variations: `path/` vs `path\`

## Reproduction Steps
1. Open Visual Studio with Amazon Q extension
2. Add the same directory to workspace multiple times (e.g., through multiple solution files or manual folder additions)
3. Create `.amazonq\rules\` files in one of the directories
4. Start a chat session with Amazon Q
5. Observe duplicate rule files in the pinned context

## Suggested Fix
Implement workspace folder deduplication:
```
1. Normalize all workspace paths (resolve to canonical absolute paths)
2. Remove duplicates based on normalized paths
3. Load .amazonq\rules\ files only from unique directories
```

## Workarounds
1. Remove duplicate workspace folder entries from IDE settings
2. Rename large README files to avoid automatic inclusion
3. Manually manage which folders are added to workspace

## Impact
- **Severity**: Medium
- **Frequency**: Occurs in every chat session when duplicates exist
- **User Impact**: Reduced available context for actual work, slower processing

## Additional Notes
This issue is particularly problematic for large documentation files (README.md) that are automatically included in context. The duplication compounds when multiple workspace folders reference the same physical directory.

Contributor guide

Open the contributing guide

Research direction

Start by tracing how Visual Studio workspace folders are enumerated and how .amazonq\rules\ files and README.md are added to pinned context. Reproduce the issue with the two path variants shown in the report and inspect the resulting context entries. Done means equivalent paths are normalized, duplicate physical directories are ignored, and each rule file is loaded once.

Written by the indexing model from the issue text.

Assessment

Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.