fix(harness): prevent OOM in verifyChecksum using stream#1125
Merged
gorkem merged 1 commit intoMar 17, 2026
Conversation
Resolves kitops-ml#1114 by replacing os.ReadFile with io.Copy to stream the file into the sha-256 hasher, rather than loading the whole file into memory first. Signed-off-by: satyam kumar <krsatyamthakur@gamil.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR mitigates an OOM risk during harness downloads by changing checksum verification to hash files via streaming rather than reading the entire archive into memory.
Changes:
- Replaced
os.ReadFile+sha256.Sum256withos.Open+sha256.New+io.CopyinverifyChecksum. - Computes the SHA-256 checksum with constant memory usage regardless of file size.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gorkem
approved these changes
Mar 17, 2026
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.
Summary
This PR fixes an Out-Of-Memory (OOM) risk in the harness download process.
Currently,
pkg/lib/harness/llm_download.gousesos.ReadFile()insideverifyChecksumto load the entire downloaded harness file (llamafile.tar.gzorui.tar.gz) into RAM all at once in order to compute the SHA-256 hash. In memory-constrained environments or with future larger harness binaries, this memory spike can trigger an OOM kill.Changes Made
os.ReadFileandsha256.Sum256with a streaming approach.io.Copyto stream the file contents directly into asha256.New()hasher.Related Issue
Closes #1114
Testing Done
kitlocally.go test ./...passes locally.-s).AI-Assisted Contribution Checklist