Skip to content

Commit 6fe9d59

Browse files
calvarezgclaude
andcommitted
triage: clamp neutralPct to 0 to honor the 0-100 contract (#3594141069)
Independent Math.round of positive and negative can push their sum over 100 (e.g. 50.5->51 and 49.5->50), making the neutral remainder negative and violating the OpenAPI 0-100 percentage contract. Clamp the remainder to 0. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent be73ee3 commit 6fe9d59

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/support/elements/definitions/sentiment-overview.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,11 @@ export function transformSentimentOverviewResponse(raw) {
194194
? Math.round((entry.positive / promptsWithSentiment) * 100) : 0;
195195
const negativePct = promptsWithSentiment > 0
196196
? Math.round((entry.negative / promptsWithSentiment) * 100) : 0;
197-
const neutralPct = promptsWithSentiment > 0 ? 100 - positivePct - negativePct : 0;
197+
// Clamp to 0: independent rounding of positive & negative can push their sum
198+
// over 100 (e.g. 50.5→51 and 49.5→50), which would make the remainder negative
199+
// and violate the schema's 0-100 contract. 0 is the correct floor for the UI.
200+
const neutralPct = promptsWithSentiment > 0
201+
? Math.max(0, 100 - positivePct - negativePct) : 0;
198202

199203
return {
200204
week,

0 commit comments

Comments
 (0)