Skip to content

fix(model): delete provider models and instances in one transaction - #19562

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
ming1523:fix/drop-provider-instances-transaction
Sep 14, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
ming1523:fix/drop-provider-instances-transaction

Conversation

@ming1523

Copy link
Copy Markdown
Contributor

Summary

  • wrap the two deletes in DropProviderInstances (modelDAO.DeleteByInstanceIDs + modelInstanceDAO.DeleteByIDs) in a single gorm transaction, so a failure of the instance delete can no longer leave the tenant models already removed (partial provider deletion)
  • add a regression test that forces the tenant_model_instance delete to fail and asserts the rollback keeps the tenant models

Why

On current main the two deletes run independently. If the second delete fails, the models of the dropped instances are already gone while the instances remain, leaving an inconsistent provider state. The same non-transactional batch loop was flagged by the review bot on #14166 and #16180.

Tests

  • go test ./internal/service/ -run TestDropProviderInstances (new rollback case + existing model provider suites)

DropProviderInstances runs two independent deletes on main: tenant
models by instance IDs, then the instances themselves. If the instance
delete fails, the tenant models are already gone, leaving a partially
deleted provider. Review bots flagged the same non-transactional batch
loop on infiniflow#14166 and infiniflow#16180.

Wrap both deletes in a single gorm transaction and add a regression
test that forces the instance delete to fail and asserts the rollback
keeps the tenant models.
@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: a201d0da-48b9-4499-b2cc-327e5407d409

📥 Commits

Reviewing files that changed from the base of the PR and between 1f5d333 and b51891b.

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

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

DropProviderInstances now deletes tenant models and instances within one transaction. A new test forces instance deletion to fail and verifies that the preceding model deletion is rolled back.

Changes

Provider instance deletion

Layer / File(s) Summary
Transactional deletion and rollback validation
internal/service/model_service.go, internal/service/model_service_test.go
DropProviderInstances executes both delete operations in one transaction. The test injects an instance-delete error and verifies the tenant model remains.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: jinhai-cn

Merge Risk: ⚪ Minimal · up to b5189

The transactional deletion path and rollback regression coverage preserve provider data consistency when instance deletion fails.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. 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 and concisely describes the main change: making provider model and instance deletion transactional.
Description check ✅ Passed The description includes the required Summary section and clearly explains the problem, implementation, rollback behavior, and regression test.
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.
  • Fix all pre-merge checks with AI

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

A rabbit checks the rows with care
No half-deleted trail is there
One failure sends the changes back
The models stay upon their track
Safe transactions guard the burrow

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

@JinHai-CN JinHai-CN self-assigned this Sep 14, 2026
@JinHai-CN JinHai-CN added the ci Continue Integration label Sep 14, 2026
@JinHai-CN
JinHai-CN merged commit d8d06bc into infiniflow:main Sep 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants