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

Open
opened 2026-02-16 17:42:01 -05:00 by yindo · 1 comment
Owner

Originally created by @maurits150 on GitHub (Dec 28, 2025).

Originally assigned to: @rekram1-node on GitHub.

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 aedb5550a8 ("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

Originally created by @maurits150 on GitHub (Dec 28, 2025). Originally assigned to: @rekram1-node on GitHub. ### 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](https://github.com/user-attachments/files/24361542/session_bloat.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 <img width="1649" height="665" alt="Image" src="https://github.com/user-attachments/assets/8509fcaf-3699-491b-95bb-9005a64f04b7" /> ### Operating System Linux Mint 21.3 ### Terminal Guake
yindo added the bugperf labels 2026-02-16 17:42:01 -05:00
Author
Owner

@ry2009 commented on GitHub (Jan 2, 2026):

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

@ry2009 commented on GitHub (Jan 2, 2026): done a couple things with lsp budget and diagnostic here is targeted one: https://github.com/sst/opencode/pull/6671
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3940