Skip to content

feat: update routing engine tracking to support multiple engines#1635

Open
Pratham-Mishra04 wants to merge 1 commit intomainfrom
02-13-feat_added_multi_routing_engine_support
Open

feat: update routing engine tracking to support multiple engines#1635
Pratham-Mishra04 wants to merge 1 commit intomainfrom
02-13-feat_added_multi_routing_engine_support

Conversation

@Pratham-Mishra04
Copy link
Collaborator

Summary

Enhance routing engine tracking by replacing the single routing engine field with an array-based approach to support multiple routing engines in a single request. This allows for more accurate tracking when requests pass through multiple routing components.

Changes

  • Renamed BifrostContextKeyRoutingEngineUsed to BifrostContextKeyRoutingEnginesUsed and changed its type from string to []string
  • Added AppendToContextList utility function to easily add routing engines to the context
  • Updated database schema to store multiple routing engines as a comma-separated string
  • Modified the logging plugin to handle arrays of routing engines
  • Updated telemetry plugin to join routing engines into a comma-separated label
  • Updated UI to display multiple routing engines with appropriate badges
  • Updated OpenAPI documentation to reflect the array-based approach

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (Next.js)
  • Docs

How to test

  1. Set up a configuration with multiple routing components (e.g., routing rules and governance)
  2. Make requests that pass through multiple routing engines
  3. Verify logs show all routing engines used in the request
  4. Check telemetry metrics include comma-separated routing engine labels
# Core/Transports
go version
go test ./...

# UI
cd ui
pnpm i
pnpm test
pnpm build

Breaking changes

  • Yes
  • No

This change renames the context key from routing_engine_used to routing_engines_used and changes its type from string to []string. Any custom plugins that directly access this field will need to be updated.

Database migration is included to rename the column and maintain backward compatibility.

Security considerations

No security implications. This change only affects telemetry and logging data structure.

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

Copy link
Collaborator Author

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

@github-actions
Copy link
Contributor

🧪 Test Suite Available

This PR can be tested by a repository admin.

Run tests for PR #1635

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Routing engine tracking now supports multiple engines per request, displayed across logs, API responses, and the UI.
  • Documentation

    • Updated API schemas and documentation to reflect support for multiple routing engines in requests.

Walkthrough

The pull request converts single routing engine tracking to multi-engine support throughout the system. Context keys are renamed, type changed from string to array, database migrations add new columns, and UI/API layer updated to handle multiple routing engines.

Changes

Cohort / File(s) Summary
Core Schema Updates
core/schemas/bifrost.go, core/schemas/context.go
Rename context key BifrostContextKeyRoutingEngineUsedBifrostContextKeyRoutingEnginesUsed, change type to []string, add routing engine constants, introduce generic AppendToContextList function for array management.
Database Schema & Queries
framework/logstore/migrations.go, framework/logstore/tables.go, framework/logstore/rdb.go
Add migration for routing_engines_used column, update Log struct with RoutingEnginesUsedStr storage and RoutingEnginesUsed virtual field with serialization/deserialization logic, modify query conditions from exact match to comma-separated substring matching.
Documentation & API Specs
framework/changelog.md, docs/features/telemetry.mdx, docs/openapi/openapi.json, docs/openapi/schemas/management/logging.yaml
Update all references from routing_engine_used string to routing_engines_used array type across docs and OpenAPI schemas with corresponding description updates.
Governance Plugin
plugins/governance/main.go, plugins/governance/changelog.md
Replace direct context writes with AppendToContextList calls; update provider-prefixing logic in loadBalanceProvider and applyRoutingRules.
Logging Plugin
plugins/logging/main.go, plugins/logging/operations.go, plugins/logging/changelog.md
Change LogMessage.RoutingEngineUsed string → RoutingEnginesUsed array, update insertInitialLogEntry signature and log aggregation logic in GetAvailableRoutingEngines.
Telemetry Plugin
plugins/telemetry/main.go, plugins/telemetry/changelog.md
Extract RoutingEnginesUsed from context and join as comma-separated string for label compatibility.
UI Layer
ui/lib/types/logs.ts, ui/app/workspace/logs/page.tsx, ui/app/workspace/logs/views/logDetailsSheet.tsx
Update LogEntry.routing_engine_used string → routing_engines_used array, modify filter logic to use .some() for array matching, render multiple engine badges with per-engine styling.
Changelog Updates
transports/changelog.md
Document multi-level routing support across transport layer.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 Through many paths the data hops,
No single engine, multiple shops!
From context lists to UI arrays bright,
Routing engines now take flight. ✨🛣️

🚥 Pre-merge checks | ✅ 3 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.56% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: update routing engine tracking to support multiple engines' is clear, concise, and accurately describes the main change—converting single routing engine tracking to support multiple engines.
Description check ✅ Passed The PR description follows the template structure with all required sections completed: Summary, Changes, Type of change, Affected areas, How to test, Breaking changes, Security considerations, and Checklist. The description is comprehensive and informative.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 02-13-feat_added_multi_routing_engine_support

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugins/governance/main.go (1)

516-520: ⚠️ Potential issue | 🟠 Major

Replace raw context key "model" with a typed key.

ctx.SetValue("model", ...) at lines 519 and 655 uses a string literal key, violating the context-key rule. A typed key BifrostContextKeyModel does not yet exist in core/schemas/bifrost.go—it must be added first as a BifrostContextKey constant, then used consistently.

Update required at:

  • plugins/governance/main.go lines 519 and 655 (SetValue calls)
  • transports/bifrost-http/integrations/genai.go lines 413 and 487 (Value retrieval calls)

Define the key in core/schemas/bifrost.go:

BifrostContextKeyModel BifrostContextKey = "bifrost-model"

Then replace all raw "model" usages with schemas.BifrostContextKeyModel.

🤖 Fix all issues with AI agents
In `@framework/logstore/migrations.go`:
- Around line 1091-1126: The AddColumn call used for the old name
("routing_engine_used") fails on fresh installs because GORM requires a
corresponding struct field; update the migration to avoid relying on a
non-existent struct field: either add a backward-compatible field to the Log
struct (e.g., a string field tagged `gorm:"column:routing_engine_used"`
alongside the existing RoutingEnginesUsedStr) so AddColumn(&Log{},
"routing_engine_used") can succeed, or change the migration that currently calls
migrator.AddColumn(&Log{}, "routing_engine_used") to execute raw SQL (e.g.,
tx.Exec("ALTER TABLE logs ADD COLUMN routing_engine_used VARCHAR(...)")) instead
of using the GORM struct-based AddColumn; update the
migrationAddRoutingEnginesUsedJSONColumn flow to match whichever approach you
choose.

In `@framework/logstore/rdb.go`:
- Around line 68-78: Skip empty strings in filters.RoutingEngineUsed and change
the LIKE predicate to match whole comma-separated tokens by wrapping the stored
column with commas; e.g. for each non-empty engine push "CONCAT(',',
routing_engines_used, ',') LIKE ?" into engineConditions and "%,"+engine+",%"
into engineArgs before calling baseQuery.Where (retain
engineConditions/engineArgs variables and the baseQuery.Where call). This avoids
matching partial substrings and prevents empty-filter behavior.

In `@plugins/governance/main.go`:
- Around line 533-534: The build fails because bifrost.AppendToContextList is
not defined; locate where AppendToContextList actually resides (e.g., in the
core package or another package) and either export and add it to the bifrost
package or change the import/receiver to the correct package that defines
AppendToContextList; update the usages in main.go that reference
bifrost.AppendToContextList (and the duplicate calls around the other
occurrence) to call the exported function from the correct package, ensuring the
package is imported so the symbol resolves at compile time (also confirm
schemas.BifrostContextKeyRoutingEnginesUsed is reachable from the same package).

