Skip to content

feat: extended plugin schemas for better stream control#248

Merged
akshaydeo merged 1 commit intomainfrom
08-09-feat-extended_plugins_for_better_stream_control
Aug 11, 2025
Merged

feat: extended plugin schemas for better stream control#248
akshaydeo merged 1 commit intomainfrom
08-09-feat-extended_plugins_for_better_stream_control

Conversation

@Pratham-Mishra04
Copy link
Copy Markdown
Collaborator

Enhanced Streaming Support and Context Management

This PR adds several improvements to Bifrost's streaming capabilities and context management:

  1. Added ChunkIndex to track the position of each chunk in streaming responses across all providers (OpenAI, Anthropic, Bedrock, Cohere)

  2. Introduced BifrostContextKey type and BifrostContextKeyRequestType constant for better context management

  3. Fixed context handling by moving nil context checks earlier in request processing to prevent blocking

  4. Added support for short-circuit streaming in plugins via a new Stream field in PluginShortCircuit

  5. Improved stream processing with proper post-hook execution for short-circuited streams

These changes enable better tracking of streaming chunks, more robust context management, and enhanced plugin capabilities for stream manipulation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 9, 2025

Warning

Rate limit exceeded

@Pratham-Mishra04 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 34 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 98e1451 and 756cc5e.

📒 Files selected for processing (8)
  • core/bifrost.go (4 hunks)
  • core/providers/anthropic.go (9 hunks)
  • core/providers/bedrock.go (7 hunks)
  • core/providers/cohere.go (6 hunks)
  • core/providers/openai.go (11 hunks)
  • core/schemas/bifrost.go (2 hunks)
  • core/schemas/plugin.go (1 hunks)
  • docs/contributing/plugin.md (1 hunks)

Summary by CodeRabbit

  • New Features
    • Streaming responses now include a chunk_index in metadata to indicate per-chunk order.
    • Consistent chunk_index support across OpenAI, Anthropic, Cohere, and Bedrock streams.
    • Plugins can short-circuit with streaming outputs, enabling direct streamed results without provider calls.
    • Post-hooks now run on each streamed chunk for more consistent processing and observability.
  • Refactor
    • Centralized context handling for request type to improve reliability across request and stream paths.

Walkthrough

Adds per-chunk sequential indexing to streaming responses across multiple providers, introduces a typed context key for request type and early nil-context handling, and enables plugin short-circuiting with streaming channels that are passed through post-hooks.

Changes

Cohort / File(s) Change Summary
Streaming chunk metadata
core/schemas/bifrost.go
Adds ChunkIndex int to BifrostResponseExtraFields (json:"chunk_index") to carry per-chunk indices for streams.
Provider streaming updates
core/providers/anthropic.go, core/providers/bedrock.go, core/providers/cohere.go, core/providers/openai.go
Introduces a local chunkIndex (start -1) in streaming loops, increments per parsed chunk, and attaches the value to each streaming output's ExtraFields. Cohere signature updated to accept postHookRunner for streaming.
Core request/context changes
core/bifrost.go
Adds typed context key BifrostContextKey and constant BifrostContextKeyRequestType; ensures non-nil context at outer request handlers and stores request type in context; moves nil-context handling out of tryRequest helpers.
Plugin streaming short-circuit
core/schemas/plugin.go, core/bifrost.go
Adds Stream chan *BifrostStream to PluginShortCircuit; tryStreamRequest/handlers now handle short-circuit streams by running post-hooks per message and forwarding processed messages to an output channel.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Bifrost
    participant Plugin
    participant PostHook

    Client->>Bifrost: tryStreamRequest(req, ctx, requestType)
    Bifrost->>Plugin: Check for short-circuit
    alt Short-circuit with Stream
        Plugin-->>Bifrost: PluginShortCircuit{Stream: streamChan}
        Bifrost->>Bifrost: Create outputChan and launch goroutine
        loop For each message from streamChan
            Plugin-->>Bifrost: *BifrostStream
            Bifrost->>PostHook: Run post-hooks on message
            PostHook-->>Bifrost: Processed message
            Bifrost-->>Client: Forward via outputChan
        end
    else No short-circuit
        Bifrost->>...: Continue normal provider streaming flow
    end
Loading
sequenceDiagram
    participant Provider
    participant StreamLoop
    participant Client

    loop For each streaming chunk
        Provider->>StreamLoop: Emit chunk
        StreamLoop->>StreamLoop: chunkIndex += 1
        StreamLoop->>Client: Send chunk with ExtraFields.ChunkIndex = chunkIndex
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~35 minutes

Poem

I hop through streams with careful paws,
Counting chunks and minding laws.
Context tucked and hooks applied,
Plugins stream with rabbits' pride.
A tiny index marks each part—🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 08-09-feat-extended_plugins_for_better_stream_control

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Collaborator Author

@Pratham-Mishra04 Pratham-Mishra04 marked this pull request as ready for review August 9, 2025 16:38
Copy link
Copy Markdown
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: 3

🔭 Outside diff range comments (1)
core/providers/anthropic.go (1)

878-913: chunkIndex increments even for chunks that are never emitted

Because chunkIndex++ is executed immediately after basic parsing, it also runs for:

  • ping events
  • unknown/ignored event types
  • events that fail JSON-unmarshal and are skipped

This causes gaps in the sequence seen by downstream consumers – e.g. client receives chunk indices 0,2,4… while 1 & 3 were “ping” events and never delivered.

Move chunkIndex++ inside each branch that actually sends a BifrostResponse, or guard it with a continue for the unsupported cases, so the index strictly reflects delivered chunks.

♻️ Duplicate comments (16)
core/providers/openai.go (7)

461-463: See previous comment – same pattern.


480-482: See previous comment – same pattern.


494-496: See previous comment – same pattern.


657-659: See earlier chunk-index comment – applies to speech stream.


731-733: See earlier chunk-index comment.


879-881: See earlier chunk-index comment – applies to transcription stream.


952-953: See earlier chunk-index comment.

core/providers/cohere.go (4)

826-828: See previous comment.


862-864: See previous comment.


907-909: See previous comment.


965-966: See previous comment.

core/providers/bedrock.go (5)

1454-1456: See previous comment.


1512-1514: See previous comment.


1547-1549: See previous comment.


1578-1580: See previous comment.


1628-1630: See previous comment.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ce9756 and ed1376e.

📒 Files selected for processing (7)
  • core/bifrost.go (4 hunks)
  • core/providers/anthropic.go (9 hunks)
  • core/providers/bedrock.go (7 hunks)
  • core/providers/cohere.go (6 hunks)
  • core/providers/openai.go (11 hunks)
  • core/schemas/bifrost.go (2 hunks)
  • core/schemas/plugin.go (1 hunks)
🧰 Additional context used
🧠 Learnings (46)
📓 Common learnings
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: core/schemas/bifrost.go:686-692
Timestamp: 2025-08-08T06:51:27.123Z
Learning: In core/schemas/bifrost.go, BifrostError.StreamControl is intended for plugin developers only and is excluded from JSON serialization; its presence controls streaming behavior internally.
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: core/schemas/bifrost.go:686-692
Timestamp: 2025-08-08T06:51:27.123Z
Learning: In Bifrost, BifrostError.StreamControl is plugin-only (excluded from JSON) and used by processAndSendResponse to optionally skip a stream chunk and optionally log; default semantics: StreamControl == nil means no overrides; individual pointer fields (LogError, SkipStream) are treated as false when nil and have effect only when set to true.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#162
File: transports/bifrost-http/integrations/openai/types.go:340-344
Timestamp: 2025-07-16T05:44:50.544Z
Learning: In the Bifrost streaming implementation, context cancellation is properly propagated through the entire stack to the producer level. The producer goroutines always close their channels when done (including on context cancellation), so manual channel draining in consumers is not necessary to prevent goroutine leaks. The streaming architecture relies on proper context propagation rather than consumer-side cleanup.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#84
File: transports/bifrost-http/main.go:2-2
Timestamp: 2025-06-15T16:05:13.489Z
Learning: For the Bifrost project, HTTP transport integration routers for new providers (like Mistral and Ollama) are implemented in separate PRs from the core provider support, following a focused PR strategy.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#202
File: transports/bifrost-http/plugins/governance/resolver.go:183-191
Timestamp: 2025-08-03T20:36:21.906Z
Learning: In the Bifrost governance plugin (transports/bifrost-http/plugins/governance/resolver.go), Pratham-Mishra04 considers the current string matching approach for determining rate limit violation decision types (DecisionTokenLimited vs DecisionRequestLimited) adequate and not important enough to refactor with more robust explicit checks, preferring functional simplicity over theoretical robustness improvements.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#54
File: core/schemas/provider.go:148-148
Timestamp: 2025-06-04T03:57:50.981Z
Learning: Breaking changes in the Bifrost codebase are managed by first merging and tagging core schema changes, then updating dependent code references in subsequent steps after the core version is released.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#162
File: transports/bifrost-http/integrations/genai/types.go:0-0
Timestamp: 2025-07-16T07:13:29.496Z
Learning: Pratham-Mishra04 prefers to avoid redundant error handling across architectural layers in the Bifrost streaming implementation. When error handling (such as timeouts, context cancellation, and JSON marshaling failures) is already handled at the provider level, they prefer not to duplicate this logic at the transport integration layer to keep the code simple and avoid unnecessary complexity.
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: docs/usage/go-package/schemas.md:740-745
Timestamp: 2025-08-08T06:49:53.899Z
Learning: In BifrostError (core/schemas/bifrost.go), StreamControl is an internal, non-serialized (*json:"-") control used by plugins. If StreamControl (or its *bool members) is nil, no overrides are applied—core default behavior proceeds (no implicit logging or skipping). A flag must be explicitly set to true to change behavior; used by processAndSendResponse in core/providers/utils.go.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#152
File: transports/bifrost-http/plugins/logging/utils.go:378-399
Timestamp: 2025-07-10T13:44:14.518Z
Learning: In the Bifrost logging plugin (transports/bifrost-http/plugins/logging/utils.go), Pratham-Mishra04 prefers not to add error handling for JSON unmarshaling operations, considering logging not very critical and being confident that JSON marshalling won't fail in practice.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#202
File: transports/bifrost-http/handlers/governance.go:1038-1049
Timestamp: 2025-08-03T20:28:00.857Z
Learning: In the Bifrost governance handler (transports/bifrost-http/handlers/governance.go), Pratham-Mishra04 is comfortable with exposing full error details including err.Error() in production responses for governance API endpoints, prioritizing simplicity over potential information disclosure concerns.
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: core/providers/openai.go:459-459
Timestamp: 2025-08-08T07:07:08.801Z
Learning: In core/providers/utils.go, processAndSendResponse and processAndSendError now take exactly five parameters: (ctx, postHookRunner, response|err, responseChan, logger). All providers (OpenAI, Anthropic, Cohere, Bedrock) must call these with the logger as the fifth argument; a repo-wide check in PR maximhq/bifrost#219 confirmed this is already consistent.
Learnt from: TejasGhatte
PR: maximhq/bifrost#238
File: transports/bifrost-http/plugins/logging/main.go:687-703
Timestamp: 2025-08-08T15:31:28.737Z
Learning: In transports/bifrost-http/plugins/logging/main.go, TejasGhatte prefers keeping separate helpers for streaming detection: isStreamingResponse (any streaming) and isTextStreamingResponse (text-only). Avoid parameterizing/merging them, as that adds code and reduces clarity.
Learnt from: TejasGhatte
PR: maximhq/bifrost#174
File: transports/bifrost-http/plugins/logging/operations.go:113-114
Timestamp: 2025-08-01T16:25:49.937Z
Learning: In the Bifrost logging plugin (transports/bifrost-http/plugins/logging/operations.go), the calculateLatency method is only called at final chunk of streaming responses and when errors are returned, not repeatedly during streaming. This makes the performance impact of the database query minimal and doesn't warrant optimization with in-memory caching.
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: plugins/jsonparser/main.go:0-0
Timestamp: 2025-08-07T13:33:18.094Z
Learning: In the JSON Parser plugin (plugins/jsonparser/main.go), the context key for enabling per-request JSON parsing is "enable-streaming-json-parser" (defined as EnableStreamingJSONParser constant), which is distinct from the plugin name constant to avoid confusion between plugin identification and per-request activation control.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:483-494
Timestamp: 2025-06-04T10:04:30.181Z
Learning: In the Anthropic provider (core/providers/anthropic.go), parallel tool calls support including the DisableParallelToolUse flag will be implemented in later commits as it's a relatively new feature that's not commonly used yet. The development approach prioritizes core functionality first.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#209
File: plugins/jsonparser/plugin_test.go:38-45
Timestamp: 2025-08-04T19:39:39.417Z
Learning: In the JSON Parser plugin (plugins/jsonparser/main.go), the PostHook method is designed with a contract that guarantees the response structure (Choices, BifrostStreamResponseChoice, Delta, Content) will always be present when called, making defensive nil checks unnecessary in tests.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:358-388
Timestamp: 2025-06-04T05:37:59.699Z
Learning: User Pratham-Mishra04 prefers not to extract small code duplications (around 2 lines) into helper functions, considering the overhead not worth it for such minor repetition.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#102
File: README.md:62-66
Timestamp: 2025-06-19T17:03:03.639Z
Learning: Pratham-Mishra04 prefers using the implicit 'latest' tag for the maximhq/bifrost Docker image rather than pinning to specific versions.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#143
File: core/mcp.go:155-196
Timestamp: 2025-07-08T15:33:47.698Z
Learning: Pratham-Mishra04 prefers not to add explanatory comments for obvious code patterns, such as the unlock/lock strategy around network I/O operations, considering them self-explanatory to experienced developers.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#141
File: core/bifrost.go:198-272
Timestamp: 2025-07-08T18:30:08.258Z
Learning: Pratham-Mishra04 follows a pattern of implementing core functionality first and deferring non-critical improvements (like race condition fixes, optimizations) to later PRs. This is a reasonable development approach that prioritizes getting the main feature working before addressing edge cases.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#150
File: transports/bifrost-http/lib/store.go:370-466
Timestamp: 2025-07-09T04:58:08.229Z
Learning: Pratham-Mishra04 prefers not to add logging or error handling for unreachable code paths in the Bifrost project. When provider types or similar entities are predefined in the system, defensive programming like logging in default cases is considered unnecessary overhead.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#138
File: docs/usage/go-package/mcp.md:408-412
Timestamp: 2025-07-01T12:40:08.576Z
Learning: Pratham-Mishra04 is okay with keeping bullet list formatting that uses colons after dashes in markdown documentation, even if it triggers linter warnings, preferring functionality over strict formatting rules.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#162
File: tests/core-providers/scenarios/chat_completion_stream.go:103-105
Timestamp: 2025-07-16T04:26:09.288Z
Learning: Pratham-Mishra04 prefers to keep test code simple when it serves its basic functional purpose. For tests that are meant to validate core functionality (like verifying streaming works), they consider hard-coded reasonable limits acceptable rather than making them configurable.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#148
File: transports/bifrost-http/lib/store.go:880-910
Timestamp: 2025-07-08T17:14:21.544Z
Learning: Pratham-Mishra04 prefers resilient system design where missing environment variables for MCP connections should not cause complete system failure. The system should continue processing other MCP connections even when some fail, maintaining partial functionality rather than implementing fail-fast behavior.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#138
File: transports/README.md:26-28
Timestamp: 2025-07-01T12:45:06.906Z
Learning: Pratham-Mishra04 prefers keeping documentation examples simple and concise, trusting users to handle production-specific considerations like version pinning themselves rather than cluttering examples with additional notes.
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#148
File: transports/bifrost-http/lib/store.go:1081-1098
Timestamp: 2025-07-08T17:16:50.811Z
Learning: Pratham-Mishra04 prefers practical redaction approaches over theoretical security improvements when the threat model is low-risk, such as admin-only interfaces in the Bifrost project. Fixed-length redaction is acceptable when only trusted administrators will see the redacted values.
📚 Learning: 2025-08-04T22:19:12.975Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#212
File: transports/bifrost-http/integrations/openai/types.go:250-288
Timestamp: 2025-08-04T22:19:12.975Z
Learning: In transports/bifrost-http/integrations/openai/types.go, the ConvertToBifrostRequest function for OpenAIEmbeddingRequest handles []interface{} input without validation for non-string elements because Pratham-Mishra04 confirmed this case will never happen in practice, consistent with their preference to avoid defensive programming for unreachable scenarios.

Applied to files:

  • core/providers/openai.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
  • core/bifrost.go
📚 Learning: 2025-08-08T06:49:53.899Z
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: docs/usage/go-package/schemas.md:740-745
Timestamp: 2025-08-08T06:49:53.899Z
Learning: In BifrostError (core/schemas/bifrost.go), StreamControl is an internal, non-serialized (*json:"-") control used by plugins. If StreamControl (or its *bool members) is nil, no overrides are applied—core default behavior proceeds (no implicit logging or skipping). A flag must be explicitly set to true to change behavior; used by processAndSendResponse in core/providers/utils.go.

Applied to files:

  • core/providers/openai.go
  • core/schemas/bifrost.go
  • core/schemas/plugin.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
  • core/bifrost.go
📚 Learning: 2025-08-08T06:51:27.123Z
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: core/schemas/bifrost.go:686-692
Timestamp: 2025-08-08T06:51:27.123Z
Learning: In core/schemas/bifrost.go, BifrostError.StreamControl is intended for plugin developers only and is excluded from JSON serialization; its presence controls streaming behavior internally.

Applied to files:

  • core/providers/openai.go
  • core/schemas/bifrost.go
  • core/schemas/plugin.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
  • core/bifrost.go
📚 Learning: 2025-08-08T07:07:08.801Z
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: core/providers/openai.go:459-459
Timestamp: 2025-08-08T07:07:08.801Z
Learning: In core/providers/utils.go, processAndSendResponse and processAndSendError now take exactly five parameters: (ctx, postHookRunner, response|err, responseChan, logger). All providers (OpenAI, Anthropic, Cohere, Bedrock) must call these with the logger as the fifth argument; a repo-wide check in PR maximhq/bifrost#219 confirmed this is already consistent.

Applied to files:

  • core/providers/openai.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
  • core/bifrost.go
📚 Learning: 2025-08-08T06:51:27.123Z
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: core/schemas/bifrost.go:686-692
Timestamp: 2025-08-08T06:51:27.123Z
Learning: In Bifrost, BifrostError.StreamControl is plugin-only (excluded from JSON) and used by processAndSendResponse to optionally skip a stream chunk and optionally log; default semantics: StreamControl == nil means no overrides; individual pointer fields (LogError, SkipStream) are treated as false when nil and have effect only when set to true.

Applied to files:

  • core/providers/openai.go
  • core/schemas/bifrost.go
  • core/schemas/plugin.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
  • core/bifrost.go
📚 Learning: 2025-08-08T15:31:28.737Z
Learnt from: TejasGhatte
PR: maximhq/bifrost#238
File: transports/bifrost-http/plugins/logging/main.go:687-703
Timestamp: 2025-08-08T15:31:28.737Z
Learning: In transports/bifrost-http/plugins/logging/main.go, TejasGhatte prefers keeping separate helpers for streaming detection: isStreamingResponse (any streaming) and isTextStreamingResponse (text-only). Avoid parameterizing/merging them, as that adds code and reduces clarity.

Applied to files:

  • core/providers/openai.go
  • core/schemas/plugin.go
  • core/providers/cohere.go
  • core/providers/anthropic.go
📚 Learning: 2025-06-10T11:00:02.875Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#63
File: transports/bifrost-http/integrations/openai/types.go:89-119
Timestamp: 2025-06-10T11:00:02.875Z
Learning: In the Bifrost OpenAI integration (transports/bifrost-http/integrations/openai/types.go), the convertOpenAIContent function currently only handles the last image URL when multiple images are present in a content array. The user Pratham-Mishra04 has acknowledged this limitation and indicated it's part of a larger architectural issue that will be addressed comprehensively later, rather than with piecemeal fixes.

Applied to files:

  • core/providers/openai.go
📚 Learning: 2025-06-20T16:21:18.912Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#103
File: .github/workflows/transport-dependency-update.yml:53-75
Timestamp: 2025-06-20T16:21:18.912Z
Learning: In the bifrost repository's transport dependency update workflow, when updating the core dependency to a new version using `go get`, the go.mod and go.sum files will always change in normal operation, making the safety check for changes more of a defensive programming practice rather than handling a common scenario.

Applied to files:

  • core/providers/openai.go
📚 Learning: 2025-06-04T09:22:18.123Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#54
File: core/schemas/bifrost.go:46-49
Timestamp: 2025-06-04T09:22:18.123Z
Learning: In core/schemas/bifrost.go, the RequestInput struct uses ChatCompletionInput *[]BifrostMessage (pointer-to-slice) rather than []BifrostMessage to properly represent union type semantics. For text completion requests, ChatCompletionInput should be nil to indicate "no chat payload at all", while for chat completion requests it should be non-nil (even if empty slice). This distinguishes between different request types rather than just empty vs non-empty chat messages.

Applied to files:

  • core/providers/openai.go
  • core/schemas/bifrost.go
  • core/schemas/plugin.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/bifrost.go
📚 Learning: 2025-06-04T09:29:46.287Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:526-550
Timestamp: 2025-06-04T09:29:46.287Z
Learning: In core/providers/anthropic.go, the content field in formattedMessages is always of type []interface{} because it's explicitly constructed that way upstream in the prepareAnthropicChatRequest function. Defensive type casting for multiple types is not needed since the type is guaranteed by the construction logic.

Applied to files:

  • core/providers/openai.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
📚 Learning: 2025-08-08T07:13:02.905Z
Learnt from: TejasGhatte
PR: maximhq/bifrost#219
File: plugins/jsonparser/main.go:125-146
Timestamp: 2025-08-08T07:13:02.905Z
Learning: In plugins/jsonparser/main.go, TejasGhatte prefers to treat only object/array payloads as JSON for enforcement (strings/numbers/booleans are out of scope). Gate invalid-JSON SkipStream logic behind a check that the accumulated content starts with '{' or '[', and clear per-request state on skip.

Applied to files:

  • core/providers/openai.go
  • core/providers/bedrock.go
📚 Learning: 2025-06-14T04:06:58.240Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#79
File: core/bifrost.go:94-103
Timestamp: 2025-06-14T04:06:58.240Z
Learning: In core/bifrost.go, the count parameter in RunPostHooks method is intentionally kept separate from p.executedPreHooks to support circuit breaker plugins that may need to trigger PostHooks for only a subset of executed plugins when detecting failure conditions mid-execution.

Applied to files:

  • core/providers/openai.go
📚 Learning: 2025-08-04T19:39:39.417Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#209
File: plugins/jsonparser/plugin_test.go:38-45
Timestamp: 2025-08-04T19:39:39.417Z
Learning: In the JSON Parser plugin (plugins/jsonparser/main.go), the PostHook method is designed with a contract that guarantees the response structure (Choices, BifrostStreamResponseChoice, Delta, Content) will always be present when called, making defensive nil checks unnecessary in tests.

Applied to files:

  • core/providers/openai.go
  • core/schemas/plugin.go
📚 Learning: 2025-07-08T16:50:27.699Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#144
File: transports/bifrost-http/handlers/providers.go:45-49
Timestamp: 2025-07-08T16:50:27.699Z
Learning: In the Bifrost project, breaking API changes are acceptable when features are not yet public. This applies to scenarios like changing struct fields from pointer to non-pointer types in request/response structures for unreleased features.

Applied to files:

  • core/schemas/bifrost.go
  • core/schemas/plugin.go
📚 Learning: 2025-06-04T03:57:50.981Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#54
File: core/schemas/provider.go:148-148
Timestamp: 2025-06-04T03:57:50.981Z
Learning: Breaking changes in the Bifrost codebase are managed by first merging and tagging core schema changes, then updating dependent code references in subsequent steps after the core version is released.

Applied to files:

  • core/schemas/bifrost.go
📚 Learning: 2025-06-10T13:51:52.859Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#65
File: transports/bifrost-http/integrations/anthropic/types.go:140-146
Timestamp: 2025-06-10T13:51:52.859Z
Learning: In Bifrost core v1.0.9, ImageContent.Type was a pointer type (*string accessed via bifrost.Ptr), but in v1.0.10 it was changed to a value type (ImageContentType). When reviewing code, check the core version being used to determine the correct assignment pattern.

Applied to files:

  • core/schemas/bifrost.go
  • core/bifrost.go
📚 Learning: 2025-06-14T06:17:54.426Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#80
File: plugins/maxim/main.go:249-264
Timestamp: 2025-06-14T06:17:54.426Z
Learning: In the BifrostError struct, the Error field is a struct (not a pointer), so accessing bifrostErr.Error.Message, bifrostErr.Error.Code, and bifrostErr.Error.Type is safe without nil checks on the Error field itself. The Code and Type fields are of type *string.

Applied to files:

  • core/schemas/bifrost.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
  • core/bifrost.go
📚 Learning: 2025-08-05T20:43:59.593Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#214
File: core/providers/azure.go:49-50
Timestamp: 2025-08-05T20:43:59.593Z
Learning: In core/providers/azure.go, the azureTextCompletionResponsePool should use AzureTextResponse type, not schemas.BifrostResponse, to maintain consistency with the acquireAzureTextResponse() and releaseAzureTextResponse() functions that work with *AzureTextResponse objects.

Applied to files:

  • core/schemas/bifrost.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
📚 Learning: 2025-06-15T14:24:49.882Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#83
File: core/providers/mistral.go:168-170
Timestamp: 2025-06-15T14:24:49.882Z
Learning: In the Bifrost codebase, performance is prioritized over defensive copying for HTTP service operations. Specifically, shallow slice assignments in provider response handling are acceptable due to object pool reset patterns and JSON unmarshaling behavior that minimize practical data corruption risks.

Applied to files:

  • core/schemas/bifrost.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
📚 Learning: 2025-06-09T16:46:32.018Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#65
File: transports/bifrost-http/integrations/anthropic/router.go:19-33
Timestamp: 2025-06-09T16:46:32.018Z
Learning: In the GenericRouter (transports/bifrost-http/integrations), ResponseFunc is not called if the BifrostResponse parameter is nil, providing built-in protection against nil response marshaling.

Applied to files:

  • core/schemas/bifrost.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
