Skip to content

fix(engine): predicted-gate-engine's local extractLinkedIssueNumbers lacks the inline-code-span exclusion its canonical repositories.ts twin has #6630

Description

@JSONbored

Context

src/db/repositories.ts's extractLinkedIssueNumbersWithOverflow (the canonical, production implementation, around line 8076) explicitly excludes regex matches that fall inside inline code spans (backtick-wrapped text), with this documented rationale:

// GitHub's native closing-keyword linker does not treat backtick-wrapped text as a real
// "Closes #N" directive, and this repo's own PR template contains "(e.g. `Closes #123`)".
// 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.
const inlineCodeSpanRanges = [...text.matchAll(/`[^`\n]*`/g)].map((match) => ({
  start: match.index!,
  end: match.index! + match[0].length,
}));

...and later filters out any keyword match whose range overlaps one of these spans.

packages/loopover-engine/src/signals/predicted-gate-engine.ts has its own, separate local extractLinkedIssueNumbers (around line 920), used internally by this file's buildPreflightResult (the function the miner's local predicted-gate preview calls via predicted-gate.ts) to detect linked issues from a PR body. This local copy has NO inline-code-span exclusion at all:

function extractLinkedIssueNumbers(text: string, repoFullName: string): number[] {
  const numbers = [...text.matchAll(/\b(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s+#(\d+)\b/gi)].map((match) => Number(match[1]));
  ...
}

Since this repo's OWN PR template contains the literal example text `Closes #123` (backtick-wrapped, per the comment in src/db/repositories.ts quoted above), a miner running the local predicted-gate preview against an unfilled or lightly-edited PR template body would have this unfilled template boilerplate misread as a real linked-issue reference to issue #123 — the exact false-positive the canonical src/db/repositories.ts implementation was fixed to guard against, still present in this file's separate local copy. This breaks predicted-gate.ts's documented predicted/live gate parity contract: the miner's local preview can silently suppress a missing_linked_issue warning (because it thinks issue #123 is linked) in a case where the live gate, using the canonical extractor, would correctly still raise it.

Requirements

  • packages/loopover-engine/src/signals/predicted-gate-engine.ts's local extractLinkedIssueNumbers function must exclude regex matches that fall inside inline code spans (backtick-wrapped text, `...`), using the same "collect inline code span ranges via text.matchAll(/[^\n]*/g), then skip any keyword match whose range overlaps one of those spans" approach as src/db/repositories.ts's extractLinkedIssueNumbersWithOverflow`. Do not replace or strip the code-span text itself (only skip matches whose range overlaps a span) — the canonical implementation's comment explains why: replacing spans with whitespace would let text on either side combine into a fake closing reference.
  • This fix is scoped ONLY to packages/loopover-engine/src/signals/predicted-gate-engine.ts's local extractLinkedIssueNumbers function. Do not modify src/db/repositories.ts (the already-correct canonical implementation) or packages/loopover-engine/src/signals/engine.ts (which imports the canonical implementation directly and does not have this bug).
  • After this fix, extractLinkedIssueNumbers("See the template: \Closes feat(data): add contributor reconciliation reports #123` for the format.", "owner/repo")must return[](no linked issues detected), whileextractLinkedIssueNumbers("Closes feat(data): add contributor reconciliation reports #123", "owner/repo")(the same reference NOT inside a code span) must still return[123]`.

Deliverables

  • extractLinkedIssueNumbers in packages/loopover-engine/src/signals/predicted-gate-engine.ts skips closing-keyword matches that fall inside inline code spans.
  • New unit test asserting a backtick-wrapped `Closes #123` reference in a PR body is NOT detected as a linked issue, while the same unwrapped reference is.

Test Coverage Requirements

This repo's Codecov patch gate is 99%+ for src/**/packages/**. The new inline-code-span exclusion branch must be covered by a new test in the suite covering predicted-gate-engine.ts (check test/unit/predicted-gate-engine-coverage.test.ts / test/unit/predicted-gate-engine-branch-coverage.test.ts for the existing coverage pattern to extend).

Expected Outcome

The miner's local predicted-gate preview no longer misreads unfilled PR-template boilerplate (or any other backtick-wrapped example text) as a real linked-issue reference, matching the canonical src/db/repositories.ts extractor's already-fixed behavior and restoring predicted/live gate parity for linked-issue detection.

Links & Resources

  • packages/loopover-engine/src/signals/predicted-gate-engine.ts (extractLinkedIssueNumbers, ~line 920)
  • src/db/repositories.ts (canonical extractLinkedIssueNumbersWithOverflow, ~line 8076, with the inline-code-span exclusion this issue ports over)

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