refactor: move isModelBlockedByList logic into BlackList.IsBlocked method on the schema type - #4222
Conversation
|
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
📝 WalkthroughWalkthroughThe PR removes internal blacklist-checking helper functions and redirects all model blocking evaluation through the ChangesBlacklist model checking refactor
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
Confidence Score: 3/5The governance blacklist enforcement is functionally broken for any model specified with a provider prefix on one side and without one on the other — virtual-key policies relying on cross-form matching will silently stop working after this merge. The normalization step that made plugins/governance/utils.go and core/schemas/account.go — the former is where the normalization logic was removed, the latter is where it needs to be added (or re-wired) to restore equivalence. Important Files Changed
|
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 `@plugins/governance/resolver.go`:
- Line 366: The current check uses pc.Provider and
pc.BlacklistedModels.IsBlocked(model) which fails to consider normalized
provider-prefixed and bare model variants; restore the prior normalization
semantics by ensuring BlackList.IsBlocked (or callers like the check in
resolver.go and the new calls in plugins/governance/main.go and
plugins/governance/utils.go) tests both provider-prefixed and bare,
case-insensitive variants (e.g., "openai/gpt-4o" and "gpt-4o") before returning
false; either update BlackList.IsBlocked to internally generate and compare the
normalized candidate list (preferred) or reintroduce the blockedModelCandidates
/ isModelBlockedByList normalization call paths so
pc.BlacklistedModels.IsBlocked receives the same normalized candidates as
before.
🪄 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: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: e07f8915-21e3-48fd-9881-beeb5b5cd1a2
📒 Files selected for processing (4)
plugins/governance/blocklist_test.goplugins/governance/main.goplugins/governance/resolver.goplugins/governance/utils.go
💤 Files with no reviewable changes (1)
- plugins/governance/blocklist_test.go
Merge activity
|
…` method on the schema type (#4222) ## Summary Moves the `isModelBlockedByList` logic from a standalone function in the governance plugin's `utils.go` into a method (`IsBlocked`) on the `BlackList` type in the core schemas package, consolidating the blocked-model check closer to the type it operates on. ## Changes - Removed `isModelBlockedByList` and `blockedModelCandidates` helper functions from `plugins/governance/utils.go` - Replaced all call sites (`loadBalanceProvider`, `isModelAllowed`, `filterModelsForVirtualKey`) with `pc.BlacklistedModels.IsBlocked(model)`, delegating to the new method on `schemas.BlackList` - Removed the corresponding unit tests from `plugins/governance/blocklist_test.go`, as the logic and its tests now live with the `BlackList` type ## Type of change - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./... ``` ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations No security implications. This is a pure refactor with no behavioral changes to the blocklist matching logic. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Removed blacklist model verification test suite. * **Refactor** * Streamlined blacklist validation across governance plugin components. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…` method on the schema type (maximhq#4222) ## Summary Moves the `isModelBlockedByList` logic from a standalone function in the governance plugin's `utils.go` into a method (`IsBlocked`) on the `BlackList` type in the core schemas package, consolidating the blocked-model check closer to the type it operates on. ## Changes - Removed `isModelBlockedByList` and `blockedModelCandidates` helper functions from `plugins/governance/utils.go` - Replaced all call sites (`loadBalanceProvider`, `isModelAllowed`, `filterModelsForVirtualKey`) with `pc.BlacklistedModels.IsBlocked(model)`, delegating to the new method on `schemas.BlackList` - Removed the corresponding unit tests from `plugins/governance/blocklist_test.go`, as the logic and its tests now live with the `BlackList` type ## Type of change - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./... ``` ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations No security implications. This is a pure refactor with no behavioral changes to the blocklist matching logic. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Removed blacklist model verification test suite. * **Refactor** * Streamlined blacklist validation across governance plugin components. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…` method on the schema type (maximhq#4222) ## Summary Moves the `isModelBlockedByList` logic from a standalone function in the governance plugin's `utils.go` into a method (`IsBlocked`) on the `BlackList` type in the core schemas package, consolidating the blocked-model check closer to the type it operates on. ## Changes - Removed `isModelBlockedByList` and `blockedModelCandidates` helper functions from `plugins/governance/utils.go` - Replaced all call sites (`loadBalanceProvider`, `isModelAllowed`, `filterModelsForVirtualKey`) with `pc.BlacklistedModels.IsBlocked(model)`, delegating to the new method on `schemas.BlackList` - Removed the corresponding unit tests from `plugins/governance/blocklist_test.go`, as the logic and its tests now live with the `BlackList` type ## Type of change - [ ] Bug fix - [ ] Feature - [x] Refactor - [ ] Documentation - [ ] Chore/CI ## Affected areas - [ ] Core (Go) - [ ] Transports (HTTP) - [ ] Providers/Integrations - [x] Plugins - [ ] UI (React) - [ ] Docs ## How to test ```sh go test ./... ``` ## Breaking changes - [ ] Yes - [x] No ## Related issues ## Security considerations No security implications. This is a pure refactor with no behavioral changes to the blocklist matching logic. ## Checklist - [ ] I read `docs/contributing/README.md` and followed the guidelines - [ ] I added/updated tests where appropriate - [ ] I updated documentation where needed - [ ] I verified builds succeed (Go and UI) - [ ] I verified the CI pipeline passes locally if applicable <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Tests** * Removed blacklist model verification test suite. * **Refactor** * Streamlined blacklist validation across governance plugin components. <!-- end of auto-generated comment: release notes by coderabbit.ai -->

Summary
Moves the
isModelBlockedByListlogic from a standalone function in the governance plugin'sutils.gointo a method (IsBlocked) on theBlackListtype in the core schemas package, consolidating the blocked-model check closer to the type it operates on.Changes
isModelBlockedByListandblockedModelCandidateshelper functions fromplugins/governance/utils.goloadBalanceProvider,isModelAllowed,filterModelsForVirtualKey) withpc.BlacklistedModels.IsBlocked(model), delegating to the new method onschemas.BlackListplugins/governance/blocklist_test.go, as the logic and its tests now live with theBlackListtypeType of change
Affected areas
How to test
go test ./...Breaking changes
Related issues
Security considerations
No security implications. This is a pure refactor with no behavioral changes to the blocklist matching logic.
Checklist
docs/contributing/README.mdand followed the guidelinesSummary by CodeRabbit
Tests
Refactor