Skip to content

[bugfix] fix model agent progress logging, deletion, and error handling#121

Merged
slin1237 merged 1 commit into
mainfrom
slin/bug-fix-2
Jul 2, 2025
Merged

[bugfix] fix model agent progress logging, deletion, and error handling#121
slin1237 merged 1 commit into
mainfrom
slin/bug-fix-2

Conversation

@slin1237
Copy link
Copy Markdown
Collaborator

@slin1237 slin1237 commented Jul 2, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

This PR fixes several critical issues in the model agent:

  1. Progress Logging: Fixed progress logging for model downloads which was not working due to logger being cleared by WithViper option. Reordered HubConfig options to apply WithViper first, then WithLogger.

  2. Model Deletion: Fixed model deletion failure where files were not being removed from filesystem. The deletion code was constructing a different path than the download code (case mismatch). Now both use the same getDestPath function.

  3. Nil Pointer Dereference: Added proper nil checks for progressManager.logger throughout the codebase to prevent panics when logger is not initialized.

  4. HTTP 429 Rate Limiting: Added proper handling for HTTP 429 (Too Many Requests) errors from Hugging Face API with:

    • Retry logic with exponential backoff
    • Respect for Retry-After header
    • RateLimitError type in handleHTTPError
  5. RBAC Permissions: Added permission for model-agent service account to get secrets at cluster scope for accessing HF tokens.

  6. Namespace Issue: Fixed ClusterBaseModels to look for secrets in "ome" namespace instead of empty string.

Which issue(s) this PR fixes:

Fixes # (no specific issue, but addresses multiple production issues)

Special notes for your reviewer:

  • The progress logging issue was particularly tricky - the WithViper option was resetting the entire config to defaults, clearing any previously set options
  • The model deletion issue was due to inconsistent path construction between download and delete operations
  • All changes have been tested with make fmt, make vet, make tidy, and make test

Does this PR introduce a user-facing change?

Fix model agent progress logging, model deletion, and HTTP 429 error handling. Model downloads now show progress logs every 5 seconds or 10% progress. Model deletion now properly removes files from the filesystem. The model agent now handles rate limiting from external APIs gracefully with automatic
retries.

  - Fix progress logging by reordering HubConfig options to prevent logger override
  - Fix model deletion using consistent path calculation with getDestPath
  - Add proper nil checks for progressManager.logger to prevent panics
  - Add HTTP 429 rate limiting handling with exponential backoff
  - Enable detailed progress logging for model downloads
  - Fix RBAC permissions to allow model-agent to get secrets
@github-actions github-actions Bot added the bug Something isn't working label Jul 2, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 significantly enhances the robustness and functionality of the model agent by resolving several long-standing issues. It improves the reliability of model downloads and deletions, makes the agent more resilient to external API rate limits, and refines Kubernetes resource configurations for better secret management and permissions.

Highlights

  • Model Agent Stability & Reliability: Fixed critical issues related to model download progress logging, ensuring consistent and visible progress updates. Addressed nil pointer dereferences to prevent panics, improving overall stability.
  • Robust Model Deletion: Resolved a bug where model files were not properly removed from the filesystem due to inconsistent path construction between download and deletion operations, ensuring clean cleanup.
  • Improved External API Handling: Implemented comprehensive handling for HTTP 429 (Too Many Requests) errors from the Hugging Face API, including retry logic with exponential backoff and respect for the Retry-After header, making the agent more resilient to rate limiting.
  • Kubernetes Permissions & Secret Management: Updated RBAC permissions to allow the model-agent service account to get secrets at the cluster scope. Corrected the namespace lookup for ClusterBaseModel secrets to ensure proper retrieval of Hugging Face tokens.
  • Model Definition Updates: Standardized Hugging Face token key references in ClusterBaseModel definitions and performed minor cleanup of metadata in some model configurations.
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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces several important bug fixes and improvements to the model agent. Key changes include fixing progress logging by reordering configuration options, ensuring consistent model pathing for deletion, adding nil-pointer checks for the logger, and implementing robust HTTP 429 rate-limiting handling with retries. It also corrects RBAC permissions for accessing secrets and fixes a namespace issue for ClusterBaseModel resources. The changes are well-described and address critical production issues. The code quality is generally high, with good use of context for cancellation and clear error handling. I've found one minor issue in a log message format that should be addressed.

Comment thread pkg/modelagent/gopher.go
secret, err := s.kubeClient.CoreV1().Secrets(namespace).Get(context.Background(), *baseModelSpec.Storage.StorageKey, metav1.GetOptions{})
if err != nil {
s.logger.Warnf("Failed to retrieve secret %s for Hugging Face token: %v", *baseModelSpec.Storage.StorageKey, err)
s.logger.Warnf("Failed to retrieve secret %s in namespace %s for Hugging Face token: %v. Opc-Request-Id: %v", *baseModelSpec.Storage.StorageKey, namespace, err, nil)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logging for a failed secret retrieval has been improved to include the namespace, which is great for debugging. However, it also adds an Opc-Request-Id field that is hardcoded to nil. This adds noise to the logs and can be misleading. Since there's no request ID available in this context, this part of the log message should be removed.

Suggested change
s.logger.Warnf("Failed to retrieve secret %s in namespace %s for Hugging Face token: %v. Opc-Request-Id: %v", *baseModelSpec.Storage.StorageKey, namespace, err, nil)
s.logger.Warnf("Failed to retrieve secret %s in namespace %s for Hugging Face token: %v", *baseModelSpec.Storage.StorageKey, namespace, err)

@slin1237 slin1237 merged commit f1d8384 into main Jul 2, 2025
23 checks passed
@slin1237 slin1237 deleted the slin/bug-fix-2 branch July 2, 2025 00:37
slin1237 added a commit that referenced this pull request Dec 22, 2025
…ng (#121)

- Fix progress logging by reordering HubConfig options to prevent logger override
  - Fix model deletion using consistent path calculation with getDestPath
  - Add proper nil checks for progressManager.logger to prevent panics
  - Add HTTP 429 rate limiting handling with exponential backoff
  - Enable detailed progress logging for model downloads
  - Fix RBAC permissions to allow model-agent to get secrets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant