Skip to content

Conversation

roomote[bot]
Copy link

@roomote roomote bot commented Aug 10, 2025

Summary

This PR fixes issue #6889 where the cost limit was not being properly reset when users clicked "Reset and Continue" after hitting the auto-approved cost limit.

Problem

When a user hit the cost limit and clicked "Reset and Continue", the cost would immediately trigger the limit again on the next API request because the total cost was still being calculated from all messages in the conversation history.

Solution

The fix tracks the message index at the time of cost reset and only calculates costs from messages after that reset point. This ensures that:

  • When users approve continuing after hitting the cost limit, only new costs are counted
  • Multiple resets are handled correctly
  • The behavior matches user expectations

Changes

  • Added costResetMessageIndex tracking in AutoApprovalHandler
  • Modified cost calculation to only include messages after the reset point
  • Updated the reset method to also reset the cost tracking index
  • Added comprehensive tests to verify the fix works correctly

Testing

  • ✅ All existing tests pass
  • ✅ Added new tests specifically for cost reset functionality
  • ✅ Verified multiple cost resets work correctly

Fixes #6889


Important

Fixes cost limit reset issue in AutoApprovalHandler by tracking message index at reset and updating cost calculations accordingly.

  • Behavior:
    • Fixes cost limit reset issue in AutoApprovalHandler by tracking lastResetMessageIndex.
    • Cost calculations now only include messages after the reset point.
    • Supports multiple resets and matches user expectations.
  • Implementation:
    • Adds lastResetMessageIndex to track message index at reset in AutoApprovalHandler.
    • Modifies checkRequestLimit() and checkCostLimit() to use messages after reset.
    • Updates resetRequestCount() to reset lastResetMessageIndex and cost tracking.
  • Testing:
    • Adds tests in AutoApprovalHandler.spec.ts for cost reset functionality.
    • Verifies correct behavior for multiple resets and floating-point precision handling.

This description was created by Ellipsis for 07283bf. You can customize this summary. It will automatically update as commits are pushed.

…ontinue"

- Track the message index at the time of cost reset
- Only calculate costs from messages after the reset point
- Prevents the issue where cost limit immediately triggers again after reset

Fixes #6889
@roomote roomote bot requested review from mrubens, cte and jr as code owners August 10, 2025 00:22
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Aug 10, 2025
Copy link
Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Reviewing my own code is like debugging in production - technically possible but morally questionable.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 10, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Aug 12, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Aug 12, 2025
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Aug 14, 2025
@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Needs Review] in Roo Code Roadmap Aug 14, 2025
@mrubens
Copy link
Collaborator

mrubens commented Aug 14, 2025

This logic feels a lot messier than it needs to be. It seems like we should use the same approach and methods for tracking number of requests and total cost.

…dler

- Use consistent message-based tracking for both request count and cost limit
- Track reset point using lastResetMessageIndex for both limits
- Calculate request count from API messages similar to cost calculation
- Simplify logic by removing separate tracking mechanisms
- Update tests to match new message-based counting approach

This addresses review feedback about inconsistent tracking approaches
between request counting and cost tracking.
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 14, 2025
@hannesrudolph
Copy link
Collaborator

@mrubens Can you please take a look?

@mrubens mrubens merged commit 38c8028 into main Oct 3, 2025
13 checks passed
@mrubens mrubens deleted the fix/cost-limit-reset-issue-6889 branch October 3, 2025 13:56
@github-project-automation github-project-automation bot moved this from PR [Needs Review] to Done in Roo Code Roadmap Oct 3, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lgtm This PR has been approved by a maintainer PR - Needs Review size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Cost Limit is not reset upon clicking cost "Reset and Continue"
4 participants