Skip to content

[fix] normalize candidate probability display in request timeline#1085

Merged
ding113 merged 1 commit into
devfrom
fix/priority-probability-timeline-20260423T081907Z
Apr 23, 2026
Merged

[fix] normalize candidate probability display in request timeline#1085
ding113 merged 1 commit into
devfrom
fix/priority-probability-timeline-20260423T081907Z

Conversation

@ding113

@ding113 ding113 commented Apr 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • fix request-details Technical Timeline candidate probabilities to use the shared percentage formatter instead of rendering raw 0..1 decimals
  • remove literal % suffixes from provider-chain candidate templates and let the formatter own percent output across locales
  • add regression coverage for formatter paths, real Technical Timeline rendering, and tooltip/popover message bundles

Root Cause

Technical Timeline candidate rows were passing raw c.probability values like 0.045454... into i18n templates that appended %, while the Decision Chain visualization already used formatProbability(...). That split formatting responsibility caused the details dialog timeline to show 0.045454...% instead of 4.5%.

Validation

  • bun run build
  • bun run typecheck
  • bunx @biomejs/biome@2.4.12 check . (passes with pre-existing repo warnings/infos only)
  • bunx vitest run src/lib/utils/provider-chain-formatter.test.ts src/app/[locale]/dashboard/logs/_components/error-details-dialog.test.tsx src/app/[locale]/dashboard/logs/_components/provider-chain-popover.test.tsx --reporter=dot
  • git diff --check

Notes

  • bun run test still hits a repo-level Vitest worker OOM near the end of the suite (523 passed / 2 skipped / 1 unhandled worker OOM in the conservative rerun). I did not see any assertion failures tied to this change.

Greptile Summary

This PR fixes a display bug where candidate probabilities in the Technical Timeline were showing raw 0.045454...% instead of formatted 4.5%. The fix pipes all probability values through the shared formatProbability() formatter before passing them to i18n templates, and removes the literal % suffix from the templates themselves. New candidateNoProbability/candidateInfoNoProbability template variants handle cases where probability is undefined, null, or NaN. Tests cover all three paths (timeline formatter, description formatter, real component rendering).

Confidence Score: 5/5

Safe to merge — targeted bug fix with no breaking changes and solid regression coverage.

The change is narrow and well-understood: raw probability values are now formatted before reaching i18n templates, the literal % is removed from templates, and fallback keys handle edge cases. Three test files cover the unit formatter, description formatter, and real component rendering. No P0/P1 issues found.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/utils/provider-chain-formatter.ts Core fix: adds formatDescriptionCandidate and formatTimelineCandidate helpers that call formatProbability() before passing values to i18n templates; also silently fixes a pre-existing 0
messages/en/provider-chain.json Removes literal % from candidate and candidateInfo templates; adds candidateNoProbability and candidateInfoNoProbability fallback templates. All 5 locales updated consistently.
src/lib/utils/provider-chain-formatter.test.ts Adds three new test cases covering formatted probability output, description formatting, and the invalid-probability (undefined/NaN) fallback to NoProbability templates.
src/app/[locale]/dashboard/logs/_components/error-details-dialog.test.tsx Upgrades the formatProviderTimeline mock to support opting into the real implementation; adds end-to-end test that verifies probability=4.5% and probability=45.5% appear in rendered HTML; replaces inline message stubs with the real locale JSON.
src/app/[locale]/dashboard/logs/_components/provider-chain-popover.test.tsx Replaces minimal inline message stub with the real providerChainMessages (spread + override), which caused the weighted_random -> Weighted Random assertion update.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Candidate probability raw 0..1] --> B{formatProbability}
    B -->|valid| C[Formatted string e.g. 4.5%]
    B -->|null or NaN or negative| D[null]

    C --> E[description.candidate with name and probability]
    C --> F[timeline.candidateInfo with name weight cost probability]

    D --> G[description.candidateNoProbability with name only]
    D --> H[timeline.candidateInfoNoProbability with name weight cost]
Loading

Reviews (1): Last reviewed commit: "fix: normalize candidate probability dis..." | Re-trigger Greptile

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9206dd0f-1574-4c52-989b-65c2fbb52b73

📥 Commits

Reviewing files that changed from the base of the PR and between 694eba6 and f7b3f28.

📒 Files selected for processing (9)
  • messages/en/provider-chain.json
  • messages/ja/provider-chain.json
  • messages/ru/provider-chain.json
  • messages/zh-CN/provider-chain.json
  • messages/zh-TW/provider-chain.json
  • src/app/[locale]/dashboard/logs/_components/error-details-dialog.test.tsx
  • src/app/[locale]/dashboard/logs/_components/provider-chain-popover.test.tsx
  • src/lib/utils/provider-chain-formatter.test.ts
  • src/lib/utils/provider-chain-formatter.ts

📝 Walkthrough

Walkthrough

跨多个语言的国际化消息文件进行了更新,移除了概率显示中的百分号,并添加了新的无概率消息变体。相应的格式化逻辑和测试也进行了调整,以支持有效和无效概率的条件渲染。

Changes

Cohort / File(s) Summary
国际化消息文件
messages/en/provider-chain.json, messages/ja/provider-chain.json, messages/ru/provider-chain.json, messages/zh-CN/provider-chain.json, messages/zh-TW/provider-chain.json
统一更新现有的 candidatecandidateInfo 消息模板,移除概率占位符后的百分号({probability}%{probability})。在所有语言版本中新增 candidateNoProbabilitycandidateInfoNoProbability 消息键,用于渲染不含概率信息的候选项。
核心格式化逻辑
src/lib/utils/provider-chain-formatter.ts
添加两个内部辅助函数(候选项描述和时间线格式化),实现概率感知的条件渲染:有效概率使用标准消息键,无效或缺失概率使用新增的 NoProbability 变体。
单元测试——格式化器
src/lib/utils/provider-chain-formatter.test.ts
扩展测试套件以验证概率百分比格式化和消息键选择逻辑,包括有效概率、缺失概率和无效概率(NaN)的场景。
集成测试——弹出框和对话框
src/app/[locale]/dashboard/logs/_components/provider-chain-popover.test.tsx, src/app/[locale]/dashboard/logs/_components/error-details-dialog.test.tsx
更新测试配置以从导入的 provider-chain.json 文件加载国际化内容,并调整断言以匹配新的本地化标签和格式化输出。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR标题准确总结了主要变更:修复请求时间线中的候选概率显示规范化,与changeset中关于概率格式化的所有更改直接相关。
Description check ✅ Passed PR描述详细说明了问题根源、解决方案和验证步骤,与changeset中的所有更改密切相关且信息充分。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/priority-probability-timeline-20260423T081907Z

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request improves the formatting of provider probabilities within the provider chain display by refactoring the formatting logic into dedicated helper functions and updating localization files. It introduces new translation keys to gracefully handle missing or invalid probability data, ensuring that UI elements like the technical timeline and descriptions do not display empty fragments or incorrect symbols. Additionally, the PR updates several test suites to verify these formatting improvements and adjusts some UI labels for better clarity. I have no feedback to provide.

@github-actions

Copy link
Copy Markdown
Contributor

🧪 测试结果

测试类型 状态
代码质量
单元测试
集成测试
API 测试

总体结果: ✅ 所有测试通过

@ding113
ding113 merged commit 88083ce into dev Apr 23, 2026
16 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Claude Code Hub Roadmap Apr 23, 2026
@github-actions github-actions Bot added the size/M Medium PR (< 500 lines) label Apr 23, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Summary

This PR successfully fixes a probability display bug in the Technical Timeline and Decision Chain visualization. The changes centralize probability formatting through the shared formatProbability() utility, ensuring consistent percentage display across all locales.

PR Size: M

  • Lines changed: 329 (277 additions, 52 deletions)
  • Files changed: 9

Issues Found

Category Critical High Medium Low
Logic/Bugs 0 0 0 0
Security 0 0 0 0
Error Handling 0 0 0 0
Types 0 0 0 0
Comments/Docs 0 0 0 0
Tests 0 0 0 0
Simplification 0 0 0 0

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate (3 new test cases covering formatter paths, real component rendering, and edge cases)
  • Code clarity - Good

Key Changes Verified

  1. Core Fix (src/lib/utils/provider-chain-formatter.ts:50-85): Added formatDescriptionCandidate() and formatTimelineCandidate() helpers that pipe probability values through formatProbability() before passing to i18n templates.

  2. i18n Templates (all 5 locales): Removed literal % suffix from description.candidate and timeline.candidateInfo templates; added candidateNoProbability and candidateInfoNoProbability variants for undefined/null/NaN cases.

  3. Test Coverage:

    • Unit tests for formatted probability output (4.5% instead of 0.045...)
    • Description formatting with real message bundles
    • Edge case handling for invalid probabilities (undefined, NaN)
    • Component-level integration test in error-details-dialog

The fix correctly addresses the root cause where raw probability values (0..1 decimals) were being passed to templates that appended %, resulting in incorrect display like 0.045454...% instead of 4.5%.


Automated review by Claude AI

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Summary

No significant issues identified in this PR.

PR Size: M

  • Lines changed: 329
  • Files changed: 9

Review Coverage

  • Logic and correctness - Clean
  • Security (OWASP Top 10) - Clean
  • Error handling - Clean
  • Type safety - Clean
  • Documentation accuracy - Clean
  • Test coverage - Adequate
  • Code clarity - Good

Automated review by Codex AI

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • Identified PR #1085 and pulled metadata, changed files, and full diff.
  • Computed PR size as M (277 additions + 52 deletions = 329 lines; 9 files) and applied label size/M.
  • Completed diff-scoped 6-perspective review + validation; no issues met the >=80 confidence threshold for reporting.
  • Submitted the required PR review summary via gh pr review --comment.

@ding113
ding113 deleted the fix/priority-probability-timeline-20260423T081907Z branch May 13, 2026 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Decision Chain area:provider bug Something isn't working size/M Medium PR (< 500 lines)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant