refactor: move virtual key validation and context attachment before passthrough check#3213
refactor: move virtual key validation and context attachment before passthrough check#3213Pratham-Mishra04 wants to merge 1 commit intomainfrom
Conversation
|
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughRefactors HTTPTransportPreHook to optimize payload processing with early-exit paths when governance rules are absent, defers unmarshalling, adds content-type parsing, and introduces a dedicated governLargePayload function for read-only large requests. ChangesHTTPTransportPreHook Optimization & Large-Payload Routing
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
b06fc15 to
16bfd46
Compare
0132257 to
e3d6e25
Compare
064ea8b to
f15baf7
Compare
e3d6e25 to
3dcc042
Compare
Confidence Score: 4/5Safe to merge; the reordering correctly fixes passthrough metadata gaps with no change to the non-passthrough code path. The core reordering is correct and the existing inactive-key guard is preserved. plugins/governance/main.go — specifically the Important Files Changed
Reviews (1): Last reviewed commit: "fix: passthrough detection for routing f..." | Re-trigger Greptile |
| @@ -364,12 +394,6 @@ func (p *GovernancePlugin) HTTPTransportPreHook(ctx *schemas.BifrostContext, req | |||
| return p.governLargePayload(ctx, req, virtualKeyValue, hasRoutingRules) | |||
There was a problem hiding this comment.
Redundant VK lookup in
governLargePayload
HTTPTransportPreHook now validates the virtual key and attaches team/customer context before reaching this call site, but governLargePayload re-runs the same p.store.GetVirtualKey lookup and re-sets the identical context values unconditionally. Because governLargePayload is only ever called from this path, both the store roundtrip and the ctx.SetValue calls are now no-ops in the happy path. If the key happens to be deactivated between the two lookups, the context will already carry stale team/customer metadata from the first lookup even though governLargePayload returns early without applying governance — a subtle inconsistency. Consider passing the already-resolved *configstoreTables.TableVirtualKey directly to governLargePayload to eliminate the double lookup and the staleness window.
3dcc042 to
e2bc0b5
Compare
f15baf7 to
7b58229
Compare
e2bc0b5 to
83ff8a4
Compare
7b58229 to
ac0cefd
Compare
83ff8a4 to
beff6d0
Compare
ac0cefd to
3f34ef9
Compare
The base branch was changed.
3f34ef9 to
6ba4e35
Compare

Summary
Virtual key validation and team/customer context attachment now occur before the passthrough path check, ensuring that metadata is correctly populated on the context even for passthrough requests that use a virtual key.
Changes
passthroughpath check, so that team and customer IDs/names are attached to the context regardless of whether the request is a passthrough.payload,virtualKey,ok, andneedsMarshalvariable declarations were relocated accordingly to maintain correct scoping after the reorder.Type of change
Affected areas
How to test
BifrostContextKeyGovernanceTeamID,BifrostContextKeyGovernanceTeamName,BifrostContextKeyGovernanceCustomerID, andBifrostContextKeyGovernanceCustomerNameare correctly set on the context after the pre-hook runs.go test ./plugins/governance/...Breaking changes
Security considerations
No new auth mechanisms introduced. The existing virtual key active/inactive check is preserved and now runs earlier in the flow, which is strictly more restrictive for passthrough paths.
Checklist
docs/contributing/README.mdand followed the guidelines