Fix duplicate context window suffix in model display#29
Conversation
Claude Code includes "(1M context)" in display_name, causing renderModel to produce "Opus 4.6 (1M context) (1M)". Strip the trailing context suffix before appending our own indicator. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a display bug where model names in the status line showed a duplicated context window suffix. By introducing a new utility function to strip pre-existing context information from the model's display name, the system now correctly formats and presents model names with a single, consistent context window indicator, improving user interface clarity. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses the issue of duplicate context window suffixes in the model display name by introducing a trimContextSuffix function. The overall approach is sound, and the addition of unit tests is appreciated. However, I've identified a potential issue in the implementation of trimContextSuffix where it might be too aggressive and incorrectly trim model names that don't actually have the context window suffix. I've provided a suggestion to make the logic more robust.
| func trimContextSuffix(name string) string { | ||
| // Match patterns like " (1M context)", " (200k context)" | ||
| if idx := strings.LastIndex(name, " ("); idx >= 0 { | ||
| tail := name[idx:] | ||
| if strings.HasSuffix(tail, " context)") { | ||
| return name[:idx] | ||
| } | ||
| } | ||
| return name |
There was a problem hiding this comment.
The current logic for trimming the suffix is a bit too broad and could incorrectly trim valid model names like "My Model (for some context)". By also checking that the suffix contains a digit, we can make this more robust and prevent most false positives.
For even greater robustness, you could consider using a regular expression to precisely match the expected format like (1M context). You could also enhance the test suite with a case like {"My Model (for some context)", "My Model (for some context)"} to cover this scenario.
| func trimContextSuffix(name string) string { | |
| // Match patterns like " (1M context)", " (200k context)" | |
| if idx := strings.LastIndex(name, " ("); idx >= 0 { | |
| tail := name[idx:] | |
| if strings.HasSuffix(tail, " context)") { | |
| return name[:idx] | |
| } | |
| } | |
| return name | |
| func trimContextSuffix(name string) string { | |
| // Match patterns like " (1M context)", " (200k context)" | |
| if idx := strings.LastIndex(name, " ("); idx >= 0 { | |
| tail := name[idx:] | |
| // To avoid false positives, also check that the suffix contains a digit. | |
| if strings.HasSuffix(tail, " context)") && strings.ContainsAny(tail, "0123456789") { | |
| return name[:idx] | |
| } | |
| } | |
| return name | |
| } |
There was a problem hiding this comment.
Fixed in 47aaa86. Added digit check to trimContextSuffix and a test case for the false-positive scenario.
Add digit check to trimContextSuffix to avoid false positives on names like "My Model (for some context)". Add test case for it. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
"(1M context)"in the modeldisplay_namefield (e.g."Opus 4.6 (1M context)")renderModel()was appending its own"(1M)"suffix, producing"Opus 4.6 (1M context) (1M)"trimContextSuffix()to strip the trailing" (Xk/M context)"before appending our own indicatorTest plan
TestTrimContextSuffix— covers various display name formats including names with existing parensTestRenderModel_TrimsContextSuffixFromDisplayName— end-to-end check that duplication is gone🤖 Generated with Claude Code