Skip to content

fix: fix some bugs in check_conn and drop_inst - #16180

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
Haruko386:mono
Jun 18, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
Haruko386:mono

Conversation

@Haruko386

Copy link
Copy Markdown
Member

What problem does this PR solve?

As title:

BUG fixed was verified in RAGFlow CLI

CHECK INSTANCE 'instance_name' FROM 'provider_name'

RAGFlow(api/default)>  check instance 'test' from 'deepseek'
CLI error: api key is required

fixed:

RAGFlow(api/default)> check instance 'test' from 'deepseek'
SUCCESS

DROP INSTANCE 'instance_name' FROM 'provider_name'

Always return success

img_v3_0212p_632983f1-7330-477c-81c6-c2c4104e13ag

fixed:

check if instance is existed before do DROP

RAGFlow(api/default)> create provider 'deepseek' instance 'test1' key ''
SUCCESS

RAGFlow(api/default)> create provider 'deepseek' instance 'test2' key ''
SUCCESS

RAGFlow(api/default)> list instnaces from 'deepseek'
CLI error: unknown LIST target: instnaces

RAGFlow(api/default)> list instances from 'deepseek'
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+
| api_key                             | extra                       | id                               | instance_name | provider_id                      | status |
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+
|                                     | {"base_url":"","region":""} | 5a5a8a2a000a46aa92066c807ec697a1 | test2         | e268f01c4a8111f186e4988fe06f3cf3 | active |
|                                     | {"base_url":"","region":""} | c399f66d0c7843ff834ee907d9addcfa | test1         | e268f01c4a8111f186e4988fe06f3cf3 | active |
| sk-xxxxxxx7xxxxxxxxxxxxxxxxxxxxxxxx | {"base_url":"","region":""} | e4cde7a84a8111f186e4988fe06f3cf3 | test          | e268f01c4a8111f186e4988fe06f3cf3 | enable |
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+

RAGFlow(api/default)> drop instance 'gvrgrdgd' from 'deepseek'
CLI error: no instance found for provider "deepseek" and instances ["gvrgrdgd"]

RAGFlow(api/default)> drop instance 'gvrgrdgd' 'test1'  from 'deepseek'
CLI error: expected FROM

RAGFlow(api/default)> drop instance 'gvrgrdgd, test1'  from 'deepseek'
CLI error: no instance found for provider "deepseek" and instances ["gvrgrdgd, test1"]

RAGFlow(api/default)> drop instance 'test1'  from 'deepseek'
SUCCESS

RAGFlow(api/default)> list instances from 'deepseek'
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+
| api_key                             | extra                       | id                               | instance_name | provider_id                      | status |
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+
|                                     | {"base_url":"","region":""} | 5a5a8a2a000a46aa92066c807ec697a1 | test2         | e268f01c4a8111f186e4988fe06f3cf3 | active |
| sk-xxxxxxx7xxxxxxxxxxxxxxxxxxxxxxxx | {"base_url":"","region":""} | e4cde7a84a8111f186e4988fe06f3cf3 | test          | e268f01c4a8111f186e4988fe06f3cf3 | enable |
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+

RAGFlow(api/default)> drop instance 'test2'  from 'deepseek'
SUCCESS

RAGFlow(api/default)> list instances from 'deepseek'
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+
| api_key                             | extra                       | id                               | instance_name | provider_id                      | status |
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+
| sk-xxxxxxx7xxxxxxxxxxxxxxxxxxxxxxxx | {"base_url":"","region":""} | e4cde7a84a8111f186e4988fe06f3cf3 | test          | e268f01c4a8111f186e4988fe06f3cf3 | enable |
+-------------------------------------+-----------------------------+----------------------------------+---------------+----------------------------------+--------+

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 18, 2026
@Haruko386 Haruko386 added ci Continue Integration and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 18, 2026
@Haruko386
Haruko386 marked this pull request as draft June 18, 2026 06:16
@dosubot dosubot Bot added the 🐞 bug Something isn't working, pull request that fix bug. label Jun 18, 2026
@Haruko386
Haruko386 marked this pull request as ready for review June 18, 2026 06:16
@coderabbitai

coderabbitai Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

DropProviderInstances in the service is refactored to extract a getProviderInstancesByNames helper for bulk instance lookup, adds input validation, and maps missing providers or instances to CodeNotFound. The handler's DropProviderInstance now propagates the returned error code, and CheckInstanceConnection fixes the API key field name from apikey to api_key.

Changes

DropProviderInstances error handling and API key field fix

Layer / File(s) Summary
getProviderInstancesByNames helper and DropProviderInstances refactor
internal/service/model_service.go
Adds getProviderInstancesByNames private helper to bulk-fetch TenantModelInstance records and collect missing instance names. Refactors DropProviderInstances to validate non-empty input, map provider-not-found to CodeNotFound, use the helper to detect all missing instances before deletion, and return CodeNotFound if any deletion reports zero affected rows.
Handler API key field fix and error code propagation
internal/handler/providers.go
Fixes the API key extraction key from apikey to api_key in CheckInstanceConnection. Updates DropProviderInstance to capture and forward the code returned by DropProviderInstances instead of always emitting CodeServerError.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, the key was wrong, api_key all along,
The error code was stuck on "server fail" — that's not a song!
Now missing instances return a "not found" with grace,
And bulk lookup leaps ahead, collecting names apace.
A tidy helper burrows in, no single miss ignored —
This rabbit fixed the field name and the error code restored! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The linked issue (#39) is a template with mostly empty checkboxes and no clear objectives defined, making it impossible to validate code changes against specific requirements. The linked issue appears to be a placeholder without defined requirements. Verify whether this is the correct issue link or if actual issue requirements exist elsewhere.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main fixes: correcting the API key field name in check_conn and fixing the drop_inst behavior to validate instance existence.
Description check ✅ Passed The description is well-related to the changeset, providing concrete examples of the bugs fixed and verification of the corrections through CLI testing.
Out of Scope Changes check ✅ Passed All code changes are directly related to the two bugs described in the PR: fixing the API key field name lookup and implementing instance validation for drop operations.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


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.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 18, 2026
@Haruko386
Haruko386 marked this pull request as draft June 18, 2026 06:16
@Haruko386
Haruko386 marked this pull request as ready for review June 18, 2026 06:17

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

🧹 Nitpick comments (2)
internal/service/model_service.go (2)

903-913: ⚡ Quick win

Consider bulk query to avoid N+1 database calls.

The loop queries the database once per instance name. For larger instance lists, this could become a performance bottleneck. A single query with WHERE instance_name IN (...) followed by local set-differencing would reduce round trips.

Not urgent given typical usage patterns, but worth considering if instance lists grow.

🤖 Prompt for 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.

In `@internal/service/model_service.go` around lines 903 - 913, The loop around
GetByProviderIDAndInstanceName is making individual database queries for each
instance name, creating an N+1 query problem. Refactor this to make a single
database query that fetches all model instances for the given providerID using
an IN clause with all instanceNames at once, then perform local set-differencing
in memory to identify missingInstanceNames by comparing the returned instances
against the requested instanceNames list.

952-964: ⚖️ Poor tradeoff

Multiple deletes without transaction can leave partial state.

The loop performs DeleteByProviderIDAndInstanceID then DeleteByProviderIDAndInstanceName for each instance. If a failure occurs mid-loop (e.g., after deleting some instances but not others, or after deleting models but before deleting the instance row), the database is left in an inconsistent state with no rollback.

Consider wrapping the entire deletion loop in a database transaction to ensure atomicity.

🤖 Prompt for 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.

In `@internal/service/model_service.go` around lines 952 - 964, The deletion
operations within the loop iterating over modelInstances (calls to
m.modelDAO.DeleteByProviderIDAndInstanceID and
m.modelInstanceDAO.DeleteByProviderIDAndInstanceName) are not wrapped in a
database transaction, risking partial state if an error occurs mid-loop. Wrap
the entire loop in a database transaction that begins before the loop starts and
commits only after all deletions complete successfully, ensuring that any error
during the loop triggers a rollback to maintain consistency.
🤖 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.

Nitpick comments:
In `@internal/service/model_service.go`:
- Around line 903-913: The loop around GetByProviderIDAndInstanceName is making
individual database queries for each instance name, creating an N+1 query
problem. Refactor this to make a single database query that fetches all model
instances for the given providerID using an IN clause with all instanceNames at
once, then perform local set-differencing in memory to identify
missingInstanceNames by comparing the returned instances against the requested
instanceNames list.
- Around line 952-964: The deletion operations within the loop iterating over
modelInstances (calls to m.modelDAO.DeleteByProviderIDAndInstanceID and
m.modelInstanceDAO.DeleteByProviderIDAndInstanceName) are not wrapped in a
database transaction, risking partial state if an error occurs mid-loop. Wrap
the entire loop in a database transaction that begins before the loop starts and
commits only after all deletions complete successfully, ensuring that any error
during the loop triggers a rollback to maintain consistency.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 15fa7f42-5e41-40ee-ae9b-82b66fd991ba

📥 Commits

Reviewing files that changed from the base of the PR and between a902152 and c948110.

📒 Files selected for processing (2)
  • internal/handler/providers.go
  • internal/service/model_service.go

@JinHai-CN
JinHai-CN merged commit 27d723e into infiniflow:main Jun 18, 2026
13 of 21 checks passed
@Haruko386
Haruko386 deleted the mono branch June 18, 2026 06:23
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:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants