[PR #5480] fix: limit LSP diagnostics to prevent context window waste #11424

Closed
opened 2026-02-16 18:16:15 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5480

State: closed
Merged: Yes


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
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5480 **State:** closed **Merged:** Yes --- 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 <img width="1715" height="936" alt="Screenshot 2025-12-13 at 12 14 38" src="https://github.com/user-attachments/assets/53c7732d-6c23-48cd-ad80-0cc8db5cd74d" />
yindo added the pull-request label 2026-02-16 18:16:15 -05:00
yindo closed this issue 2026-02-16 18:16:15 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11424