Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Aug 11, 2025

This PR fixes a UI crash that occurs when the ContextCondenseRow component receives null or undefined values for token counts.

Problem

The UI was crashing with the error: TypeError: Cannot read properties of null (reading 'toLocaleString') when prevContextTokens or newContextTokens were null/undefined.

Solution

  • Added null-safe operators (?.) for prevContextTokens, newContextTokens, and cost
  • Fallback to "0" for null/undefined token values
  • Added comprehensive test coverage for edge cases

Testing

  • Created new test file with 10 test cases covering all edge cases
  • All existing tests continue to pass
  • Verified the fix handles null, undefined, and mixed values gracefully

Fixes #6914


Important

Fixes UI crash in ContextCondenseRow by handling null/undefined token values with null-safe operators and fallback defaults, adding comprehensive test coverage.

  • Behavior:
    • Fixes UI crash in ContextCondenseRow by handling null/undefined prevContextTokens, newContextTokens, and cost.
    • Uses null-safe operators (?.) and defaults to "0" for null/undefined values.
  • Testing:
    • Adds ContextCondenseRow.spec.tsx with 10 test cases for edge cases.
    • Ensures all existing tests pass and verifies handling of null, undefined, and mixed values.

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

…ent UI crash

- Added null-safe operators for prevContextTokens, newContextTokens, and cost
- Fallback to "0" for null/undefined token values
- Added comprehensive test coverage for edge cases
- Fixes #6914
@roomote roomote bot requested review from cte, jr and mrubens as code owners August 11, 2025 02:34
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Aug 11, 2025
@roomote roomote bot mentioned this pull request Aug 11, 2025
Copy link
Contributor 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 a mirror - everything looks backwards but the bugs are still mine.

<span className="font-bold text-vscode-foreground">{t("chat:contextCondense.title")}</span>
<span className="text-vscode-descriptionForeground text-sm">
{prevContextTokens.toLocaleString()}{newContextTokens.toLocaleString()} {t("tokens")}
{prevContextTokens?.toLocaleString() ?? "0"}{newContextTokens?.toLocaleString() ?? "0"}{" "}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I notice there's a type mismatch here. The ContextCondense type from packages/types/src/message.ts defines these fields as required numbers, but we're now treating them as potentially null/undefined. Should we update the type definition to make these fields optional, or should we ensure the data provider always sends valid numbers?

</span>
<VSCodeBadge className={cost > 0 ? "opacity-100" : "opacity-0"}>${cost.toFixed(2)}</VSCodeBadge>
<VSCodeBadge className={cost > 0 ? "opacity-100" : "opacity-0"}>
${(cost ?? 0).toFixed(2)}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it intentional that when cost is null/undefined, we hide the badge (opacity-0) but still display "$0.00"? This seems correct for consistency, but just wanted to confirm this is the desired behavior.

// Should not show any error text when not provided
expect(queryByText(/Failed/)).not.toBeInTheDocument()
})
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great test coverage! Consider adding a test case for negative cost values to ensure we handle all edge cases properly. What should happen if cost is -1?

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Aug 11, 2025
@daniel-lxs
Copy link
Member

Duplicate of #6913

@daniel-lxs daniel-lxs marked this as a duplicate of #6913 Aug 13, 2025
@daniel-lxs daniel-lxs closed this Aug 13, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Aug 13, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Aug 13, 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 Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

UI crashed (v3.25.10)

4 participants