Skip to content

Language Server shows stale diagnostics after Copilot agent delete + recreate cycle #8187

@tharveysa

Description

@tharveysa

Environment

  • VS Code Version: Latest (January 2026)
  • AL Language Extension Version: (check via Extensions panel)
  • Business Central Version: v26.5 OnPrem
  • OS: Windows 11

Description

When using GitHub Copilot in agent mode, certain file operations can cause the AL Language Server to retain stale diagnostic data. Specifically, when the agent:

  1. Deletes a file using run_in_terminal (PowerShell Remove-Item)
  2. Recreates it using create_file tool (VS Code file creation API)
  3. The new file contains a syntax error
  4. Agent fixes the error using replace_string_in_file tool (in-place edit)

...the Problems panel continues displaying the original errors even though the file is now correct.

Reproduction Steps

  1. Have an existing AL file open in VS Code, e.g., MyPage.Page.al

  2. Copilot agent executes run_in_terminal:

    Remove-Item "c:\path\to\MyPage.Page.al" -Force
  3. Agent immediately executes create_file tool to recreate the file with same path, but the new content has a syntax error (e.g., duplicate line, extra parenthesis)

  4. Problems panel correctly shows the syntax error(s)

  5. Agent executes replace_string_in_file tool to fix the syntax error via in-place edit

  6. Bug: Problems panel still shows the original error(s)

Key Detail: Tool Chain Interaction

This appears to be an interaction issue between:

  • Terminal execution (run_in_terminal -> PowerShell Remove-Item)
  • VS Code file API (create_file tool)
  • AL Language Server (file watcher / diagnostics cache)

The replace_string_in_file tool correctly updates the language server (errors would clear if ONLY this tool was used). The issue is that the prior delete+create sequence puts the language server in a state where subsequent in-place edits don't properly refresh the diagnostics cache.

Evidence

  • AL: Build (Ctrl+Shift+B) shows successful compilation with 0 errors
  • VS Code's get_errors API returns empty array (correct)
  • Problems panel UI shows stale errors (incorrect)
  • Error line numbers in Problems panel may not match actual file content

Workaround

Developer: Reload Window clears the stale cache.

Hypothesis

The AL Language Server's file watcher may not properly handle the rapid sequence of:

  1. File deleted (external via terminal)
  2. File created (via VS Code API)
  3. File modified (via VS Code API)

The delete event from the terminal may not be fully processed before the create event arrives, causing the language server to retain state from the pre-delete file version.

Related Issue

This may be related to #7891 (AL languages internal cache is not always correctly refreshed), which describes similar stale cache behavior with external file modifications.

Why This Matters

AI coding agents (Copilot, Cursor, etc.) increasingly use these tool patterns. As agent-assisted development grows, this interaction between terminal operations and VS Code file APIs will become more common.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions