-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: deduplicate @-referenced files in session context #4499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
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 implements deduplication of file and directory references in session context to prevent the same resources from being loaded multiple times within a conversation. The implementation scans non-compacted message history for existing file parts and skips loading any @ references that match already-loaded file paths.
Key changes:
- Added logic to scan message history and track loaded file paths before processing new message parts
- Implemented Set-based deduplication using absolute file paths derived from file URLs
- Added early-return checks for both files and directories to prevent duplicate loading
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e3990f9 to
26ff322
Compare
|
Hm tbh idk if I like this because if I have a session go longer, I sometimes @ reference the file later in context so the agent "remembers" what it looks like, or sometimes I myself make edits and say: I made edits to @ |
|
I do not like that referencing files always adds them to context, I always assumed referencing a file multiple times would just add the path the second time Embedding the file contents always wastes too much context imo. Most of the times I just want to auto complete a file path and not load it all into the prompt. For your use case you can just prefix with "read @filepath" to make sure it reads it again |
That's fair use case, I kinda liked when we had tab completions for filepaths but it'd be kinda confusing now given the @ stuff |
917250b to
f4593c6
Compare
|
Any blockers? |
f1dc981 to
3e15a39
Compare
df8bdf9 to
0dd5039
Compare
|
i'm not super sure about this - it is more efficient but i don't think the majority of people will understand how this works and be unsure why doing @ doesn't cause a re-read |
|
Adding the file contents to the model context is just an optimization in my opinion. It is a smart optimization because it saves you one turn (request to model API) but doing it even for already referenced files is wasteful because the model already has it in context. In the case where you updated the file and want to let the model know: the model will have to read the file anyway because it will get the error "This file changed since the last time you read it" |
Prevents files and directories referenced via
@from being loaded into the context window multiple times if they are already present in the active conversation history.This implementation:
@reference that matches an already loaded file or directory path.