In `@ui/app/workspace/logs/views/logDetailsSheet.tsx`:
- Around line 308-319: The mapped Badge elements use key={engine}, which can
collide if log.routing_engines_used contains duplicates; update the mapping in
the LogEntryDetailsView render to use a stable composite key or dedupe the list
first: either map with both value and index (e.g., use `${engine}-${idx}`) when
iterating log.routing_engines_used in the Badge rendering, or replace the source
with a deduped array (e.g., Array.from(new Set(log.routing_engines_used)))
before mapping; ensure you update the map call that references
RoutingEngineUsedColors, RoutingEngineUsedIcons, and RoutingEngineUsedLabels so
the keys remain unique and stable.
🧹 Nitpick comments (4)
transports/changelog.md (1)

1-1: Minor grammar fix: hyphenate "multi-level".

The compound adjective "multi level" should be hyphenated when used as a modifier.

📝 Suggested fix
-- feat: added multi level routing support for routing rules + vk based provider routing
+- feat: added multi-level routing support for routing rules + vk-based provider routing
plugins/governance/changelog.md (1)

1-1: Minor grammar fix: hyphenate "multi-level".

Same as transports/changelog.md — compound adjectives should be hyphenated.

📝 Suggested fix
-- feat: added multi level routing support for routing rules + vk based provider routing
+- feat: added multi-level routing support for routing rules + vk-based provider routing
framework/logstore/migrations.go (1)

1095-1095: Consider renaming the migration ID for clarity.

The migration ID logs_add_routing_engines_used_json_column suggests adding a JSON column, but the migration actually renames an existing column. A more accurate ID like logs_rename_routing_engine_to_engines_used would better reflect the operation.

plugins/telemetry/main.go (1)

380-385: Consider de‑duplicating routing engines before labeling.

If the context list can contain repeats, label values like "governance,governance" add noise. A small de‑dupe keeps labels cleaner while preserving order.

♻️ Suggested de-duplication before join
-	// Get routing engines array and join into comma-separated string
-	routingEngines := []string{}
-	if engines, ok := ctx.Value(schemas.BifrostContextKeyRoutingEnginesUsed).([]string); ok {
-		routingEngines = engines
-	}
-	routingEngineUsed := strings.Join(routingEngines, ",")
+	// Get routing engines array and join into comma-separated string
+	routingEngines := []string{}
+	if engines, ok := ctx.Value(schemas.BifrostContextKeyRoutingEnginesUsed).([]string); ok {
+		seen := make(map[string]struct{}, len(engines))
+		for _, engine := range engines {
+			if engine == "" {
+				continue
+			}
+			if _, ok := seen[engine]; ok {
+				continue
+			}
+			seen[engine] = struct{}{}
+			routingEngines = append(routingEngines, engine)
+		}
+	}
+	routingEngineUsed := strings.Join(routingEngines, ",")

@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 02-13-feat_added_multi_routing_engine_support branch from 65a466d to 6806b74 Compare February 13, 2026 11:47
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
plugins/governance/main.go (1)

516-520: ⚠️ Potential issue | 🟠 Major

Use a typed context key instead of raw "model" strings.

Lines 519 and 655 use raw string keys ctx.SetValue("model", ...), which violates the no-raw-context-keys rule. However, the suggested schemas.BifrostContextKeyModel does not exist.

Define a typed key following the existing pattern in this file (e.g., modelContextKey schemas.BifrostContextKey = "bifrost-model"), or add BifrostContextKeyModel to core/schemas/bifrost.go if it should be shared across plugins. Update both lines to use the typed key.

