Skip to content

fix: deterministic package repo tie-break#4263

Open
epipav wants to merge 3 commits into
mainfrom
fix/package-repo-tiebreak
Open

fix: deterministic package repo tie-break#4263
epipav wants to merge 3 commits into
mainfrom
fix/package-repo-tiebreak

Conversation

@epipav

@epipav epipav commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Note

Low Risk
Narrow query-ordering change; may shift which repo is shown when ties exist, but does not alter auth, writes, or broader business logic.

Overview
When a package maps to multiple repos with the same confidence, which repo wins was undefined, so scorecard-driven health, filters, and detail views could flip between runs.

Postgres (osspckgs/api.ts): Every lateral that picks one package_repos row for scorecard (status counts, package list, scatter) now sorts by confidence DESC then repo_id DESC. Package detail keeps its existing declared preference and adds repo_id DESC after that.

Tinybird (ossPackages_enriched.pipe): The per-package argMax(repoId, …) tie-break tuple now includes repoId after confidence and verifiedAt, matching the same deterministic rule for enriched health scores.

Reviewed by Cursor Bugbot for commit ecab2d3. Bugbot is set up for automated code reviews on this repo. Configure here.

Signed-off-by: anilb <epipav@gmail.com>
@epipav epipav requested review from Copilot and ulemons and removed request for Copilot June 25, 2026 08:19
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

Copilot AI review requested due to automatic review settings June 25, 2026 08:34

Copilot AI 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.

Pull request overview

This PR aims to make “winner repo” selection deterministic when a package maps to multiple repositories with tied confidence, so Postgres-derived API responses and Tinybird-enriched health/scorecard data don’t fluctuate run-to-run.

Changes:

  • Postgres: adds repo_id DESC as a deterministic tie-breaker to several LIMIT 1 repo-selection laterals in services/libs/data-access-layer/src/osspckgs/api.ts.
  • Tinybird: adds repoId as a final component in the argMax tuple for per-package repo selection in ossPackages_enriched.pipe.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
services/libs/data-access-layer/src/osspckgs/api.ts Adds deterministic ordering for selecting a single repo per package in multiple Postgres queries.
services/libs/tinybird/pipes/ossPackages_enriched.pipe Adds a final tie-break key to Tinybird argMax selection to make repo choice deterministic under ties.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

JOIN repos r ON r.id = pr.repo_id
WHERE pr.package_id = p.id
ORDER BY pr.confidence DESC
ORDER BY pr.confidence DESC, pr.repo_id DESC
JOIN repos r ON r.id = pr.repo_id
WHERE pr.package_id = p.id
ORDER BY pr.confidence DESC
ORDER BY pr.confidence DESC, pr.repo_id DESC
FROM package_repos pr2
WHERE pr2.package_id = p.id
ORDER BY pr2.confidence DESC, (pr2.source = 'declared') DESC
ORDER BY pr2.confidence DESC, (pr2.source = 'declared') DESC, pr2.repo_id DESC
JOIN repos r ON r.id = pr.repo_id
WHERE pr.package_id = p.id
ORDER BY pr.confidence DESC
ORDER BY pr.confidence DESC, pr.repo_id DESC
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.

4 participants