📚 Learning: 2025-06-16T06:56:55.290Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#88
File: core/providers/mistral.go:170-176
Timestamp: 2025-06-16T06:56:55.290Z
Learning: When JSON unmarshaling into pooled structs, slice fields like `Choices []schemas.BifrostResponseChoice` get fresh heap memory allocations from `json.Unmarshal()`. The slice data is not part of the pooled struct's memory, so defensive copying is unnecessary. Resetting pooled structs with `*resp = ResponseType{}` only clears slice headers, not the underlying data.

Applied to files:

  • core/schemas/bifrost.go
  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
📚 Learning: 2025-08-01T16:25:49.937Z
Learnt from: TejasGhatte
PR: maximhq/bifrost#174
File: transports/bifrost-http/plugins/logging/operations.go:113-114
Timestamp: 2025-08-01T16:25:49.937Z
Learning: In the Bifrost logging plugin (transports/bifrost-http/plugins/logging/operations.go), the calculateLatency method is only called at final chunk of streaming responses and when errors are returned, not repeatedly during streaming. This makes the performance impact of the database query minimal and doesn't warrant optimization with in-memory caching.

Applied to files:

  • core/schemas/bifrost.go
  • core/providers/cohere.go
📚 Learning: 2025-06-18T15:15:51.323Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#94
File: core/bifrost.go:823-845
Timestamp: 2025-06-18T15:15:51.323Z
Learning: In the Bifrost project, the team prioritizes maintaining consistent error handling patterns over exposing detailed error context. All errors should be wrapped in the standard `BifrostError` structure rather than creating specific error types or exposing richer error details like exit codes or stderr output.

Applied to files:

  • core/schemas/bifrost.go
  • core/bifrost.go
📚 Learning: 2025-06-16T04:13:55.437Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#81
File: tests/core-providers/scenarios/end_to_end_tool_calling.go:43-45
Timestamp: 2025-06-16T04:13:55.437Z
Learning: In the Bifrost codebase, errors returned from client methods like ChatCompletionRequest are of type BifrostError, not the standard error interface. For testing these errors, use require.Nilf instead of require.NoErrorf since BifrostError doesn't work with the standard error assertion methods.

Applied to files:

  • core/schemas/bifrost.go
  • core/providers/bedrock.go
  • core/bifrost.go
📚 Learning: 2025-06-16T04:12:05.427Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#81
File: tests/core-providers/scenarios/complete_end_to_end.go:39-41
Timestamp: 2025-06-16T04:12:05.427Z
Learning: In the Bifrost system, error returns are of type `BifrostError` rather than the standard Go `error` interface. Therefore, use `require.Nilf(t, err, ...)` instead of `require.NoError(t, err)` when checking for errors in Bifrost function calls.

Applied to files:

  • core/schemas/bifrost.go
  • core/bifrost.go
📚 Learning: 2025-06-16T04:13:42.755Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#81
File: tests/core-providers/scenarios/simple_chat.go:39-41
Timestamp: 2025-06-16T04:13:42.755Z
Learning: In the Bifrost codebase, errors returned from methods like ChatCompletionRequest are of type BifrostError (a custom error type) rather than the standard Go error interface. Therefore, require.Nilf should be used for error assertions instead of require.NoErrorf.

Applied to files:

  • core/schemas/bifrost.go
  • core/bifrost.go
📚 Learning: 2025-06-15T13:50:41.418Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#83
File: core/providers/mistral.go:96-101
Timestamp: 2025-06-15T13:50:41.418Z
Learning: In the Bifrost project, when a provider doesn't support a specific operation (like text completion), the IsBifrostError flag should be set to false to mark it as a provider-level error rather than a Bifrost framework error. This is intentional design for unsupported operations.

Applied to files:

  • core/schemas/bifrost.go
📚 Learning: 2025-07-16T07:13:29.496Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#162
File: transports/bifrost-http/integrations/genai/types.go:0-0
Timestamp: 2025-07-16T07:13:29.496Z
Learning: Pratham-Mishra04 prefers to avoid redundant error handling across architectural layers in the Bifrost streaming implementation. When error handling (such as timeouts, context cancellation, and JSON marshaling failures) is already handled at the provider level, they prefer not to duplicate this logic at the transport integration layer to keep the code simple and avoid unnecessary complexity.

Applied to files:

  • core/schemas/bifrost.go
📚 Learning: 2025-07-16T05:44:50.544Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#162
File: transports/bifrost-http/integrations/openai/types.go:340-344
Timestamp: 2025-07-16T05:44:50.544Z
Learning: In the Bifrost streaming implementation, context cancellation is properly propagated through the entire stack to the producer level. The producer goroutines always close their channels when done (including on context cancellation), so manual channel draining in consumers is not necessary to prevent goroutine leaks. The streaming architecture relies on proper context propagation rather than consumer-side cleanup.

Applied to files:

  • core/providers/cohere.go
  • core/bifrost.go
📚 Learning: 2025-07-29T16:10:52.088Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#196
File: core/providers/openai.go:180-183
Timestamp: 2025-07-29T16:10:52.088Z
Learning: In the Bifrost provider architecture, `handleProviderResponse` is a utility function that only parses and returns raw response data when the `sendBackRawResponse` flag is true. It's the responsibility of each individual provider (OpenAI, Anthropic, etc.) to conditionally set `response.ExtraFields.RawResponse` using the returned raw response data based on their `sendBackRawResponse` flag. This represents a separation of concerns where the utility handles parsing and the provider handles response object construction.

Applied to files:

  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
  • core/bifrost.go
📚 Learning: 2025-06-15T14:18:32.703Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#83
File: core/schemas/bifrost.go:186-190
Timestamp: 2025-06-15T14:18:32.703Z
Learning: In core/schemas/bifrost.go, the ToolChoice UnmarshalJSON validation intentionally only checks for empty Type fields and lets providers handle validation of specific tool choice values. This architectural decision keeps schema validation focused on structure while allowing provider-specific semantic validation.

Applied to files:

  • core/providers/cohere.go
  • core/providers/bedrock.go
  • core/providers/anthropic.go
📚 Learning: 2025-07-17T08:56:59.907Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#169
File: docs/usage/http-transport/openapi.json:1352-1358
Timestamp: 2025-07-17T08:56:59.907Z
Learning: In the Bifrost project, the fallback format has been updated from object structure {"provider": "...", "model": "..."} to a simpler string format "provider/model" (e.g., "anthropic/claude-3-sonnet-20240229"). The current OpenAPI schema correctly reflects this new format.

Applied to files:

  • core/providers/cohere.go
📚 Learning: 2025-06-04T09:32:15.826Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/bedrock.go:443-468
Timestamp: 2025-06-04T09:32:15.826Z
Learning: In core/providers/bedrock.go, for tool call result messages (ModelChatMessageRoleTool), the Content field represents the actual tool call output. A tool result message should only be created when msg.Content is non-nil, as there's no semantic meaning to a tool result without output content.

Applied to files:

  • core/providers/bedrock.go
📚 Learning: 2025-06-11T15:05:45.355Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#74
File: core/providers/bedrock.go:909-916
Timestamp: 2025-06-11T15:05:45.355Z
Learning: In Bedrock chat responses (`core/providers/bedrock.go`), image content blocks are only possible in messages with the `user` role; assistant and tool messages will never contain image blocks.

Applied to files:

  • core/providers/bedrock.go
📚 Learning: 2025-06-18T15:16:23.127Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#94
File: core/schemas/bifrost.go:20-23
Timestamp: 2025-06-18T15:16:23.127Z
Learning: In the Bifrost project, BifrostConfig struct is never marshaled/unmarshaled, so serialization tags (json, yaml) are not needed for its fields.

Applied to files:

  • core/providers/bedrock.go
  • core/providers/anthropic.go
  • core/bifrost.go
📚 Learning: 2025-06-10T13:11:37.867Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#65
File: transports/bifrost-http/integrations/anthropic/types.go:131-180
Timestamp: 2025-06-10T13:11:37.867Z
Learning: In Anthropic API integration for Bifrost, messages won't contain both image and tool_result content blocks in the same message, so defensive guards against multiple embedded message structs are unnecessary in the content processing loop.

Applied to files:

  • core/providers/anthropic.go
📚 Learning: 2025-06-04T05:44:09.141Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:0-0
Timestamp: 2025-06-04T05:44:09.141Z
Learning: For the Anthropic provider in core/providers/anthropic.go, it's acceptable to pass potentially malformed messages with invalid roles because Anthropic's API will return suitable error responses for role issues, eliminating the need for additional validation logging.

Applied to files:

  • core/providers/anthropic.go
📚 Learning: 2025-06-04T10:04:30.181Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#55
File: core/providers/anthropic.go:483-494
Timestamp: 2025-06-04T10:04:30.181Z
Learning: In the Anthropic provider (core/providers/anthropic.go), parallel tool calls support including the DisableParallelToolUse flag will be implemented in later commits as it's a relatively new feature that's not commonly used yet. The development approach prioritizes core functionality first.

Applied to files:

  • core/providers/anthropic.go
📚 Learning: 2025-06-17T14:04:21.104Z
Learnt from: connyay
PR: maximhq/bifrost#92
File: core/providers/utils.go:60-64
Timestamp: 2025-06-17T14:04:21.104Z
Learning: The bifrost codebase uses string alias types (like `type ContextKey string`) for context keys consistently across multiple packages including plugins/maxim/main.go and transports/bifrost-http/tracking/plugin.go. This pattern should be maintained for consistency rather than switching to the canonical struct{} approach.

Applied to files:

  • core/bifrost.go
📚 Learning: 2025-06-09T11:27:00.925Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#63
File: transports/bifrost-http/integrations/openai/router.go:62-64
Timestamp: 2025-06-09T11:27:00.925Z
Learning: The `lib.ConvertToBifrostContext` function in the bifrost HTTP transport never returns nil and handles the conversion internally, so nil checks are not needed when calling this function.

Applied to files:

  • core/bifrost.go
📚 Learning: 2025-06-09T11:27:00.925Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#63
File: transports/bifrost-http/integrations/openai/router.go:62-64
Timestamp: 2025-06-09T11:27:00.925Z
Learning: The `lib.ConvertToBifrostContext` function in the bifrost HTTP transport never returns nil and always returns a pointer to a valid context. It starts with context.Background() and only adds values to it, so nil checks are not needed when calling this function.

Applied to files:

  • core/bifrost.go
📚 Learning: 2025-06-27T17:07:39.462Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#135
File: docs/core-package.md:105-116
Timestamp: 2025-06-27T17:07:39.462Z
Learning: In Go, when importing a package, the identifier used to access it is determined by the `package` declaration in the Go source files, not the directory name. For the Bifrost project, the core directory files declare `package bifrost`, so importing `"github.com/maximhq/bifrost/core"` automatically makes it accessible as `bifrost.Init`, `bifrost.Ptr`, etc., without needing an explicit alias.

Applied to files:

  • core/bifrost.go
📚 Learning: 2025-06-09T17:33:52.234Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#65
File: transports/bifrost-http/integrations/utils.go:169-173
Timestamp: 2025-06-09T17:33:52.234Z
Learning: The ChatCompletionRequest method in the Bifrost client follows a contract where the result parameter will never be nil if the error parameter is nil. This means when error checking passes (err == nil), the result is guaranteed to be valid and can be safely used without additional nil checks.

Applied to files:

  • core/bifrost.go
📚 Learning: 2025-06-10T11:19:29.604Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#67
File: transports/bifrost-http/integrations/anthropic/router.go:26-34
Timestamp: 2025-06-10T11:19:29.604Z
Learning: The Generic router in transports/bifrost-http/integrations/utils.go already handles nil pointers from RequestConverter functions. When a RequestConverter returns a nil *schemas.BifrostRequest, the Generic router automatically returns an HTTP 400 error with "Invalid request" message, making additional nil checks in individual router implementations redundant.

Applied to files:

  • core/bifrost.go
📚 Learning: 2025-06-10T11:19:29.604Z
Learnt from: Pratham-Mishra04
PR: maximhq/bifrost#67
File: transports/bifrost-http/integrations/anthropic/router.go:26-34
Timestamp: 2025-06-10T11:19:29.604Z
Learning: The Generic router in transports/bifrost-http/integrations/utils.go already handles nil pointers from RequestConverter functions. When a RequestConverter returns a nil *schemas.BifrostRequest, the Generic router automatically returns an HTTP 400 error, making additional nil checks in individual router implementations redundant.

Applied to files:

  • core/bifrost.go
🧬 Code Graph Analysis (3)
core/schemas/bifrost.go (3)
core/schemas/provider.go (1)
  • Provider (132-151)
ui/lib/types/config.ts (1)
  • ModelProvider (4-4)
ui/lib/types/logs.ts (1)
  • ErrorField (185-192)
core/schemas/plugin.go (2)
plugins/mocker/main.go (1)
  • Response (97-103)
core/schemas/bifrost.go (3)
  • BifrostResponse (374-387)
  • BifrostStream (668-671)
  • BifrostError (679-688)
core/bifrost.go (1)
core/schemas/bifrost.go (3)
  • BifrostStream (668-671)
  • BifrostResponse (374-387)
  • BifrostError (679-688)
🔇 Additional comments (7)
core/schemas/bifrost.go (2)

680-688: 👍 Field visibility clarified.

Moving Provider, AllowFallbacks, and StreamControl behind json:"-" keeps transport payloads clean while still exposing them internally. Looks correct.


691-693: StreamControl tags stay internal – LGTM.

No further action.

core/providers/openai.go (1)

393-432: Chunk indexing logic looks sound.

Initialising to ‑1 then pre-incrementing gives first chunk index 0 – consistent with non-stream semantics. No concurrency concerns as the scanner goroutine is single-writer.

core/providers/cohere.go (1)

763-798: Consistent chunk indexing added.

Same implementation as OpenAI – OK.

core/providers/bedrock.go (1)

1369-1409: Bedrock stream now emits chunk_index – good.

Logic mirrors other providers; no state leakage across streams.

core/bifrost.go (2)

85-90: Good introduction of typed context key

Defining a private BifrostContextKey type avoids cross-package key collisions.


845-852: Early nil-ctx handling & request-type injection LGTM

Handling nil by falling back to a shared background context and tagging the request type keeps downstream code simple.

Also applies to: 897-904

Comment thread core/bifrost.go
Comment thread core/schemas/bifrost.go
Comment thread core/schemas/plugin.go
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 08-09-feat-extended_plugins_for_better_stream_control branch from ed1376e to 98e1451 Compare August 11, 2025 07:31
@Pratham-Mishra04 Pratham-Mishra04 force-pushed the 08-09-feat-extended_plugins_for_better_stream_control branch from 98e1451 to 756cc5e Compare August 11, 2025 11:58
Copy link
Copy Markdown
Contributor

akshaydeo commented Aug 11, 2025

Merge activity

  • Aug 11, 2:00 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 11, 2:00 PM UTC: @akshaydeo merged this pull request with Graphite.

@akshaydeo akshaydeo merged commit 8c8dc24 into main Aug 11, 2025
4 of 9 checks passed
@akshaydeo akshaydeo deleted the 08-09-feat-extended_plugins_for_better_stream_control branch August 31, 2025 17:28
akshaydeo pushed a commit that referenced this pull request Nov 17, 2025
# Enhanced Streaming Support and Context Management

This PR adds several improvements to Bifrost's streaming capabilities and context management:

1. Added `ChunkIndex` to track the position of each chunk in streaming responses across all providers (OpenAI, Anthropic, Bedrock, Cohere)

2. Introduced `BifrostContextKey` type and `BifrostContextKeyRequestType` constant for better context management

3. Fixed context handling by moving nil context checks earlier in request processing to prevent blocking

4. Added support for short-circuit streaming in plugins via a new `Stream` field in `PluginShortCircuit`

5. Improved stream processing with proper post-hook execution for short-circuited streams

These changes enable better tracking of streaming chunks, more robust context management, and enhanced plugin capabilities for stream manipulation.
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