🤖 Fix all issues with AI agents
In `@framework/logstore/rdb.go`:
- Around line 68-85: The routing engine filter currently builds SQL using
CONCAT(',', routing_engines_used, ',') which fails on SQLite; make the filter
dialect-aware by selecting the correct concatenation expression based on the DB
dialect (use "CONCAT(',', routing_engines_used, ',')" for MySQL/Postgres and
"','" || routing_engines_used || ',' (SQLite) or equivalent), then use that
expression when constructing engineConditions and passing to baseQuery.Where;
detect the dialect the same way other code in this package does (e.g., via the
DB dialector/name helper used elsewhere) and update the logic that builds
engineConditions, engineArgs, and the call to baseQuery.Where to use the chosen
concat expression for routing_engines_used and keep the existing LIKE
"%,engine,%" pattern.

In `@plugins/governance/changelog.md`:
- Line 1: Update the changelog line "feat: added multi level routing support for
routing rules + vk based provider routing" to hyphenate compound modifiers:
change "multi level routing" to "multi-level routing" and "vk based provider
routing" to "vk-based provider routing" so the final line reads e.g. "feat:
added multi-level routing support for routing rules + vk-based provider
routing".

In `@plugins/logging/operations.go`:
- Around line 471-492: The query filter in GetAvailableRoutingEngines
incorrectly checks for a JSON empty array; update the call to p.store.FindAll to
remove the "!= '[]'" condition so it only filters "routing_engines_used IS NOT
NULL" (since routing_engines_used is stored as comma-separated values or NULL).
Keep the rest of GetAvailableRoutingEngines unchanged (parsing
log.RoutingEnginesUsed and deduplicating) and ensure p.store.FindAll is invoked
with the simplified WHERE clause referencing routing_engines_used.

In `@transports/changelog.md`:
- Line 1: Update the changelog line to hyphenate compound modifiers: change
"multi level routing support" to "multi-level routing support" and "vk based
provider routing" to "vk-based provider routing" in the existing changelog entry
(the line containing "feat: added multi level routing support for routing rules
+ vk based provider routing").
🧹 Nitpick comments (1)
plugins/governance/main.go (1)

487-490: Consider tracking the TODO as a follow‑up task.
Right now the code silently continues when all providers are filtered out; if that’s intentional, a small follow‑up issue to return a clear error/telemetry signal would help avoid blind spots.

Would you like me to draft a follow‑up issue or a minimal error response patch?

@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 02-13-feat_added_multi_routing_engine_support branch from 6806b74 to e7890aa Compare February 13, 2026 12:45
core/utils.go Outdated
if !ok {
existingValues = []T{}
}
ctx.SetValue(key, append(existingValues, value))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pratham-Mishra04 instead of this we can just introduce this method in BifrostContext itself.

ctx.AppendValue() which internally can ensure all this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes can do

Copy link
Collaborator Author

@Pratham-Mishra04 Pratham-Mishra04 Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot set generics to an interface so will have to do datatype specific function like ctx.AppendStringValue() - is that okay?

p.logger.Debug("[Governance] Allowed providers after filtering: %v", allowedProviders)

if len(allowedProviderConfigs) == 0 {
// TODO: Send proper error if (overall VK budget/rate limit) or (all provider budgets/rate limits) are violated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can start sending already right?

Copy link
Collaborator Author

@Pratham-Mishra04 Pratham-Mishra04 Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but will need to brainstorming first cause early returns directly (from HTTPPreHook) will present request from entering plugin flow, affecting error logging and loadbalancing

@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 02-13-feat_added_multi_routing_engine_support branch from e7890aa to 9360f73 Compare February 15, 2026 06:37
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 02-13-feat_added_multi_routing_engine_support branch from 9360f73 to e5acb8b Compare February 15, 2026 06:49
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@plugins/governance/main.go`:
- Around line 650-666: Replace the raw string key "model" used in ctx.SetValue
with a typed constant: define BifrostContextKeyModel of type BifrostContextKey
with the value "model" in the schemas/bifrost package (symbol:
BifrostContextKeyModel), then update both ctx.SetValue("model", newModel) calls
in the governance plugin to ctx.SetValue(schemas.BifrostContextKeyModel,
newModel); ensure you reference the schemas package
(schemas.BifrostContextKeyModel) and adjust any imports/types so the typed key
compiles with the existing ctx.SetValue signature.
🧹 Nitpick comments (2)
framework/logstore/migrations.go (1)

1138-1140: Wrap the migration error for consistency.

Other migration functions in this file wrap errors with context (e.g., fmt.Errorf("error while adding X: %s", err.Error())), but this function returns m.Migrate() directly.

♻️ Suggested fix
-	return m.Migrate()
+	err := m.Migrate()
+	if err != nil {
+		return fmt.Errorf("error while adding routing engines used column: %s", err.Error())
+	}
+	return nil
plugins/governance/main.go (1)

487-490: TODO for provider/budget violation handling.

If you want, I can help turn this into a concrete error response and add tests.

Comment on lines +650 to +666
newModel := decision.Model + genaiRequestSuffix
// Add provider prefix if present (because there can be other routing rules down stream that can add the provider)
if decision.Provider != "" {
newModel = decision.Provider + "/" + newModel
}
ctx.SetValue("model", newModel)
} else {
// For regular requests, update in body
body["model"] = decision.Provider + "/" + decision.Model
newModel := decision.Model
// Add provider prefix if present (because there can be other routing rules down stream that can add the provider)
if decision.Provider != "" {
newModel = decision.Provider + "/" + newModel
}
body["model"] = newModel
}
ctx.SetValue(schemas.BifrostContextKeyRoutingEngineUsed, "routing-rule")
// Append routing-rule to routing engines used
schemas.AppendToContextList(ctx, schemas.BifrostContextKeyRoutingEnginesUsed, schemas.RoutingEngineRoutingRule)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, find and check the file structure
find . -name "main.go" -path "*/governance/*" | head -5
find . -name "bifrost.go" -path "*/schemas/*" | head -5

Repository: maximhq/bifrost

Length of output: 113


🏁 Script executed:

# Check the content at the specified lines in plugins/governance/main.go
if [ -f "plugins/governance/main.go" ]; then
  echo "=== Lines 650-666 in plugins/governance/main.go ==="
  sed -n '650,666p' plugins/governance/main.go
fi

Repository: maximhq/bifrost

Length of output: 885


🏁 Script executed:

# Check line 519 for the reference to loadBalanceProvider
if [ -f "plugins/governance/main.go" ]; then
  echo "=== Lines 515-525 around line 519 ==="
  sed -n '515,525p' plugins/governance/main.go
fi

Repository: maximhq/bifrost

Length of output: 588


🏁 Script executed:

# Search for BifrostContextKeyModel in the schemas
fd bifrost.go | xargs grep -n "BifrostContextKeyModel" 2>/dev/null || echo "Key not found"

Repository: maximhq/bifrost

Length of output: 72


🏁 Script executed:

# Run the suggested verification script to find all raw "model" context key usages
rg -n 'SetValue\("model"\)|Value\("model"\)' --type go

Repository: maximhq/bifrost

Length of output: 224


🏁 Script executed:

# View core/schemas/bifrost.go to see existing BifrostContextKey patterns
head -100 core/schemas/bifrost.go

Repository: maximhq/bifrost

Length of output: 3167


🏁 Script executed:

# Search for all BifrostContextKey definitions to understand the pattern
rg "BifrostContextKey" core/schemas/bifrost.go -A 1

Repository: maximhq/bifrost

Length of output: 9364


🏁 Script executed:

# More comprehensive search for "model" key usage with different patterns
rg '(SetValue|Value|UserValue)\s*\(\s*["\x27]?model["\x27]?' --type go -n

Repository: maximhq/bifrost

Length of output: 565


🏁 Script executed:

# Check if there are any type definitions for context keys
rg "type.*[Kk]ey" core/schemas/bifrost.go -B 2 -A 2

Repository: maximhq/bifrost

Length of output: 427


🏁 Script executed:

# Check the genai.go context usage to understand SetUserValue vs SetValue
sed -n '410,420p' transports/bifrost-http/integrations/genai.go
sed -n '484,494p' transports/bifrost-http/integrations/genai.go

Repository: maximhq/bifrost

Length of output: 839


🏁 Script executed:

# Check the BifrostContext implementation to understand SetValue vs SetUserValue
fd -e go -x grep -l "type BifrostContext" {} \;

Repository: maximhq/bifrost

Length of output: 110


🏁 Script executed:

# View the BifrostContext definition
rg "type BifrostContext" -A 20

Repository: maximhq/bifrost

Length of output: 5234


🏁 Script executed:

# Check if model key set in governance is read in genai by searching context flow
rg -B 3 -A 3 'ctx.UserValue\("model"\)' transports/bifrost-http/integrations/genai.go

Repository: maximhq/bifrost

Length of output: 658


🏁 Script executed:

# Find the SetValue and Value method implementations in BifrostContext
rg -A 10 "func.*BifrostContext.*SetValue" core/schemas/context.go
rg -A 10 "func.*BifrostContext.*Value\(" core/schemas/context.go

Repository: maximhq/bifrost

Length of output: 2677


🏁 Script executed:

# Check if BifrostContext uses standard context.Context Value/WithValue
rg "context.WithValue|context.Value" core/schemas/context.go

Repository: maximhq/bifrost

Length of output: 107


🏁 Script executed:

# Check if genai functions receive BifrostContext and use it
rg -B 5 'ctx.UserValue\("model"\)' transports/bifrost-http/integrations/genai.go | head -40

Repository: maximhq/bifrost

Length of output: 628


🏁 Script executed:

# Check the function signatures that use ctx.UserValue("model")
rg 'func.*\(ctx \*fasthttp.RequestCtx' transports/bifrost-http/integrations/genai.go | head -5

Repository: maximhq/bifrost

Length of output: 433


🏁 Script executed:

# Check where the model key is set in governance main.go to understand context flow
rg -B 10 'ctx.SetValue\("model"' plugins/governance/main.go | head -30

Repository: maximhq/bifrost

Length of output: 1134


🏁 Script executed:

# Search for reads of the "model" key in BifrostContext context (Value calls)
rg 'Value\("model"\)' --type go

Repository: maximhq/bifrost

Length of output: 216


🏁 Script executed:

# Check if there are any references to the model in governance that read it back
rg -A 5 'SetValue\("model"' plugins/governance/main.go | grep -i "value\|model"

Repository: maximhq/bifrost

Length of output: 278


🏁 Script executed:

# Check the full context of the loadBalanceProvider function around line 519
sed -n '510,540p' plugins/governance/main.go

Repository: maximhq/bifrost

Length of output: 1350


Replace raw "model" context key with a typed key.

ctx.SetValue("model", ...) at lines 519 and 655 uses a string literal key, which violates the context-key rule. Switch to a typed BifrostContextKey constant.

Suggested fix

First, add the typed key constant to core/schemas/bifrost.go:

const (
    BifrostContextKeyModel BifrostContextKey = "model"
)

Then replace both usages in plugins/governance/main.go:

- ctx.SetValue("model", newModelWithRequestSuffix)
+ ctx.SetValue(schemas.BifrostContextKeyModel, newModelWithRequestSuffix)
- ctx.SetValue("model", newModel)
+ ctx.SetValue(schemas.BifrostContextKeyModel, newModel)
🤖 Prompt for AI Agents
In `@plugins/governance/main.go` around lines 650 - 666, Replace the raw string
key "model" used in ctx.SetValue with a typed constant: define
BifrostContextKeyModel of type BifrostContextKey with the value "model" in the
schemas/bifrost package (symbol: BifrostContextKeyModel), then update both
ctx.SetValue("model", newModel) calls in the governance plugin to
ctx.SetValue(schemas.BifrostContextKeyModel, newModel); ensure you reference the
schemas package (schemas.BifrostContextKeyModel) and adjust any imports/types so
the typed key compiles with the existing ctx.SetValue signature.

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