Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Jan 28, 2026

Follow-up to #11034

Fixes the percentage calculation in the collapsed task header to show the correct value.

Problem

The percentage in the header was showing 45% when it should show ~19%. For example, with:

  • 50.4k tokens used
  • 128k reserved for response
  • 400k context window

The old formula calculated: (tokensUsed + reservedForOutput) / contextWindow * 100 = (50.4k + 128k) / 400k * 100 = 44.6% (incorrect)

Solution

The new formula calculates: tokensUsed / (contextWindow - reservedForOutput) * 100 = 50.4k / (400k - 128k) * 100 = 18.5% (correct)

This represents the percentage of available input space that is currently used. The reserved output tokens should not be counted towards the used percentage since they are reserved for the model response.

Changes

  • Updated the percentage calculation in TaskHeader.tsx to use the correct formula
  • Added edge case handling for when available input space is 0 or negative
  • Added a test to document the expected behavior

Testing

  • All existing tests pass
  • Added new test case for percentage calculation logic

View task on Roo Code Cloud


Important

Fixes percentage calculation in TaskHeader.tsx to correctly compute available input space usage, with updated tests in TaskHeader.spec.tsx.

  • Behavior:
    • Fixes percentage calculation in TaskHeader.tsx to use tokensUsed / (contextWindow - reservedForOutput) * 100.
    • Handles edge cases where available input space is 0 or negative.
  • Testing:
    • Adds test cases in TaskHeader.spec.tsx for new percentage calculation logic.
    • Ensures tests cover edge cases and correct percentage display.
  • Misc:
    • Updates comments and documentation in TaskHeader.tsx to reflect new calculation logic.

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

The percentage in the collapsed task header was showing 45% when it
should show ~19%. This was because the formula incorrectly calculated:

  (tokensUsed + reservedForOutput) / contextWindow * 100

Instead of the correct formula:

  tokensUsed / (contextWindow - reservedForOutput) * 100

The correct formula shows the percentage of available input space
that is currently used. The reserved output tokens should not be
counted towards the used percentage since they are reserved for the
model response.

Example with 50.4k tokens, 128k reserved, 400k context window:
- Old (incorrect): (50.4k + 128k) / 400k = 44.6%
- New (correct): 50.4k / (400k - 128k) = 18.5%

Fixes EXT-675
@roomote
Copy link
Contributor Author

roomote bot commented Jan 28, 2026

Rooviewer Clock   See task on Roo Cloud

All issues have been resolved. The test now properly mocks useSelectedModel and getModelMaxOutputTokens with known values and verifies the rendered percentage matches the expected calculation.

  • Test does not verify percentage calculation - add assertions for the actual rendered percentage value
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph marked this pull request as ready for review January 28, 2026 19:48
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jan 28, 2026
@roomote
Copy link
Contributor Author

roomote bot commented Jan 28, 2026

Rooviewer Clock   See task on Roo Cloud

Review complete. The core formula fix is correct, but the test needs improvement.

  • Test does not verify percentage calculation - add assertions for the actual rendered percentage value

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@roomote
Copy link
Contributor Author

roomote bot commented Jan 28, 2026

Fixaroo Clock   See task on Roo Cloud

Fixed the test to properly verify percentage calculation by mocking useSelectedModel and getModelMaxOutputTokens with known values and asserting the rendered percentage. All local checks passed.

View commit | Revert commit

@hannesrudolph
Copy link
Collaborator

Tested it. Works

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 28, 2026
@mrubens mrubens merged commit 8640fd1 into main Jan 28, 2026
12 checks passed
@mrubens mrubens deleted the feature/EXT-675-fix-header-percentage-calculation branch January 28, 2026 20:29
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Jan 28, 2026
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Jan 28, 2026
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 size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants