Skip to content

feat: openai compaction support - #4053

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
06-04-feat_openai_compaction_support
Jun 5, 2026
Merged

feat: openai compaction support#4053
Pratham-Mishra04 merged 1 commit into
devfrom
06-04-feat_openai_compaction_support

Conversation

@TejasGhatte

@TejasGhatte TejasGhatte commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds support for OpenAI's context compaction endpoint (POST /v1/responses/compact), which compacts a conversation context window to reduce token usage. All other providers return an unsupported-operation error for this request type.

Changes

  • Introduced CompactionRequest as a new RequestType constant and added BifrostCompactionRequest / BifrostCompactionResponse schema types as a strict subset of the responses API (no tools, sampling params, or streaming).
  • Added Compaction to the Provider interface and implemented it for OpenAI via HandleOpenAICompactionRequest, routing to /v1/responses/compact. All other providers return NewUnsupportedOperationError.
  • Wired CompactionRequest through BifrostRequest / BifrostResponse field accessors (GetRequestFields, SetProvider, SetModel, SetFallbacks, SetRawRequestBody, GetExtraFields, PopulateExtraFields) and through the fallback preparation and request dispatch logic in bifrost.go.
  • Registered POST /v1/responses/compact in the HTTP transport with a dedicated compaction handler, CompactionHTTPRequest type, and compactionParamsKnownFields validation map.
  • Added CompactionResponseConverter to RouteConfig and handled CompactionRequest in the generic router's non-streaming dispatch path.
  • Added the OpenAI integration route config for /v1/responses/compact (and aliased paths), including OpenAICompactionRequest wire type with ToOpenAICompactionRequest / ToBifrostCompactionRequest converters.
  • Extended model catalog pricing to treat CompactionRequest the same as ResponsesRequest for cost computation, usage extraction, and fallback pricing lookups, normalizing it to the "responses" base type.
  • Extended the logging plugin to extract usage and output from CompactionResponse when building log entries.
  • Added "compaction" to the UI request type list, labels, and color map (indigo), and updated the log detail view to recognize "compaction" as a responses-family object for copy-request-body support.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

# Core/Transports
go test ./...

# Send a compaction request via the HTTP transport
curl -X POST http://localhost:8080/v1/responses/compact \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o",
    "input": [
      {"role": "user", "content": "Hello, summarize this conversation."}
    ]
  }'
# Expected: 200 with a BifrostCompactionResponse (object: "response.compaction")

# Verify unsupported providers return an error
curl -X POST http://localhost:8080/v1/responses/compact \
  -H "Content-Type: application/json" \
  -d '{"model": "anthropic/claude-opus-4-5", "input": []}'
# Expected: error indicating unsupported operation for the Anthropic provider

# UI
cd ui
pnpm i
pnpm build

Breaking changes

  • Yes
  • No

The Provider interface gains a new required method Compaction. Any custom provider implementations outside this repository must add a Compaction method returning NewUnsupportedOperationError (or a real implementation) to satisfy the interface.

Related issues

Security considerations

No new auth mechanisms are introduced. The compaction endpoint forwards the caller's API key as a Bearer token to OpenAI, consistent with all other provider requests. No PII handling changes.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

Summary by CodeRabbit

  • New Features

    • Added a compaction operation with a public POST /v1/responses/compact endpoint; OpenAI and Azure compaction supported.
  • Integration

    • Pricing, usage tracking, logging, routing, and passthrough flows updated to surface compaction results, provider headers, and latency/metadata.
  • UI

    • Logs/UI now include a "Compaction" request type and copy/export behavior for compaction entries.
  • Tests

    • New toggleable end-to-end compaction tests validating response contract and follow-up usability.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new "compaction" request/response type and wires it through schemas, the Bifrost pipeline, providers (OpenAI/Azure/XAI implementations + unsupported stubs), HTTP routing, pricing, logging, UI, and comprehensive external tests.

Changes

Compaction Request Feature

Layer / File(s) Summary
Request/Response schemas and provider interface
core/schemas/bifrost.go, core/schemas/responses.go, core/schemas/provider.go
Adds BifrostCompactionRequest/BifrostCompactionResponse, RequestType "compaction", BifrostRequest.CompactionRequest / BifrostResponse.CompactionResponse, AllowedRequests.Compaction, and Provider.Compaction signature.
Core Bifrost request pipeline integration
core/bifrost.go
Adds Bifrost.CompactionRequest API, propagates compaction through fallback preparation, dispatches to provider.Compaction, and clears pooled request compaction state.
OpenAI provider: full compaction implementation
core/providers/openai/openai.go, core/providers/openai/responses.go
Implements OpenAIProvider.Compaction and HandleOpenAICompactionRequest for /v1/responses/compact, adds OpenAICompactionRequest wire type and converters, preserves compaction encrypted reasoning content, supports large-payload passthrough and raw request/response flags.
Provider wrappers: Azure & XAI
core/providers/azure/azure.go, core/providers/xai/xai.go, transports/bifrost-http/integrations/openai.go
Adds Azure and XAI compaction paths that call OpenAI-compatible compaction endpoints/handlers and populate provider metadata and headers.
Provider stubs: unsupported compaction (many providers)
core/providers/*/*.go
Adds Compaction stubs returning unsupported-operation errors across multiple non-OpenAI providers to satisfy the extended Provider interface.
HTTP transport and routing for compaction
transports/bifrost-http/handlers/inference.go, transports/bifrost-http/integrations/router.go
Adds POST /v1/responses/compact request shape, preparation/validation, route registration, OpenAI integration routes, and generic router compaction response conversion (CompactionResponseConverter).
Pricing framework and billing integration
framework/modelcatalog/pricing.go, framework/modelcatalog/utils.go, transports/config.schema.json
Classifies compaction as responses-type for passthrough, routes compaction through text-cost billing and usage extraction, extends fallback pricing lookups, and adds compaction to config/schema enums and allowed-requests.
Logging and observability support
plugins/logging/operations.go, plugins/logging/utils.go
Extracts compaction input for logs and maps non-streaming compaction usage/output into log entries for token accounting and content logging.
UI constants and log view support
ui/app/workspace/logs/sheets/logDetailView.tsx, ui/lib/constants/logs.ts
Adds "compaction" request type constants, label/color, and treats compaction logs as responses-like in the log detail view.
External tests
core/internal/llmtests/*, core/providers/*/*_test.go
Adds configurable ExternalCompaction test scenario, registers tests in comprehensive runs, and enables the scenario in OpenAI/Azure/XAI test configs to validate compaction contract and follow-up usability.

Sequence Diagram(s)

sequenceDiagram
  participant Bifrost
  participant OpenAIProvider
  participant OpenAIResponsesAPI
  Bifrost->>OpenAIProvider: Compaction(ctx, key, BifrostCompactionRequest)
  OpenAIProvider->>OpenAIProvider: HandleOpenAICompactionRequest(ToOpenAICompactionRequest)
  OpenAIProvider->>OpenAIResponsesAPI: POST /v1/responses/compact (JSON)
  OpenAIResponsesAPI-->>OpenAIProvider: response.compaction
  OpenAIProvider-->>Bifrost: BifrostCompactionResponse + ExtraFields
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • maximhq/bifrost#3661: Azure/OpenAI request routing changes that interact with the Azure compaction wiring added here.

Suggested reviewers

  • danpiths
  • akshaydeo
  • roroghost17

Poem

