Skip to content

fix(scoring): cap non-code explicit totals - #1102

Merged
JSONbored merged 1 commit into
mainfrom
codex/fix-non-code-line-cap-bypass-issue
Jun 23, 2026
Merged

fix(scoring): cap non-code explicit totals#1102
JSONbored merged 1 commit into
mainfrom
codex/fix-non-code-line-cap-bypass-issue

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • A recent change introduced a non-code line cap via applyNonCodeLineCap, but the cap was only applied when totalTokenScore was not provided, allowing callers (and the local-branch path which always sets totalTokenScore) to bypass the cap and inflate previews.
  • The intent is to ensure the MAX_LINES_SCORED_FOR_NON_CODE_EXT cap affects both derived totals and caller-supplied aggregate totalTokenScore when nonCodeTokenScore/nonCodeLines are present.

Description

  • Use a derived total (derivedTotalTokenScore) when input.totalTokenScore is undefined and otherwise apply a new cap-adjustment to caller-supplied totals via applyNonCodeCapToTotal in computeScoreCore (src/scoring/preview.ts).
  • Add the helper applyNonCodeCapToTotal(totalTokenScore, input, cappedNonCodeTokenScore) which subtracts the uncapped non-code excess from an explicit total without double-capping derived totals.
  • Preserve previous behavior for derived totals so they continue to include the capped non-code component when totalTokenScore is not supplied.
  • Add a regression test in test/unit/scoring.test.ts that verifies an explicit totalTokenScore with excessive nonCodeLines is normalized to match the capped non-code case.

Testing

  • Ran the targeted scoring unit suite with npx vitest run test/unit/scoring.test.ts and the suite passed (48 tests, 0 failures).
  • Ran type checking with npm run typecheck (tsc --noEmit) and it succeeded with no errors.
  • The change adds a focused regression test that demonstrates explicit totals no longer bypass MAX_LINES_SCORED_FOR_NON_CODE_EXT.

Codex Task

@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.77%. Comparing base (b34fddd) to head (4d9b3cd).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1102   +/-   ##
=======================================
  Coverage   94.77%   94.77%           
=======================================
  Files         153      153           
  Lines       18550    18554    +4     
  Branches     6705     6706    +1     
=======================================
+ Hits        17580    17584    +4     
  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 commented Jun 23, 2026

Copy link
Copy Markdown

Tip

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

✅ Gittensory review — safe to merge

2 files · 2 AI reviewers · no blockers · readiness 93/100 · CI green · unstable

✅ Approved — safe to merge

Review summary
The change introduces a new helper `applyNonCodeCapToTotal` and adjusts `computeScoreCore` to apply the non‑code line cap to both derived and caller‑provided total token scores. The logic correctly caps explicit totals by subtracting the uncapped non‑code excess, and a regression test validates the behavior. The implementation compiles and aligns with the described intent.

Blockers

  • The function `applyNonCodeCapToTotal` does not handle the case where `totalTokenScore` is negative, which could lead to incorrect results in `src/scoring/preview.ts` (line 984).

<details>
<summary>Nits (5)</summary>

  • The removed comment about applying the cap only when `totalTokenScore` is not provided no longer reflects the current logic.
  • `applyNonCodeCapToTotal` lacks a JSDoc comment describing its purpose and parameters.
  • The strict `=== undefined` check treats `null` as a provided total, which may be unintended.
  • The variable name `derivedTotalTokenScore` could be clearer (e.g., `computedTotalTokenScore`).
  • The new test relies on a previously defined `cappedNonCode` variable; ensure its scope is appropriate.
    </details>
Signal Result Evidence
Code review ✅ No blockers 2 reviewers, synthesized
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Review load ✅ 20/20 Readiness component derived from cached public PR metadata and labels; size label size:S.
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 JSONbored; Gittensor profile; 84 PR(s), 253 issue(s).
Gate result ✅ Passing No configured blocker found.
Nits — 1 non-blocking
  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, JavaScript, Ruby, Go, Kotlin, MDX, Shell
  • Official Gittensor activity: 84 PR(s), 253 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
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 change introduces a new helper `applyNonCodeCapToTotal` and adjusts `computeScoreCore` to apply the non‑code line cap to both derived and caller‑provided total token scores. The logic correctly caps explicit totals by subtracting the uncapped non‑code excess, and a regression test validates the behavior. The implementation compiles and aligns with the described intent.

Blockers

  • The function `applyNonCodeCapToTotal` does not handle the case where `totalTokenScore` is negative, which could lead to incorrect results in `src/scoring/preview.ts` (line 984).

<details>
<summary>Nits (5)</summary>

  • The removed comment about applying the cap only when `totalTokenScore` is not provided no longer reflects the current logic.
  • `applyNonCodeCapToTotal` lacks a JSDoc comment describing its purpose and parameters.
  • The strict `=== undefined` check treats `null` as a provided total, which may be unintended.
  • The variable name `derivedTotalTokenScore` could be clearer (e.g., `computedTotalTokenScore`).
  • The new test relies on a previously defined `cappedNonCode` variable; ensure its scope is appropriate.
    </details>

🟩 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 gittensory:reviewed gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. labels Jun 23, 2026
@JSONbored JSONbored self-assigned this Jun 23, 2026
@JSONbored
JSONbored merged commit 549a6c9 into main Jun 23, 2026
18 checks passed
@JSONbored
JSONbored deleted the codex/fix-non-code-line-cap-bypass-issue branch June 23, 2026 21:10
@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:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant