-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: exclude batch echo rows from missing-cost filter, prevent recalculation billing them, and enforce model allowlist for inline batch requests #6522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Pratham-Mishra04
merged 1 commit into
dev
from
08-25-fix_block_models_on_model_level_budget_exceeds_for_batches
Aug 25, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package logstore | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/maximhq/bifrost/core/schemas" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // A /results call that did not settle the batch gets a log row carrying a read-only | ||
| // copy of the settled price and no cost of its own. That NULL cost is final — no | ||
| // recalculation will ever fill it — so the row must stay out of "show missing cost | ||
| // only", which it used to flood. | ||
| func TestMissingCostOnlyExcludesBatchEchoRows(t *testing.T) { | ||
| store := newTestSQLiteStore(t) | ||
| ctx := context.Background() | ||
| base := time.Date(2026, 3, 4, 5, 6, 0, 0, time.UTC) | ||
| settled := 1.25 | ||
|
|
||
| newBatchRow := func(id string, ts time.Time, cost *float64, echo bool) *Log { | ||
| entry := &Log{ | ||
| ID: id, | ||
| Timestamp: ts, | ||
| Object: string(schemas.BatchResultsRequest), | ||
| Provider: "anthropic", | ||
| Model: "claude-sonnet-4", | ||
| Status: "success", | ||
| Cost: cost, | ||
| BatchDebugParsed: &schemas.BifrostBatchDebug{ | ||
| BatchID: "batch_1", | ||
| Accounting: &schemas.BatchAccountingDebug{ | ||
| Echo: echo, | ||
| ModelBreakdowns: map[string]schemas.BatchModelBreakdown{ | ||
| "claude-sonnet-4": {Model: "claude-sonnet-4", RequestCount: 1}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| require.NoError(t, entry.SerializeFields()) | ||
| return entry | ||
| } | ||
|
|
||
| unpricedChat := &Log{ | ||
| ID: "chat-unpriced", | ||
| Timestamp: base, | ||
| Object: "chat.completion", | ||
| Provider: "anthropic", | ||
| Model: "claude-sonnet-4", | ||
| Status: "success", | ||
| } | ||
| // An aggregate row that failed to price is exactly what the filter is for. | ||
| unpricedAggregate := newBatchRow("batch-aggregate-unpriced", base.Add(time.Minute), nil, false) | ||
| pricedAggregate := newBatchRow("batch-aggregate-priced", base.Add(2*time.Minute), &settled, false) | ||
| echoRow := newBatchRow("batch-echo", base.Add(3*time.Minute), nil, true) | ||
|
|
||
| for _, entry := range []*Log{unpricedChat, unpricedAggregate, pricedAggregate, echoRow} { | ||
| require.NoError(t, store.Create(ctx, entry)) | ||
| } | ||
|
|
||
| result, err := store.SearchLogs(ctx, SearchFilters{MissingCostOnly: true}, PaginationOptions{ | ||
| Limit: 50, SortBy: "timestamp", Order: "asc", | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| got := make([]string, 0, len(result.Logs)) | ||
| for _, l := range result.Logs { | ||
| got = append(got, l.ID) | ||
| } | ||
| require.ElementsMatch(t, []string{"chat-unpriced", "batch-aggregate-unpriced"}, got, | ||
| "only rows a recalculation can actually resolve belong in the missing-cost scope") | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.