bifrost: route every provider through the gateway, fall back per VK grant (aieo 0.1.38) - #5299
Merged
Merged
Conversation
…rant (aieo 0.1.38) Follow-up to #5296, which granted xai on VKs but left the xai/ bypasses in place. Removes the bypasses in task-workflow and the agent route, opens the canvas agent's Anthropic-only gate and passes the resolved model through, so all five providers ride Bifrost on every call site. aieo 0.1.38 prefixes OpenRouter model ids on the gateway path, which is what Bifrost routes on. The reconciler now snapshots the VK's provider grants on WorkspaceMember.bifrostVkProviders (new column + migration) and reports whether the requested model's provider is granted. The orchestrator returns undefined when it isn't, so the caller keeps its direct key instead of failing at the gateway; unknown grants fail open as before. A miss re-checks the gateway after 15 minutes instead of the 24h window.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #5296, which granted xai on VKs but deliberately left the
xai/bypasses in place. This removes them and opens the canvas agent's Anthropic-only gate, so all five providers ride Bifrost on every call site. Needs aieo 0.1.38.src/services/task-workflow.tsandsrc/app/api/agent/route.ts. Both already passed the model through; nothing else changes there.src/lib/ai/runCanvasAgent.ts) calls the orchestrator for every provider and hands it the resolved model, sobaseUrlgets the provider suffix (/openai/v1for openai / openrouter / xai,/genai/v1betafor google). aieo 0.1.38 prefixes OpenRouter ids withopenrouter/on the gateway path (google and xai already did); Bifrost routes on that prefix and defaults to OpenAI without it, so Kimi-through-gateway would otherwise have 404'd at OpenAI.WorkspaceMember.bifrostVkProviders(new column + migration) and reportsmodelProvider/providers/modelProviderGranted. The orchestrator returnsundefinedwhen the snapshot says the model's provider isn't granted (a swarm whose gateway has noXAI_API_KEYyet), so the caller keeps its direct key instead of sending a call the gateway would reject — nothing downstream retries. Unknown grants (empty snapshot: rows from before the column, or an unreadable gateway) fail open exactly as before.BIFROST_VK_PROVIDER_MISS_REFRESH_MS), so a gateway that just gained xai flips its cached VKs in minutes. A refresh only overwrites the snapshot when it actually observed the VK.AIEO_TO_BIFROST_PROVIDERmaps aieo prefixes to Bifrost provider ids (google→gemini), typed against aieo'sProviderunion so a new aieo provider fails to compile here until it's mapped.startin the canvas agent).Not in this PR: the canvas agent still falls back to Anthropic when Hive itself lacks the provider's env key —
hasApiKeyForProviderruns before Bifrost is consulted. Hive holds all five keys today, so no behaviour change, but Bifrost routing doesn't yet remove that dependency. Whether the Stakwork worker and goose forward the prefixed model id unchanged is on their side.Test plan
npx vitest run src/__tests__/unit/services/bifrost/— 165 passing (48 in reconciler.test.ts incl. 8 new grant-snapshot cases; 24 in orchestrator.test.ts incl. 3 new fallback cases)TEST_SUITE=integrationreconciler integration test against the migrated test DB — 2 passingnpx eslint --max-warnings=0on every changed filenpx tsc --noEmit— no errors in changed source files (only the repo's pre-existingdbMocktyping noise on test lines)npx prisma migrate dev(20260910203512_add_workspace_member_bifrost_vk_providers)[callStakworkAPI] model routingwithbifrostActive: trueand abaseUrlending in/openai/v1, and the request shows on the gateway under the member's VKBifrost VK has no grant for the model's provider; falling back to direct keyis logged and the run completes onXAI_API_KEYopenrouter/*preference: the gateway sees modelopenrouter/<id>on/openai/v1