Skip to content

feat(scoring): model upstream review-collateral and non-code caps (Fi… - #1049

Merged
JSONbored merged 5 commits into
JSONbored:mainfrom
bohdansolovie:feat/809-review-collateral-noncode-cap
Jun 23, 2026
Merged

feat(scoring): model upstream review-collateral and non-code caps (Fi…#1049
JSONbored merged 5 commits into
JSONbored:mainfrom
bohdansolovie:feat/809-review-collateral-noncode-cap

Conversation

@bohdansolovie

Copy link
Copy Markdown
Contributor

Fixes #809

Summary

Pull three upstream scoring constants into the snapshot and apply them in preview math:

  • MAX_OPEN_PR_REVIEW_COLLATERAL_MULTIPLIER — scales open-PR collateral when reviews request changes
  • MAX_LINES_SCORED_FOR_NON_CODE_EXT — caps non-code token contribution when line count exceeds upstream limit
  • DEFAULT_ISSUE_DISCOVERY_SHARE — single source of truth for registry normalization defaults

Problem

Gittensory synced OPEN_PR_COLLATERAL_PERCENT but applied it as a flat fraction, ignoring upstream's review-collateral multiplier tied to CHANGES_REQUESTED count. Non-code tokens were counted at full weight with no line cap. Registry issue_discovery_share defaulted to a local 0.5 literal instead of the scoring constant.

Changes

  • src/scoring/model.ts — add constants + export DEFAULT_ISSUE_DISCOVERY_SHARE
  • src/scoring/preview.tsreviewCollateralMultiplier, effective collateralFraction, applyNonCodeLineCap(), nonCodeLines input
  • src/registry/normalize.ts — default issueDiscoveryShare from DEFAULT_ISSUE_DISCOVERY_SHARE
  • src/signals/local-branch.ts — pass nonCodeLines from diff stats
  • src/api/routes.ts, src/openapi/schemas.ts, apps/gittensory-ui/public/openapi.jsonnonCodeLines input + reviewCollateralMultiplier gate field

API / OpenAPI / MCP contract

  • Score preview input accepts optional nonCodeLines (≥ 0)
  • Score preview gates output includes reviewCollateralMultiplier (number)

Validation

npm run test:ci

@bohdansolovie
bohdansolovie requested a review from JSONbored as a code owner June 22, 2026 16:59
@dosubot dosubot Bot added the size:M label Jun 22, 2026
@ghost

ghost commented Jun 22, 2026

Copy link
Copy Markdown

Tip

🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩

✅ Gittensory review — safe to merge

9 files · 2 AI reviewers · no blockers · readiness 82/100 · CI green

✅ Approved — safe to merge

Review summary
The PR introduces three upstream scoring constants into the model, makes them available to the registry normalization, and updates the preview scoring logic to respect review-collateral multipliers and a line‑count cap for non‑code token scores. The new `DEFAULT_ISSUE_DISCOVERY_SHARE` constant is exported and used as the default for registry payloads. The preview flow now accepts a raw `nonCodeLines` count, applies a proportional cap via `applyNonCodeLineCap`, and returns both `reviewCollateralMultiplier` and the derived `collateralFraction` in the gates. API schemas, OpenAPI definitions, and route validation are extended accordingly, and tests are updated to verify the new behavior. All added fields are wired through the scoring pipeline, and the changes appear type‑safe and logically consistent with the upstream specifications.

Blockers

  • In `src/scoring/preview.ts`, the `applyNonCodeLineCap` function does not handle the case where `input.nonCodeLines` is `undefined` or `null`, which could lead to a runtime error. The function should include a check for `undefined` or `null` values for `input.nonCodeLines`.
  • In `src/scoring/preview.ts`, the `computeScoreCore` function does not handle the case where `input.nonCodeLines` is `undefined` or `null`, which could lead to incorrect calculations. The function should include a check for `undefined` or `null` values for `input.nonCodeLines`.

Nits

  • src/scoring/preview.ts: the helper function applyNonCodeLineCap is defined after its first use, which relies on function hoisting; moving it above computeScoreCore would improve readability.
  • src/scoring/model.ts: the constant DEFAULT_ISSUE_DISCOVERY_SHARE is exported before being referenced in DEFAULT_SCORING_CONSTANTS; while valid, grouping related constants together could aid maintainability.
  • src/registry/normalize.ts: the import path uses a relative '../scoring/model' which is correct but could be made absolute via tsconfig paths for consistency across the repo.
  • Add a unit test for applyNonCodeLineCap where nonCodeLines exceeds the cap to explicitly assert the proportional reduction logic.
  • Consider renaming `reviewCollateralMultiplier` to `openPrReviewCollateralMultiplier` to make its purpose clearer, matching the naming of `OPEN_PR_COLLATERAL_PERCENT`.
  • In `src/scoring/model.ts`, the `DEFAULT_ISSUE_DISCOVERY_SHARE` constant is defined twice — once at the top and once within the `DEFAULT_SCORING_CONSTANTS` object. The duplicate definition should be removed.
  • In `src/scoring/preview.ts`, the `applyNonCodeLineCap` function could benefit from a docstring explaining its purpose and parameters.
  • In `src/scoring/preview.ts`, the `computeScoreCore` function is quite long and complex. Consider breaking it down into smaller, more manageable functions to improve readability and maintainability.
  • In `test/unit/scoring.test.ts`, the test cases for the new constants could be more descriptive. For example, the test case for `buildScorePreview` with `changesRequestedCount: 4` could be named `should apply review collateral multiplier correctly`.
  • In `src/signals/local-branch.ts`, the `nonCodeLines` field is added to the `buildLocalScoreInput` function without a corresponding comment explaining its purpose.
  • In `src/api/routes.ts`, the `nonCodeLines` field is added to the `scorePreviewSchema` without a corresponding comment explaining its purpose.
Signal Result Evidence
Code review ✅ No blockers 2 reviewers, synthesized
Linked issue ✅ Linked #809
Related work ⚠️ 1 scoped overlap Top overlaps are listed below; lower-confidence bulk is hidden.
Review load ❌ 8/20 Readiness component derived from cached public PR metadata and labels; size label size:M.
Validation evidence ✅ 25/25 PR body includes validation/test evidence.
Open PR queue ✅ 10/10 0 open PR(s), 0 likely reviewable.
Contributor context ✅ Confirmed Gittensor contributor bohdansolovie; Gittensor profile; 15 PR(s), 3 issue(s).
Gate result ✅ Passing No configured blocker found.
Review context
  • Author: bohdansolovie
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python
  • Official Gittensor activity: 15 PR(s), 3 issue(s).
  • Related work: Titles/paths share 5 meaningful terms. (issue #809, issue #814)
Contributor next steps
  • Review top overlaps.
  • Add scope summary.
  • Check active issues and PRs before submitting.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Review load = cached public PR metadata such as size labels, changed paths, and preflight status.
  • Open PR queue = repo-wide review pressure; it is not a PR quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
Review details

Generated from public PR metadata and the diff. Advisory only; deterministic signals remain authoritative.

The PR introduces three upstream scoring constants into the model, makes them available to the registry normalization, and updates the preview scoring logic to respect review-collateral multipliers and a line‑count cap for non‑code token scores. The new `DEFAULT_ISSUE_DISCOVERY_SHARE` constant is exported and used as the default for registry payloads. The preview flow now accepts a raw `nonCodeLines` count, applies a proportional cap via `applyNonCodeLineCap`, and returns both `reviewCollateralMultiplier` and the derived `collateralFraction` in the gates. API schemas, OpenAPI definitions, and route validation are extended accordingly, and tests are updated to verify the new behavior. All added fields are wired through the scoring pipeline, and the changes appear type‑safe and logically consistent with the upstream specifications.

Blockers

  • In `src/scoring/preview.ts`, the `applyNonCodeLineCap` function does not handle the case where `input.nonCodeLines` is `undefined` or `null`, which could lead to a runtime error. The function should include a check for `undefined` or `null` values for `input.nonCodeLines`.
  • In `src/scoring/preview.ts`, the `computeScoreCore` function does not handle the case where `input.nonCodeLines` is `undefined` or `null`, which could lead to incorrect calculations. The function should include a check for `undefined` or `null` values for `input.nonCodeLines`.

Nits

  • src/scoring/preview.ts: the helper function applyNonCodeLineCap is defined after its first use, which relies on function hoisting; moving it above computeScoreCore would improve readability.
  • src/scoring/model.ts: the constant DEFAULT_ISSUE_DISCOVERY_SHARE is exported before being referenced in DEFAULT_SCORING_CONSTANTS; while valid, grouping related constants together could aid maintainability.
  • src/registry/normalize.ts: the import path uses a relative '../scoring/model' which is correct but could be made absolute via tsconfig paths for consistency across the repo.
  • Add a unit test for applyNonCodeLineCap where nonCodeLines exceeds the cap to explicitly assert the proportional reduction logic.
  • Consider renaming `reviewCollateralMultiplier` to `openPrReviewCollateralMultiplier` to make its purpose clearer, matching the naming of `OPEN_PR_COLLATERAL_PERCENT`.
  • In `src/scoring/model.ts`, the `DEFAULT_ISSUE_DISCOVERY_SHARE` constant is defined twice — once at the top and once within the `DEFAULT_SCORING_CONSTANTS` object. The duplicate definition should be removed.
  • In `src/scoring/preview.ts`, the `applyNonCodeLineCap` function could benefit from a docstring explaining its purpose and parameters.
  • In `src/scoring/preview.ts`, the `computeScoreCore` function is quite long and complex. Consider breaking it down into smaller, more manageable functions to improve readability and maintainability.
  • In `test/unit/scoring.test.ts`, the test cases for the new constants could be more descriptive. For example, the test case for `buildScorePreview` with `changesRequestedCount: 4` could be named `should apply review collateral multiplier correctly`.
  • In `src/signals/local-branch.ts`, the `nonCodeLines` field is added to the `buildLocalScoreInput` function without a corresponding comment explaining its purpose.
  • In `src/api/routes.ts`, the `nonCodeLines` field is added to the `scorePreviewSchema` without a corresponding comment explaining its purpose.
Visual preview
Route Viewport Before (production) After (this PR's preview)
/ desktop before / after /
/ mobile before / (mobile) after / (mobile)

Click any thumbnail to open the full-size screenshot. Before = production · After = this PR's preview deploy.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@ghost ghost added the gittensory:reviewed label Jun 22, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.77%. Comparing base (2c35207) to head (a75ff36).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1049   +/-   ##
=======================================
  Coverage   94.76%   94.77%           
=======================================
  Files         153      153           
  Lines       18540    18550   +10     
  Branches     6705     6707    +2     
=======================================
+ Hits        17570    17580   +10     
  Misses        418      418           
  Partials      552      552           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ghost ghost added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jun 22, 2026
@ghost ghost closed this Jun 22, 2026
@JSONbored JSONbored reopened this Jun 22, 2026
bohdansolovie and others added 2 commits June 23, 2026 08:00
 JSONbored#809)

Pull MAX_OPEN_PR_REVIEW_COLLATERAL_MULTIPLIER, MAX_LINES_SCORED_FOR_NON_CODE_EXT,
and DEFAULT_ISSUE_DISCOVERY_SHARE into the scoring snapshot and apply them in
preview collateral math, non-code line capping, and registry normalization defaults.

Co-authored-by: Cursor <cursoragent@cursor.com>
The prior CI run for 2c8261a was cancelled before test/lint completed,
leaving validate red despite the draft timer flake fix.

Co-authored-by: Cursor <cursoragent@cursor.com>

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

Gittensory approves — the gate is satisfied and CI is green.

Repository owner deleted a comment Jun 23, 2026
@dosubot dosubot Bot added the lgtm label Jun 23, 2026
@JSONbored
JSONbored merged commit f759e88 into JSONbored:main Jun 23, 2026
16 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 24, 2026
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(scoring): pull + model upstream constants not currently fetched

2 participants