Skip to content

refactor: simplify load balancing skip logic to use parsed provider field directly - #4279

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
06-11-fix_governance_provider_load_balancing_fixes
Jun 11, 2026
Merged

Pratham-Mishra04 merged 1 commit into
devfrom
06-11-fix_governance_provider_load_balancing_fixes

Conversation

@Pratham-Mishra04

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

Copy link
Copy Markdown
Collaborator

Summary

Simplifies the load balancing skip logic in the governance plugin by leveraging the provider value already parsed from GetRequestFields(), and bumps several indirect dependencies in the model catalog resolver module.

Changes

  • The loadBalanceProvider function previously discarded the provider returned by GetRequestFields() and re-parsed it manually from the model string when a / was detected, with additional branching to check the in-memory store for configured providers. This logic is replaced by a straightforward check: if provider is already non-empty (as returned directly by GetRequestFields()), skip load balancing immediately. This removes the dependency on inMemoryStore for this check and eliminates the strings.Contains slash-detection path.
  • Bumped cloud.google.com/go/iam from v1.5.3 to v1.7.0.
  • Bumped github.com/aws/aws-sdk-go-v2 from v1.41.7 to v1.41.12.
  • Bumped github.com/aws/aws-sdk-go-v2/internal/configsources from v1.4.23 to v1.4.28.
  • Bumped github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 from v2.7.23 to v2.7.28.
  • Bumped github.com/aws/smithy-go from v1.25.1 to v1.27.1.

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 ./plugins/governance/...

Verify that requests with a provider already set on the request are not load balanced, and that requests without a provider still proceed through load balancing as expected.

Breaking changes

  • Yes
  • No

Related issues

Security considerations

None.

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

  • Improvements

    • Refined load-balancing behavior to respect an explicitly set provider and avoid fallback parsing, improving selection predictability.
  • Chores

    • Updated indirect dependencies, including Google Cloud IAM and AWS SDK modules, to newer stable versions.

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

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6d647fae-a9a2-416a-b4aa-e5b407f46d13

📥 Commits

Reviewing files that changed from the base of the PR and between 046594b and 14d6864.

⛔ Files ignored due to path filters (1)
  • plugins/modelcatalogresolver/go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • plugins/governance/main.go
  • plugins/modelcatalogresolver/go.mod

📝 Walkthrough

Walkthrough

Simplifies governance plugin provider-selection by exiting early when request provider is set; removes model-string prefix inference. Also updates indirect Go module versions in the modelcatalogresolver module.

Changes

Governance & Dependency Updates

Layer / File(s) Summary
Load Balance Provider Logic Simplification
plugins/governance/main.go
loadBalanceProvider now destructures req.GetRequestFields() to obtain provider, logs and returns immediately when provider is non-empty, and no longer attempts to infer/validate a provider from modelStr prefixes.
Go Module Dependency Version Updates
plugins/modelcatalogresolver/go.mod
Indirect dependencies bumped: cloud.google.com/go/iam v1.5.3→v1.7.0, AWS SDK v2 internal modules updated, and github.com/aws/smithy-go v1.25.1→v1.27.1.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • maximhq/bifrost#3933: Also modifies plugins/governance/main.go's provider/model parsing and skip logic.
  • maximhq/bifrost#3924: Changes related provider allowlist population that can affect load-balance decisions.
  • maximhq/bifrost#4221: Alters PreRequestHook/published allowlist which interacts with routing decisions seen by loadBalanceProvider.

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

🐰 I nudged the provider, quick and spry,
No more prefix hunts that made me sigh.
Bumped some deps, a tiny hop and hum—
Simpler checks now skip where set is from.
Hooray, the load balance nap is done!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor: simplify load balancing skip logic to use parsed provider field directly' accurately and specifically summarizes the main change—simplifying the load-balancing logic in the governance plugin by using the provider field directly.
Description check ✅ Passed The description covers all essential sections: Summary, Changes (with detailed explanation), Type of change, Affected areas, How to test, Breaking changes, and Security considerations. All critical information required by the template is present and complete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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-11-fix_governance_provider_load_balancing_fixes

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 11, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The governance logic change is not safe to merge as-is: the large-payload routing path builds a synthetic request without a Provider field, so the new guard silently lets provider-prefixed model strings pass through load balancing instead of being left unchanged.

