Skip to content

fix(review): exclude current head from auto-pause count - #3719

Merged
JSONbored merged 1 commit into
mainfrom
codex/fix-auto-pause-functionality-to-retain-ai-blockers
Jul 6, 2026
Merged

fix(review): exclude current head from auto-pause count#3719
JSONbored merged 1 commit into
mainfrom
codex/fix-auto-pause-functionality-to-retain-ai-blockers

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent a regression where the auto-pause threshold for AI reviews counted the current head and thereby skipped reuse of already-published cached AI findings, which could remove blockers from later gate evaluations.

Description

  • Change countPublishedAiReviewHeads to accept an optional currentHeadSha and exclude it from the SQL COUNT(DISTINCT head_sha) so the threshold only counts prior published heads.
  • Wire the current advisory head (headSha) into resolveAutoReviewSkipForPullRequest so the helper can exclude the active head when deciding a pause.
  • Add a regression unit test that asserts the current published head is excluded from the pause threshold and retain the old null/no-current-head behavior.
  • Update an existing auto-review-wiring test to expect the current head SHA is forwarded to the count helper.

Testing

  • Ran the targeted unit tests with npx vitest run test/unit/ai-review-cache.test.ts test/unit/auto-review-wiring.test.ts, and all tests in those files passed.
  • Ran TypeScript typecheck with npm run typecheck, which passed.
  • Attempted a full coverage run (npm run test:coverage) and a coverage-enabled run of the two targeted tests; the targeted tests ran cleanly but a full global coverage run was not completed in this environment (global coverage threshold check did not finish here).
  • npm audit --audit-level=moderate could not complete due to the registry 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 6, 2026
@loopover-orb

loopover-orb Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Warning

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

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-06 06:30:24 UTC

4 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 fixes a real regression: countPublishedAiReviewHeads previously counted the current PR head among 'already reviewed' heads for the auto_pause_after_reviewed_commits threshold, which could trigger a premature pause and cause cached blocker findings from the current head to be skipped/dropped from gate evaluation. The fix adds an optional currentHeadSha parameter, conditionally appends 'AND head_sha != ?' to the SQL COUNT(DISTINCT head_sha) query with correctly ordered bind params, and wires args.headSha through resolveAutoReviewSkipForPullRequest at the actual call site. Tests cover both the exclusion behavior and the prior null/no-current-head behavior, and an existing wiring test was updated to assert headSha is forwarded to the count helper — this is a root-cause fix at the source query, not a symptom patch.

Nits — 4 non-blocking
  • src/db/repositories.ts: currentHeadSha is only excluded when truthy, so an empty-string head_sha (if that could ever occur) would silently fall back to counting it — worth a comment noting head_sha is always non-empty by contract.
  • The regression test in ai-review-cache.test.ts is a good addition, but consider also asserting the SQL bind argument order directly (e.g. via a prepare spy) to guard against future param-order regressions rather than relying solely on end-to-end count assertions.
  • Consider extracting the conditional-clause-building pattern (`currentHeadClause` + conditional bind array) into a small helper if this exclude-current-head pattern is likely to recur elsewhere in repositories.ts.
  • Double check other callers of countPublishedAiReviewHeads (if any exist beyond resolveAutoReviewSkipForPullRequest) also pass currentHeadSha where applicable, since the parameter is optional and easy to forget at a new call site.

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: 54 registered-repo PR(s), 46 merged, 439 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 54 PR(s), 439 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 registration is not available in the local Gittensory cache.
  • Public profile languages: Python, TypeScript, JavaScript, Ruby, Go, Kotlin, MDX, Shell
  • Official Gittensor activity: 54 PR(s), 439 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.
  • No action.
  • 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 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.36%. Comparing base (1c0a636) to head (6b96a7d).
⚠️ Report is 9 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3719   +/-   ##
=======================================
  Coverage   93.36%   93.36%           
=======================================
  Files         315      315           
  Lines       32204    32206    +2     
  Branches    11812    11814    +2     
=======================================
+ Hits        30066    30068    +2     
  Misses       1507     1507           
  Partials      631      631           
Files with missing lines Coverage Δ
src/db/repositories.ts 96.52% <100.00%> (+<0.01%) ⬆️
src/queue/processors.ts 94.07% <100.00%> (ø)
🚀 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 6, 2026
@JSONbored
JSONbored merged commit a6ce5fa into main Jul 6, 2026
10 checks passed
@JSONbored
JSONbored deleted the codex/fix-auto-pause-functionality-to-retain-ai-blockers branch July 6, 2026 06:33
JSONbored added a commit that referenced this pull request Jul 8, 2026
…it never paused (#4319)

countPublishedAiReviewHeads excluded the current head SHA from its count
(#3719), meaning a PR swept repeatedly with no new commits could never
reach auto_pause_after_reviewed_commits' threshold -- the one head it had
ever been reviewed on was always the "current" one, always subtracted
back out. Confirmed live: one PR took 63 fresh AI calls across 12 hours
of scheduled sweeps with zero new commits.

#3719 excluded the current head specifically to avoid a real problem:
once paused, the cached review's findings were never reapplied, so an
already-published blocker would silently vanish from later gate
evaluations. Fixes that properly instead of avoiding it: the count now
includes the current head (matching its own "published review count"
contract), and a new reuse branch in processors.ts reapplies the last
published review's findings whenever the pause reason fires, mirroring
the existing frozen-for-manual-review reuse pattern.
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