fix(ability): report an emptied group as no channel, not DB corruption - #6504
fix(ability): report an emptied group as no channel, not DB corruption#6504tryingmeow wants to merge 3 commits into
Conversation
When auto-ban disables the last enabled channel serving a model in a group, an in-flight request's next retry re-queries that group and finds no abilities. getPriority treated the empty result as a broken invariant and returned "数据库一致性被破坏", which surfaced to the client instead of the ordinary no-available-channel message. Report the empty result as "group does not serve this model" and let the caller fall through to its existing no-channel handling. Only the retry path is affected: retry=0 selects via a MAX(priority) subquery and never reached this check.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughUpdates retry channel selection so an empty ability result is treated as no available channel. Adds a regression test that disables the only channel and verifies that ChangesChannel retry regression
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change makes an emptied ability group follow the existing no-available-channel path instead of exposing a misleading database-corruption error, with a focused regression test covering the retry scenario. No actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@model/ability_no_channel_test.go`:
- Around line 29-43: Update the test setup around the Channel and Ability
creation to remove the hardcoded Id from Channel, let GORM generate it, and
assign the created channel’s generated ID to Ability.ChannelId before creating
the ability.
🪄 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 Plus
Run ID: bf67b303-0812-482d-86ed-b97dcf957e86
📒 Files selected for processing (2)
model/ability.gomodel/ability_no_channel_test.go
Addresses review feedback: hardcoding the primary key risks colliding with shared test state, and the project asks for GORM-generated keys.
|
Thanks — applied in a1e36c1. The test now lets GORM generate the channel id and derives Re-verified after the change: the test still fails on current |
6ca8c0c to
a1e36c1
Compare
…the test a1e36c1 was meant to change only the regression test, but it also reverted model/ability.go, leaving the branch with a test that asserts behaviour the code no longer had. TestGetChannelReportsNoChannelAfterLastAbilityDisabled fails on the branch as it stands. Restores the original change: an emptied group reports no channel instead of "数据库一致性被破坏", which is reachable during retries because auto-disable flips the channel that just failed.
51fdfc5 to
2b6f1df
Compare
📝 变更描述 / Description
getPriority在查不到优先级时返回errors.New("数据库一致性被破坏")。但这个空结果在重试路径上是可以正常出现的:自动禁用会通过UpdateAbilityStatus把刚失败的渠道的 ability 置为禁用,因此一个只剩最后一个渠道的分组会在请求进行中合法地变空。于是一个正常的“没有可用渠道了”被报成了数据损坏,并一路冒到客户端。改法:
getPriority额外返回一个found标志;getChannelQuery在未找到时返回 nil query;GetChannel据此返回(nil, nil),交由调用方走既有的无可用渠道处理逻辑。只影响
retry != 0:retry = 0用的是MAX(priority)子查询,从不经过这个检查,行为不变。🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
新增
model/ability_no_channel_test.go,复刻“自动禁用后重试”的场景,不依赖真实上游、不依赖网络:先取一次渠道,再UpdateAbilityStatus(1, false)模拟自动禁用,然后以retry = 1再次GetChannel。当前 main(
afe16c64):本 PR 之后:
gofmt -l model/、go vet ./model/、go build ./model/均通过。说明
本 PR 的代码为 AI 辅助编写。问题定位、改法取舍与最终代码由我逐行复核;测试是不依赖网络的确定性用例,上面的红/绿输出可由维护者直接复跑验证。
Summary by CodeRabbit
Bug Fixes
Tests