The simplified guard is correct for the normal HTTP path but breaks the large-payload runPreRequestRouting path where the synthetic BifrostRequest always has an empty Provider. A provider-prefixed metadata.Model will now reach the weighted-selection logic and potentially have its provider replaced.

plugins/governance/main.go — specifically the interaction between runPreRequestRouting (lines 410–444) and the updated loadBalanceProvider guard (line 466).

Important Files Changed

Filename Overview
plugins/governance/main.go Simplifies loadBalanceProvider skip guard from a slash-detection + inMemoryStore lookup to provider != ""; correct for the normal request path but the runPreRequestRouting synthetic request (large-payload branch) still builds a ChatRequest with no Provider set, so provider-prefixed model strings that arrived via that path silently bypass the guard and proceed to load balancing instead of being left unchanged.
plugins/modelcatalogresolver/go.mod Routine indirect-dependency version bumps for cloud.google.com/go/iam and multiple AWS SDK v2 packages; no API-breaking changes expected.
plugins/modelcatalogresolver/go.sum Checksum updates corresponding to the go.mod version bumps; no issues.

Reviews (2): Last reviewed commit: "fix: governance provider load balancing ..." | Re-trigger Greptile

Comment thread plugins/governance/main.go
Comment on lines +461 to 469
provider, modelStr, existingFallbacks := req.GetRequestFields()
if modelStr == "" {
return nil
}

// Model already has provider prefix pointing to a configured provider → leave it alone.
if strings.Contains(modelStr, "/") {
provider, _ := schemas.ParseModelString(modelStr, "")
// Checking valid provider when store is available; if store is nil,
// assume the prefixed model should be left unchanged.
if p.inMemoryStore != nil {
if _, ok := p.inMemoryStore.GetConfiguredProviders()[provider]; ok {
ctx.AppendRoutingEngineLog(schemas.RoutingEngineGovernance, schemas.LogLevelInfo, fmt.Sprintf("Skipping load balancing for model %s: already prefixed with configured provider %s", modelStr, provider))
return nil
}
} else {
ctx.AppendRoutingEngineLog(schemas.RoutingEngineGovernance, schemas.LogLevelWarn, fmt.Sprintf("Skipping load balancing for model %s: provider-prefixed and no in-memory store to validate against", modelStr))
return nil
}
if provider != "" {
ctx.AppendRoutingEngineLog(schemas.RoutingEngineGovernance, schemas.LogLevelInfo, fmt.Sprintf("Skipping load balancing for model %s: provider %s already set", modelStr, provider))
return nil
}

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.

P2 No test coverage for loadBalanceProvider skip behavior

There are no existing tests that exercise the "skip load balancing when provider is already set" path, nor the large-payload synthetic-request path through runPreRequestRouting. The PR description suggests testing go test ./plugins/governance/..., but the test files don't include a case that sends a request with a non-empty provider (or a provider-prefixed model string) to loadBalanceProvider and verifies the function returns immediately without mutating the request. Given the behavioral change introduced here, a targeted table-driven test covering both the provider != "" early exit and the synthetic-request / raw-model-string case would help prevent future regressions.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Pratham-Mishra04 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Jun 11, 7:18 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 11, 7:39 AM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 11, 7:39 AM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from 06-10-docs_semantic_cache_doc_updates to graphite-base/4279 June 11, 2026 07:36
@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from graphite-base/4279 to dev June 11, 2026 07:38
@Pratham-Mishra04
Pratham-Mishra04 requested a review from a team as a code owner June 11, 2026 07:38
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-11-fix_governance_provider_load_balancing_fixes branch from 046594b to 14d6864 Compare June 11, 2026 07:38
@Pratham-Mishra04
Pratham-Mishra04 merged commit 10a4d84 into dev Jun 11, 2026
13 of 15 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 06-11-fix_governance_provider_load_balancing_fixes branch June 11, 2026 07:39
akshaydeo pushed a commit that referenced this pull request Jun 12, 2026
…ield directly (#4279)

## Summary

Simplifies the load balancing skip logic in the governance plugin by leveraging the provider value already parsed from `GetRequestFields()`, and bumps several indirect dependencies in the model catalog resolver module.

## Changes

- The `loadBalanceProvider` function previously discarded the provider returned by `GetRequestFields()` and re-parsed it manually from the model string when a `/` was detected, with additional branching to check the in-memory store for configured providers. This logic is replaced by a straightforward check: if `provider` is already non-empty (as returned directly by `GetRequestFields()`), skip load balancing immediately. This removes the dependency on `inMemoryStore` for this check and eliminates the `strings.Contains` slash-detection path.
- Bumped `cloud.google.com/go/iam` from `v1.5.3` to `v1.7.0`.
- Bumped `github.com/aws/aws-sdk-go-v2` from `v1.41.7` to `v1.41.12`.
- Bumped `github.com/aws/aws-sdk-go-v2/internal/configsources` from `v1.4.23` to `v1.4.28`.
- Bumped `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from `v2.7.23` to `v2.7.28`.
- Bumped `github.com/aws/smithy-go` from `v1.25.1` to `v1.27.1`.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [x] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [x] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go test ./plugins/governance/...
```

Verify that requests with a provider already set on the request are not load balanced, and that requests without a provider still proceed through load balancing as expected.

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

None.

## 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

* **Improvements**
  * Optimized load balancing logic for more efficient provider selection

* **Chores**
  * Updated dependencies including Google Cloud IAM and AWS SDK modules to latest stable versions

<!-- 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
…ield directly (maximhq#4279)

## Summary

Simplifies the load balancing skip logic in the governance plugin by leveraging the provider value already parsed from `GetRequestFields()`, and bumps several indirect dependencies in the model catalog resolver module.

## Changes

- The `loadBalanceProvider` function previously discarded the provider returned by `GetRequestFields()` and re-parsed it manually from the model string when a `/` was detected, with additional branching to check the in-memory store for configured providers. This logic is replaced by a straightforward check: if `provider` is already non-empty (as returned directly by `GetRequestFields()`), skip load balancing immediately. This removes the dependency on `inMemoryStore` for this check and eliminates the `strings.Contains` slash-detection path.
- Bumped `cloud.google.com/go/iam` from `v1.5.3` to `v1.7.0`.
- Bumped `github.com/aws/aws-sdk-go-v2` from `v1.41.7` to `v1.41.12`.
- Bumped `github.com/aws/aws-sdk-go-v2/internal/configsources` from `v1.4.23` to `v1.4.28`.
- Bumped `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from `v2.7.23` to `v2.7.28`.
- Bumped `github.com/aws/smithy-go` from `v1.25.1` to `v1.27.1`.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [x] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [x] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go test ./plugins/governance/...
```

Verify that requests with a provider already set on the request are not load balanced, and that requests without a provider still proceed through load balancing as expected.

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

None.

## 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

* **Improvements**
  * Optimized load balancing logic for more efficient provider selection

* **Chores**
  * Updated dependencies including Google Cloud IAM and AWS SDK modules to latest stable versions

<!-- 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
…ield directly (maximhq#4279)

## Summary

Simplifies the load balancing skip logic in the governance plugin by leveraging the provider value already parsed from `GetRequestFields()`, and bumps several indirect dependencies in the model catalog resolver module.

## Changes

- The `loadBalanceProvider` function previously discarded the provider returned by `GetRequestFields()` and re-parsed it manually from the model string when a `/` was detected, with additional branching to check the in-memory store for configured providers. This logic is replaced by a straightforward check: if `provider` is already non-empty (as returned directly by `GetRequestFields()`), skip load balancing immediately. This removes the dependency on `inMemoryStore` for this check and eliminates the `strings.Contains` slash-detection path.
- Bumped `cloud.google.com/go/iam` from `v1.5.3` to `v1.7.0`.
- Bumped `github.com/aws/aws-sdk-go-v2` from `v1.41.7` to `v1.41.12`.
- Bumped `github.com/aws/aws-sdk-go-v2/internal/configsources` from `v1.4.23` to `v1.4.28`.
- Bumped `github.com/aws/aws-sdk-go-v2/internal/endpoints/v2` from `v2.7.23` to `v2.7.28`.
- Bumped `github.com/aws/smithy-go` from `v1.25.1` to `v1.27.1`.

## Type of change

- [ ] Bug fix
- [ ] Feature
- [x] Refactor
- [ ] Documentation
- [x] Chore/CI

## Affected areas

- [ ] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [x] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

```sh
go test ./plugins/governance/...
```

Verify that requests with a provider already set on the request are not load balanced, and that requests without a provider still proceed through load balancing as expected.

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

None.

## 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

* **Improvements**
  * Optimized load balancing logic for more efficient provider selection

* **Chores**
  * Updated dependencies including Google Cloud IAM and AWS SDK modules to latest stable versions

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

2 participants