Skip to content

feat: add support for Safetensors model format error handling#191

Merged
ilopezluna merged 2 commits intomainfrom
dont-pull-safetensors
Oct 2, 2025
Merged

feat: add support for Safetensors model format error handling#191
ilopezluna merged 2 commits intomainfrom
dont-pull-safetensors

Conversation

@ilopezluna
Copy link
Contributor

@ilopezluna ilopezluna commented Oct 2, 2025

This pull request adds explicit handling and error messaging for unsupported Safetensors model formats in the model distribution client. It ensures that attempts to pull Safetensors models are properly rejected and tested, improving clarity and robustness around supported model types.

Summary by Sourcery

Reject safetensors models when pulling via the distribution client by introducing ErrUnsupportedFormat and add tests to validate this behavior

Enhancements:

  • Add explicit detection and rejection of safetensors model format in checkCompat with ErrUnsupportedFormat

Tests:

  • Add unit test to verify pulling a safetensors model returns ErrUnsupportedFormat

Copilot AI review requested due to automatic review settings October 2, 2025 13:51
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 2, 2025

Reviewer's Guide

This PR enforces explicit rejection of Safetensors format in the model distribution client by introducing a new ErrUnsupportedFormat, extending compatibility checks in checkCompat, and adding a dedicated test to verify error handling when pulling safetensors models.

Class diagram for updated error handling in model distribution client

classDiagram
    class ModelArtifact {
        +Config() ModelConfig
    }
    class ModelConfig {
        +Format: string
    }
    class Client {
        +checkCompat(image: ModelArtifact) error
    }
    ModelArtifact --> ModelConfig : Config()
    Client --> ModelArtifact : checkCompat(image)
    Client ..> ErrUnsupportedFormat
    class ErrUnsupportedFormat {
        <<error>>
    }
Loading

Flow diagram for Safetensors format rejection in checkCompat

flowchart TD
    A["checkCompat(image)"] --> B["Read manifest.Config.MediaType"]
    B --> C{"MediaType == MediaTypeModelConfigV01?"}
    C -- No --> D["Return ErrUnsupportedMediaType"]
    C -- Yes --> E["image.Config()"]
    E --> F{"config.Format == FormatSafetensors?"}
    F -- Yes --> G["Return ErrUnsupportedFormat"]
    F -- No --> H["Return nil (success)"]
Loading

File-Level Changes

Change Details Files
define new ErrUnsupportedFormat error
  • introduced ErrUnsupportedFormat with a descriptive message
  • reordered ErrConflict declaration to accommodate the new error
pkg/distribution/distribution/errors.go
extend checkCompat to reject safetensors format
  • added model.Config() call to retrieve format
  • inserted conditional to return ErrUnsupportedFormat when format is Safetensors
pkg/distribution/distribution/client.go
add test case for safetensors pull failure
  • imported safetensors package in client_test.go
  • created temp safetensors file and model
  • pushed safetensors model to registry and asserted PullModel errors with ErrUnsupportedFormat
pkg/distribution/distribution/client_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@ilopezluna ilopezluna requested a review from a team October 2, 2025 13:51
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ilopezluna, 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 enhances the model distribution client by implementing explicit error handling for unsupported Safetensors model formats. It ensures that any attempt to pull a Safetensors model is properly rejected with a clear error message, thereby improving the system's robustness and clarity regarding supported model types. This change includes adding a new error type and a corresponding test case.

Highlights

  • Explicit Safetensors Error Handling: The model distribution client now explicitly checks for Safetensors model formats during compatibility checks and returns a specific error if detected, preventing unsupported models from being processed.
  • New Error Definition: A new error, ErrUnsupportedFormat, has been introduced in errors.go to provide a clear message when Safetensors models are encountered, stating that only GGUF models are currently supported.
  • Comprehensive Test Coverage: A dedicated test case has been added to client_test.go to ensure that attempting to pull a Safetensors model correctly triggers and returns the ErrUnsupportedFormat.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request adds explicit error handling for unsupported Safetensors model formats in the model distribution client. The implementation ensures that attempts to pull Safetensors models are properly rejected with a clear error message, improving the robustness of the model distribution system.

  • Introduces a new error constant ErrUnsupportedFormat with a clear message about Safetensors format support
  • Adds format validation in the checkCompat function to reject Safetensors models
  • Includes comprehensive test coverage for the new error handling behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/distribution/distribution/errors.go Adds new error constant for unsupported Safetensors format
pkg/distribution/distribution/client.go Implements format validation to reject Safetensors models in checkCompat function
pkg/distribution/distribution/client_test.go Adds test case to verify proper error handling when pulling Safetensors models

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +413 to +416
config, err := image.Config()
if err != nil {
return fmt.Errorf("reading model config: %w", err)
}
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

[nitpick] The config is retrieved and parsed even when it may not be needed. Consider checking if the config has already been retrieved earlier in the call chain to avoid redundant operations.

Copilot uses AI. Check for mistakes.
Copy link
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 effectively adds error handling for unsupported Safetensors model formats. The changes are clear and well-contained, introducing a new error type and a check in the checkCompat function. A comprehensive test case has been added to validate that pulling a Safetensors model correctly returns the new ErrUnsupportedFormat error. My review includes a minor suggestion to make the test assertion more concise.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings October 2, 2025 13:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ilopezluna ilopezluna merged commit 50465f9 into main Oct 2, 2025
5 checks passed
@ilopezluna ilopezluna deleted the dont-pull-safetensors branch October 2, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants