Skip to content

fix: parse provider-prefixed model string in runPreRequestRouting large-payload path - #4282

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

fix: parse provider-prefixed model string in runPreRequestRouting large-payload path#4282
Pratham-Mishra04 merged 1 commit into
devfrom
06-11-fix_governance_routing_for_large_payloads_fixes

Conversation

@Pratham-Mishra04

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

Copy link
Copy Markdown
Collaborator

Summary

When a large-payload request arrives via the PreRequestHook path, the request body is not parsed, so req.Model is taken directly from metadata and may carry a provider-prefixed string like openai/gpt-4o. Previously, runPreRequestRouting passed this raw string directly as the model name without parsing the provider prefix, causing load balancing to ignore the caller's explicit routing intent. This change ensures the provider prefix is extracted and honored in the same way the transport layer handles body-having requests.

Changes

  • runPreRequestRouting now calls schemas.ParseModelString on the incoming model string before constructing the synthetic BifrostRequest, populating both Provider and Model on the ChatRequest so that an explicit prefix like openai/gpt-4o correctly pins routing to that provider instead of being subject to VK load balancing.
  • Added prerequestrouting_test.go covering three cases: an explicit provider prefix bypasses load balancing and always resolves to the specified provider; a bare model string still goes through VK load balancing and returns provider-prefixed; and an unknown slash-containing prefix (e.g. a HuggingFace-style namespace like meta-llama/llama-3.1-8b-instant) is treated as part of the model name with load balancing still applied.

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

Expected: all three new tests pass, confirming that provider-prefixed models in the large-payload path are routed to the correct provider, bare models still load balance, and unknown slash-prefixes are preserved as model namespaces.

Breaking changes

  • Yes
  • No

Related issues

Security considerations

No security implications. This change only affects internal routing logic for constructing synthetic requests during pre-request hook processing.

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

Release Notes

  • Bug Fixes

    • Fixed request routing to properly preserve explicit provider specifications in model names (e.g., provider/model format), ensuring routing intent is maintained for large-payload requests.
  • Tests

    • Added comprehensive tests for pre-request routing behavior, including explicit provider prefix handling and load balancing scenarios.

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

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6772bd4d-b08f-47ea-9eb4-d250386d86c2

📥 Commits

Reviewing files that changed from the base of the PR and between a68e9df and fab812d.

📒 Files selected for processing (2)
  • plugins/governance/main.go
  • plugins/governance/prerequestrouting_test.go

📝 Walkthrough

Walkthrough

This PR updates the large-payload routing path in runPreRequestRouting to parse provider-prefixed model strings (e.g., openai/gpt-4o) using schemas.ParseModelString and populate both ChatRequest.Provider and ChatRequest.Model fields, ensuring explicit caller routing intent is preserved. Three test cases validate the behavior for prefixed models, unprefixed models, and unknown prefix namespaces.

Changes

Large-payload routing provider parsing

Layer / File(s) Summary
Provider-prefix parsing in runPreRequestRouting
plugins/governance/main.go
runPreRequestRouting now parses provider-prefixed modelIn strings via schemas.ParseModelString and sets both ChatRequest.Provider and ChatRequest.Model in the synthetic request, preserving explicit routing intent for the large-payload path.
Provider-prefix routing test coverage
plugins/governance/prerequestrouting_test.go
New test file with three test cases: explicit provider prefixes skip load balancing, unprefixed models apply load balancing and get a provider prefix, and unknown prefix-like segments are treated as model namespaces with provider load balancing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • maximhq/bifrost#3458: The change to parse and set provider from provider-prefixed model strings directly addresses provider selection and routing intent in the governance layer.

Possibly related PRs

  • maximhq/bifrost#4279: Updates loadBalanceProvider to skip load balancing when the parsed Provider field is present, directly building on this PR's provider-prefix parsing.
  • maximhq/bifrost#3933: The earlier governance routing refactor that introduced the large-payload PreRequestHook path and BifrostRequest-native mutations this PR extends.
  • maximhq/bifrost#4221: Also updates large-payload governance routing to parse LargePayloadMetadata.Model into resolved provider+model so downstream routing is based on the correct routed provider/model.

Suggested reviewers

  • akshaydeo
  • danpiths

Poem

🐰 A rabbit hops through provider strings,
Parsing openai/gpt-4o and such things,
With Provider and Model now both set right,
The routing path glows with routing light! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. 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 accurately and concisely describes the main change: parsing provider-prefixed model strings in the large-payload routing path, which directly addresses the bug being fixed.
Description check ✅ Passed The description covers all critical sections: summary explaining the problem, detailed changes, type of change marked, affected areas selected, test instructions provided, and security/breaking changes addressed.
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_routing_for_large_payloads_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 core fix is correct and the transport-layer analogue works the same way; the change is narrow and low-risk.

The fix is a one-call change that delegates to a well-tested utility (ParseModelString) and the three new tests directly validate the affected paths. The only gap is that the hasRoutingRules: true branch with a provider-prefixed model in the large-payload path has no test coverage — it's a minor omission, not a defect in the fix itself.

No files require special attention; the change is confined to plugins/governance/main.go and its new test file.

Important Files Changed

Filename Overview
plugins/governance/main.go Calls schemas.ParseModelString before constructing the synthetic BifrostRequest so provider-prefixed models correctly pin routing; change is minimal and consistent with the rest of the file
plugins/governance/prerequestrouting_test.go Three new table-style tests cover the explicit-prefix, bare-model, and unknown-namespace paths; missing coverage for the hasRoutingRules: true branch with a provider-prefixed model

Reviews (1): Last reviewed commit: "fix: governance routing for large payloa..." | Re-trigger Greptile

Pratham-Mishra04 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

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

@Pratham-Mishra04
Pratham-Mishra04 merged commit b75c842 into dev Jun 11, 2026
14 of 16 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 06-11-fix_governance_routing_for_large_payloads_fixes branch June 11, 2026 07:47
akshaydeo pushed a commit that referenced this pull request Jun 12, 2026
…arge-payload path (#4282)

## Summary

When a large-payload request arrives via the `PreRequestHook` path, the request body is not parsed, so `req.Model` is taken directly from metadata and may carry a provider-prefixed string like `openai/gpt-4o`. Previously, `runPreRequestRouting` passed this raw string directly as the model name without parsing the provider prefix, causing load balancing to ignore the caller's explicit routing intent. This change ensures the provider prefix is extracted and honored in the same way the transport layer handles body-having requests.

## Changes

- `runPreRequestRouting` now calls `schemas.ParseModelString` on the incoming model string before constructing the synthetic `BifrostRequest`, populating both `Provider` and `Model` on the `ChatRequest` so that an explicit prefix like `openai/gpt-4o` correctly pins routing to that provider instead of being subject to VK load balancing.
- Added `prerequestrouting_test.go` covering three cases: an explicit provider prefix bypasses load balancing and always resolves to the specified provider; a bare model string still goes through VK load balancing and returns provider-prefixed; and an unknown slash-containing prefix (e.g. a HuggingFace-style namespace like `meta-llama/llama-3.1-8b-instant`) is treated as part of the model name with load balancing still applied.

## Type of change

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

## Affected areas

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

## How to test

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

Expected: all three new tests pass, confirming that provider-prefixed models in the large-payload path are routed to the correct provider, bare models still load balance, and unknown slash-prefixes are preserved as model namespaces.

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

## Security considerations

No security implications. This change only affects internal routing logic for constructing synthetic requests during pre-request hook processing.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [x] 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

## Release Notes

* **Bug Fixes**
  * Fixed request routing to properly preserve explicit provider specifications in model names (e.g., `provider/model` format), ensuring routing intent is maintained for large-payload requests.

* **Tests**
  * Added comprehensive tests for pre-request routing behavior, including explicit provider prefix handling and load balancing scenarios.

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