opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Sessions become unusable due to large LSP diagnostics (Lua + possibly others)

Open maurits150 opened this issue 3 weeks ago • 1 comments

Description

After using the edit/write tools a few times in larger LSP enabled Lua (.lua extension) projects, sessions slow to a crawl.

Root Cause

  • Edit/write tools store full LSP diagnostics in metadata.
  • Lua LSP returns diagnostics for entire workspace (for me thousands of files, tens of thousands of diagnostics
  • This bloats session storage rapidly, as full diagnostics are attached to EACH message that does an edit/write tool call.
  • Other LSPs may have the same issue.

Impact

  • OpenCode session grows to 1GB+ quickly
  • New messages takes minutes to send: OpenCode sits at 100% CPU usage (presumably decoding JSON).
  • Cancelling via ESC becomes unresponsive.

Potential fix In packages/opencode/src/tool/edit.ts and write.ts, change from storing the entire diagnostics object to just the edited file's diagnostics:

+++ b/packages/opencode/src/tool/edit.ts   (or write.ts) 
     return {
       metadata: {
-        diagnostics,
+        // Only store diagnostics for the edited file, not entire workspace
+        diagnostics: { [normalizedFilepath]: diagnostics[normalizedFilepath] ?? [] },

My domain knowledge about this project is too small to judge how good of a this fix is. So I let an agent check for it.

Agent findings (Opus 4.5) Commit aedb5550a87d79550ce08080ac93910a2f31b243 ("fix: limit LSP diagnostics to prevent context window waste") also addressed the problem of sending too many diagnostics to the LLM by limiting the output message to max 20 diagnostics per file and max 5 project files.

However, that commit only limited what goes in the tool's output string shown to the LLM. It didn't touch the storage layer - the full workspace diagnostics (all files, all issues) were still being saved to session metadata on every edit/write. Your proposed fix compliments that work by also limiting what gets persisted to disk.

OpenCode version

1.0.204 (latest as of writing)

Steps to reproduce

  1. Extract the test project ZIP (contains 1000 test lua files + an AGENTS.md to tell the agent to continue the pattern)
  2. Start opencode in that folder and send a message.
  3. Watch how a 44.3MB json file gets created under opencode/storage/part/, containing diagnostics of all 1000 files, even tho the agent only touched 2 files.

Screenshot and/or share link

Image

Operating System

Linux Mint 21.3

Terminal

Guake

maurits150 avatar Dec 28 '25 19:12 maurits150

done a couple things with lsp budget and diagnostic here is targeted one: https://github.com/sst/opencode/pull/6671

ry2009 avatar Jan 02 '26 18:01 ry2009