Skip to content

fix: save cache creation 5m/1h tokens and TTL to database, fix React …#310

Merged
ding113 merged 1 commit intodevfrom
fix/pricing-with-cache
Dec 10, 2025
Merged

fix: save cache creation 5m/1h tokens and TTL to database, fix React …#310
ding113 merged 1 commit intodevfrom
fix/pricing-with-cache

Conversation

@ding113
Copy link
Owner

@ding113 ding113 commented Dec 10, 2025

Summary

Fix missing cache token fields in database updates and React rendering bugs in billing tooltips.

Problem

After the differentiated cache billing feature was implemented (#277/#278), two bugs were discovered:

  1. Missing database fields: The updateMessageRequestDetails calls in handleNonStream and finalizeStream were not saving the new cache fields (cacheCreation5mInputTokens, cacheCreation1hInputTokens, cacheTtlApplied), causing cache token data to be lost.

  2. React short-circuit rendering bug: Conditional renders using x && x > 0 && <Component /> would render a literal 0 when x = 0 due to JavaScript's short-circuit evaluation behavior. This affected billing tooltips in the logs UI.

Related Issues:

Solution

Database Fix

Added the missing fields to updateMessageRequestDetails calls in both handleNonStream and finalizeStream functions:

  • cacheCreation5mInputTokens
  • cacheCreation1hInputTokens
  • cacheTtlApplied

React Rendering Fix

Changed conditional rendering pattern from:

{x && x > 0 && <Component />}

to:

{(x ?? 0) > 0 && <Component />}

This ensures 0 is never passed to the JSX expression, preventing the literal 0 from being rendered.

Changes

File Purpose
src/app/v1/_lib/proxy/response-handler.ts Add missing cache fields to database updates
src/app/[locale]/dashboard/logs/_components/error-details-dialog.tsx Fix conditional rendering for cache tokens
src/app/[locale]/dashboard/logs/_components/usage-logs-table.tsx Fix conditional rendering for cache tokens

Checklist

  • Code follows project conventions
  • Self-review completed
  • No breaking changes

Description enhanced by Claude AI

…rendering bug

- Add missing cacheCreation5mInputTokens, cacheCreation1hInputTokens, cacheTtlApplied
  fields to updateMessageRequestDetails calls in handleNonStream and finalizeStream
- Fix React short-circuit rendering bug where '0 && expr' renders literal '0'
  in error-details-dialog.tsx and usage-logs-table.tsx billing tooltips
- Change conditional renders from 'x && x > 0 &&' to '(x ?? 0) > 0 &&'
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ding113, 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 two distinct but important areas: enhancing data persistence for cache-related usage metrics and rectifying a user interface rendering anomaly. It ensures that comprehensive cache creation and TTL information is saved to the database, providing a more complete picture of system usage. Concurrently, it fixes a subtle React rendering issue that caused '0' to appear in billing tooltips when a numerical value was zero, improving the clarity and correctness of the displayed information.

Highlights

  • Cache Metrics Persistence: Added cacheCreation5mInputTokens, cacheCreation1hInputTokens, and cacheTtlApplied fields to the database update calls for message request details, ensuring these cache-related metrics are properly stored.
  • React Rendering Bug Fix: Resolved a React short-circuit rendering bug where a value of 0 would incorrectly render as the literal character '0' in billing tooltips within error-details-dialog.tsx and usage-logs-table.tsx.
  • Conditional Rendering Logic: Updated conditional rendering expressions from x && x > 0 && to (x ?? 0) > 0 && to correctly handle cases where x might be 0 or null/undefined without rendering '0'.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions bot added the bug Something isn't working label Dec 10, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces two main improvements. First, it correctly persists cache creation metrics (cacheCreation5mInputTokens, cacheCreation1hInputTokens, cacheTtlApplied) to the database by updating the updateMessageRequestDetails calls for both streaming and non-streaming responses in response-handler.ts. Second, it resolves a React rendering issue in error-details-dialog.tsx and usage-logs-table.tsx where a token count of zero would cause the number '0' to be displayed in the UI. The conditional rendering logic has been updated from x && x > 0 to (x ?? 0) > 0, which is a robust fix. The changes are well-executed and address the described issues effectively. The code quality is high, and I have no further suggestions.

@github-actions github-actions bot added the size/XS Extra Small PR (< 50 lines) label Dec 10, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

No significant issues identified in this PR. The changes correctly fix two distinct bugs:

  1. React short-circuit rendering bug: Changed x && x > 0 && to (x ?? 0) > 0 && in billing tooltips to prevent React from rendering the literal 0 when token counts are zero.

  2. Missing cache token fields: Added cacheCreation5mInputTokens, cacheCreation1hInputTokens, and cacheTtlApplied fields to database updates in handleNonStream and finalizeStream functions.

PR Size: XS

  • Lines changed: 50
  • Files changed: 3

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - N/A (UI rendering fix)
  • Code clarity - Good

Automated review by Claude AI

@ding113 ding113 merged commit 1ec0778 into dev Dec 10, 2025
7 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in Claude Code Hub Roadmap Dec 10, 2025
@ding113 ding113 deleted the fix/pricing-with-cache branch December 11, 2025 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size/XS Extra Small PR (< 50 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant

Comments