Skip to content

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

@maurits150

Description

@maurits150

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingperfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions