opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: limit LSP diagnostics to prevent context window waste

Open remorses opened this issue 1 month ago • 0 comments

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

remorses avatar Dec 13 '25 11:12 remorses