Chat implicit "active selection" context stays stuck after its source document is closed/deleted

Open
#321,905 0 comments 0 reactions 1 assignee View on GitHub

@justschen is already working on this.

Since Jun 18, 2026.

Assessment

This issue has not been assessed yet.

Description

Copilot Chat Extension Version: 0.53.0
VS Code Version: Version: 1.125.0 (Universal)
Commit: 93cfdd489c3b228840d0f86ec77c3636277c93ea
Date: 2026-06-15T22:24:03Z
OS Version: macOS 26.5 (25F71) — Darwin 25.5.0 arm64
Feature (e.g. agent/edit/ask mode): Agent mode (applies to all chat modes)
Selected model (e.g. GPT 4.1, Claude 3.7 Sonnet): All models (model-independent)
Logs: na (no related entries in Copilot Chat log — see Debug data)

Steps to Reproduce:

  1. Open a document and select some text → it attaches as the implicit "active selection" context chip in the Chat input.
  2. Delete or close that document while its editor stays focused.
  3. Submit a chat turn → the stale selection is still attached.
  4. Try to remove it via "unpin" in the chat window → it only suppresses for one send and re-attaches next turn.
    ( Symbol pin is still "not attached" though, but visible in Chat window and also llm agrees to see it fresh again. )
  5. Focus another editor chat window → the chip frequently persists. Cannot get rid of it.
  6. Make a fresh text selection / copy text in another editor (or open a real file with a selection) → only now does the chip clear.
Remark: _WriteUp via Opus 4.8 of the situation was performend from here on

Summary

The Chat input's implicit "active selection" context is bound to the last active text selection and is only invalidated on the next selection-change event. Closing or deleting the backing document emits no such event, so the chip remains attached and keeps being sent on every turn. "Unpin" does not remove it permanently, and merely focusing another editor is often insufficient.

Current Behaviour
After the source document is closed/deleted, the active-selection chip lingers in the input and re-attaches each turn. It is only cleared when a new selection-change fires elsewhere (selecting/copying text in another editor, or opening a real file with a selection). Reproduced with both a memory:-scheme virtual document and a regular workspace file.

Expected Behaviour
When the backing document of an implicit active-selection context is closed or deleted, the context should be invalidated immediately. Unpinning the chip should also remove it permanently rather than for a single submission.

Workaround
Trigger a fresh selection-change — select or copy text in another editor, or open a different file — which replaces the stale reference. Alternatively start a New Chat or reload the window.

Impact
Stale, unremovable context silently pollutes every subsequent turn, wasting tokens and skewing the model's grounding toward a deleted document, with no reliable UI affordance to clear it.

Debug data
Reviewed GitHub.copilot-chat/GitHub Copilot Chat.log across all windows for the session — no related error/warning is logged, consistent with a renderer-side chat-widget state issue rather than an extension fault. Only unrelated entries were present ([CopilotCLIModels] 401 Unauthorized: Bad credentials at startup, and a benign Error compiling input schema for tool run_in_terminal: unknown keyword "enumDescriptions").

Dominant language
TypeScript
Stars
193k
Forks
42.9k
PR merge metrics
PR metrics pending

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/vscode

All issues in microsoft/vscode

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.