Skip to content

feat: Fix model attribution for prefix-stripped token usage callbacks#1491

Merged
MODSetter merged 6 commits into
MODSetter:devfrom
AnishSarkar22:feat/unified-model-connections
Jun 15, 2026
Merged

feat: Fix model attribution for prefix-stripped token usage callbacks#1491
MODSetter merged 6 commits into
MODSetter:devfrom
AnishSarkar22:feat/unified-model-connections

Conversation

@AnishSarkar22

@AnishSarkar22 AnishSarkar22 commented Jun 14, 2026

Copy link
Copy Markdown
Collaborator

Description

  • Reconciles LiteLLM callback model names with registered model metadata when provider prefixes are stripped.
  • Ensures token usage summaries preserve correct provider, display_name, model_id, and model_ref.
  • Fixes incorrect model labels/icons in the message info menu caused by bare model-name collisions.
  • Adds regression coverage for prefix-stripped model callbacks and exact metadata precedence.
  • Integrates chat model selection handling in Composer and related components so selecting a model returns focus to the main composer input.
  • Modified model selector chat models display logic.

Motivation and Context

FIX #

Screenshots

API Changes

  • This PR includes API changes

Change Type

  • Bug fix
  • New feature
  • Performance improvement
  • Refactoring
  • Documentation
  • Dependency/Build system
  • Breaking change
  • Other (specify):

Testing Performed

  • Tested locally
  • Manual/QA verification

Checklist

  • Follows project coding standards and conventions
  • Documentation updated as needed
  • Dependencies updated as needed
  • No lint/build errors or new warnings
  • All relevant tests are passing

High-level PR Summary

This PR fixes a model attribution bug where LiteLLM strips provider prefixes (e.g., azure/gpt-5.2-chat becomes gpt-5.2-chat) before invoking token tracking callbacks, causing incorrect model metadata to be displayed in the UI. The fix implements a dual-indexing system in TurnTokenAccumulator that reconciles both prefixed and bare model names with their metadata, preferring exact matches when available. Additionally, the PR improves UX by returning focus to the composer input after selecting a chat model and contains a minor metadata title change replacing en-dashes with hyphens.

⏱️ Estimated Review Time: 15-30 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_backend/app/services/token_tracking_service.py
2 surfsense_backend/tests/unit/services/test_token_quota_service_cost.py
3 surfsense_web/components/new-chat/model-selector.tsx
4 surfsense_web/components/new-chat/chat-header.tsx
5 surfsense_web/components/assistant-ui/thread.tsx
6 surfsense_web/app/layout.tsx
⚠️ Inconsistent Changes Detected
File Path Warning
surfsense_web/app/layout.tsx Changing en-dashes to hyphens in metadata titles appears unrelated to the model attribution fix described in the PR

Need help? Join our Discord

@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@AnishSarkar22 is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel.

A member of the Team first needs to authorize it.

@AnishSarkar22 AnishSarkar22 marked this pull request as ready for review June 14, 2026 07:12
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 76beaed3-b684-48d8-afce-2c21d0aead6f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@AnishSarkar22 AnishSarkar22 marked this pull request as draft June 14, 2026 17:11
@AnishSarkar22 AnishSarkar22 marked this pull request as ready for review June 14, 2026 17:39
@MODSetter MODSetter merged commit 69bdcf5 into MODSetter:dev Jun 15, 2026
9 of 11 checks passed
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