Skip to content

fix(queue): cap contributor PR live checks - #3911

Merged
JSONbored merged 1 commit into
mainfrom
codex/fix-unbounded-pr-cap-vulnerability
Jul 7, 2026
Merged

fix(queue): cap contributor PR live checks#3911
JSONbored merged 1 commit into
mainfrom
codex/fix-unbounded-pr-cap-vulnerability

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent an availability/resource-exhaustion regression where a single webhook could walk an unbounded same-author PR set and generate O(N) GitHub live reads and O(N) sibling wake jobs.
  • Preserve the existing "oldest PRs win" duplicate-winner semantics while bounding per-webhook work so an attacker cannot amplify API/queue usage by creating many PRs.

Description

  • Add a fixed 100-row cap to the author-scoped sibling query in src/db/repositories.ts so the author-scoped sample is limited and still ordered by ascending PR number (listOtherOpenPullRequestsForAuthor).
  • Update explanatory comments in src/queue/processors.ts to document the fixed-budget author-scoped sample plus the existing bounded concurrency (CONTRIBUTOR_CAP_LIVE_CHECK_CONCURRENCY = 10).
  • Add a regression unit test in test/unit/duplicate-winner.test.ts that verifies the author-scoped query filters by author/self and returns the lowest 100 same-author siblings while excluding unrelated PRs and the subject PR.

Testing

  • Ran focused unit tests for the changed behavior with npx vitest run test/unit/duplicate-winner.test.ts -t "author-scoped contributor-cap", which passed.
  • Exercised the contributor-cap related suite with npx vitest run test/unit/duplicate-winner.test.ts test/unit/queue.test.ts -t "contributor open-PR cap|listOtherOpenPullRequests", and the focused tests covering the modified paths passed.
  • npm run typecheck completed successfully, while a full npm run test:coverage attempt aborted due to an existing RangeError: Maximum call stack size exceeded in the large test/unit/queue.test.ts run (this is an existing suite recursion encountered while running the full coverage job, not introduced by these changes).
  • npm audit --audit-level=moderate could not complete due to the npm registry audit endpoint returning 403 Forbidden in this environment.

Codex Task

@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 7, 2026
@loopover-orb

loopover-orb Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Warning

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

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-07 06:52:06 UTC

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

⏸️ 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 PR adds a fixed LIMIT 100 to the ascending-PR-number-ordered author-scoped sibling query (`listOtherOpenPullRequestsForAuthor` in src/db/repositories.ts) and updates surrounding comments in src/queue/processors.ts to describe the resulting fixed-budget sample instead of the previous unbounded scan, closing a real O(N) GitHub-live-read / sibling-wake amplification vector. The change is narrow, preserves "oldest PRs win" semantics (ORDER BY ascending PR number, then LIMIT), and is backed by a new regression test that inserts 103 same-author PRs (including one inserted out of order) plus unrelated-author and subject-PR rows, and asserts the returned set is exactly the lowest 100 same-author siblings. The test exercises the real repository function against a real test DB rather than a mock, so it's a legitimate regression guard, not a fabricated one.

Nits — 4 non-blocking
  • The 100-row cap is applied at the query layer, but the diff doesn't show whether `contributorOpenPrCap` config validation enforces an upper bound below 100 — if an operator ever configured a cap above 100, the fixed-budget sample would silently undercount true open-sibling count for very prolific authors; worth a comment or validation guard confirming this is intentionally out of realistic range.
  • The comment updates (e.g. src/queue/processors.ts around the mapWithConcurrency block) are informative but slightly redundant across three separate locations describing the same fixed-budget rationale — could consolidate into one canonical explanation with the others referencing it.
  • Consider asserting in the new test (test/unit/duplicate-winner.test.ts) that the returned siblings are also correctly ordered ascending for the full 100 (not just spot-checking the first element and absence of feat(mcp): ingest GitHub CI status hints for local branches #102), to fully pin the ordering contract the cap depends on.
  • If `contributorOpenPrCap` is user/config-configurable, add an explicit clamp or validation note near its schema/config definition referencing the new 100-row query cap in src/db/repositories.ts so the two stay in sync if either changes independently.

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: 51 registered-repo PR(s), 43 merged, 343 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 51 PR(s), 343 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: Python, TypeScript, JavaScript, Ruby, Go, Kotlin, MDX, Shell
  • Official Gittensor activity: 51 PR(s), 343 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

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3911   +/-   ##
=======================================
  Coverage   93.57%   93.57%           
=======================================
  Files         340      340           
  Lines       33516    33516           
  Branches    12262    12262           
=======================================
  Hits        31364    31364           
  Misses       1528     1528           
  Partials      624      624           
Files with missing lines Coverage Δ
src/db/repositories.ts 96.61% <ø> (ø)
src/queue/processors.ts 94.53% <ø> (ø)
🚀 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 manual-review Gittensor contributor context label Jul 7, 2026
@JSONbored
JSONbored merged commit 4fab661 into main Jul 7, 2026
10 checks passed
@JSONbored
JSONbored deleted the codex/fix-unbounded-pr-cap-vulnerability branch July 7, 2026 07:15
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

Development

Successfully merging this pull request may close these issues.

1 participant