🐇 I hopped through routes and schema lines so bright,
A compact request now finds its light.
OpenAI answers, others politely stall,
Logs and billing learn to count it all —
A happy rabbit cheered into the night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: openai compaction support' clearly and concisely summarizes the main change—adding OpenAI's compaction endpoint support—and is directly related to the primary objective of the PR.
Description check ✅ Passed The PR description covers all major template sections: Summary explains the feature, Changes details the implementation across multiple components, Type/Affected areas/Testing/Breaking changes/Checklist are all addressed with appropriate detail and clarity.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-04-feat_openai_compaction_support

Comment @coderabbitai help to get the list of available commands and usage tips.

@CLAassistant

CLAassistant commented Jun 4, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

TejasGhatte commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

@TejasGhatte
TejasGhatte marked this pull request as ready for review June 4, 2026 11:36
@greptile-apps

greptile-apps Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

  • The change is well-scoped and follows established Bifrost patterns throughout; the one finding is a minor defensive normalisation gap that OpenAI's API behaviour makes harmless in practice.
  • The compaction feature is consistently threaded through all layers — schemas, providers, transport handlers, pricing, logging, and UI. The only gap found is that BifrostCompactionResponse.WithDefaults() is never called in the CompactionResponseConverter, unlike every other responses-family converter. Because OpenAI reliably returns object and output on this endpoint, the absence of the defensive call has no observable effect today.
  • transports/bifrost-http/integrations/openai.go (CompactionResponseConverter missing WithDefaults call), core/schemas/responses.go (WithDefaults defined but never invoked)

Important Files Changed

Filename Overview
core/bifrost.go Adds CompactionRequest dispatch method, prepareFallbackRequest handling, handleProviderRequest routing, and resetBifrostRequest reset — all consistent with existing patterns.
core/schemas/responses.go Introduces BifrostCompactionRequest/Response types. WithDefaults() is defined but never invoked in the compaction response converter path, leaving object/output normalisation as dead code.
core/providers/openai/openai.go HandleOpenAICompactionRequest follows the same fasthttp acquire/release and finalizeOpenAIResponse pattern as CountTokens; respOwned flag, large-payload passthrough, and error paths all look correct.
core/providers/openai/responses.go ToOpenAICompactionRequest reuses ToOpenAIResponsesRequest for input normalisation. The isCompactionMessage guard correctly preserves encrypted_content on compaction items during reasoning-content stripping.
transports/bifrost-http/handlers/inference.go prepareCompactionRequest correctly validates that either input or previous_response_id is present. The compaction handler follows the same pattern as countTokens including provider header forwarding.
transports/bifrost-http/integrations/openai.go Route config for /v1/responses/compact is complete, but CompactionResponseConverter returns resp directly without calling WithDefaults(), unlike all other responses-family converters in this file.
transports/bifrost-http/integrations/router.go Adds CompactionResponseConverter type and the compaction case in handleNonStreamingRequest, consistent with the CountTokens pattern including PostCallback and nil-guard.
framework/modelcatalog/pricing.go CompactionRequest correctly added to all pricing lookup fallback chains and to detectPassthroughRequestType. extractCostInput extracts usage from CompactionResponse.Usage when present.

Reviews (8): Last reviewed commit: "feat: openai compaction support" | Re-trigger Greptile

Comment thread core/schemas/responses.go Outdated
Comment thread core/schemas/responses.go Outdated
Comment thread framework/modelcatalog/pricing.go

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
core/schemas/provider.go (1)

326-400: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add the compaction schema allow-lists in the same PR.

The Go-side gate is wired here, but the transport config schema is still missing compaction. That means custom_provider_config.allowed_requests.compaction cannot be configured through validated/persisted config, and pricing overrides still cannot target compaction requests, so the feature remains partially unreachable outside in-memory config.

As per coding guidelines, transports/config.schema.json is the source of truth for config fields, and the referenced schema contents say $defs.custom_provider_config.allowed_requests plus $defs.pricing_override_request_type still lack compaction.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/schemas/provider.go` around lines 326 - 400, The AllowedRequests Go
struct and IsOperationAllowed already handle Compaction, but
transports/config.schema.json is missing the compaction field and enum value;
update the JSON schema by adding "compaction": { "type": "boolean" } to
$defs.custom_provider_config.allowed_requests and add "compaction" to
$defs.pricing_override_request_type (or equivalent enum for RequestType) so
custom_provider_config.allowed_requests.compaction is validated/persisted and
compaction can be targeted in pricing overrides; ensure the schema description
and examples (if any) are consistent with other boolean flags.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/schemas/bifrost.go`:
- Line 157: The schema changes add a new RequestType constant CompactionRequest
but the JSON transport schema is missing "compaction" in its allow-lists; update
transports/config.schema.json by adding "compaction" to the enum under
$defs.pricing_override_request_type and to the allowed values array/object under
$defs.custom_provider_config.properties.allowed_requests.properties so that the
new CompactionRequest is recognized by transport-side
governance/pricing/custom-provider checks.

In `@core/schemas/responses.go`:
- Around line 69-78: Add a WithDefaults() method on BifrostCompactionResponse
that returns a normalized copy (or nil if receiver is nil); ensure it sets
Object = "response.compaction", preserves ID/Usage/ExtraFields, sets CreatedAt
to time.Now().Unix() if zero, and ensures Output is a non-nil []ResponsesMessage
(copy resp.Output if present, otherwise empty slice). Name the method
WithDefaults on type BifrostCompactionResponse to match other response types so
the pipeline can call it consistently.

In `@framework/modelcatalog/pricing.go`:
- Around line 339-340: Passthrough requests for the compaction endpoint aren’t
being classified as schemas.CompactionRequest, so /v1/responses/compact can fall
through to chat and be billed via computeTextCost incorrectly; update the
passthrough/type-inference code that maps request paths (the function that
infers passthrough types) to return schemas.CompactionRequest for the
"/v1/responses/compact" route, ensure the billing switch that calls
computeTextCost(...) already handles schemas.CompactionRequest, and add a unit
test verifying that a passthrough request to "/v1/responses/compact" is
classified as schemas.CompactionRequest (not chat) so it uses the compaction
billing path.

In `@transports/bifrost-http/handlers/inference.go`:
- Around line 699-700: Add the missing "compaction" request type to the
transport config schema: update the enum at
$defs.pricing_override_request_type.enum to include "compaction" and add a
corresponding property named "compaction" under
$defs.custom_provider_config.allowed_requests.properties so POST
"/v1/responses/compact" is explicitly allowed (preserve existing keys like
max_request_body_size_mb and large_payload_optimization when adding the new
entry).
- Around line 1536-1556: In prepareCompactionRequest, ensure we validate that
the compaction payload contains at least an input or a PreviousResponseID before
returning the BifrostCompactionRequest: after you normalize
ResponsesRequestInputArray from ResponsesRequestInputStr (the input variable),
if input is nil/empty and req.PreviousResponseID (or PreviousResponseID on the
returned BifrostCompactionRequest) is also empty, return a validation error
(HTTP 400 / appropriate handler error) instead of forwarding the request; update
the function to perform this check and return early with an error when both are
missing.

In `@transports/bifrost-http/integrations/openai.go`:
- Around line 842-852: The pre-hook openAILargePayloadPreHook is used for
compaction requests but hydrateOpenAIRequestFromLargePayloadMetadata doesn't
handle *openai.OpenAICompactionRequest, so compaction requests can end up with
an empty Model; update hydrateOpenAIRequestFromLargePayloadMetadata to detect
and populate openai.OpenAICompactionRequest (setting the Model and any other
required fields from the large-payload metadata or hydrated payload), ensure
GetRequestModel (the closure returning r.Model) sees the filled value, and add a
fallback/error when Model remains empty to avoid broken compaction routing.

---

Outside diff comments:
In `@core/schemas/provider.go`:
- Around line 326-400: The AllowedRequests Go struct and IsOperationAllowed
already handle Compaction, but transports/config.schema.json is missing the
compaction field and enum value; update the JSON schema by adding "compaction":
{ "type": "boolean" } to $defs.custom_provider_config.allowed_requests and add
"compaction" to $defs.pricing_override_request_type (or equivalent enum for
RequestType) so custom_provider_config.allowed_requests.compaction is
validated/persisted and compaction can be targeted in pricing overrides; ensure
the schema description and examples (if any) are consistent with other boolean
flags.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3429ea98-2e1f-4e6a-94dc-62eabb87823c

📥 Commits

Reviewing files that changed from the base of the PR and between a1beab5 and c8cdf9c.

📒 Files selected for processing (37)
  • core/bifrost.go
  • core/providers/anthropic/anthropic.go
  • core/providers/azure/azure.go
  • core/providers/bedrock/bedrock.go
  • core/providers/cerebras/cerebras.go
  • core/providers/cohere/cohere.go
  • core/providers/elevenlabs/elevenlabs.go
  • core/providers/fireworks/fireworks.go
  • core/providers/gemini/gemini.go
  • core/providers/groq/groq.go
  • core/providers/huggingface/huggingface.go
  • core/providers/mistral/mistral.go
  • core/providers/nebius/nebius.go
  • core/providers/ollama/ollama.go
  • core/providers/openai/openai.go
  • core/providers/openai/responses.go
  • core/providers/openrouter/openrouter.go
  • core/providers/parasail/parasail.go
  • core/providers/perplexity/perplexity.go
  • core/providers/replicate/replicate.go
  • core/providers/runway/runway.go
  • core/providers/sgl/sgl.go
  • core/providers/vertex/vertex.go
  • core/providers/vllm/vllm.go
  • core/providers/xai/xai.go
  • core/schemas/bifrost.go
  • core/schemas/provider.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/utils.go
  • plugins/logging/operations.go
  • plugins/logging/utils.go
  • transports/bifrost-http/handlers/inference.go
  • transports/bifrost-http/integrations/openai.go
  • transports/bifrost-http/integrations/router.go
  • ui/app/workspace/logs/sheets/logDetailView.tsx
  • ui/lib/constants/logs.ts

Comment thread core/schemas/bifrost.go
Comment thread core/schemas/responses.go
Comment thread framework/modelcatalog/pricing.go
Comment thread transports/bifrost-http/handlers/inference.go
Comment thread transports/bifrost-http/handlers/inference.go
Comment thread transports/bifrost-http/integrations/openai.go Outdated
@TejasGhatte
TejasGhatte force-pushed the 06-04-feat_openai_compaction_support branch from c8cdf9c to 7c72bca Compare June 4, 2026 12:33

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

♻️ Duplicate comments (1)
transports/bifrost-http/handlers/inference.go (1)

1536-1538: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Allow compaction requests to pass through without mandatory input.

This guard rejects valid compaction payloads for this endpoint and breaks the intended passthrough validation boundary.

💡 Proposed fix
-	if len(req.Input.ResponsesRequestInputArray) == 0 && req.Input.ResponsesRequestInputStr == nil {
-		return nil, nil, fmt.Errorf("input is required for compaction")
-	}

Based on learnings: In maximhq/bifrost, POST /v1/responses/compact intentionally does NOT require input or previous_response_id at handler level; validation is delegated to the upstream provider.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@transports/bifrost-http/handlers/inference.go` around lines 1536 - 1538,
Remove the mandatory input guard that rejects requests when both
req.Input.ResponsesRequestInputArray is empty and
req.Input.ResponsesRequestInputStr is nil for the compaction endpoint;
specifically, in the handler that serves POST /v1/responses/compact (the code
around inference.go using req.Input.ResponsesRequestInputArray and
req.Input.ResponsesRequestInputStr), either delete this if-block or wrap it so
it only runs for non-compaction paths, allowing compaction requests to pass
through and letting upstream providers validate presence of
input/previous_response_id.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/openai/openai.go`:
- Around line 4151-4154: The code currently calls logger.Debug with the full
upstream response body (logger.Debug("error from %s provider: %s", providerName,
string(resp.Body()))) which can leak sensitive data; remove or replace that call
with a safe, non-sensitive log (e.g., log providerName, resp.StatusCode(), and
optionally a redacted/truncated indicator or body length). In the block around
providerUtils.MaterializeStreamErrorBody(ctx, resp) and the return that calls
providerUtils.EnrichError(ctx, ParseOpenAIError(resp), jsonData, nil,
sendBackRawRequest, sendBackRawResponse), delete the raw resp.Body() logging and
instead log only non-sensitive metadata (providerName and status code or
"response body omitted/redacted") or a truncated/hashed summary if you must
record something for debugging; keep MaterializeStreamErrorBody and EnrichError
behavior unchanged.
- Around line 4061-4078: HandleOpenAICompactionRequest is currently logging the
full upstream error body (logger.Debug("error from %s provider: %s", ...,
string(resp.Body()))) for non-200 responses when calling POST
/v1/responses/compact; change this to avoid leaking sensitive content by either
truncating the body to a small safe length, or preferably only logging the
parsed ParseOpenAIError fields (e.g., error.message, error.type, error.param,
error.code) and a short hex/sha256 of the raw body if needed for correlation;
update the logging call in HandleOpenAICompactionRequest to use those sanitized
fields and remove any direct string(resp.Body()) usage, and ignore the reviewer
note about disableStore parity since BifrostCompactionRequest /
OpenAICompactionRequest and ToOpenAICompactionRequest do not send a store field.

In `@core/providers/openai/responses.go`:
- Around line 450-466: The conversion in ToBifrostCompactionRequest currently
only sets Input to r.Input.OpenAIResponsesRequestInputArray, dropping
string-form inputs; update ToBifrostCompactionRequest to preserve the string
form by setting Input to r.Input.OpenAIResponsesRequestInputArray when
non-empty, otherwise use the string input (e.g.,
r.Input.OpenAIResponsesRequestInputString or r.Input.String) so that
OpenAICompactionRequest -> BifrostCompactionRequest retains either the array or
the original string input; keep all other fields (Provider, Model, Instructions,
PreviousResponseID, PromptCacheKey, PromptCacheRetention, ServiceTier)
unchanged.

In `@transports/config.schema.json`:
- Around line 4629-4630: The schema update added "compaction" to
$defs.pricing_override_request_type but
provider_pricing_override.request_types.items still allows any string so the
enum isn't enforced; update provider_pricing_override.request_types.items to
reference the shared definition ($defs.pricing_override_request_type) or to use
the same enum values so validation will reject unknown request types —
specifically change the items schema under
provider_pricing_override.request_types to $ref:
"`#/`$defs/pricing_override_request_type" (or mirror that enum) to make the new
"compaction" value effective.

---

Duplicate comments:
In `@transports/bifrost-http/handlers/inference.go`:
- Around line 1536-1538: Remove the mandatory input guard that rejects requests
when both req.Input.ResponsesRequestInputArray is empty and
req.Input.ResponsesRequestInputStr is nil for the compaction endpoint;
specifically, in the handler that serves POST /v1/responses/compact (the code
around inference.go using req.Input.ResponsesRequestInputArray and
req.Input.ResponsesRequestInputStr), either delete this if-block or wrap it so
it only runs for non-compaction paths, allowing compaction requests to pass
through and letting upstream providers validate presence of
input/previous_response_id.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 839df775-86d7-4786-9417-5d1b3e927740

📥 Commits

Reviewing files that changed from the base of the PR and between c8cdf9c and 7c72bca.

📒 Files selected for processing (42)
  • core/bifrost.go
  • core/internal/llmtests/account.go
  • core/internal/llmtests/compaction.go
  • core/internal/llmtests/tests.go
  • core/providers/anthropic/anthropic.go
  • core/providers/azure/azure.go
  • core/providers/bedrock/bedrock.go
  • core/providers/cerebras/cerebras.go
  • core/providers/cohere/cohere.go
  • core/providers/elevenlabs/elevenlabs.go
  • core/providers/fireworks/fireworks.go
  • core/providers/gemini/gemini.go
  • core/providers/groq/groq.go
  • core/providers/huggingface/huggingface.go
  • core/providers/mistral/mistral.go
  • core/providers/nebius/nebius.go
  • core/providers/ollama/ollama.go
  • core/providers/openai/openai.go
  • core/providers/openai/openai_test.go
  • core/providers/openai/responses.go
  • core/providers/openrouter/openrouter.go
  • core/providers/parasail/parasail.go
  • core/providers/perplexity/perplexity.go
  • core/providers/replicate/replicate.go
  • core/providers/runway/runway.go
  • core/providers/sgl/sgl.go
  • core/providers/vertex/vertex.go
  • core/providers/vllm/vllm.go
  • core/providers/xai/xai.go
  • core/schemas/bifrost.go
  • core/schemas/provider.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/utils.go
  • plugins/logging/operations.go
  • plugins/logging/utils.go
  • transports/bifrost-http/handlers/inference.go
  • transports/bifrost-http/integrations/openai.go
  • transports/bifrost-http/integrations/router.go
  • transports/config.schema.json
  • ui/app/workspace/logs/sheets/logDetailView.tsx
  • ui/lib/constants/logs.ts

Comment thread core/providers/openai/openai.go
Comment thread core/providers/openai/openai.go
Comment thread core/providers/openai/responses.go
Comment thread transports/config.schema.json
@TejasGhatte
TejasGhatte force-pushed the 06-04-feat_openai_compaction_support branch from 7c72bca to 49a9c29 Compare June 4, 2026 13:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/bifrost.go`:
- Around line 924-925: The exported doc comment for CompactionRequest is
outdated and should be updated to accurately describe which providers support
compaction; edit the top-of-declaration comment for the exported
CompactionRequest type/function so it begins with "CompactionRequest" (Go doc
convention) and clearly lists the current supported providers and behavior for
others (e.g., "supported by OpenAI and <OtherProviderName>; other providers
return an unsupported-operation error"), and include any relevant details about
the /v1/responses/compact endpoint and expected semantics so SDK users and
maintainers see the true provider surface.
- Around line 6229-6234: Before calling provider.Compaction in the
schemas.CompactionRequest branch, check the provider's allowed_requests
compaction flag and refuse dispatch if compaction is not allowed; specifically,
inspect the provider's custom config (e.g.,
provider.CustomProviderConfig.AllowedRequests.Compaction or
provider.AllowedRequests.Compaction) and return an appropriate bifrost error
when false instead of invoking provider.Compaction, otherwise proceed to call
provider.Compaction and set response.CompactionResponse as before.

In `@core/providers/azure/azure.go`:
- Around line 2694-2706: completeRequest may set large-response streaming mode
which leaves responseBody nil; before calling
providerUtils.HandleProviderResponse, check the context flag used by Azure
handlers (ctx.Value(schemas.BifrostContextKeyLargeResponseMode)) and
short-circuit when it's set (i.e., return immediately the same way other Azure
unary handlers do so the streaming path handles the response) instead of
attempting to unmarshal a nil responseBody; add this check right after
provider.completeRequest returns and before calling
providerUtils.HandleProviderResponse in the function that contains
provider.completeRequest/response handling.

In `@core/providers/openai/responses.go`:
- Around line 146-149: The loop that early-continues for non-reasoning models is
still skipping compaction items before the later guard preserves
encrypted_content; update the earlier skip condition to exempt compaction items
by checking message.Type against schemas.ResponsesMessageTypeCompaction (i.e.,
treat isCompactionMessage as a pass-through), so compaction messages with
content blocks reach the branch that preserves
ResponsesReasoning.EncryptedContent; adjust the condition that uses isReasoning
and the continue to include a check like "and not isCompactionMessage" (using
the existing message.Type / schemas.ResponsesMessageTypeCompaction symbols) so
compaction items are not dropped.
- Around line 431-447: To avoid bypassing OpenAI-specific message normalization,
update ToOpenAICompactionRequest so it does not assign req.Input verbatim;
instead reuse the same conversion/normalization used by ToOpenAIResponsesRequest
(extract or call the shared helper that shapes inputs into
OpenAIResponsesRequestInput) to produce the OpenAIResponsesRequestInput shape
(preserving role cleanup and compaction-content conversion) and assign that to
r.Input; reference the ToOpenAICompactionRequest and ToOpenAIResponsesRequest
conversion path (or create a small shared helper like
NormalizeOpenAIResponsesInput used by both) and replace the direct
OpenAIResponsesRequestInput{...: req.Input} assignment with a call to that
normalization function.

In `@transports/bifrost-http/handlers/inference.go`:
- Around line 1536-1538: Remove the hard input requirement that rejects
compaction payloads by deleting or disabling the conditional that returns an
error when both req.Input.ResponsesRequestInputArray and
req.Input.ResponsesRequestInputStr are empty/nil in the compaction handler in
inference.go; allow the compaction request to proceed with nil/empty input (so
previous_response_id-only requests are accepted) and rely on upstream validation
instead of returning fmt.Errorf("input is required for compaction") from that
check.

In `@transports/bifrost-http/integrations/openai.go`:
- Around line 846-847: The compaction route currently assigns PreCallback:
openAILargePayloadPreHook but that hook doesn't set the
BifrostContextKeyIsAzureUserAgent flag, so Azure SDK requests can be misrouted;
update the compaction route to ensure Azure-compatible routing by either (a)
modifying openAILargePayloadPreHook to set BifrostContextKeyIsAzureUserAgent
when the request matches Azure user-agent/headers, or (b) wrap/replace the
PreCallback for the compaction handler so it calls the existing Azure-aware
prehook used by /responses (preserving current behavior) before delegating to
openAILargePayloadPreHook; target the PreCallback assignment and ensure
BifrostContextKeyIsAzureUserAgent is set consistently with the /responses flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fca686f6-afc3-4954-a14c-8c7a0df1da2a

📥 Commits

Reviewing files that changed from the base of the PR and between 7c72bca and 49a9c29.

📒 Files selected for processing (44)
  • core/bifrost.go
  • core/internal/llmtests/account.go
  • core/internal/llmtests/compaction.go
  • core/internal/llmtests/tests.go
  • core/providers/anthropic/anthropic.go
  • core/providers/azure/azure.go
  • core/providers/azure/azure_test.go
  • core/providers/bedrock/bedrock.go
  • core/providers/cerebras/cerebras.go
  • core/providers/cohere/cohere.go
  • core/providers/elevenlabs/elevenlabs.go
  • core/providers/fireworks/fireworks.go
  • core/providers/gemini/gemini.go
  • core/providers/groq/groq.go
  • core/providers/huggingface/huggingface.go
  • core/providers/mistral/mistral.go
  • core/providers/nebius/nebius.go
  • core/providers/ollama/ollama.go
  • core/providers/openai/openai.go
  • core/providers/openai/openai_test.go
  • core/providers/openai/responses.go
  • core/providers/openrouter/openrouter.go
  • core/providers/parasail/parasail.go
  • core/providers/perplexity/perplexity.go
  • core/providers/replicate/replicate.go
  • core/providers/runway/runway.go
  • core/providers/sgl/sgl.go
  • core/providers/vertex/vertex.go
  • core/providers/vllm/vllm.go
  • core/providers/xai/xai.go
  • core/providers/xai/xai_test.go
  • core/schemas/bifrost.go
  • core/schemas/provider.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/utils.go
  • plugins/logging/operations.go
  • plugins/logging/utils.go
  • transports/bifrost-http/handlers/inference.go
  • transports/bifrost-http/integrations/openai.go
  • transports/bifrost-http/integrations/router.go
  • transports/config.schema.json
  • ui/app/workspace/logs/sheets/logDetailView.tsx
  • ui/lib/constants/logs.ts

Comment thread core/bifrost.go Outdated
Comment thread core/bifrost.go
Comment thread core/providers/azure/azure.go
Comment thread core/providers/openai/responses.go
Comment thread core/providers/openai/responses.go
Comment thread transports/bifrost-http/handlers/inference.go Outdated
Comment thread transports/bifrost-http/integrations/openai.go Outdated
@TejasGhatte
TejasGhatte force-pushed the 06-04-feat_openai_compaction_support branch from 49a9c29 to e20e7d2 Compare June 4, 2026 14:33

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ui/app/workspace/logs/sheets/logDetailView.tsx (1)

2244-2285: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Include canonical Responses object aliases in copy-request detection.

Line 2244 adds compaction, but isResponses still misses common response object values like responses / responses_stream, so copy-request can still be incorrectly blocked while Line 2284 says responses are supported.

Suggested fix
-		const isResponses = log.object === "response" || log.object === "response.completion.chunk" || log.object === "compaction";
+		const isResponses =
+			log.object === "response" ||
+			log.object === "response.completion.chunk" ||
+			log.object === "responses" ||
+			log.object === "responses_stream" ||
+			log.object === "websocket_responses" ||
+			log.object === "compaction";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/app/workspace/logs/sheets/logDetailView.tsx` around lines 2244 - 2285, The
copy-request detection misses canonical Responses aliases: update the
isResponses expression to include the additional object values "responses" and
"responses_stream" (alongside the existing "response",
"response.completion.chunk", and "compaction") so that isResponses (and thus
isSupportedType) correctly treats those logs as supported for copy-request;
locate the isResponses constant in logDetailView.tsx and add those two string
checks to its condition.
♻️ Duplicate comments (1)
transports/config.schema.json (1)

4629-4630: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

compaction enum addition is not enforced in pricing overrides

$defs.pricing_override_request_type now includes compaction, but provider_pricing_override.request_types.items (Line 4588) is still "type": "string", so invalid request types still pass schema validation.

Suggested fix
 "request_types": {
   "type": "array",
   "description": "Request types this override applies to. At least one value is required.",
   "minItems": 1,
   "items": {
-    "type": "string"
+    "$ref": "`#/`$defs/pricing_override_request_type"
   }
 },

As per coding guidelines, transports/config.schema.json is the source of truth for config fields.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@transports/config.schema.json` around lines 4629 - 4630, The schema added
"compaction" to $defs.pricing_override_request_type but did not enforce it in
provider_pricing_override.request_types.items; update
provider_pricing_override.request_types.items to reference the canonical enum
($ref to $defs.pricing_override_request_type) or replace its "type": "string"
with an "enum" that matches $defs.pricing_override_request_type so only valid
request types (including "compaction") pass validation; target the
provider_pricing_override.request_types.items node to make this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/bifrost.go`:
- Around line 927-949: In Bifrost.CompactionRequest, add an early guard that
checks req.Input (the input field on the incoming
*schemas.BifrostCompactionRequest) and return a *schemas.BifrostError with
IsBifrostError:false, Error: &schemas.ErrorField{Message: "compaction input is
nil"} and ExtraFields.RequestType set to schemas.CompactionRequest when Input is
nil/empty; keep this check before creating bifrostReq or calling
bifrost.handleRequest so the exported API enforces the same contract as the HTTP
endpoint.

In `@transports/bifrost-http/handlers/inference.go`:
- Around line 1531-1560: The compaction path drops provider-specific extra
params: prepareRequest fills base.ExtraParams but the returned
schemas.BifrostCompactionRequest does not include them; update the code that
constructs the BifrostCompactionRequest in the compaction handler to copy/assign
base.ExtraParams (or a properly typed clone) into the request (e.g., set the
ExtraParams/Extra fields on the returned BifrostCompactionRequest to
base.ExtraParams) so unknown/sdk-specific fields are preserved when dispatching;
keep the existing Input conversion logic and ensure the field name matches the
schemas.BifrostCompactionRequest definition.

---

Outside diff comments:
In `@ui/app/workspace/logs/sheets/logDetailView.tsx`:
- Around line 2244-2285: The copy-request detection misses canonical Responses
aliases: update the isResponses expression to include the additional object
values "responses" and "responses_stream" (alongside the existing "response",
"response.completion.chunk", and "compaction") so that isResponses (and thus
isSupportedType) correctly treats those logs as supported for copy-request;
locate the isResponses constant in logDetailView.tsx and add those two string
checks to its condition.

---

Duplicate comments:
In `@transports/config.schema.json`:
- Around line 4629-4630: The schema added "compaction" to
$defs.pricing_override_request_type but did not enforce it in
provider_pricing_override.request_types.items; update
provider_pricing_override.request_types.items to reference the canonical enum
($ref to $defs.pricing_override_request_type) or replace its "type": "string"
with an "enum" that matches $defs.pricing_override_request_type so only valid
request types (including "compaction") pass validation; target the
provider_pricing_override.request_types.items node to make this change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 599eb010-bc76-45e3-a559-5bfe81b237a9

📥 Commits

Reviewing files that changed from the base of the PR and between 49a9c29 and e20e7d2.

📒 Files selected for processing (44)
  • core/bifrost.go
  • core/internal/llmtests/account.go
  • core/internal/llmtests/compaction.go
  • core/internal/llmtests/tests.go
  • core/providers/anthropic/anthropic.go
  • core/providers/azure/azure.go
  • core/providers/azure/azure_test.go
  • core/providers/bedrock/bedrock.go
  • core/providers/cerebras/cerebras.go
  • core/providers/cohere/cohere.go
  • core/providers/elevenlabs/elevenlabs.go
  • core/providers/fireworks/fireworks.go
  • core/providers/gemini/gemini.go
  • core/providers/groq/groq.go
  • core/providers/huggingface/huggingface.go
  • core/providers/mistral/mistral.go
  • core/providers/nebius/nebius.go
  • core/providers/ollama/ollama.go
  • core/providers/openai/openai.go
  • core/providers/openai/openai_test.go
  • core/providers/openai/responses.go
  • core/providers/openrouter/openrouter.go
  • core/providers/parasail/parasail.go
  • core/providers/perplexity/perplexity.go
  • core/providers/replicate/replicate.go
  • core/providers/runway/runway.go
  • core/providers/sgl/sgl.go
  • core/providers/vertex/vertex.go
  • core/providers/vllm/vllm.go
  • core/providers/xai/xai.go
  • core/providers/xai/xai_test.go
  • core/schemas/bifrost.go
  • core/schemas/provider.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/utils.go
  • plugins/logging/operations.go
  • plugins/logging/utils.go
  • transports/bifrost-http/handlers/inference.go
  • transports/bifrost-http/integrations/openai.go
  • transports/bifrost-http/integrations/router.go
  • transports/config.schema.json
  • ui/app/workspace/logs/sheets/logDetailView.tsx
  • ui/lib/constants/logs.ts

Comment thread core/bifrost.go
Comment thread transports/bifrost-http/handlers/inference.go
@TejasGhatte
TejasGhatte force-pushed the 06-04-feat_openai_compaction_support branch from e20e7d2 to 54f6513 Compare June 4, 2026 16:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
core/bifrost.go (1)

940-952: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Enforce mandatory input in CompactionRequest for contract parity.

Line 940 currently permits empty input when PreviousResponseID is set, which makes the Go API behavior diverge from the compaction endpoint contract.

🛠️ Suggested fix
-	if len(req.Input) == 0 && req.PreviousResponseID == nil && !isLargePayloadPassthrough(ctx) {
+	if len(req.Input) == 0 && !isLargePayloadPassthrough(ctx) {
 		return nil, &schemas.BifrostError{
 			IsBifrostError: false,
 			Error: &schemas.ErrorField{
 				Message: "input not provided for compaction request",
 			},

Based on learnings, the compaction endpoint intentionally requires input to be present and returns an error when it is absent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@core/bifrost.go` around lines 940 - 952, The compaction handler currently
allows empty req.Input when req.PreviousResponseID is set, diverging from the
compaction endpoint contract; change the validation in the compaction request
path so that if req.Input is empty (len(req.Input) == 0) it always returns the
schemas.BifrostError (same structure shown) regardless of req.PreviousResponseID
or isLargePayloadPassthrough(ctx); locate the check around the compaction
request handling (references: req.Input, req.PreviousResponseID,
isLargePayloadPassthrough(ctx), schemas.BifrostError, RequestType:
schemas.CompactionRequest) and remove the conditional exemption that permits
empty input when PreviousResponseID is present so the error is consistently
returned.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@core/providers/openai/responses.go`:
- Around line 485-494: The returned BifrostCompactionRequest from
(*OpenAICompactionRequest).ToBifrostCompactionRequest is missing the ExtraParams
field, so inbound req.ExtraParams are discarded; update
ToBifrostCompactionRequest to set ExtraParams: r.ExtraParams on the returned
schemas.BifrostCompactionRequest (referencing the ToBifrostCompactionRequest
method and schemas.BifrostCompactionRequest/ExtraParams field) so the map is
preserved when converting.

---

Duplicate comments:
In `@core/bifrost.go`:
- Around line 940-952: The compaction handler currently allows empty req.Input
when req.PreviousResponseID is set, diverging from the compaction endpoint
contract; change the validation in the compaction request path so that if
req.Input is empty (len(req.Input) == 0) it always returns the
schemas.BifrostError (same structure shown) regardless of req.PreviousResponseID
or isLargePayloadPassthrough(ctx); locate the check around the compaction
request handling (references: req.Input, req.PreviousResponseID,
isLargePayloadPassthrough(ctx), schemas.BifrostError, RequestType:
schemas.CompactionRequest) and remove the conditional exemption that permits
empty input when PreviousResponseID is present so the error is consistently
returned.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 8ad75d80-6b7f-4c06-94a4-c9e1e23527ff

📥 Commits

Reviewing files that changed from the base of the PR and between e20e7d2 and 54f6513.

📒 Files selected for processing (44)
  • core/bifrost.go
  • core/internal/llmtests/account.go
  • core/internal/llmtests/compaction.go
  • core/internal/llmtests/tests.go
  • core/providers/anthropic/anthropic.go
  • core/providers/azure/azure.go
  • core/providers/azure/azure_test.go
  • core/providers/bedrock/bedrock.go
  • core/providers/cerebras/cerebras.go
  • core/providers/cohere/cohere.go
  • core/providers/elevenlabs/elevenlabs.go
  • core/providers/fireworks/fireworks.go
  • core/providers/gemini/gemini.go
  • core/providers/groq/groq.go
  • core/providers/huggingface/huggingface.go
  • core/providers/mistral/mistral.go
  • core/providers/nebius/nebius.go
  • core/providers/ollama/ollama.go
  • core/providers/openai/openai.go
  • core/providers/openai/openai_test.go
  • core/providers/openai/responses.go
  • core/providers/openrouter/openrouter.go
  • core/providers/parasail/parasail.go
  • core/providers/perplexity/perplexity.go
  • core/providers/replicate/replicate.go
  • core/providers/runway/runway.go
  • core/providers/sgl/sgl.go
  • core/providers/vertex/vertex.go
  • core/providers/vllm/vllm.go
  • core/providers/xai/xai.go
  • core/providers/xai/xai_test.go
  • core/schemas/bifrost.go
  • core/schemas/provider.go
  • core/schemas/responses.go
  • framework/modelcatalog/pricing.go
  • framework/modelcatalog/utils.go
  • plugins/logging/operations.go
  • plugins/logging/utils.go
  • transports/bifrost-http/handlers/inference.go
  • transports/bifrost-http/integrations/openai.go
  • transports/bifrost-http/integrations/router.go
  • transports/config.schema.json
  • ui/app/workspace/logs/sheets/logDetailView.tsx
  • ui/lib/constants/logs.ts

Comment thread core/providers/openai/responses.go
@TejasGhatte
TejasGhatte force-pushed the 06-04-feat_openai_compaction_support branch 2 times, most recently from bb9a927 to 01b9003 Compare June 5, 2026 10:39
@TejasGhatte TejasGhatte mentioned this pull request Jun 5, 2026
18 tasks
@TejasGhatte
TejasGhatte force-pushed the 06-04-feat_openai_compaction_support branch from 01b9003 to c6586a0 Compare June 5, 2026 11:05

Pratham-Mishra04 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Merge activity

  • Jun 5, 1:36 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 5, 1:37 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 5, 1:39 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 5, 1:39 PM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_openai_compaction_support branch from c6586a0 to 21d3113 Compare June 5, 2026 13:36
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-04-feat_openai_compaction_support branch from 21d3113 to b4b1697 Compare June 5, 2026 13:38
@Pratham-Mishra04
Pratham-Mishra04 merged commit 351bbb7 into dev Jun 5, 2026
14 of 16 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 06-04-feat_openai_compaction_support branch June 5, 2026 13:39
@akshaydeo akshaydeo mentioned this pull request Jun 5, 2026
18 tasks
akshaydeo added a commit that referenced this pull request Jun 6, 2026
## Summary

This PR bumps the Go toolchain version from `1.26.3` to `1.26.4` across all modules and CI workflows, and cuts a new release (`core` v1.5.17, `framework` v1.3.17, `transports` v1.5.9, `plugins/compat` v0.1.16, `plugins/governance` v1.5.17, and associated plugin versions) incorporating a large batch of features and fixes accumulated since the previous release.

## Changes

- **Go 1.26.4** — Updated `go-version` in all GitHub Actions workflows (`e2e-tests`, `helm-release`, `pr-tests`, `release-cli`, `release-pipeline`, `snyk`) and all `go.mod` files (core, framework, transports, cli, all plugins, examples, and test modules).
- **Core (v1.5.17)** — OpenAI compaction support, multi-customer logs and usage tracking, multiple team/business unit support, `request_headers` wildcard pattern capture for OTel and Maxim plugins, xAI `x_search` tool, fetch URL validation with SSRF hardening, `file://` pricing URL scheme, virtual key provider fan-out filtering, and a broad set of fixes including Anthropic prompt cache key, empty thinking block stripping, OpenAI stream usage event cleanup, Gemini numeric schema constraints, stale connection retries, Azure Claude diagnostic strip, and passthrough budget handling.
- **Framework (v1.3.17)** — Scope-aware budgets and limits wired from model configs, provider-level governance, multiple customer budget support with `calendar_aligned` windows, paginated virtual key fetch, `config.json` source-of-truth flow, FTS index cap reduction, sync worker drift fix, cascade deletes for model configs, and high-scale virtual key flow improvements.
- **Transports (v1.5.9)** — Full changelog covering all of the above plus UI improvements (log navigation, customer detail sheet, `BudgetDisplay` component, inline loading shell, materialized view alias), SCIM provisioning fields, Helm/config schema additions (`roles`, `per_user_oauth`), client IP resolution from forwarded headers, and dependency upgrades (`recharts` to 3.8.1, `golang.org/x` CVE remediation).
- **Plugins** — `governance` v1.5.17 adds team budget/rate-limit exporters, ghost node reconciliation fix, and VK double usage counting fix; `logging` v1.5.17 adds wildcard header capture and file attachment rendering; `otel` v1.2.17 adds `disable_content_logging` and multiple collectors support; `maxim` v1.6.17 adds `request_headers` wildcard capture; `compat` v0.1.16 fixes `max_tokens` preservation during param filtering.

## Type of change

- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [ ] Documentation
- [x] Chore/CI

## Affected areas

- [x] Core (Go)
- [x] Transports (HTTP)
- [x] Providers/Integrations
- [x] Plugins
- [x] UI (React)
- [ ] Docs

## How to test

```sh
# Verify Go version
go version  # should report go1.26.4

# Run core tests
cd core && go test ./...

# Run framework tests
cd framework && go test ./...

# Run transports tests
cd transports && go test ./...

# Run plugin tests
cd plugins/governance && go test ./...
cd plugins/logging && go test ./...
cd plugins/otel && go test ./...

# UI
cd ui
pnpm i
pnpm build
pnpm test
```

## Breaking changes

- [ ] Yes
- [x] No

## Related issues

#4053, #4066, #4041, #4012, #3976, #3947, #3991, #4045, #3957, #3938, #3937, #3939, #3981, #3998, #3997, #4092, #4091, #4079, #4080, #4086, #3929, #3994, #4028, #3970, #3919, #3861, #3664, #3999, #4088, #4070, #4051, #4043, #4057, #4023, #3941, #3955, #4024, #3956, #3967, #3925, #3992, #3900

## Security considerations

- Fetch URL validation hardened against SSRF by tightening IP checks for private networks and link-local addresses (#4092, #3947, #3991).
- Transitive `golang.org/x` dependencies (crypto, net, sys, text) bumped to address Docker Scout CVEs (#3900).

## Checklist

- [x] I read `docs/contributing/README.md` and followed the guidelines
- [x] I added/updated tests where appropriate
- [x] I updated documentation where needed
- [x] I verified builds succeed (Go and UI)
- [x] I verified the CI pipeline passes locally if applicable

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * OpenAI compaction, multi-customer/team logstore support, request-header wildcard capture, enhanced governance (provider-level & scope-aware limits), disable-content-logging option, support for multiple OpenTelemetry collectors, SSRF hardening and URL validation.

* **Chores**
  * Bumped Go toolchain across modules and updated component/plugin version releases.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@akshaydeo akshaydeo mentioned this pull request Jun 7, 2026
akshaydeo pushed a commit that referenced this pull request Jun 7, 2026
## Summary

Adds support for OpenAI's context compaction endpoint (`POST /v1/responses/compact`), which compacts a conversation context window to reduce token usage. All other providers return an unsupported-operation error for this request type.

## Changes

- Introduced `CompactionRequest` as a new `RequestType` constant and added `BifrostCompactionRequest` / `BifrostCompactionResponse` schema types as a strict subset of the responses API (no tools, sampling params, or streaming).
- Added `Compaction` to the `Provider` interface and implemented it for OpenAI via `HandleOpenAICompactionRequest`, routing to `/v1/responses/compact`. All other providers return `NewUnsupportedOperationError`.
- Wired `CompactionRequest` through `BifrostRequest` / `BifrostResponse` field accessors (`GetRequestFields`, `SetProvider`, `SetModel`, `SetFallbacks`, `SetRawRequestBody`, `GetExtraFields`, `PopulateExtraFields`) and through the fallback preparation and request dispatch logic in `bifrost.go`.
- Registered `POST /v1/responses/compact` in the HTTP transport with a dedicated `compaction` handler, `CompactionHTTPRequest` type, and `compactionParamsKnownFields` validation map.
- Added `CompactionResponseConverter` to `RouteConfig` and handled `CompactionRequest` in the generic router's non-streaming dispatch path.
- Added the OpenAI integration route config for `/v1/responses/compact` (and aliased paths), including `OpenAICompactionRequest` wire type with `ToOpenAICompactionRequest` / `ToBifrostCompactionRequest` converters.
- Extended model catalog pricing to treat `CompactionRequest` the same as `ResponsesRequest` for cost computation, usage extraction, and fallback pricing lookups, normalizing it to the `"responses"` base type.
- Extended the logging plugin to extract usage and output from `CompactionResponse` when building log entries.
- Added `"compaction"` to the UI request type list, labels, and color map (indigo), and updated the log detail view to recognize `"compaction"` as a responses-family object for copy-request-body support.

## Type of change

- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [x] Transports (HTTP)
- [x] Providers/Integrations
- [x] Plugins
- [x] UI (React)
- [ ] Docs

## How to test

```sh
# Core/Transports
go test ./...

# Send a compaction request via the HTTP transport
curl -X POST http://localhost:8080/v1/responses/compact \
  -H "Content-Type: application/json" \
  -d '{
    "model": "openai/gpt-4o",
    "input": [
      {"role": "user", "content": "Hello, summarize this conversation."}
    ]
  }'
# Expected: 200 with a BifrostCompactionResponse (object: "response.compaction")

# Verify unsupported providers return an error
curl -X POST http://localhost:8080/v1/responses/compact \
  -H "Content-Type: application/json" \
  -d '{"model": "anthropic/claude-opus-4-5", "input": []}'
# Expected: error indicating unsupported operation for the Anthropic provider

# UI
cd ui
pnpm i
pnpm build
```

## Breaking changes

- [x] Yes
- [ ] No

The `Provider` interface gains a new required method `Compaction`. Any custom provider implementations outside this repository must add a `Compaction` method returning `NewUnsupportedOperationError` (or a real implementation) to satisfy the interface.

## Related issues

## Security considerations

No new auth mechanisms are introduced. The compaction endpoint forwards the caller's API key as a Bearer token to OpenAI, consistent with all other provider requests. No PII handling changes.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Added a compaction operation with a public POST /v1/responses/compact endpoint; OpenAI and Azure compaction supported.

* **Integration**
  * Pricing, usage tracking, logging, routing, and passthrough flows updated to surface compaction results, provider headers, and latency/metadata.

* **UI**
  * Logs/UI now include a "Compaction" request type and copy/export behavior for compaction entries.

* **Tests**
  * New toggleable end-to-end compaction tests validating response contract and follow-up usability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
akshaydeo added a commit that referenced this pull request Jun 7, 2026
## ✨ Features

- **OpenAI Compaction** — Added OpenAI conversation compaction support
across core, framework, logging, and the API surface (#4053)
- **Multi-Customer & Org Hierarchy** — Logs and usage tracking now
support multiple customers, teams, and business units, including
business unit CRUD, team assignment, and governance endpoints in the
OpenAPI spec (#4066, #4041, #4082)
- **Provider-Level Governance** — Budgets & limits are now scope-aware
and can be applied at the virtual-key top level and per provider, wired
from the model configs table, with UI filters for scope and providers
(#3938, #3937, #3939, #3981, #3962)
- **Customer Budgets** — Customers support multiple budgets and
`calendar_aligned` budget windows (#3998, #3997)
- **Virtual Key Attribution & Controls** — Added a `created_by` user
attribution column and a `blacklisted_models` column for virtual key
provider configs (#3672, #3653)
- **Request Header Capture** — OTel and Maxim observability plugins
capture `request_headers` by pattern, with wildcard support (e.g.
`x-custom-*`); logging gained the same wildcard header capture (#4012,
#3958)
- **OTel Content Controls & Collectors** — New `disable_content_logging`
option drops message/tool content from exported spans, plus support for
multiple OTel collectors (#4064, #3894)
- **xAI x_search** — Added xAI `x_search` tool support (#3976)
- **URL Validation** — Added fetch URL validation with private-network
configuration and link-local blocking (#3947, #3991)
- **File Scheme Pricing URLs** — Pricing source URLs now accept the
`file://` scheme for air-gapped and self-hosted deployments (#4045)
- **Paginated Virtual Keys** — Virtual key fetching is paginated to
handle deployments with very large numbers of keys (#3957)
- **Client IP Resolution** — Resolve client IP from
`X-Forwarded-For`/`X-Real-IP` headers
- **SCIM Provisioning** — Added `attributeType`/`attributeValue` SCIM
provisioning fields
- **Helm/Config Schema** — Added `roles` RBAC governance config and
`per_user_oauth` MCP auth to the Helm chart and config schema (#4004,
#4009)
- **Log Navigation UI** — Added a "View logs" menu item to customer,
team, and virtual key tables, clickable links in log detail views, a
customer detail sheet, and a reusable `BudgetDisplay` component (#4073,
#4054, #4026, #4055)
- **Faster First Paint** — Added an inline loading shell to `#root`
before React mounts (#4063)
- **Materialized View Alias** — Added an `alias` column to the
materialized view with filter support (#4078)

## 🐞 Fixed

- **Fetch URL IP Checks** — Hardened fetch URL IP checks against SSRF
(#4092)
- **Mantle Model Matching** — Broadened Mantle model matching to all
`gpt` variants (#4091)
- **Empty Thinking Blocks** — Strip thinking blocks when the signature
is empty (#4079)
- **OpenAI Stream Usage** — Removed usage from the `responses.created`
event in the OpenAI stream (#4080)
- **Prompt Cache Key** — Set the prompt cache key from the Anthropic
integration (#4086)
- **Upstream Failure Status** — Map upstream connection failures to 502
instead of 400 (#3929) (thanks
[@chris-colinsky](https://github.com/chris-colinsky)!)
- **Gemini Schema Constraints** — Accept numeric schema integer
constraints for Gemini (#3994) (thanks
[@yanhao98](https://github.com/yanhao98)!)
- **Files Provider Param** — Accept the `?provider=` query param on `GET
/v1/files` (#3971) (thanks [@alexef](https://github.com/alexef)!)
- **Optional Batch Model** — Made the `model` field optional on `POST
/v1/batches` (#3973) (thanks [@alexef](https://github.com/alexef)!)
- **Helm Azure Config** — Added missing `azure_key_config` fields to the
Helm schema (#3996) (thanks
[@axelray-dev](https://github.com/axelray-dev)!)
- **Text Completion Chunk Model** — Added the missing `Model` field to
`TextCompletionChunkResponse` (#3970) (thanks
[@kuishou68](https://github.com/kuishou68)!)
- **MCP Inline stdio Env** — MCP stdio server configs accept inline
environment variable assignments (#3861) (thanks
[@Shushmitaaaa](https://github.com/Shushmitaaaa)!)
- **Orphaned Tool Results** — Orphaned tool results in the OpenAI to
Anthropic conversion flow are no longer rejected by the Anthropic API
(#3919)
- **Node Usage Reconciliation** — Added a monotonic `inc_number` log
cursor so node usage reconciliation does not skip late async log writes
(#3664)
- **Bedrock Output Assessments** — Corrected the type of
`outputAssessments` in Bedrock responses (#4028)
- **Model Pool Pricing Reloads** — Preserve non-pricing model pool
entries across pricing reloads (#3999)
- **Ghost Node Reconciliation** — Replicate the VK hierarchy flow for
ghost node reconciliation (#4088)
- **VK Double Usage Counting** — Fixed double usage counting when
creating a virtual key (#4070)
- **Model Config Lifecycle** — Cascade deletes for model configs and
removal of stale in-memory model configs (#4051, #4043)
- **FTS Index Cap** — Reduced the FTS index `left()` cap from 800k to
250k chars to stay within the tsvector limit (#4057)
- **Sync Worker Drift** — Reduced the sync worker ticker period to 5m to
prevent threshold drift (#4023)
- **Passthrough** — Fixed passthrough budgets, gated passthrough models
per VK, model extraction for Azure passthrough, and restricted
fallbacks/provider selection to the VK boundary (#3941, #3988, #3983,
#3924)
- **Provider Response Headers** — Strip provider response headers and
add a content-type filter (#3955, #4024)
- **Stream Handling** — Drain non-SSE stream readers and retry stale
connections (#3956, #3967)
- **Azure Claude** — Strip Azure diagnostic property for Claude models
(#3925)
- **Compat max_tokens** — Preserve chat `max_tokens` during param
filtering (#3992)
- **Raw Request Flag** — Removed the raw request flag from providers
that don't support it (#4058)
- **UI Fixes** — Standardized page container layout, virtual key model
configs UI, and dashboard chart tooltips (#4046, #4052, #4044)

## 🔧 Maintenance

- **Dependency Upgrades** — Bumped transitive `golang.org/x`
dependencies (crypto, net, sys, text) for Docker Scout CVE remediation
and `recharts` to 3.8.1; cascaded version bumps across all modules
(#3900, #4003)
@coderabbitai coderabbitai Bot mentioned this pull request Jun 7, 2026
11 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jun 15, 2026
18 tasks
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.

3 participants