-
Notifications
You must be signed in to change notification settings - Fork 187
fix: ensure request ID is set in context before PreHooks #1227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughEnsure a RequestID is injected into the request context in Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Bifrost
participant PreHook
participant Plugin as "Maxim Plugin"
rect rgb(230, 245, 255)
Client->>Bifrost: Send request
Bifrost->>Bifrost: Ensure RequestID in context (generate UUID if missing)
Bifrost->>PreHook: Invoke PreHooks with context (contains RequestID)
end
rect rgb(245, 255, 230)
PreHook->>Plugin: Call plugin PreHook (reads RequestID from ctx)
alt Plugin finds non-string/missing RequestID
Plugin->>Plugin: Generate local UUID, log warning (does not set ctx)
else Plugin reads RequestID string
Plugin-->>PreHook: Continue
end
PreHook-->>Bifrost: Return control
Bifrost->>Client: Process request and respond
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
💤 Files with no reviewable changes (1)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (1)**⚙️ CodeRabbit configuration file
Files:
🧠 Learnings (2)📚 Learning: 2025-12-09T17:07:42.007ZApplied to files:
📚 Learning: 2025-12-29T11:54:55.836ZApplied to files:
🧬 Code graph analysis (1)plugins/maxim/main.go (2)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🧪 Test Suite AvailableThis PR can be tested by a repository admin. |
There was a problem hiding this 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
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
core/bifrost.gocore/schemas/context.goplugins/maxim/main.go
💤 Files with no reviewable changes (1)
- core/schemas/context.go
🧰 Additional context used
📓 Path-based instructions (1)
**
⚙️ CodeRabbit configuration file
always check the stack if there is one for the current PR. do not give localized reviews for the PR, always see all changes in the light of the whole stack of PRs (if there is a stack, if there is no stack you can continue to make localized suggestions/reviews)
Files:
core/bifrost.goplugins/maxim/main.go
🧠 Learnings (2)
📚 Learning: 2025-12-09T17:07:42.007Z
Learnt from: qwerty-dvorak
Repo: maximhq/bifrost PR: 1006
File: core/schemas/account.go:9-18
Timestamp: 2025-12-09T17:07:42.007Z
Learning: In core/schemas/account.go, the HuggingFaceKeyConfig field within the Key struct is currently unused and reserved for future Hugging Face inference endpoint deployments. Do not flag this field as missing from OpenAPI documentation or require its presence in the API spec until the feature is actively implemented and used. When the feature is added, update the OpenAPI docs accordingly; otherwise, treat this field as non-breaking and not part of the current API surface.
Applied to files:
core/bifrost.goplugins/maxim/main.go
📚 Learning: 2025-12-29T11:54:55.836Z
Learnt from: akshaydeo
Repo: maximhq/bifrost PR: 1153
File: framework/configstore/rdb.go:2221-2246
Timestamp: 2025-12-29T11:54:55.836Z
Learning: In Go reviews, do not flag range-over-int patterns like for i := range n as compile-time errors, assuming Go 1.22+ semantics. Only flag actual range-capable values (slices, arrays, maps, channels, strings) and other compile-time issues. This applies to all Go files across the repository.
Applied to files:
core/bifrost.goplugins/maxim/main.go
🧬 Code graph analysis (2)
core/bifrost.go (1)
core/schemas/bifrost.go (1)
BifrostContextKeyRequestID(124-124)
plugins/maxim/main.go (1)
core/schemas/bifrost.go (1)
BifrostContextKeyRequestID(124-124)
🔇 Additional comments (2)
core/bifrost.go (2)
2217-2221: LGTM! Request ID initialization ensures consistent tracing.The implementation correctly ensures a request ID exists in the context before PreHooks execute. The type assertion check handles both missing keys and incorrect types, guaranteeing downstream plugins can rely on this value.
2315-2319: LGTM! Consistent request ID initialization for streaming requests.The streaming path correctly mirrors the non-streaming implementation to ensure request ID presence before PreHooks. While this duplicates the logic from
handleRequest, the duplication is acceptable given these are two distinct request paths.
23755a3 to
69ea61d
Compare

Summary
Ensure request ID is consistently set in context before PreHooks are executed, fixing an issue where request IDs might be missing or inconsistently generated.
Changes
handleRequestandhandleStreamRequestfunctions to ensure it's set before PreHooks are executedBifrostContextKeyStreamEndIndicatorfrom the reserved keys list as it was no longer neededType of change
Affected areas
How to test
Verify that request IDs are consistently present in logs and responses:
Breaking changes
Related issues
Fixes inconsistent request ID generation across the application.
Security considerations
This change improves traceability by ensuring request IDs are consistently generated and available throughout the request lifecycle.
Checklist
docs/contributing/README.mdand followed the guidelines