Conversation
Summary by CodeRabbit
WalkthroughA new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Bifrost
participant PluginPipeline
participant Provider
Client->>Bifrost: Send Request
Bifrost->>PluginPipeline: RunPreHooks(ctx, req)
PluginPipeline-->>Bifrost: (req', shortCircuitResp, count)
alt Short-circuit response
Bifrost->>PluginPipeline: RunPostHooks(ctx, shortCircuitResp, nil, count)
PluginPipeline-->>Bifrost: (resp, err)
Bifrost-->>Client: resp or err
else No short-circuit
Bifrost->>Provider: Process Request
Provider-->>Bifrost: (resp, err)
Bifrost->>PluginPipeline: RunPostHooks(ctx, resp, err, count)
PluginPipeline-->>Bifrost: (finalResp, finalErr)
Bifrost-->>Client: finalResp or finalErr
end
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🧪 Generate Unit Tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Actionable comments posted: 4
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
core/bifrost.go(5 hunks)core/schemas/plugin.go(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
core/schemas/plugin.go (1)
core/schemas/bifrost.go (2)
BifrostResponse(237-247)BifrostError(365-371)
core/bifrost.go (3)
core/schemas/plugin.go (1)
Plugin(21-41)core/schemas/logger.go (1)
Logger(18-35)core/schemas/bifrost.go (3)
BifrostRequest(59-69)BifrostResponse(237-247)BifrostError(365-371)
🔇 Additional comments (4)
core/schemas/plugin.go (2)
22-24: LGTM! The GetName() method enhances plugin identification.This addition improves error reporting and debugging capabilities by allowing the pipeline to identify plugins by name in log messages.
32-35: LGTM! Enhanced PostHook signature enables flexible error handling.The updated signature allows plugins to transform both responses and errors, enabling sophisticated error recovery and response modification scenarios. This is a well-designed enhancement that provides greater flexibility in the plugin lifecycle.
core/bifrost.go (2)
53-72: LGTM! Well-designed PluginPipeline abstraction.The struct properly encapsulates plugin execution state with clear separation of concerns. Tracking which plugins ran their PreHook ensures correct PostHook execution order.
635-642:⚠️ Potential issueFix variable shadowing in error handling.
The
:=operator creates a newbifrostErrPtrvariable in the inner scope, shadowing the outer one. This prevents the PostHook from properly modifying the error.case bifrostErrVal := <-msg.Err: bifrostErrPtr := &bifrostErrVal - resp, bifrostErrPtr := pipeline.RunPostHooks(&ctx, nil, bifrostErrPtr, len(bifrost.plugins)) + resp, bifrostErrPtr = pipeline.RunPostHooks(&ctx, nil, bifrostErrPtr, len(bifrost.plugins)) bifrost.releaseChannelMessage(msg) if bifrostErrPtr != nil { return nil, bifrostErrPtr } return resp, nilLikely an incorrect or invalid review comment.
There was a problem hiding this comment.
Bug: Plugin Lifecycle Violation in Completion Hooks
The PluginPipeline's RunPostHooks is incorrectly called with len(bifrost.plugins) instead of preCount in tryTextCompletion and tryChatCompletion functions. This bug occurs for both successful responses and error paths, causing PostHooks to execute for plugins whose PreHooks did not run, violating the intended plugin lifecycle.
core/bifrost.go#L627-L628
Lines 627 to 628 in db1a389
core/bifrost.go#L746-L747
Lines 746 to 747 in db1a389
core/bifrost.go#L755-L756
Lines 755 to 756 in db1a389
BugBot free trial expires on June 17, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
| // Indices of plugins whose PreHook ran (for reverse PostHook) | ||
| preHookRan []int | ||
| // Errors from PreHooks and PostHooks | ||
| preHookErrors []error |
There was a problem hiding this comment.
usually we can wrap it under a separate struct for better abstraction. Also we can create pool of these objects to avoid any runtime allocations
type Errs struct {
Errors []errors
}
func (e *Errs) Print() {
}
func (e *Errs) Add(e error) {
}There was a problem hiding this comment.
yes I've made changes to this, I pushed it to the next pr by mistake
There was a problem hiding this comment.
I'll add sync pools, even I was thinking about it
…rost_enchancements feat: implement PluginPipeline for improved plugin execution flow

Refactor Plugin Pipeline for Better Error Handling
This PR introduces a new
PluginPipelineabstraction to improve the handling of plugin execution in Bifrost. The key improvements include:Added proper error aggregation for both PreHooks and PostHooks
Enhanced PostHook interface to allow plugins to:
Implemented consistent execution flow for both text and chat completion requests
Added a
GetName()method to the Plugin interface for better error reportingThe pipeline tracks which plugins ran during PreHook to ensure only those plugins have their PostHook called, and in the correct reverse order. This maintains the expected plugin execution lifecycle while providing more flexibility in how plugins can transform the request/response flow.