Skip to content

Add maintenance health scores - #221

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
abhinavgautam01:feature/maintainer-risk-22
Jun 8, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
abhinavgautam01:feature/maintainer-risk-22

Conversation

@abhinavgautam01

Copy link
Copy Markdown
Contributor

Closes #22

Summary

  • Add git pkgs health to score dependency maintenance health
  • Use enrichment-backed package metadata for maintainer count and usage signals
  • Cache health metadata in the packages table with a 24h TTL
  • Support --threshold, --all, --ecosystem, --commit, --branch and --format=json
  • Document the new command and include pager flag coverage

Tests

  • go test ./cmd -run 'TestBuildHealthResult|TestFetchHealthPackageData|TestPagerFlagAccepted'
  • go test ./internal/database
  • go test ./...
  • git diff --check

@abhinavgautam01
abhinavgautam01 force-pushed the feature/maintainer-risk-22 branch from bd79675 to 0af096c Compare June 2, 2026 08:41

@andrew andrew 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.

A few things before this can land.

Schema collision with #215. This PR sets SchemaVersion = 12 and adds maintainer-related columns to packages. The maintainers PR (#215) also sets SchemaVersion = 12 and adds a maintainers JSON column. Whichever lands second will need to rebase, and the maintainer_count integer here duplicates info that #215's maintainers column already carries (it's len(JSON)).

Since #215 is older and farther along, please defer to it: drop the dedicated maintainer_count column from the health schema, and either read the count from #215's cached maintainers blob on cache hit or just compute len(pkg.Maintainers) from the BulkLookup result on miss. After #215 lands, rebase and bump SchemaVersion accordingly. The other health columns (downloads, downloads_period, dependent_packages_count, dependent_repos_count, health_synced_at) are fine to keep.

At-risk vs threshold split. --threshold controls what's displayed, but at_risk_dependencies is computed against a hardcoded score < 75. If I set --threshold=60 I'd expect "at risk" to mean "below 60". Either tie the count to --threshold or document in --help that the at-risk bucket is fixed and the threshold is just a display filter.

Score model is opaque. The penalties (30/25/10/5) are hardcoded in maintenanceHealthScore with no user-facing explanation. The README should at least sketch what lowers the score (no/single maintainer, low usage, missing download data) so the numbers aren't surprising.

@andrew

andrew commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #225 just landed and centralizes the user agent string into a package-level userAgent var in cmd/root.go. When you rebase, please change enrichment.WithUserAgent("git-pkgs/" + version) to enrichment.WithUserAgent(userAgent) so we keep the format in one place.

@abhinavgautam01
abhinavgautam01 force-pushed the feature/maintainer-risk-22 branch from 0af096c to 72c0b07 Compare June 3, 2026 14:28
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

A few things before this can land.

Schema collision with #215. This PR sets SchemaVersion = 12 and adds maintainer-related columns to packages. The maintainers PR (#215) also sets SchemaVersion = 12 and adds a maintainers JSON column. Whichever lands second will need to rebase, and the maintainer_count integer here duplicates info that #215's maintainers column already carries (it's len(JSON)).

Since #215 is older and farther along, please defer to it: drop the dedicated maintainer_count column from the health schema, and either read the count from #215's cached maintainers blob on cache hit or just compute len(pkg.Maintainers) from the BulkLookup result on miss. After #215 lands, rebase and bump SchemaVersion accordingly. The other health columns (downloads, downloads_period, dependent_packages_count, dependent_repos_count, health_synced_at) are fine to keep.

At-risk vs threshold split. --threshold controls what's displayed, but at_risk_dependencies is computed against a hardcoded score < 75. If I set --threshold=60 I'd expect "at risk" to mean "below 60". Either tie the count to --threshold or document in --help that the at-risk bucket is fixed and the threshold is just a display filter.

Score model is opaque. The penalties (30/25/10/5) are hardcoded in maintenanceHealthScore with no user-facing explanation. The README should at least sketch what lowers the score (no/single maintainer, low usage, missing download data) so the numbers aren't surprising.

fixed. i dropped the dedicated maintainer_count column from the health schema/cache path and removed it from the health save/query helpers. Maintainer count is now computed from PackageInfo.Maintainers when enrichment metadata is fetched, while the health cache keeps only the usage/download signals. i also tied at_risk_dependencies to the configured --threshold, updated the flag help, added a test for that behavior and expanded the README score explanation.

@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Heads-up: #225 just landed and centralizes the user agent string into a package-level userAgent var in cmd/root.go. When you rebase, please change enrichment.WithUserAgent("git-pkgs/" + version) to enrichment.WithUserAgent(userAgent) so we keep the format in one place.

Fixed after rebasing onto current main. health now uses enrichment.WithUserAgent(userAgent) instead of rebuilding the user-agent string locally.

@andrew andrew 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.

Threshold/scoring/userAgent fixes are right. Two issues to address before this can land:

Maintainer count missing on cache hit. healthDataFromCached populates downloads / dependent counts but leaves MaintainerCount at its zero value. The next call to maintenanceHealthScore then takes the case 0 branch (-30 and signals = ["no maintainer data"]), so every cached row scores 30 points lower than the same row would score on a cold cache. That defeats the cache. The earlier review asked you to either keep a maintainer count column or read it from #215's maintainers JSON blob on hit. Since #215 has just landed, the right move now is to read packages.maintainers alongside the health columns in GetCachedPackageHealth and set cached.MaintainerCount = len(parsedMaintainers). A regression test that runs the command twice (first cold, second cached) and asserts the scores match would also be welcome.

Rebase needed. #215 merged this morning and also bumps SchemaVersion to 12, adds the maintainers/maintainers_synced_at columns to packages, and expands the docs/internals.md cache paragraph. After rebasing:

  • bump SchemaVersion to 13
  • keep #215's new packages columns (this PR's CREATE TABLE additions go beside them)
  • in docs/internals.md, extend the now-expanded "funding / maintainers / deprecated" sentence to also mention health, instead of inserting in the middle
  • the README network-commands sentence will also need a 3-way merge to keep maintainers and add health

@abhinavgautam01
abhinavgautam01 force-pushed the feature/maintainer-risk-22 branch from 72c0b07 to 733af76 Compare June 5, 2026 16:19
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Threshold/scoring/userAgent fixes are right. Two issues to address before this can land:

Maintainer count missing on cache hit. healthDataFromCached populates downloads / dependent counts but leaves MaintainerCount at its zero value. The next call to maintenanceHealthScore then takes the case 0 branch (-30 and signals = ["no maintainer data"]), so every cached row scores 30 points lower than the same row would score on a cold cache. That defeats the cache. The earlier review asked you to either keep a maintainer count column or read it from #215's maintainers JSON blob on hit. Since #215 has just landed, the right move now is to read packages.maintainers alongside the health columns in GetCachedPackageHealth and set cached.MaintainerCount = len(parsedMaintainers). A regression test that runs the command twice (first cold, second cached) and asserts the scores match would also be welcome.

Rebase needed. #215 merged this morning and also bumps SchemaVersion to 12, adds the maintainers/maintainers_synced_at columns to packages, and expands the docs/internals.md cache paragraph. After rebasing:

  • bump SchemaVersion to 13
  • keep Add dependency maintainer data command #215's new packages columns (this PR's CREATE TABLE additions go beside them)
  • in docs/internals.md, extend the now-expanded "funding / maintainers / deprecated" sentence to also mention health, instead of inserting in the middle
  • the README network-commands sentence will also need a 3-way merge to keep maintainers and add health

Rebased onto main after #215. SchemaVersion is now 13 and the packages schema keeps the maintainers cache columns plus the health metadata columns.

GetCachedPackageHealth now selects packages.maintainers and derives MaintainerCount from the parsed maintainer JSON, so cache hits no longer score 30 points lower. Health lookups also save the maintainer list returned by enrichment into the existing maintainers cache and i added a regression test that runs cold then cached and asserts the maintainer count and score stay the same.

README and docs/internals.md were merged to keep maintainers and add health in the network/cache wording.

Verified with go test ./..., go tool golangci-lint run ./..., and git diff --check upstream/main..HEAD.

@abhinavgautam01
abhinavgautam01 requested a review from andrew June 5, 2026 16:21

@andrew andrew 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.

Cache/schema/docs fixes all look right; CI is green and the regression test is exactly the shape I asked for.

One small boundary inconsistency to fix before merge.

AtRiskDependencies and display use different thresholds. In buildHealthResult, at-risk is incremented for score < threshold while display continues only on score > threshold. So with --threshold=70, a dependency scoring exactly 70 appears in the list but isn't counted in the at-risk summary. The flag help says "at or below this threshold; at-risk count uses the same threshold", which reads as <= for both.

Tighten the at-risk check to score <= threshold (one-line change in cmd/health.go), and add a boundary case to TestBuildHealthResult — e.g. a dep with score equal to the threshold should be both displayed and counted as at-risk.

@abhinavgautam01
abhinavgautam01 force-pushed the feature/maintainer-risk-22 branch from 733af76 to 4bcee98 Compare June 6, 2026 10:36
@abhinavgautam01

Copy link
Copy Markdown
Contributor Author

Cache/schema/docs fixes all look right; CI is green and the regression test is exactly the shape I asked for.

One small boundary inconsistency to fix before merge.

AtRiskDependencies and display use different thresholds. In buildHealthResult, at-risk is incremented for score < threshold while display continues only on score > threshold. So with --threshold=70, a dependency scoring exactly 70 appears in the list but isn't counted in the at-risk summary. The flag help says "at or below this threshold; at-risk count uses the same threshold", which reads as <= for both.

Tighten the at-risk check to score <= threshold (one-line change in cmd/health.go), and add a boundary case to TestBuildHealthResult — e.g. a dep with score equal to the threshold should be both displayed and counted as at-risk.

fixed. AtRiskDependencies now uses the same inclusive threshold as display (score <= threshold), matching the flag help text.

i also added a boundary case to TestBuildHealthResult confirming a dependency scoring exactly at the threshold is both displayed and counted as at-risk.

Verified with go test ./cmd -run Health, go test ./..., go tool golangci-lint run ./..., and git diff --check.

@abhinavgautam01
abhinavgautam01 requested a review from andrew June 6, 2026 10:45

@andrew andrew 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.

Tested locally — build, full test suite, and smoke run on a fresh repo all good. Threshold filter and JSON output behave as documented.

@andrew
andrew merged commit c98db00 into git-pkgs:main Jun 8, 2026
4 checks passed
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.

Maintenance health scores

2 participants