Skip to content

fix: fix size not substract#627

Open
fatelei wants to merge 2 commits intolanggenius:mainfrom
fatelei:issue-355
Open

fix: fix size not substract#627
fatelei wants to merge 2 commits intolanggenius:mainfrom
fatelei:issue-355

Conversation

@fatelei
Copy link
Contributor

@fatelei fatelei commented Mar 8, 2026

Description

fix #355

Type of Change

  • Bug fix
  • New feature
  • Refactor
  • Performance improvement
  • Other

Essential Checklist

Testing

  • I have tested the changes locally and confirmed they work as expected
  • I have added unit tests where necessary and they pass successfully

Bug Fix (if applicable)

  • I have used GitHub syntax to close the related issue (e.g., Fixes #123 or Closes #123)

Additional Information

Please provide any additional context that would help reviewers understand the changes.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 8, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 critical bug in the persistence layer where the storage size was not being accurately managed when existing data was overwritten. The changes introduce a more robust mechanism to calculate size differences and apply them to the stored records, ensuring that storage limits are respected and the reported storage usage is always correct. This prevents potential data integrity issues and improves resource management.

Highlights

  • Corrected Storage Size Calculation on Overwrite: The Save function in the persistence layer now accurately calculates the change in data size (delta) when overwriting an existing entry. This ensures that the stored size for a tenant/plugin combination is correctly incremented or decremented, rather than always adding the new data's size.
  • Improved Storage Limit Enforcement: Storage limits are now properly enforced during data overwrites. The system checks if the new data size, considering the delta from the old data, would exceed the maximum allowed storage, preventing potential overflows.
  • Enhanced Test Coverage for Overwrite Scenarios: New unit tests have been added to validate the correct adjustment of storage counters and the enforcement of storage limits when data is overwritten, ensuring the reliability of the persistence mechanism.

🧠 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
  • internal/core/persistence/persistence.go
    • Imported the errors package for improved error handling.
    • Refactored the Save function to calculate the delta (new size minus old size) when data is overwritten.
    • Updated storage size updates to use db.Inc for positive deltas and db.Dec for negative deltas, ensuring accurate size tracking.
    • Modified the storage limit check to consider the delta when evaluating if an overwrite would exceed maxSize or c.maxStorageSize.
    • Adjusted error handling for cache deletion to use errors.Is(err, cache.ErrNotFound).
  • internal/core/persistence/persistence_test.go
    • Imported the models package.
    • Added TestPersistenceOverwriteAdjustsCounter to verify that overwriting data correctly updates the stored size.
    • Added TestPersistenceOverwriteLimitEnforcedByDelta to ensure that storage limits are enforced based on the size delta during overwrites.
Activity
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.

@dosubot dosubot bot added bug Something isn't working go Pull requests that update go code labels Mar 8, 2026
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 correctly fixes a bug where the storage size was not being properly adjusted when data was overwritten. The new logic correctly calculates the size difference and updates the total size accordingly, and the new tests are comprehensive. However, the implementation of the storage size accounting logic in the Save method is prone to race conditions and improper error handling. This could lead to incorrect storage accounting, potentially resulting in a Denial of Service for tenants due to over-counting or a bypass of storage limits due to under-counting. Additionally, errors from cache deletion are being suppressed, which can lead to persistent stale data in the cache and potential security issues. There is also an opportunity for code simplification. Addressing these concerns will significantly improve the robustness, security, and maintainability of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allocated size is greater than max storage size

1 participant