Skip to content

fix(review): count blank context lines in addedLinesFromPatch so blocker anchors don't drift - #9781

Merged
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/added-lines-blank-context-9663
Jul 29, 2026
Merged

fix(review): count blank context lines in addedLinesFromPatch so blocker anchors don't drift#9781
JSONbored merged 1 commit into
JSONbored:mainfrom
shin-core:fix/added-lines-blank-context-9663

Conversation

@shin-core

Copy link
Copy Markdown
Contributor

What & why

src/review/ has two parallel unified-diff line-number walkers over the same payload.patch:
rightSideLinesFromPatch (RIGHT-side commentable lines) and addedLinesFromPatch (ADDED + lines only). #9076 fixed a line-number desync in the first and documented it inline, but addedLinesFromPatch still had the pre-#9076 code — and since #9076 it is the authoritative anchor validator for blocker-severity inline findings (inline-comments-select.ts:103) and gates every committable suggestion via isSuggestionAnchorable.

The bug: a zero-length patch line (a context line whose single leading space the split stripped → marker undefined) was continued past without advancing right, desyncing every later added-line number. On the patch "@@ -1,3 +1,3 @@\n one\n\n+three", rightSideLinesFromPatch returns {1,2,3} but addedLinesFromPatch returned {2} instead of {3}. So a correctly-anchored blocker on the added line 3 was silently dropped, and a blocker the model anchored on the blank context line 2 was accepted and posted — exactly the "telling a contributor their bug is on a line they did not write" failure #9076 exists to prevent. A second divergence: no trailing-empty-element pop, so a patch ending in a newline counted one extra line.

The fix

Mirror rightSideLinesFromPatch line-for-line:

  • Drop the trailing empty split artifact before the walk (rawLines.pop() when the last element is "").
  • Remove marker === undefined from the skip condition so a zero-length line falls through to right += 1 — still not added (only "+" adds), but counted as the context line it is.
  • "-" / "\\" handling and the added-only semantics are unchanged; no caller signature changes; rightSideLinesFromPatch and isSuggestionAnchorable untouched.

Both walkers now agree on every line number for every patch shape.

Tests

Each behavior-changing case fails against main (regression-proven). Diff coverage on the changed file is 100% line and branch.

Validation

  • npm run typecheck green; the three inline suites green.
  • git diff --check <base> HEAD clean; diff is three files (one src + two tests), no route/schema/migration change.

Closes #9663

…ker anchors don't drift

`addedLinesFromPatch` (the authoritative anchor validator for blocker-severity
inline findings since JSONbored#9076) still had the pre-JSONbored#9076 walker: it `continue`d past
a zero-length patch line (a context line whose single leading space the split
stripped) without advancing `right`, desyncing every later added-line number. On
the patch `"@@ -1,3 +1,3 @@\n one\n\n+three"` it returned {2} instead of {3}, so
a correctly-anchored blocker on the added line 3 was silently dropped and a
blocker the model anchored on the blank *context* line 2 was accepted and posted
— exactly the "your bug is on a line you did not write" failure JSONbored#9076 prevents.

Mirror `rightSideLinesFromPatch` line-for-line: drop the trailing empty split
artifact before the walk, and let a zero-length line fall through to `right += 1`
(still not added, but counted as the context line it is). `"-"`/`"\\"` handling
and the added-only set are unchanged.

Closes JSONbored#9663
@shin-core
shin-core requested a review from JSONbored as a code owner July 29, 2026 08:23
@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 29, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

🚨 Contributor flagged. Click here for more info: Superagent Dashboard

@loopover-orb

loopover-orb Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Warning

⏸️ LoopOver review result - manual review recommended

Review updated: 2026-07-29 08:34:30 UTC

3 files · 1 AI reviewer · no blockers · CI green · unstable

⏸️ Suggested Action - Manual Review

Review summary
This fixes a real desync bug in `addedLinesFromPatch`: a zero-length patch line (stripped leading space on a blank context line) was previously skipped without advancing `right`, causing every subsequent added-line number to be off by one, which could cause a blocker anchored on an added line to be dropped and one on a context line to be wrongly accepted. The fix mirrors the sibling `rightSideLinesFromPatch` walker exactly (dropping the trailing empty split artifact and letting a zero-length line fall through to `right += 1` without adding it), and is well covered by targeted unit tests including an end-to-end `selectInlineComments` test demonstrating the exact anchor-drift scenario. The change is narrow, self-contained, and the tests exercise the real code path rather than a fabricated one.

Nits — 4 non-blocking
  • The PR description is verbose with heavy inline comments explaining the same rationale multiple times (file and tests); could be trimmed for readability.
  • No mention of an issue number being formally linked/closed in the repo's issue tracker beyond 'orb(review): fix addedLinesFromPatch dropping blank context lines — blocker anchors drift #9663' referenced in comments — worth confirming this closes an actual open issue per repo convention.
  • Consider extracting the shared line-walking logic between `rightSideLinesFromPatch` and `addedLinesFromPatch` into one function to prevent this exact class of drift bug from recurring when one walker is updated without the other (src/review/inline-suggestion-anchor.ts, src/review/inline-comments.ts).
  • The inline comments in the diff are lengthy for what's a fairly small, well-tested fix — could be tightened.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #9663
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ❌ 5/25 Preflight is holding this PR: the review lane is unavailable, so it is not ready for automated review.
Contributor workload ✅ 10/10 Author activity: 50 registered-repo PR(s), 35 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor shin-core; Gittensor profile; 50 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor
Linked issue satisfaction

Addressed
The diff mirrors rightSideLinesFromPatch by popping the trailing empty split artifact and removing the `marker === undefined` continue so blank context lines advance `right`, matching all stated requirements. All four required tests are present: the unit test for the blank-context patch expecting {3}, the trailing-newline equivalence test, the end-to-end selectInlineComments regression test postin

Review context
  • Author: shin-core
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is registered but has no active allocation in the current snapshot.
  • Public profile languages: not available
  • Official Gittensor activity: 50 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Await review-lane availability.
  • Then work through the remaining 2 steps in the Signals table above.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

Decision record
  • action: hold · clause: success
  • config: 0942b3ba452ad51b0cee5084e04ece151ff5097a479aa1b42d89a0e57d26f5b8 · pack: oss-anti-slop · ci: passed
  • record: a964e479d178cb06434bfe903131a4ba8ab212edde479b230755a402fe6497bd (schema v5, head 3bd9d63)

🟩 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 LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@superagent-security

Copy link
Copy Markdown
Contributor

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

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 29, 2026
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.60%. Comparing base (bf654cf) to head (3bd9d63).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #9781       +/-   ##
===========================================
- Coverage   90.30%   76.60%   -13.71%     
===========================================
  Files         912      283      -629     
  Lines      113555    59494    -54061     
  Branches    26955     8488    -18467     
===========================================
- Hits       102544    45573    -56971     
- Misses       9682    13639     +3957     
+ Partials     1329      282     -1047     
Flag Coverage Δ
backend 100.00% <100.00%> (+4.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/review/inline-suggestion-anchor.ts 100.00% <100.00%> (ø)

... and 763 files with indirect coverage changes

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 29, 2026
@loopover-orb

loopover-orb Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Held for manual review: the gate and required CI are green, but GitHub reports this pull request's mergeable state as unstable because a non-required check or status is not passing, so LoopOver will not auto-merge. A maintainer can resolve the failing check or review and merge manually. This is an automated maintenance action.

@JSONbored
JSONbored merged commit 09258a4 into JSONbored:main Jul 29, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:flagged Contributor flagged for review by trust analysis. gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

orb(review): fix addedLinesFromPatch dropping blank context lines — blocker anchors drift

2 participants