Skip to content

Commit 996a5cc

Browse files
kevin-dpclaude
andcommitted
fix(agents-server-ui): show "<1%" for tiny non-zero breakdown segments [review #4596]
A segment with a small but non-zero share rendered a coloured swatch + bar sliver labelled "0%", which reads as a contradiction. Label any non-zero segment that rounds to 0% as "<1%" instead. (Per-segment rounding can still make the four rows not sum to exactly 100% — acceptable for a composition popover; exact apportionment isn't worth the complexity here.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent cc7f8bf commit 996a5cc

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

packages/agents-server-ui/src/components/ContextUsageDetails.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ interface ContextUsageDetailsProps {
1414
modelId?: string
1515
}
1616

17+
/**
18+
* Percent label for a legend row. A non-zero segment that would round to `0%`
19+
* shows `<1%` instead, so a visibly-coloured swatch/bar isn't labelled "0%".
20+
*/
21+
function formatSegmentPercent(ratio: number): string {
22+
return ratio > 0 && Math.round(ratio * 100) === 0
23+
? `<1%`
24+
: formatContextUsagePercent(ratio)
25+
}
26+
1727
/**
1828
* The hover/click popover body for the context-usage indicator — a stacked
1929
* composition bar plus a legend of how each part of the prompt fills the
@@ -68,7 +78,7 @@ export function ContextUsageDetails({
6878
{formatTokenCount(seg.tokens)}
6979
</span>
7080
<span className={styles.legendPercent}>
71-
{formatContextUsagePercent(seg.ratio)}
81+
{formatSegmentPercent(seg.ratio)}
7282
</span>
7383
</li>
7484
))}

0 commit comments

Comments
 (0)