Skip to content

refactor: move isModelBlockedByList logic into BlackList.IsBlocked method on the schema type - #4222

Merged
akshaydeo merged 2 commits into
devfrom
06-09-fix_reverts_vk_blocklist_changes
Jun 9, 2026
Merged

akshaydeo merged 2 commits into
devfrom
06-09-fix_reverts_vk_blocklist_changes

Conversation

@Pratham-Mishra04

@Pratham-Mishra04 Pratham-Mishra04 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

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
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

go test ./...

Breaking changes

  • Yes
  • 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

Summary by CodeRabbit

  • Tests

    • Removed blacklist model verification test suite.
  • Refactor

    • Streamlined blacklist validation across governance plugin components.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Pratham-Mishra04 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR removes internal blacklist-checking helper functions and redirects all model blocking evaluation through the BlacklistedModels.IsBlocked method. The slices import and helper functions are deleted from utils.go, and all three call sites across main.go, resolver.go, and utils.go are updated to invoke the method directly instead.

Changes

Blacklist model checking refactor

Layer / File(s) Summary
Remove helper function and import dependency
plugins/governance/utils.go
Remove the internal isModelBlockedByList and blockedModelCandidates helper functions, along with the unused slices import that supported them.
Update all call sites to use BlacklistedModels.IsBlocked method
plugins/governance/main.go, plugins/governance/resolver.go, plugins/governance/utils.go
Replace isModelBlockedByList calls in loadBalanceProvider, isModelAllowed, and filterModelsForVirtualKey with direct invocation of BlacklistedModels.IsBlocked(model) method.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • maximhq/bifrost#3727: Refactor of blacklist-matching logic in plugins/governance replacing isModelBlockedByList with method invocation.
  • maximhq/bifrost#3718: Modifies the same governance blacklist enforcement logic by swapping between isModelBlockedByList(...) and BlacklistedModels.IsBlocked(...) in main.go/resolver.go/utils.go.
  • maximhq/bifrost#3653: Introduces the virtual-key governance blacklist logic that is refactored here to use BlacklistedModels.IsBlocked(...) method directly.

Suggested reviewers

  • akshaydeo
  • danpiths
  • roroghost17

Poem

🐰 The helpers hop away, their work now done,
Method calls take the stage—simplification won!
No more slices, no more tests to keep,
Cleaner governance code runs deep. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring change—moving the isModelBlockedByList logic into a BlackList.IsBlocked method on the schema type.
Description check ✅ Passed The PR description is comprehensive and covers all key template sections: summary, changes, type of change, affected areas, testing instructions, breaking changes, and checklist confirmation.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-09-fix_reverts_vk_blocklist_changes

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 @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 3/5

The 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 "ollama/mistral:latest" and "mistral:latest" interchangeable in blacklist comparisons was the core behavior of the deleted code; the replacement IsBlocked omits it, and the tests confirming it were deleted. This directly affects governance enforcement on any deployment that mixes prefixed and bare model identifiers in blacklist config.

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

Filename Overview
plugins/governance/utils.go Removes isModelBlockedByList and blockedModelCandidates; the provider-prefix normalization logic (via ParseModelString) they contained is absent from BlackList.IsBlocked, causing a behavioral regression in cross-form model matching.
plugins/governance/blocklist_test.go Deleted file; the deleted cross-form test cases ("prefixed blacklist blocks bare request", "bare blacklist blocks prefixed request") captured behavior that is now broken and were not ported to account_test.go.
plugins/governance/main.go Call site updated from isModelBlockedByList to IsBlocked; structurally correct but inherits the regression in IsBlocked's matching logic.
plugins/governance/resolver.go Call site updated from isModelBlockedByList to IsBlocked; same regression exposure as main.go.

Comments Outside Diff (1)

  1. plugins/governance/utils.go, line 63-95 (link)

    P1 Provider-prefix normalization silently dropped — blacklist matching now broken

    The removed isModelBlockedByList generated both forms of a model string via blockedModelCandidates (which calls ParseModelString), so "mistral:latest" and "ollama/mistral:latest" were treated as equivalent on both sides of the comparison. BlackList.IsBlocked only calls bl.Contains, which does a bare strings.EqualFold, so cross-form pairs are no longer matched. A virtual-key policy of ["mistral:latest"] will no longer block a request for "ollama/mistral:latest", and vice versa — the deleted test cases "prefixed blacklist blocks bare request" and "bare blacklist blocks prefixed request" directly covered these now-broken paths and were removed along with the function without equivalent coverage being added to account_test.go.

Reviews (1): Last reviewed commit: "fix: reverts vk blocklist changes" | Re-trigger Greptile

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

📥 Commits

Reviewing files that changed from the base of the PR and between bd0db20 and 4ea80eb.

📒 Files selected for processing (4)
  • plugins/governance/blocklist_test.go
  • plugins/governance/main.go
  • plugins/governance/resolver.go
  • plugins/governance/utils.go
💤 Files with no reviewable changes (1)
  • plugins/governance/blocklist_test.go

Comment thread plugins/governance/resolver.go

akshaydeo commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Merge activity

  • Jun 9, 6:28 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 9, 6:30 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo
akshaydeo changed the base branch from 06-09-fix_routing_governance_allowlsit_fixes to graphite-base/4222 June 9, 2026 18:29
@akshaydeo
akshaydeo changed the base branch from graphite-base/4222 to dev June 9, 2026 18:29
@akshaydeo
akshaydeo merged commit ca21298 into dev Jun 9, 2026
10 of 11 checks passed
@akshaydeo
akshaydeo deleted the 06-09-fix_reverts_vk_blocklist_changes branch June 9, 2026 18:30
akshaydeo pushed a commit that referenced this pull request Jun 12, 2026
…` 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 -->
akhsaul pushed a commit to akhsaul/bifrost that referenced this pull request Aug 27, 2026
…` 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 -->
occcat pushed a commit to occcat/bifrost that referenced this pull request Sep 2, 2026
…` 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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants