Skip to content

Hosted models list - #332

Open
sanskaraggarwal2025 wants to merge 6 commits into
mainfrom
hosted-models-list
Open

sanskaraggarwal2025 wants to merge 6 commits into
mainfrom
hosted-models-list

Conversation

@sanskaraggarwal2025

Copy link
Copy Markdown
Collaborator

Closes #323

  • have to change correct hosted List Repo Link

@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@sanskaraggarwal2025, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 52 minutes and 49 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ef87d37-0762-4f0e-a66a-bc3782978613

📥 Commits

Reviewing files that changed from the base of the PR and between 783f4a4 and 5d8e91a.

⛔ Files ignored due to path filters (3)
  • backend/chatservice/proto/chatservice.pb.go is excluded by !**/*.pb.go
  • backend/chatservice/proto/chatservice_grpc.pb.go is excluded by !**/*.pb.go
  • backend/go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • backend/chatservice/api/api.go
  • backend/chatservice/dao/dao.go
  • backend/chatservice/dao/dao_postgres.go
  • backend/chatservice/dao/dao_sqlite.go
  • backend/chatservice/dao/db/postgres/scripts/migrations/15_add_model_catalog_versions.up.sql
  • backend/chatservice/dao/db/sqlite/scripts/migrations/23_add_model_catalog_versions.up.sql
  • backend/chatservice/dao/models.go
  • backend/chatservice/service/service.go
  • docs/design decisions/update_models_list.md
  • frontend/proto/chatservice.ts
  • frontend/src/pages/setting.tsx
  • frontend/src/store/setting.ts
  • proto/chatservice.proto
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hosted-models-list

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

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.

Code Review

This pull request implements a dynamic update system for the hosted models catalog, allowing the application to fetch and sync model metadata from a remote repository. The changes include a new UpdateModelsList RPC, database schema updates for version tracking, and a frontend synchronization interface. The review identifies several critical improvements: implementing database transactions for atomic version updates, avoiding hardcoded URLs, and reusing HTTP clients for better performance. Further feedback suggests addressing potential version sorting bugs, adding timeouts to background contexts, and optimizing string allocations in the DAO layer.

Comment on lines +1838 to +1852
for _, model := range manifest.Models {
if strings.TrimSpace(model.ID) == "" {
slog.Warn("service:UpdateModelsList", "message", "skipping hosted model with empty id")
continue
}

if strings.TrimSpace(model.Name) == "" {
model.Name = model.ID
}

if err := s.dao.UpsertHostedModel(model, version); err != nil {
slog.Error("service:UpdateModelsList", "message", "failed to upsert hosted model", "error", err, "modelID", model.ID)
return fmt.Errorf("failed to update models list")
}
}

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.

high

The version update logic is flawed. Currently, the version is updated for each model individually within the loop. Since GetModelCatalogVersion (line 1734) retrieves the latest version from any row in the table, a partial failure during this loop will leave the database in an inconsistent state. Specifically, if at least one model is successfully updated, subsequent calls to UpdateModelsList will see the new version and skip the update, leaving the remaining models outdated. The version should be stored in a separate metadata table and updated only after the entire loop completes successfully, or the entire operation should be wrapped in a database transaction.

SELECT json_schema_version, model_revision_version
FROM shared_models_metadata
WHERE COALESCE(model_revision_version, '') <> '' OR COALESCE(json_schema_version, '') <> ''
ORDER BY model_revision_version DESC, id ASC

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 lexicographical sorting of model_revision_version is fragile. If the versioning scheme uses a format like 20260522.2 and 20260522.10, the string comparison will incorrectly identify 20260522.2 as the greater (and thus latest) version because '2' > '1'. Consider using a strictly lexicographical format (e.g., zero-padding the minor version) or a numeric comparison if possible.

Comment on lines +1029 to +1034
func defaultJSONObjectBytes(value []byte) string {
if strings.TrimSpace(string(value)) == "" {
return "{}"
}
return string(value)
}

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 string(value) conversion is performed twice, which is inefficient as it results in redundant allocations. It is better to convert the byte slice once and reuse the resulting string.

Suggested change
func defaultJSONObjectBytes(value []byte) string {
if strings.TrimSpace(string(value)) == "" {
return "{}"
}
return string(value)
}
func defaultJSONObjectBytes(value []byte) string {
s := string(value)
if strings.TrimSpace(s) == "" {
return "{}"
}
return s
}

}

var row catalogVersionRow
// <> is not but not equal-to operator in sql

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

Typo in comment: "not but not" should likely be "but not".

Suggested change
// <> is not but not equal-to operator in sql
// <> is the not equal-to operator in sql

Comment on lines +71 to +72
hostedModelsCatalogURL = "https://raw.githubusercontent.com/sanskaraggarwal2025/hosted_models/main/models.json"
hostedModelsVersionURL = "https://raw.githubusercontent.com/sanskaraggarwal2025/hosted_models/main/models_version.json"

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 URLs for the models catalog and version are hardcoded to a personal GitHub repository. This creates a maintenance risk and a single point of failure. These should be configurable via the application's configuration or environment variables.

}
versionReq.Header.Set("Accept", "application/json")

client := &http.Client{Timeout: hostedModelsHTTPTimeout}

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

Creating a new http.Client on every invocation of UpdateModelsList is inefficient. In Go, http.Client is designed to be reused across multiple requests to benefit from connection pooling and reduced resource overhead. Consider making the client a field in the ChatService struct.

}
return nil

go s.UpdateModelsList(context.Background())

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

Using context.Background() for a network-dependent background task is risky as it lacks a timeout. If the HTTP request hangs indefinitely, the goroutine will leak. It is recommended to use a context with a reasonable timeout for this background operation.

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.

Sorted chat should be able to get latest Providers and Models

1 participant