Skip to content

fix: limit LSP diagnostics to prevent context window waste - #5480

Merged
rekram1-node merged 4 commits into
anomalyco:devfrom
remorses:fix/limit-lsp-diagnostics
Dec 14, 2025
Merged

rekram1-node merged 4 commits into
anomalyco:devfrom
remorses:fix/limit-lsp-diagnostics

Conversation

@remorses

@remorses remorses commented Dec 13, 2025 •

Copy link
Copy Markdown
Contributor

LSP diagnostics returned after file writes and edits were unbounded, which could easily fill up the context window when a project has many errors.

This adds limits:

  • Max 10 diagnostics per file (sorted by severity - errors first)
  • Max 5 files for project-wide diagnostics (in write tool)
  • Shows "... and N more" suffix when truncated

Fixes #5259

I encountered this issue while working on a big codebase with many broken scripts. All the LSP issues were filling in the context. I even made a cli to investigate why just 1 file write was consuming so much context. The issue is that LSP diagnostics are unbounded. As you can see in the image a single file write was consuming 400k characters of context

Screenshot 2025-12-13 at 12 14 38

Copilot AI review requested due to automatic review settings December 13, 2025 11:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds limits to LSP diagnostics returned after file writes and edits to prevent context window overflow when projects have many errors. The implementation sorts diagnostics by severity (errors first) and truncates the output with a clear indication of how many additional diagnostics exist.

  • Adds configurable constants for limiting diagnostics per file (10) and project-wide files (5 in write tool)
  • Implements sorting by severity with errors prioritized
  • Adds "... and N more" suffix when diagnostics are truncated

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/opencode/src/tool/write.ts Adds MAX_DIAGNOSTICS_PER_FILE and MAX_PROJECT_DIAGNOSTICS_FILES constants; implements sorting and limiting for both file-specific and project-wide diagnostics with truncation messages
packages/opencode/src/tool/edit.ts Adds MAX_DIAGNOSTICS_PER_FILE constant; replaces severity filtering (errors-only) with sorting and limiting that includes all diagnostic severities

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/opencode/src/tool/edit.ts Resolved
@rekram1-node

Copy link
Copy Markdown
Contributor

/review

@github-actions

Copy link
Copy Markdown
Contributor

lgtm

@rekram1-node
rekram1-node merged commit aedb555 into anomalyco:dev Dec 14, 2025
3 checks passed
nalin-singh pushed a commit to nalin-singh/opencode that referenced this pull request Dec 17, 2025
…#5480)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
rekram1-node added a commit that referenced this pull request Dec 27, 2025
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request May 5, 2026
…#5480)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
…#5480)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request Jun 14, 2026
…#5480)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
MarsQiu007 referenced this pull request in MarsQiu007/openNovel Jul 31, 2026
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
meSingh pushed a commit to meSingh/opencode that referenced this pull request Sep 6, 2026
…#5480)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
androidand pushed a commit to androidand/opencode-skein that referenced this pull request Sep 19, 2026
…#5480)

Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
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.

Unbounded LSP output may use entire token quota

3 participants