Skip to content

Fix model namespace normalization for package and tag commands#262

Merged
ericcurtin merged 1 commit intomainfrom
fix-local-model-error
Oct 20, 2025
Merged

Fix model namespace normalization for package and tag commands#262
ericcurtin merged 1 commit intomainfrom
fix-local-model-error

Conversation

@ericcurtin
Copy link
Copy Markdown
Contributor

@ericcurtin ericcurtin commented Oct 19, 2025

Add test to verify model namespace normalization consistency

Summary by Sourcery

Use models.NormalizeModelName to normalize model names in both package and tag commands, ensuring default namespace and tag are applied consistently, and add tests to verify this behavior.

Bug Fixes:

  • Normalize model names in the package command to include default 'ai/' namespace and ':latest' tag when missing
  • Normalize both source and target names in the tag command to ensure valid tags

Enhancements:

  • Apply NormalizeModelName to preprocess user-provided tags in the package command
  • Pre-normalize source and target model names in the tag command using NormalizeModelName

Tests:

  • Add TestNormalizeModelNameConsistency to verify consistent namespace and tag normalization across scenarios

Copilot AI review requested due to automatic review settings October 19, 2025 12:10
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Oct 19, 2025

Reviewer's Guide

This PR enforces consistent normalization of model namespaces by applying NormalizeModelName in the package and tag commands and adding a comprehensive test to verify the expected normalization behavior.

Sequence diagram for model name normalization in package and tag commands

sequenceDiagram
participant User as actor User
participant CLI as CLI Command
participant Models as models.NormalizeModelName
participant Registry as Registry

User->>CLI: Run package/tag command with model name
CLI->>Models: NormalizeModelName(modelName)
Models-->>CLI: Normalized model name
CLI->>Registry: Use normalized model name for further processing
Loading

Class diagram for NormalizeModelName usage in CLI commands

classDiagram
class CLICommand {
  +string modelName
  +string normalizedModelName
  +run()
}
class Models {
  +NormalizeModelName(name string) string
}
CLICommand --> Models : uses
Loading

File-Level Changes

Change Details Files
Add consistency tests for model namespace normalization
  • Introduce TestNormalizeModelNameConsistency to verify normalization behavior
  • Define scenarios for missing namespace, custom tags, and explicit namespaces
  • Assert that NormalizeModelName produces expected default namespace and tag
cmd/cli/commands/utils_test.go
Apply normalization in the package command before parsing tags
  • Import NormalizeModelName from models package
  • Normalize provided tag input via NormalizeModelName
  • Use normalized value when creating a new name.Tag
cmd/cli/commands/package.go
Apply normalization in the tag command before tag creation
  • Normalize target argument with NormalizeModelName prior to parsing
  • Ensure both source and target names are consistently normalized
cmd/cli/commands/tag.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

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ericcurtin, 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 standardizes the handling of model names within the CLI's package and tag commands. By consistently applying a model name normalization function, it resolves an inconsistency that previously prevented locally packaged models from being runnable. The change ensures that model names are uniformly processed, leading to a more predictable and reliable user experience, and includes a new test to validate this behavior.

Highlights

  • Model Name Normalization: Ensured consistent normalization of model names across package and tag commands by applying the models.NormalizeModelName function to both source and target model names.
  • Bug Fix: Addressed a bug where locally packaged models without an explicit namespace (e.g., my-model) could not be run because their names were not consistently normalized to include the default ai/ namespace and :latest tag.
  • Test Coverage: Introduced a new test case, TestNormalizeModelNameConsistency, to explicitly verify and document the correct behavior of model name normalization, especially for locally packaged models.
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
Copy Markdown
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.

@ericcurtin
Copy link
Copy Markdown
Contributor Author

@mikesir87 I think this fixes your issue WDYT?

Copy link
Copy Markdown
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

Fixes inconsistent model name normalization across package and tag commands; adds tests to document and prevent regressions.

  • Normalize target name in tag command to include default org/tag
  • Normalize tag string in package command before parsing
  • Add tests to verify NormalizeModelName consistency

Reviewed Changes

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

File Description
cmd/cli/commands/tag.go Ensures both source and target refs are normalized before tagging.
cmd/cli/commands/package.go Normalizes the user-supplied tag/model ref prior to name.NewTag parsing.
cmd/cli/commands/utils_test.go Adds table-driven tests asserting NormalizeModelName behavior.

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

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 effectively addresses the inconsistency in model name normalization across the package and tag commands by consistently applying models.NormalizeModelName. The changes are clear and the addition of TestNormalizeModelNameConsistency is a great step towards ensuring this behavior doesn't regress.

However, I've identified a critical issue that could lead to a panic. In the package command flow, if an empty string is provided as the model name (e.g., docker model package ""), newModelRunnerTarget is called with an empty tag. This results in target.tag being nil. Subsequently, the modelRunnerTarget.Write method will panic when it calls t.tag.String(). While the fix for this panic is outside the changed lines of this PR (it would involve adding a nil check for t.tag in modelRunnerTarget.Write before calling methods on it), this is a critical bug that can be triggered from the CLI and should be addressed.

I have also left one comment regarding test structure to improve maintainability.

Comment thread cmd/cli/commands/utils_test.go
Copy link
Copy Markdown
Contributor

@ilopezluna ilopezluna left a comment

Choose a reason for hiding this comment

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

Trying to package a local model using the branch I get the following error:

docker model package --gguf /Users/ilopezluna/Desktop/models/gemma3n-4b-it-text-GGUF/model.gguf \
  ignaciolopezluna020/embedding:dir-test       
Adding GGUF file from "/Users/ilopezluna/Desktop/models/gemma3n-4b-it-text-GGUF/model.gguf"
Loading model to Model Runner...
Transferred: 13103.58 MB
Failed to package model
package model: failed to load packaged model: tag model: tagging failed with status 404 Not Found: tagging model: model not found

@ericcurtin ericcurtin force-pushed the fix-local-model-error branch from a1aefad to 57e7644 Compare October 20, 2025 10:33
@ericcurtin
Copy link
Copy Markdown
Contributor Author

Thanks @ilopezluna removing this line fixes it, I think:

func (c *Client) Tag(source, targetRepo, targetTag string) error {
	source = dmrm.NormalizeModelName(source)

please keep reporting these issues, it's appreciated.

@ericcurtin ericcurtin force-pushed the fix-local-model-error branch from 57e7644 to 10d2d97 Compare October 20, 2025 10:37
Copilot AI review requested due to automatic review settings October 20, 2025 10:44
Copy link
Copy Markdown
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.

Add test to verify model namespace normalization consistency

Signed-off-by: Eric Curtin <eric.curtin@docker.com>
@ericcurtin ericcurtin force-pushed the fix-local-model-error branch from 771713b to 82db531 Compare October 20, 2025 10:56
@ericcurtin ericcurtin merged commit ed99eef into main Oct 20, 2025
9 checks passed
@ericcurtin ericcurtin deleted the fix-local-model-error branch October 20, 2025 10:59
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