fix(billing): fix overage strategy lifecycle and settings integration#21236
Conversation
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 refines the billing experience by ensuring that the AI credit overage strategy correctly resets for each user turn when configured to 'ask', preventing unintended automatic credit usage. It also expands credit eligibility to include the Flash model and streamlines notifications by displaying the 'Using AI Credits' banner only once per turn. These changes collectively enhance the clarity and control users have over their AI credit consumption. Highlights
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 a bug where the billing overage strategy would permanently switch to 'always' for the session after a single use in 'ask' mode. The fix properly resets the strategy at the start of each user turn by storing and restoring the originally configured value. The implementation is robust and is well-covered by new unit tests that validate the reset logic.
Supporting changes further improve the billing functionality. The Flash model is now correctly included in the overage-eligible models list. The "Using AI Credits" notification has been refactored to prevent duplicates, showing only once per turn by centralizing its state in the Config object. Additionally, some unreachable code within the useQuotaAndFallback hook has been cleaned up, improving maintainability. Overall, these are high-quality changes that resolve the issue and enhance the codebase.
Emit coreEvents.emitFeedback in CodeAssistServer when credits are auto-attached to a request. Deduplicate by userPromptId so the banner appears exactly once per user turn, not on agent sub-calls. Remove the duplicate banner from creditsFlowHandler since the server now handles it for all cases.
6be1d36 to
42dda76
Compare
Reset billing.overageStrategy back to the configured value in resetTurn(), so 'ask' mode re-prompts the user on every turn instead of permanently becoming 'always' after first acceptance. Also removes dead initialOverageStrategy code from useQuotaAndFallback and adds unit tests covering the resetTurn billing behaviour.
42dda76 to
1e0f117
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively resolves several issues related to the AI credits billing feature. The changes correctly address the overage strategy lifecycle by resetting it on each new prompt and ensuring that live settings are used. The fix for forwarding billing settings from settings.json is also correctly implemented. The deduplication of the "Using AI Credits" banner and the addition of the Flash model to the allowlist are good enhancements. The new tests provide solid coverage for the updated logic. Overall, the changes are well-structured and improve the robustness and correctness of the billing functionality.
Note: Security Review did not run due to the size of the PR.
|
/patch preview |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
…#21236) # Conflicts: # packages/core/src/code_assist/server.ts
|
🚀 Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 Patch Release Started! 📋 Release Details:
⏳ Status: The patch release is now running. You'll receive another update when it completes. 🔗 Track Progress: |
|
/patch preview |
|
✅ Patch workflow(s) dispatched successfully! 📋 Details:
🔗 Track Progress: |
…#21236) # Conflicts: # packages/core/src/code_assist/server.ts
|
🚀 Patch PR Created! 📋 Patch Details:
📝 Next Steps:
🔗 Track Progress: |
|
🚀 Patch Release Started! 📋 Release Details:
⏳ Status: The patch release is now running. You'll receive another update when it completes. 🔗 Track Progress: |
|
✅ Patch Release Complete! 📦 Release Details:
🎉 Status: Your patch has been successfully released and published to npm! 📝 What's Available:
🔗 Links: |
Summary
Fixes three issues with the AI credits billing feature:
Overage strategy reset per turn: When
overageStrategyisask, accepting credits on one turn permanently mutated the strategy toalwaysfor the rest of the session. Now the strategy resets on each new user prompt.Billing settings not forwarded:
billing.overageStrategyfromsettings.jsonwas never passed to theConfigconstructor, so the setting had no effect. Fixed by passingsettings.billingthrough.In-process setting changes ignored:
configuredOverageStrategywas a stale snapshot from Config construction. Replaced with live settings read —resetBillingTurnState()now accepts the current value fromsettings.merged.billing.overageStrategy, so changes via/settingstake effect on the next prompt.Also includes two supporting commits: adding Flash model to the credits allowlist and deduplicating the "Using AI Credits" banner to show once per turn.
Changes
Commit 1: Add Flash model to credits allowlist
billing.ts— Addgemini-2.5-flashtoOVERAGE_ELIGIBLE_MODELSCommit 2: Deduplicate "Using AI Credits" banner
server.ts— Gate notification onConfig.creditsNotificationShownconfig.ts— AddcreditsNotificationShownflagcreditsFlowHandler.ts— Remove deadinitialOverageStrategylistener codeCommit 3: Fix overage strategy lifecycle
config.ts— Split billing resets fromresetTurn()intoresetBillingTurnState(overageStrategy?), removed staleconfiguredOverageStrategyfieldconfig.ts(CLI) — Passbilling: settings.billingto Config constructoruseGeminiStream.ts— Callconfig.resetBillingTurnState(settings.merged.billing?.overageStrategy)in the!isContinuationguard; fixed pre-existing unnecessaryconfigdep in useCallbackuseQuotaAndFallback.ts— Remove deadinitialOverageStrategycodeuseGeminiStream.test.tsx— AddresetBillingTurnStatemockconfig.test.ts— Tests forresetTurnnot resetting billing,resetBillingTurnStatewith/without argsHow to Validate
Integration testing instructions at go/gemini-cli-x-ai-credits-integration-testing
Pre-Merge Checklist
npm run preflightpasses