Skip to content

fix(comparison): use strict score comparisons for insights ties - #1

Closed
Beehtrix wants to merge 1 commit into
mainfrom
cursor/insights-tie-handling-1798
Closed

Beehtrix wants to merge 1 commit into
mainfrom
cursor/insights-tie-handling-1798

Conversation

@Beehtrix

@Beehtrix Beehtrix commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

InsightsList used >= when picking category leaders, so User 1 was always credited on ties. Leaders are now chosen with strict >; tied metrics show the existing equal notes and do not award strengths or improvement recommendations.

Changes

  • Add pickScoreLeader helper that returns null on equal scores
  • Award strengths only when a developer strictly leads a category
  • Show insights.equal.* / banner.tie copy for tied metrics and final scores
  • Skip category recommendations when scores are tied
  • Add insights-list.test.tsx coverage for ties and strict leads

Testing

  • pnpm exec vitest run src/features/comparison/tests/insights-list.test.tsx

Fixes O2sa#268


Summary by cubic

Fixes tie handling in the insights comparison so User 1 is no longer always credited as the leader when scores are equal. Category leaders are now chosen with strict > comparisons, and tied metrics display the existing equal notes without awarding strengths or improvement recommendations.

  • Adds pickScoreLeader, which returns null when scores are tied.
  • Awards strengths and recommendations only when a developer strictly leads a category.
  • Shows tie copy for the summary, key differences, and final scores when applicable.
  • Adds insights-list.test.tsx coverage for tied scores and strict category leads.

Written for commit 05eeaf2. Summary will update on new commits.

View guided diff Turn on auto-fix

Confidence Score: 5/5RetriggerView in Greptile

The PR appears safe to merge.

Summary

InsightsList now treats equal scores as ties instead of crediting the first developer.

  • Comparison insights report ties when developers have equal scores.

No actionable issues found. Tests were not run because dependencies are not installed.

Reviews (1) · Last reviewed commit: "fix(comparison): use strict score compar..." · Reviewed by Greptile

Award category strengths and recommendations only when one developer
strictly leads; show equal/tie notes when metrics match.

Fixes O2sa#268
Copilot AI lite review requested due to automatic review settings December 2, 2026 00:35
@sourcery-ai

sourcery-ai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Sorry @Beehtrix, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 hours and 54 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-12-02T00:35:32.971518Z
We couldn’t complete this review. Comment @codex review to try again.
05eeaf2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: cfa60d66-97fc-414d-bd33-5e40cee9962d
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@greptile-apps

greptile-apps Bot commented Dec 2, 2026

Copy link
Copy Markdown

security Security Review

This PR appears safe to merge from a security standpoint.

What was checked
  • The diff only changes score-comparison display logic in a React component and adds tests; it touches no authentication, authorization, API, or data-access code.
  • GitHub-sourced display names are rendered only as escaped JSX text, and the i18n t function does plain string interpolation with no HTML sink, so profile names cannot inject markup.
  • No secrets, credentials, or sensitive data are added, logged, or exposed by the change.
  • The automated scan flagged nothing, and reviewing its output confirmed no leads to chase.

@mergestorm-vortex

mergestorm-vortex Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Repository overview

Vortex generated this as context for automated review — expand for the architecture summary and data-flow diagram.

Repository overview & data flow

Architecture

  • DevImpact is a single-package TypeScript application built on Next.js App Router, React, and Tailwind. src/app contains localized routes and thin API handlers; src/features organizes comparison, developer, leaderboard, and scoring domains. Shared infrastructure adapters and cross-cutting utilities live under src/lib.
  • Feature services are used by routes and feature UI. The shared scoring engine serves developer profiles, comparisons, and leaderboard calculation. src/components provides reusable UI, layout, and providers. English/Arabic translations live in src/locales; middleware uses cookie/browser language to resolve locale paths.

Key modules and data flow

  • Profiles and comparison: /api/compare accepts two usernames and optional language filters, then calls comparison services to fetch profile results and derive winner/insight data. The developer profile service first checks Redis profile cache, then fresh canonical profile scores in PostgreSQL. On a miss it requests GitHub data, calculates scores, returns a profile and schedules persistence/cache warming.
  • GitHub and scoring: src/lib/github wraps GitHub GraphQL access and data normalization. src/features/scoring evaluates repository, external merged pull-request, and external issue/discussion metrics into raw and normalized scores; selected language filters can produce a separate language score.
  • Leaderboard: PostgreSQL stores user/profile scores in github_users and calculation state in leaderboard_calculation. The leaderboard read service queries PostgreSQL and optionally caches responses in Redis. A scheduled worker runs scripts/calculate-next-country.ts, claims a country, invokes the leaderboard calculation service to seed/refresh users, then records completion or failure. Web and worker processes share DB/cache configuration.

Conventions and operations

  • This is one pnpm application, not a multi-package workspace. Root scripts cover Next.js development/build, Vitest, lint/format, database initialization, locale validation, and manual leaderboard calculation. Tests are colocated in feature/lib directories and use Vitest.
  • ARCHITECTURE.md documents thin App Router controllers, feature-oriented ownership, shared infrastructure, server-side data access, and service-level testing. Feature modules keep domain UI/services/types together; generic UI and providers remain in src/components.
  • ops/ contains Docker configurations for web and worker, Compose definitions, Supercronic schedule, and deployment scripts. .env.example configures GitHub access, PostgreSQL, optional Redis, leaderboard limits, and worker scheduling.

Reviewer orientation

  • For profiles/comparison, trace API handlers into features/comparison or features/developer, then follow cache/database/GitHub access and scoring. For leaderboard display, follow leaderboard routes/services and DB reads; for refreshes, inspect the worker script and features/leaderboard/services/calculate-leaderboard.ts. Localization/presentation changes can touch src/app/[locale], feature UI, shared providers, and both locale dictionaries.

Data flow

flowchart TD
  Browser[Browser] --> Route[Localized route or profile API]
  Route --> Service[Profile and comparison services]
  Service --> Lookup{Redis or PostgreSQL profile available?}
  Lookup -->|yes| Result[Profile result]
  Lookup -->|no| GitHub[GitHub GraphQL]
  GitHub --> Scoring[Scoring engine]
  Scoring --> Result
  Result --> UI[Profile or comparison UI]
  Scoring --> Persist[Background cache and score persistence]
  Persist --> Lookup
Loading

Reviews (1): Last reviewed commit: "fix(comparison): use strict score comparisons for insights ties" · 05eeaf2 · Generated from main

@mergestorm-vortex mergestorm-vortex Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Vortex: 1 issue to fix at 05eeaf2 · 2/2 files reviewed

Actionable comment posted: 1

🤖 Prompt for AI agents (1 finding)
Pull request Beehtrix/DevImpact#1: https://github.com/Beehtrix/DevImpact/pull/1 (head branch `cursor/insights-tie-handling-1798`)

Verify each finding against current code. Fix only still-valid concrete bugs, skip the
rest with a brief reason, keep changes minimal, and validate. Skip Decision required,
policy forks, and "consider X" alternatives. Do not add new features, refactors, or
architecture beyond the fix; prefer the smallest diff.

To dispute, defer or ask about a finding, reply in that finding's review thread, or
mention @mergestorm-vortex in a pull request comment. A fix needs no reply: Vortex
reviews the next push.

Findings to address:
1. In `@src/features/comparison/components/insights-list.tsx` (line 42, Important):
   `pickScoreLeader` compares raw floats with `===`/`>`, but the UI shows `Math.round(score)`. Scores come from `score-engine.ts` unrounded (via `sanitizeNumber`), so e.g. repoScore 10.2 vs 10.4 yields a leader (Bob) and a `insights.recommendation.repo` for Alice, while the line reads "Bob 10 vs Alice 10". Similarly, finalScore 15.2 vs 15.4 renders `insights.summaryText` with `diff: 0` instead of the tie copy. Compare on the rounded values (or round the scores before comparing) so the displayed tie matches the logic.

Auto land this PR in Mergestorm


Mergestorm: 40 free reviews a month

return null;
}

return score1 > score2 ? user1 : user2;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 Important

pickScoreLeader compares raw floats with ===/>, but the UI shows Math.round(score). Score...

pickScoreLeader compares raw floats with ===/>, but the UI shows Math.round(score). Scores come from score-engine.ts unrounded (via sanitizeNumber), so e.g. repoScore 10.2 vs 10.4 yields a leader (Bob) and a insights.recommendation.repo for Alice, while the line reads "Bob 10 vs Alice 10". Similarly, finalScore 15.2 vs 15.4 renders insights.summaryText with diff: 0 instead of the tie copy. Compare on the rounded values (or round the scores before comparing) so the displayed tie matches the logic.

🤖 Prompt for AI agents
Pull request Beehtrix/DevImpact#1: https://github.com/Beehtrix/DevImpact/pull/1 (head branch `cursor/insights-tie-handling-1798`)

Verify each finding against current code. Fix only still-valid concrete bugs, skip the
rest with a brief reason, keep changes minimal, and validate. Skip Decision required,
policy forks, and "consider X" alternatives. Do not add new features, refactors, or
architecture beyond the fix; prefer the smallest diff.

To dispute, defer or ask about a finding, reply in that finding's review thread, or
mention @mergestorm-vortex in a pull request comment. A fix needs no reply: Vortex
reviews the next push.

In `@src/features/comparison/components/insights-list.tsx` (line 42, Important):
`pickScoreLeader` compares raw floats with `===`/`>`, but the UI shows `Math.round(score)`. Scores come from `score-engine.ts` unrounded (via `sanitizeNumber`), so e.g. repoScore 10.2 vs 10.4 yields a leader (Bob) and a `insights.recommendation.repo` for Alice, while the line reads "Bob 10 vs Alice 10". Similarly, finalScore 15.2 vs 15.4 renders `insights.summaryText` with `diff: 0` instead of the tie copy. Compare on the rounded values (or round the scores before comparing) so the displayed tie matches the logic.

@gitar-bot

gitar-bot Bot commented Dec 2, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@Beehtrix

Beehtrix commented Dec 2, 2026

Copy link
Copy Markdown
Owner Author

Closing this fork PR: the matching upstream PR is O2sa#288 (open). The branch is kept.

@Beehtrix Beehtrix closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: InsightsList incorrectly favors User 1 when metrics are tied

2 participants