Skip to content

optimize the modelInfo#45

Merged
InftyAI-Agent merged 5 commits intoInftyAI:mainfrom
kerthcet:cleanup/cache
Apr 26, 2026
Merged

optimize the modelInfo#45
InftyAI-Agent merged 5 commits intoInftyAI:mainfrom
kerthcet:cleanup/cache

Conversation

@kerthcet
Copy link
Copy Markdown
Member

What this PR does / why we need it

Which issue(s) this PR fixes

Fixes #

Special notes for your reviewer

Does this PR introduce a user-facing change?


Signed-off-by: kerthcet <kerthcet@gmail.com>
Copilot AI review requested due to automatic review settings April 26, 2026 16:13
@InftyAI-Agent InftyAI-Agent added needs-triage Indicates an issue or PR lacks a label and requires one. needs-priority Indicates a PR lacks a label and requires one. do-not-merge/needs-kind Indicates a PR lacks a label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 26, 2026
Copy link
Copy Markdown

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 PR refactors the model metadata shape by renaming the stored “artifact” metadata to “cache” and adjusts ModelInfo field ordering, updating all call sites (CLI, downloader, registry, and tests) to match.

Changes:

  • Rename ArtifactInfoCacheInfo and ModelMetadata.artifactModelMetadata.cache across the codebase.
  • Reorder ModelInfo fields (move provider earlier) and update SQLite row-to-struct mapping accordingly.
  • Update CLI output and unit/integration tests to use the new cache field names.

Reviewed changes

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

Show a summary per file
File Description
src/storage/sqlite.rs Updates SQLite row mapping to ModelInfo and adjusts storage tests for metadata.cache.
src/registry/model_registry.rs Renames metadata structs/fields (artifactcache) and updates registry deletion path usage.
src/downloader/huggingface.rs Writes downloaded model metadata using CacheInfo/metadata.cache.
src/cli/rm.rs Updates CLI rm tests to construct models with metadata.cache.
src/cli/ls.rs Updates CLI ls tests to construct models with metadata.cache.
src/cli/inspect.rs Updates inspect display to read revision/size/path from metadata.cache.
src/cli/commands.rs Updates listing logic and CLI command tests to use metadata.cache.
src/api/tests.rs Updates API integration test model setup to use metadata.cache.
Comments suppressed due to low confidence (2)

src/registry/model_registry.rs:24

  • Renaming ModelMetadata.artifact to cache changes the serialized JSON shape. Since metadata is persisted as JSON in SQLite and deserialized with serde_json::from_str, any existing rows containing { "artifact": ... } will fail to deserialize after this change, breaking load_models() / get_model() for existing users. Consider adding backward compatibility via #[serde(alias = "artifact")] on cache (and/or a DB migration to rewrite stored JSON), and document this as a user-facing change if intentional.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ModelMetadata {
    pub cache: CacheInfo,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub context_window: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub safetensors: Option<serde_json::Value>,
}

src/storage/sqlite.rs:256

  • Tests were updated for the new cache field, but there’s no regression test covering backward compatibility with previously persisted JSON ({"artifact": ...}) in the SQLite metadata column. Adding a test that deserializes old metadata JSON into ModelMetadata (or loads a row containing the old key) would prevent accidental breaking changes in the future.
        });

        ModelInfo {
            uuid: uuid.to_string(),
            name: name.to_string(),
            provider: "huggingface".to_string(),
            author: Some("test-author".to_string()),
            task: Some("text-generation".to_string()),
            model_series: Some("gpt2".to_string()),
            license: Some("mit".to_string()),
            created_at: "2025-01-01T00:00:00Z".to_string(),
            updated_at: "2025-01-01T00:00:00Z".to_string(),
            metadata: ModelMetadata {
                cache: CacheInfo {
                    revision: "abc123".to_string(),
                    size: 1000,
                    path: "/tmp/test".to_string(),
                },
                context_window: Some(2048),
                safetensors: Some(safetensors),
            },
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/storage/sqlite.rs
Comment on lines 108 to 116
let metadata_json: String = row.get(7)?;
let metadata: ModelMetadata = serde_json::from_str(&metadata_json)
.map_err(|e| rusqlite::Error::ToSqlConversionFailure(Box::new(e)))?;

Ok(ModelInfo {
uuid: row.get(0)?,
name: row.get(1)?,
provider: row.get(5)?,
author: row.get(2)?,
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

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

metadata is deserialized from the SQLite JSON column (serde_json::from_str). With the artifact -> cache rename in ModelMetadata, existing databases written by previous versions will contain artifact and will fail to parse here, causing load_models() / get_model() to error. Address via serde aliasing on the struct field and/or a migration that updates the stored JSON key.

Copilot uses AI. Check for mistakes.
Comment thread src/registry/model_registry.rs Outdated
Comment thread src/cli/inspect.rs Outdated
Signed-off-by: kerthcet <kerthcet@gmail.com>
Signed-off-by: kerthcet <kerthcet@gmail.com>
Copilot AI review requested due to automatic review settings April 26, 2026 16:25
Signed-off-by: kerthcet <kerthcet@gmail.com>
@kerthcet
Copy link
Copy Markdown
Member Author

/lgtm
/kind cleanup

@InftyAI-Agent InftyAI-Agent added lgtm Looks good to me, indicates that a PR is ready to be merged. cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed do-not-merge/needs-kind Indicates a PR lacks a label and requires one. labels Apr 26, 2026
Signed-off-by: kerthcet <kerthcet@gmail.com>
@InftyAI-Agent InftyAI-Agent removed the lgtm Looks good to me, indicates that a PR is ready to be merged. label Apr 26, 2026
Copy link
Copy Markdown

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 10 out of 10 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/registry/model_registry.rs:24

  • ModelMetadata is persisted as JSON in SQLite (see serde_json::to_string(&model.metadata) / from_str in SqliteStorage). Renaming the JSON field from artifact to cache will make existing registries fail to deserialize on startup. Add a serde alias (e.g., #[serde(alias = "artifact")] on the cache field) or implement a custom deserializer to accept both keys for backward compatibility.
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ModelMetadata {
    pub cache: CacheInfo,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub context_window: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub safetensors: Option<serde_json::Value>,
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kerthcet
Copy link
Copy Markdown
Member Author

/lgtm

@InftyAI-Agent InftyAI-Agent added the lgtm Looks good to me, indicates that a PR is ready to be merged. label Apr 26, 2026
@InftyAI-Agent InftyAI-Agent merged commit 89cbd85 into InftyAI:main Apr 26, 2026
17 checks passed
@kerthcet kerthcet deleted the cleanup/cache branch April 26, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Looks good to me, indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a label and requires one. needs-triage Indicates an issue or PR lacks a label and requires one.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants