[bugfix] fix: resolve model agent download loops and timeout issues#126
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @slin1237, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses several critical issues within the model agent's download mechanism, aiming to significantly enhance the reliability and stability of model downloads. It resolves problems such as infinite download loops, timeout failures for large files, and race conditions during concurrent downloads, while also reducing log verbosity.
Highlights
- Infinite Download Loop Fix: Prevented the model agent from updating
ClusterBaseModelCRD specs after parsing model configurations, which previously triggered continuous re-downloads and infinite loops. (Note: The specific code change for this fix was not included in the provided patch, but it is a stated intent of the PR.) - Download Timeout Increase: Increased the HTTP client timeout for model downloads from 10 minutes to 2 hours to accommodate large model files (e.g., >10GB) and prevent 'context deadline exceeded' errors.
- Race Condition Handling: Improved the robustness of the download process by adding checks to handle race conditions during file renaming. The system now verifies if the destination file already exists with the correct size, preventing errors when multiple workers might attempt to download or move the same file concurrently.
- Log Verbosity Reduction: Disabled detailed HuggingFace hub progress logging to reduce excessive log entries that were flooding the logs during model downloads.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request addresses several critical issues related to model downloads, including infinite loops, timeouts, race conditions, and log flooding. The changes look good and align with the described fixes. I've made one suggestion in pkg/hfutil/hub/download.go to improve the implementation of the race condition fix by removing a redundant system call and making error handling more explicit. Overall, a solid set of fixes.
| if _, destErr := os.Stat(destPath); destErr == nil { | ||
| // Destination exists, verify size | ||
| destInfo, _ := os.Stat(destPath) | ||
| if metadata.Size > 0 && destInfo.Size() == metadata.Size { | ||
| // File already moved successfully, remove incomplete file if it exists | ||
| os.Remove(incompletePath) | ||
| return nil | ||
| } | ||
| } |
There was a problem hiding this comment.
This is a good fix for the race condition. However, the implementation can be improved:
- Redundant
os.Stat: Theos.Stat(destPath)call on line 287 is redundant. TheFileInfocan be retrieved from theos.Statcall on line 285, which avoids an unnecessary system call. - Ignored Error: The error from the second
os.Staton line 287 is ignored. It's better practice to handle or at least check errors. - Implicitly Ignored Error: The error from
os.Remove(incompletePath)on line 290 is also ignored. It's better to make this explicit using the blank identifier (_ = ...) to show this is intentional.
Here is a suggested change that addresses these points.
| if _, destErr := os.Stat(destPath); destErr == nil { | |
| // Destination exists, verify size | |
| destInfo, _ := os.Stat(destPath) | |
| if metadata.Size > 0 && destInfo.Size() == metadata.Size { | |
| // File already moved successfully, remove incomplete file if it exists | |
| os.Remove(incompletePath) | |
| return nil | |
| } | |
| } | |
| if destInfo, destErr := os.Stat(destPath); destErr == nil { | |
| // Destination exists, verify size | |
| if metadata.Size > 0 && destInfo.Size() == metadata.Size { | |
| // File already moved successfully, remove incomplete file if it exists. | |
| // We can ignore the error since another worker might have already removed it. | |
| _ = os.Remove(incompletePath) | |
| return nil | |
| } | |
| } |
What type of PR is this?
/kind bug
What this PR does / why we need it:
This PR fixes critical issues with the model agent that were causing infinite download loops and download failures for large models:
Infinite Download Loop Fix: The model agent was updating ClusterBaseModel specs after parsing model configurations, which triggered other agents to re-download
the same model. This created an infinite loop where models were continuously downloaded. Fixed by preventing model agents from updating the ClusterBaseModel CRD.
Download Timeout Fix: Large model files (>10GB) were failing with "context deadline exceeded" errors because the HTTP client timeout was set to only 10
minutes. Increased the timeout to 2 hours to accommodate large model downloads.
Race Condition Fix: Multiple workers downloading the same model could encounter a race condition where the
.incompletefile was missing when trying to renameit. Added proper handling to check if the destination file already exists with the correct size.
Log Flooding Fix: Disabled detailed HuggingFace hub progress logging that was creating excessive log entries during downloads.
Which issue(s) this PR fixes:
Fixes # (Please link the issue if one exists)
Special notes for your reviewer:
config_parser.goafter model metadata extractionpkg/hfutil/hub/constants.go- changed from 10 minutes to 2 hourspkg/hfutil/hub/download.goin thedownloadToTmpAndMovefunctionDoes this PR introduce a user-facing change?