Skip to content

Conversation

@remorses
Copy link
Contributor

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:

  • Scans the current (non-compacted) message history for existing file parts.
  • Uses the absolute file path (derived from the file URL) to identify loaded resources.
  • Skips loading any @ reference that matches an already loaded file or directory path.
  • Ensures that if a message containing a file is compacted away, the file can be re-loaded in a new message.

Copilot AI review requested due to automatic review settings November 19, 2025 15:50
Copilot finished reviewing on behalf of remorses November 19, 2025 15:51
Copy link
Contributor

Copilot AI left a 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.

@rekram1-node
Copy link
Collaborator

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 @

@remorses
Copy link
Contributor Author

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

@rekram1-node
Copy link
Collaborator

Most of the times I just want to auto complete a file path and not load it all into the prompt.

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

@github-actions github-actions bot force-pushed the dev branch 2 times, most recently from 917250b to f4593c6 Compare November 22, 2025 05:02
@remorses
Copy link
Contributor Author

Any blockers?

@thdxr
Copy link
Contributor

thdxr commented Nov 22, 2025

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

@remorses
Copy link
Contributor Author

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"

@remorses remorses closed this Nov 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants