fix(opencode): guard against large files in diffFull#18986
Closed
elijahmorg wants to merge 1 commit intoanomalyco:devfrom
Closed
fix(opencode): guard against large files in diffFull#18986elijahmorg wants to merge 1 commit intoanomalyco:devfrom
elijahmorg wants to merge 1 commit intoanomalyco:devfrom
Conversation
Prevent large files from being stored in sessions potentially causing oom issues or crash in session/summary.ts Storage.write
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Found a potential duplicate: PR #17481 - "fix(opencode): guard against large files in diffFull"
You should verify if PR #17481 is still open and if so, consolidate with it or close one as a duplicate. |
Author
|
Demonstration of bug Demonstration of fix |
Member
|
thanks for prodding us on this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prevent large files from being stored in sessions potentially causing oom issues.
This is a small, targeted, non AI slop PR. I have carefully reviewed and understand the changes myself.
Issue for this PR
Closes #17252 #2585 #17226
Type of change
What does this PR do?
Use
git file-stat -sto check size of text file before reading it inSnapshot.diffFull. If it is larger than 2MB the file is not read.This simple fix mitigates one avenue that causes OpenCodes memory usage to balloon w/o harming current functionality.
How did you verify your code works?
Write heap snapshotin opencode).opencode export <session id>w/ fix the exported session will be small
w/o fix the exported session will be large (at least the size of the heapsnapshot file).
If the heap snapshot is very large then you can just look at memory usage and see it jump. If the jump is temporary grep dev.log for ERROR and you'll see
ERROR 2026-03-24T17:31:26 +90ms service=default e=Out of memory rejectionThis is from
session/summary.ts:101await Storage.write(["session_diff", input.sessionID], diffs)Where it tries to write the large file and blows up.
If you want to verify yourself
This fix applies to many large text files - the heap snapshot is just an easy way to generate a large text file.
Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist
If you do not follow this template your PR will be automatically rejected.