Unbounded LSP output may use entire token quota #3413

Closed
opened 2026-02-16 17:39:59 -05:00 by yindo · 7 comments
Owner

Originally created by @dan-kirberger on GitHub (Dec 8, 2025).

Originally assigned to: @rekram1-node on GitHub.

Description

You'll see bash.ts has some mechanisms for limiting its output, we may want the same in write.ts, namely, where it processes the response of the language server call here

I was pointed in this direction here: https://github.com/sst/opencode/issues/2464#issuecomment-3583939028

In my particular case, it may ask the language server to fully inspect a repo, and trigger tons of errors due to the language server not knowing about a particular plugin or config ("Lombok" in my case, for java). Ultimately best solved by configuring the LSP appropriately on my end, but I don't think we ever want this code adding an unbounded amount of data to the context, right?

Would a pattern similar to bash.ts make sense?

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @dan-kirberger on GitHub (Dec 8, 2025). Originally assigned to: @rekram1-node on GitHub. ### Description You'll see [bash.ts ](https://github.com/sst/opencode/blob/dev/packages/opencode/src/tool/bash.ts#L19) has some mechanisms for limiting its output, we may want the same in write.ts, namely, where it [processes the response of the language server call here](https://github.com/sst/opencode/blob/bbf457447687b173a070e9bf0634ee77b66f7a00/packages/opencode/src/tool/write.ts#L79-L97) I was pointed in this direction here: https://github.com/sst/opencode/issues/2464#issuecomment-3583939028 In my particular case, it may ask the language server to fully inspect a repo, and trigger tons of errors due to the language server not knowing about a particular plugin or config ("Lombok" in my case, for java). Ultimately best solved by configuring the LSP appropriately on my end, but I don't think we ever want this code adding an unbounded amount of data to the context, right? Would a pattern similar to bash.ts make sense? ### OpenCode version _No response_ ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:39:59 -05:00
yindo closed this issue 2026-02-16 17:39:59 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 8, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #4826: [Question] Is automatic tool calling output truncation supported? - directly addresses truncation of unbounded tool output to prevent token quota issues
  • #4560: [FEATURE]: Context protection for tool calls when response is large - proposes automatic detection and handling of large tool responses
  • #5178: [FEATURE]: Allow continuation after context overflow - related to handling context overflow scenarios
  • #2464: AT_APICallError: prompt token count exceeds limit - real-world case of token quota being exceeded
  • #4315: Memory stays unbounded - related issue about tool output memory management

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Dec 8, 2025): This issue might be a duplicate of existing issues. Please check: - #4826: [Question] Is automatic tool calling output truncation supported? - directly addresses truncation of unbounded tool output to prevent token quota issues - #4560: [FEATURE]: Context protection for tool calls when response is large - proposes automatic detection and handling of large tool responses - #5178: [FEATURE]: Allow continuation after context overflow - related to handling context overflow scenarios - #2464: AT_APICallError: prompt token count exceeds limit - real-world case of token quota being exceeded - #4315: Memory stays unbounded - related issue about tool output memory management Feel free to ignore if none of these address your specific case.
Author
Owner

@dan-kirberger commented on GitHub (Dec 8, 2025):

Some of the suggested dupes are valid, for a general pattern to follow for tools. This issue could conceivably stick around if a focused solution is desired around LSP output maybe?

@dan-kirberger commented on GitHub (Dec 8, 2025): Some of the suggested dupes are valid, for a general pattern to follow for tools. This issue could conceivably stick around if a focused solution is desired around LSP output maybe?
Author
Owner

@rekram1-node commented on GitHub (Dec 8, 2025):

Yes we should do that

@rekram1-node commented on GitHub (Dec 8, 2025): Yes we should do that
Author
Owner

@rekram1-node commented on GitHub (Dec 8, 2025):

I was thinking we cap the # of diagnostics to show

Are your diagnostics huge? Or would that work

@rekram1-node commented on GitHub (Dec 8, 2025): I was thinking we cap the # of diagnostics to show Are your diagnostics huge? Or would that work
Author
Owner

@dan-kirberger commented on GitHub (Dec 8, 2025):

I'll have to tinker to get it to show up again, i think what i saw was hundreds of individual files were flagged with various compiler issues because the java LSP didnt understand some annotations. I'm not 100% sure how how that was represented in the data model in write.ts. I'll tinker later with a local debug build perhaps.

@dan-kirberger commented on GitHub (Dec 8, 2025): I'll have to tinker to get it to show up again, i think what i saw was hundreds of individual files were flagged with various compiler issues because the java LSP didnt understand some annotations. I'm not 100% sure how how that was represented in the data model in write.ts. I'll tinker later with a local debug build perhaps.
Author
Owner

@rekram1-node commented on GitHub (Dec 8, 2025):

Sounds good, I think normally each diagnostic isn't insanely big and we can just grab the top 20 or so (or just the highest severity ones). And that should do it.

Happy to do that for you we talked about it internally once but forgot about it

@rekram1-node commented on GitHub (Dec 8, 2025): Sounds good, I think normally each diagnostic isn't insanely big and we can just grab the top 20 or so (or just the highest severity ones). And that should do it. Happy to do that for you we talked about it internally once but forgot about it
Author
Owner

@remorses commented on GitHub (Dec 13, 2025):

Opened a PR to fix this issue: https://github.com/sst/opencode/pull/5480

@remorses commented on GitHub (Dec 13, 2025): Opened a PR to fix this issue: https://github.com/sst/opencode/pull/5480
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3413