Skip to content

fix(miner): bring extractLinkedIssueNumbers to parity with the host's byte-range code-span exclusion and full-URL closing form #7527

Description

@JSONbored

Context

The module's own comment says this function "Mirrors src/db/repositories.ts's
extractLinkedIssueNumbers." The current miner-side implementation:

const LINKED_ISSUE_PATTERN = /\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+(?:([\w.-]+\/[\w.-]+)#|#)(\d+)\b/gi;
function extractLinkedIssueNumbers(body: any, repoFullName: any) {
  // Strip backtick code spans first so a closing-keyword pattern quoted as example code doesn't count.
  const withoutCodeSpans = body.replace(/`[^`]*`/g, "");
  const numbers = [];
  const normalizedRepo = repoFullName.toLowerCase();
  for (const match of withoutCodeSpans.matchAll(LINKED_ISSUE_PATTERN)) {
    ...
  }
}

But the real host implementation this claims to mirror (extractLinkedIssueNumbersWithOverflow,
src/db/repositories.ts:8015) deliberately does not strip code spans by string replacement — it
computes code-span byte ranges and rejects regex hits that fall inside them, with this exact rationale
in its own comment:

"Keep the original text while rejecting regex hits that occur inside inline code spans; replacing
spans with whitespace would let text on either side combine into a fake closing reference."

The miner's port does precisely the thing the host's own comment warns against. Concrete repro: a PR
body containing "Fixes some code #45" — after body.replace(/[^]*/g, "")this becomes"Fixes #45"(the two spaces on either side of the removed span still satisfy\s+), which now matches LINKED_ISSUE_PATTERNand links issue #45 — even though the original text never had the closing keyword adjacent to the issue reference; a code span sat between them. This is a genuine false-positive linked-issue match that flows intobuildIssueQualityReport/duplicate-cluster detection in the same file's fetchSelfReviewContext`, exactly the class of bug the host's own comment documents having fixed
once already (and explicitly warns a future port not to reintroduce).

Separately, the host's extractLinkedIssueNumbersWithOverflow also recognizes the full-GitHub-URL
closing form (Closes https://github.com/owner/repo/issues/N), added as an explicit fix (its own
comment: "a contributor pasting the full issue URL... previously produced zero linked issues and
tripped the 'no linked issue' hard-rule close on a PR that genuinely had one"). The miner's
LINKED_ISSUE_PATTERN only recognizes the bare #N and owner/repo#N forms — it has no URL branch —
so a miner-authored PR body that closes an issue via a pasted URL undercounts its own linked issues in
self-review-context.ts's pre-submission check, the same failure mode the host fixed for the maintainer
gate.

Requirements

  • Replace the body.replace(/[^`]*`/g, "")` string-stripping approach with the host's byte-range exclusion approach: compute inline-code-span ranges via `matchAll(/`[^`\n]*/g), then for each
    LINKED_ISSUE_PATTERN match, skip it when its [start, end) range overlaps any code-span range
    (matchStart < range.end && matchEnd > range.start) — do not replace/strip the original text.
  • Extend LINKED_ISSUE_PATTERN (or restructure the match loop, matching the host's named-group
    approach) to additionally recognize KEYWORD https://github.com/owner/repo/issues/N (and
    www.github.com), case-insensitively matching owner/repo against the resolved repoFullName exactly
    like the existing qualified owner/repo#N form already does.
  • Preserve the existing behavior for the bare #N and qualified owner/repo#N forms exactly as today
    (this is an additive parity fix, not a rewrite of the matching semantics).

Deliverables

  • extractLinkedIssueNumbers in self-review-context.ts uses byte-range code-span exclusion instead of string replacement.
  • extractLinkedIssueNumbers recognizes the full-GitHub-URL closing form, same-repo-scoped like the qualified form.
  • A comment update noting the two functions are now in sync (or documenting any deliberate remaining delta, e.g. the host's overflow-limit/dedup behavior if that's intentionally left out of the miner's lighter port).

Test Coverage Requirements

99%+ Codecov patch gate (this package's equivalent unit-test coverage gate — confirm the exact threshold
in this package's own package.json/CI config, but treat it as hard). Add regression tests: (1) a body
like "Fixes some code #45" must NOT be linked to #45; (2) a body like "Fixes #999 for real,
Closes #45" must still correctly link #45 (code-span exclusion must not swallow a legitimate adjacent
match); (3) "Closes https://github.com//issues/45" must link #45; (4) a URL referencing a
different repo must not match (mirroring the existing qualified-form same-repo test).

Expected Outcome

self-review-context.ts's linked-issue extraction can no longer fabricate a false-positive link across a
stripped code span, and correctly recognizes a full-issue-URL closing reference the same way the host
gate already does — removing a source of incorrect buildIssueQualityReport/duplicate-cluster signal in
the miner's own pre-submission self-review.

Links & Resources

  • src/db/repositories.ts's extractLinkedIssueNumbersWithOverflow (~line 8015) — the host implementation to converge onto.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.help wantedExtra attention is needed

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions