Skip to content

refactor(queue): extract duplicate-cluster adjudication into its own module - #4823

Merged
JSONbored merged 1 commit into
mainfrom
refactor/4013-extract-duplicate-detection
Jul 11, 2026
Merged

refactor(queue): extract duplicate-cluster adjudication into its own module#4823
JSONbored merged 1 commit into
mainfrom
refactor/4013-extract-duplicate-detection

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

  • Part of refactor(queue): split processors.ts into cohesive modules #4013's module-split sequence for src/queue/processors.ts. Step 3, after transient-locks.ts (refactor(queue): extract transient-lock primitives into their own module #4157) and signal-snapshot.ts (refactor(queue): extract signal-snapshot generation into its own module #4820).
  • Moves the duplicate-cluster winner adjudication functions into src/queue/duplicate-detection.ts: dupWinnerLinkedDuplicateCount, dupWinnerLinkedDuplicateWinnerNumber, reconcileLiveDuplicateSiblings, linkedIssueDuplicatePullRequestsForGate, linkedIssueDuplicatePullRequestRecordsForGate. Pure mechanical move — no behavior change.
  • processors.ts's own local githubAdmissionKeyForToken wrapper (used at ~13 other call sites there, so it stays put) is not imported back into the new file — that single call site instead uses the wrapper's own underlying githubRateLimitAdmissionKeyForToken(env, token, installationId) directly (a documented one-line arg-reorder with no logic of its own), keeping the dependency one-directional instead of making the two files circularly import each other.
  • A re-export shim (import { ... } from "./duplicate-detection"; export { ... } from "./duplicate-detection";) keeps this file's own internal callers and test/unit/duplicate-winner.test.ts / test/unit/reconcile-live-duplicate-siblings.test.ts's existing import { ... } from "../../src/queue/processors" working unchanged.
  • One coverage note: the moved .catch(() => undefined) in reconcileLiveDuplicateSiblings was flagged as newly-uncovered once isolated in its own small file (previously invisible inside processors.ts's overall coverage). Traced it to the source: fetchLivePullRequestState (src/github/backfill.ts) already catches its own errors internally and never rejects, so the wrapping .catch is provably unreachable defense-in-depth. Marked with /* v8 ignore next */, matching this file's own established convention for the same shape (e.g. processors.ts's invalidatePrStateCache(...).catch(() => undefined) at the webhook handler).

Part of #4013 (more extraction steps remain in the sequence — not closing the tracking issue).

Test plan

  • npx tsc --noEmit -p . — zero errors
  • npx vitest run test/unit test/integration — 695/696 files passed (1 skipped, pre-existing)
  • npm run test:coverage (unsharded) — 94.43% statements / 93.4% branches / 93.6% functions / 95.02% lines, no threshold failures; duplicate-detection.ts itself is 100% line + branch + function covered
  • npm run docs:drift-check, npm run manifest:drift-check, npm run engine-parity:drift-check — all ok
  • npm audit --audit-level=moderate — 0 vulnerabilities

@JSONbored JSONbored self-assigned this Jul 11, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

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

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.25%. Comparing base (aa2bc7c) to head (bc1ad90).
⚠️ Report is 3 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4823   +/-   ##
=======================================
  Coverage   94.24%   94.25%           
=======================================
  Files         445      446    +1     
  Lines       38880    38878    -2     
  Branches    14160    14160           
=======================================
- Hits        36644    36643    -1     
+ Misses       1577     1576    -1     
  Partials      659      659           
Flag Coverage Δ
shard-1 46.46% <25.00%> (-0.29%) ⬇️
shard-2 33.56% <50.00%> (+0.27%) ⬆️
shard-3 31.56% <53.12%> (+0.14%) ⬆️
shard-4 32.51% <68.75%> (-0.49%) ⬇️
shard-5 34.42% <0.00%> (+0.92%) ⬆️
shard-6 45.47% <21.87%> (+0.24%) ⬆️

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

Files with missing lines Coverage Δ
src/queue/duplicate-detection.ts 100.00% <100.00%> (ø)
src/queue/processors.ts 95.60% <ø> (-0.02%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

loopover-orb Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-11 02:55:38 UTC

2 files · 1 AI reviewer · 2 blockers · readiness 93/100 · CI green · dirty

⏸️ Suggested Action - Manual Review

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.

Review summary
This is a clean, behavior-preserving extraction of five duplicate-cluster adjudication functions from processors.ts into a new duplicate-detection.ts, part of an ongoing tracked module-split (#4013, following #4157 and #4820). The re-export shim keeps existing internal callers and both dependent test files (duplicate-winner.test.ts, reconcile-live-duplicate-siblings.test.ts) working unchanged via the unchanged `import ... from "../../src/queue/processors"` path, and the one previously-invisible `.catch(() => undefined)` in reconcileLiveDuplicateSiblings is correctly traced to fetchLivePullRequestState (which never rejects) and marked unreachable with `/* v8 ignore next */`. The only genuine risk area is the inlined `githubRateLimitAdmissionKeyForToken(env, token, installationId)` call replacing `githubAdmissionKeyForToken(env, installationId, token)` — an argument-order swap that must exactly match the underlying signature; it isn't independently verifiable from this diff since client.ts isn't shown, but CI (including validate/typecheck and the existing reconcile-live-duplicate-siblings test suite) is green on this exact commit, which is strong evidence the reorder is correct.

Nits — 5 non-blocking
  • src/queue/duplicate-detection.ts: the admission-key call was changed from `githubAdmissionKeyForToken(env, installationId, token)` to `githubRateLimitAdmissionKeyForToken(env, token, installationId)` — worth a one-line confirmation in the PR that this positional reorder was checked against client.ts's actual signature rather than just asserted in the comment, since a mismatch here would silently compute the wrong rate-limit admission key on the live-reconcile path.
  • No new tests were added for this extraction (+160/-0 net across 2 source files, 0 test files); that's appropriate for a pure move since the shim keeps duplicate-winner.test.ts and reconcile-live-duplicate-siblings.test.ts exercising the same code, but it's worth confirming patch coverage on duplicate-detection.ts still clears ~97% now that it's a small standalone file (the PR already caught and `v8 ignore`'d one line that fell below threshold once isolated — check there isn't a second one).
  • Once the refactor(queue): split processors.ts into cohesive modules #4013 split sequence is complete, consider repointing duplicate-winner.test.ts and reconcile-live-duplicate-siblings.test.ts at src/queue/duplicate-detection.ts directly and dropping the re-export shim from processors.ts, so the module boundary is enforced by imports rather than convention.
  • The extensive JSDoc on reconcileLiveDuplicateSiblings references `{@​link isDuplicateClusterWinner}`, which lives in processors.ts or signals/duplicate-winner.ts rather than this file — double check that doc link still resolves for consumers of the new module.
  • Code changes lack test evidence — Add focused regression tests or explain why existing coverage is sufficient.

Concerns raised — review before merging

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.
Signal Result Evidence
Code review ❌ 2 blockers 1 reviewer
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.
Change scope ✅ 20/20 Low review scope from cached public metadata (no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 48 registered-repo PR(s), 40 merged, 312 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 48 PR(s), 312 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
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: not available
  • Official Gittensor activity: 48 PR(s), 312 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.
  • 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.

🟩 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

…module

Part of #4013's module-split sequence (step 3, after transient-locks.ts
and signal-snapshot.ts): dupWinnerLinkedDuplicateCount,
dupWinnerLinkedDuplicateWinnerNumber, reconcileLiveDuplicateSiblings,
linkedIssueDuplicatePullRequestsForGate, and
linkedIssueDuplicatePullRequestRecordsForGate move to
src/queue/duplicate-detection.ts. Pure mechanical move, no behavior
change -- a re-export shim keeps processors.ts's own internal callers
and the existing test/unit/duplicate-winner.test.ts and
test/unit/reconcile-live-duplicate-siblings.test.ts imports working
unchanged.
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. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant