Skip to content

feat[Go]: add modelID for delete_model and update_status - #16025

Merged
JinHai-CN merged 11 commits into
infiniflow:mainfrom
Haruko386:main
Jun 18, 2026
Merged

JinHai-CN merged 11 commits into
infiniflow:mainfrom
Haruko386:main

Conversation

@Haruko386

Copy link
Copy Markdown
Member

What problem does this PR solve?

  1. add modelID for delete_model and update_status
  2. fix the bug when update-status delete model

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)

@Haruko386 Haruko386 added 🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration labels Jun 15, 2026
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 15, 2026
@Haruko386 Haruko386 changed the title feat[Go]: add modelID for deleta_model and update_status feat[Go]: add modelID for delete_model and update_status Jun 15, 2026
@Haruko386
Haruko386 marked this pull request as draft June 15, 2026 09:12
@Haruko386
Haruko386 marked this pull request as ready for review June 15, 2026 09:12
@coderabbitai

coderabbitai Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds two ID-scoped TenantModelDAO methods (DeleteByModelIDAndProviderIDAndInstanceID, UpdateStatusByIDAndScope), extends handler request structs with model_id/model_ids fields, rewrites DropInstanceModels and UpdateModelStatus service methods to operate in dual ID/name mode, and propagates resolvedModelName/resolvedProviderName through all chat, embed, and rerank driver call sites.

Changes

Tenant Model ID-Based Operations and Resolved Routing

Layer / File(s) Summary
DAO: ID-scoped delete and status update
internal/dao/tenant_model.go
Adds DeleteByModelIDAndProviderIDAndInstanceID (hard-delete via Unscoped()) and UpdateStatusByIDAndScope (updates status column), both scoped by (id, provider_id, instance_id).
Handler: updated request schemas and validation
internal/handler/providers.go, internal/router/router.go
EnableOrDisableModelRequest adds model_id; DropInstanceModelRequest adds model_ids. Both drop binding:"required" from their respective status/models fields. Handlers trim inputs, reject both-empty cases, validate status as active/inactive, and pass new fields to service calls. Router gains a comment block with illustrative model JSON.
Service: ID-based DropInstanceModels and UpdateModelStatus
internal/service/model_service.go
DropInstanceModels accepts a modelIDs slice and deletes by scope, returning NotFound for missing IDs. UpdateModelStatus adds a modelID parameter and branches: by ID it verifies scope and calls UpdateStatusByIDAndScope; by name it creates a new TenantModel from factory schema if absent.
Chat/Embed/Rerank: resolved model name and baseURL driver routing
internal/service/model_service.go
ChatToModelWithMessages, ChatToModelStreamWithSender, EmbedText, and RerankDocument each compute resolvedModelName/resolvedProviderName from the tenant entity, validate model types against resolved info, construct baseURL-aware drivers for active tenant models via newModelDriverForBaseURL, and pass resolvedModelName to all driver call sites.

Sequence Diagram(s)

sequenceDiagram
    actor Client
    participant Handler as providers.go Handler
    participant ModelProviderService
    participant TenantModelDAO
    participant Driver

    rect rgba(100, 149, 237, 0.5)
        Note over Client,TenantModelDAO: UpdateModelStatus (ID-based path)
        Client->>Handler: PUT /enable-disable {model_id, status}
        Handler->>ModelProviderService: UpdateModelStatus(providerName, instanceName, modelName, userID, modelID, status)
        ModelProviderService->>TenantModelDAO: FindByID(modelID)
        TenantModelDAO-->>ModelProviderService: TenantModel
        ModelProviderService->>TenantModelDAO: UpdateStatusByIDAndScope(modelID, providerID, instanceID, status)
        TenantModelDAO-->>ModelProviderService: rowsAffected
        ModelProviderService-->>Handler: success/NotFound
        Handler-->>Client: 200 OK / 404
    end

    rect rgba(144, 238, 144, 0.5)
        Note over Client,Driver: Chat/Embed/Rerank with resolved naming
        Client->>Handler: POST /chat or /embed or /rerank
        Handler->>ModelProviderService: ChatToModelWithMessages / EmbedText / RerankDocument
        ModelProviderService->>TenantModelDAO: resolve tenant entity
        TenantModelDAO-->>ModelProviderService: entity (name, baseURL, region)
        ModelProviderService->>ModelProviderService: derive resolvedModelName, resolvedProviderName
        ModelProviderService->>Driver: newModelDriverForBaseURL(resolvedProviderName, baseURL, region)
        Driver-->>ModelProviderService: driver instance
        ModelProviderService->>Driver: Chat/Embed/Rerank(resolvedModelName)
        Driver-->>Client: response
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • infiniflow/ragflow#15999: Implements model_id-based model resolution in the same internal/handler/providers.go payloads and refactors internal/service/model_service.go chat/driver selection with tenant active model resolved names—directly overlapping with this PR's changes.

Suggested labels

💞 feature, size:M

Poem

🐇 Hop hop, the model IDs now flow,
No longer just names for the rabbit to know!
Resolved names bounce through chat, embed, rerank,
With baseURL drivers to give extra rank.
Factory schemas fill gaps in the warren,
The tenant model DAO is no longer foreign! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding modelID support for delete_model and update_status operations, which aligns with the primary objectives of the PR.
Description check ✅ Passed The PR description addresses the template requirements by identifying the problem (adding modelID support and fixing a bug) and selecting appropriate change type checkboxes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/handler/providers.go`:
- Around line 706-709: The EnableOrDisableModelRequest struct now accepts
model_id for ID-only updates, but the current route handler still
unconditionally requires the path parameter model_name, preventing clients from
using the ID-only mode. Register an additional PATCH route without the
/*model_name path parameter so that requests can be routed to a handler that
supports true ID-only status updates using only the model_id field from the
request body. This new route should complement the existing route that uses
model_name from the path.

In `@internal/service/model_service.go`:
- Around line 1143-1148: The code checks the `err` variable twice against the
same error from GetModelByProviderIDAndInstanceIDAndModelName. After assigning
modelID from utility.GenerateToken() on line 1146, the subsequent if err != nil
check on line 1147 still references the stale error from the GetModel call, not
from GenerateToken, making the create-on-missing logic unreachable. Either
remove the stale error check if GenerateToken cannot fail, or properly capture
and check the error returned by GenerateToken() with a new variable assignment
using := operator instead of reusing the old err variable.
- Around line 1156-1161: The code accessing modelSchema.ModelTypes[0] in the
model assignment block does not check if the ModelTypes slice is non-empty
before indexing, which will cause a panic if the slice is empty. Add a guard
condition to verify that modelSchema.ModelTypes has at least one element before
accessing index 0, and handle the empty case appropriately (either by returning
an error or using a sensible default value).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 05a09cb3-5bc8-4748-9293-b538c67cf5b4

📥 Commits

Reviewing files that changed from the base of the PR and between f6a2075 and 151e9b8.

📒 Files selected for processing (5)
  • internal/dao/tenant_model.go
  • internal/handler/providers.go
  • internal/router/router.go
  • internal/service/model_service.go
  • internal/service/model_service_test.go

Comment thread internal/handler/providers.go Resolved
Comment thread internal/service/model_service.go Resolved
Comment thread internal/service/model_service.go Resolved
@codecov

codecov Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (7d94b08) to head (f11cc02).
⚠️ Report is 65 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #16025   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This README provides installation instructions for RAGFlow CLI on Linux, macOS, and Windows, including usage examples for the installation scripts.
Removed commented-out JSON structure for model configurations.
}

if count == 0 {
return common.CodeNotFound, fmt.Errorf("model %s not found", modelID)

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.

Seems like there's no tests for this file. Is it possible to add? At least add tests for the method that's being modified.

@JinHai-CN
JinHai-CN merged commit 6beae94 into infiniflow:main Jun 18, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants