Skip to content

fix(review): only count real D1 writes in backfillContributorGateHistory inserted (#7804) - #7821

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
RealDiligent:fix/backfill-gate-history-inserted-count-7804
Jul 21, 2026
Merged

fix(review): only count real D1 writes in backfillContributorGateHistory inserted (#7804)#7821
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
RealDiligent:fix/backfill-gate-history-inserted-count-7804

Conversation

@RealDiligent

Copy link
Copy Markdown
Contributor

Summary

  • Only increment inserted when result.meta.changes > 0 after the INSERT ... ON CONFLICT DO NOTHING, mirroring src/ams/ingest.ts and src/orb/ingest.ts
  • Add regression test simulating a duplicate-id conflict (meta.changes === 0) asserting inserted stays 0 while scanned still reflects the candidate was examined

Closes #7804

Test plan

  • npm run typecheck passes locally
  • CI validate-code + validate-tests green
  • codecov/patch >= 99% on changed lines

Made with Cursor

@RealDiligent
RealDiligent requested a review from JSONbored as a code owner July 21, 2026 13:36
@superagent-security

Copy link
Copy Markdown
Contributor

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

…ory inserted (JSONbored#7804)

Co-authored-by: Cursor <cursoragent@cursor.com>
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.86%. Comparing base (ead55ca) to head (44e11de).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7821       +/-   ##
===========================================
+ Coverage   77.60%   88.86%   +11.25%     
===========================================
  Files         730       89      -641     
  Lines       76959    21239    -55720     
  Branches    22787     3681    -19106     
===========================================
- Hits        59725    18874    -40851     
+ Misses      14356     2187    -12169     
+ Partials     2878      178     -2700     
Flag Coverage Δ
shard-1 8.00% <0.00%> (-45.63%) ⬇️
shard-2 100.00% <100.00%> (?)
shard-3 64.00% <50.00%> (+13.76%) ⬆️

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

Files with missing lines Coverage Δ
src/review/contributor-gate-history-backfill.ts 100.00% <100.00%> (ø)

... and 641 files with indirect coverage changes

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

loopover-orb Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-21 13:46:36 UTC

2 files · 1 AI reviewer · no blockers · readiness 95/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
Straightforward, correctly targeted fix: `inserted` is now only incremented when `result.meta.changes > 0`, so an `ON CONFLICT DO NOTHING` no-op on `contributor_gate_history` no longer inflates the count, matching the same pattern already used in `src/ams/ingest.ts` and `src/orb/ingest.ts`. The added regression test mocks `meta.changes: 0` on the insert path and asserts `inserted` stays 0 while `scanned` still reflects the examined candidate, which is a real (not fabricated) reproduction of the bug being fixed. This closes #7804 with a minimal, well-scoped two-line change plus a matching test.

Nits — 4 non-blocking
  • The mocked D1 env in the new test (test/unit/contributor-gate-history-backfill.test.ts:152-176) duplicates the inline-mock pattern used elsewhere in the file rather than reusing createTestEnv/insertGateDecision helpers — consider whether a real D1 duplicate-id insert (two inserts with the same computed id) would exercise the same path with less mock boilerplate.
  • No test covers the case where `result.meta` itself could be shaped differently across D1 versions/self-host adapters (e.g. Postgres adapter) — worth a quick check that `meta.changes` is populated consistently by createPgAdapter's `run()` for ON CONFLICT DO NOTHING.
  • Consider adding a real (non-mocked) duplicate-id regression using createTestEnv, inserting the same review_audit/pull_requests pair twice within one batch, to prove the fix against actual D1 semantics rather than a mocked meta.changes value.
  • Verify src/selfhost/pg-adapter.ts's run() returns meta.changes accurately for a no-op ON CONFLICT so this fix behaves identically on the Postgres self-host backend.

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #7804
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 (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 395 registered-repo PR(s), 185 merged, 36 issue(s).
Contributor context ✅ Confirmed Gittensor contributor RealDiligent; Gittensor profile; 395 PR(s), 36 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: minor
Linked issue satisfaction

Addressed
The diff captures the D1 .run() result and gates the inserted increment on result.meta.changes > 0, exactly mirroring the ams/orb pattern the issue requested, and adds a regression test with meta.changes: 0 asserting inserted stays 0 while scanned reflects the examined candidate.

Review context
  • Author: RealDiligent
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, JavaScript, Ruby, Svelte, TypeScript, Markdown, MDX
  • Official Gittensor activity: 395 PR(s), 36 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
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.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 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 LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit a314577 into JSONbored:main Jul 21, 2026
12 checks passed
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

backfillContributorGateHistory's inserted counter overcounts on an ON CONFLICT DO NOTHING no-op

1 participant