Skip to content

feat(metrics): count Redis webhook dedup hits (#2075)#3544

Merged
JSONbored merged 1 commit into
JSONbored:mainfrom
james3773:feat/metrics-redis-webhook-dedup-counter-2075
Jul 5, 2026
Merged

feat(metrics): count Redis webhook dedup hits (#2075)#3544
JSONbored merged 1 commit into
JSONbored:mainfrom
james3773:feat/metrics-redis-webhook-dedup-counter-2075

Conversation

@james3773

Copy link
Copy Markdown
Contributor

Summary

  • Add isWebhookDeliveryDuplicate and rememberWebhookDelivery in src/selfhost/redis-cache.ts to emit gittensory_webhook_dedup_total{backend="redis"} on Redis-backed webhook redelivery hits
  • Wire the self-host webhook handler through those helpers; Redis errors fail open without incrementing
  • Unit tests cover first-time delivery, dedup hit, and Redis-error paths

Closes #2075

Test plan

  • npm run test -- test/unit/selfhost-redis-cache.test.ts
  • npm run selfhost:env-reference:check (no UI/env-reference drift)
  • Full npm run test:ci (9323/9324 passed; one unrelated flaky timeout in ai-summaries.test.ts)

Made with Cursor

Expose isWebhookDeliveryDuplicate/rememberWebhookDelivery helpers and
wire server dedup through them so redeliveries increment
gittensory_webhook_dedup_total{backend="redis"} without shifting
selfhost env-reference line numbers.

Closes JSONbored#2075

Co-authored-by: Cursor <cursoragent@cursor.com>
@james3773
james3773 requested a review from JSONbored as a code owner July 5, 2026 16:33
@superagent-security superagent-security Bot added the contributor:flagged Contributor flagged for review by trust analysis. label Jul 5, 2026
@superagent-security

Copy link
Copy Markdown
Contributor

🚨 Contributor flagged. Click here for more info: Superagent Dashboard

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

loopover-orb Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Warning

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

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-05 16:40:04 UTC

3 files · 1 AI reviewer · no blockers · readiness 80/100 · CI green · clean

⏸️ Suggested Action - Manual Review

  • Touches a guarded path — held for manual review: This PR changes guardrail-protected path(s): src/selfhost/redis-cache.ts (matched src/selfhost/**).

Review summary
This PR adds `isWebhookDeliveryDuplicate` and `rememberWebhookDelivery` helpers in redis-cache.ts to encapsulate the existing delivery-ID dedup cache lookup/write, and wires them into server.ts's webhook handler so a dedup hit increments `gittensory_webhook_dedup_total{backend="redis"}` while Redis errors still fail open (return false / skip the metric) exactly as before. The change preserves the original control flow (204 on dedup hit, best-effort write on success) and adds a labeled seed value in the metrics-seeding loop so the series appears from first scrape. Tests cover first-time delivery, dedup hit with metric assertion, and the Redis-error fail-open path, which matches the actual behavior in the diff.

Nits — 6 non-blocking
  • src/selfhost/redis-cache.ts: `rememberWebhookDelivery` already swallows errors internally via try/catch, so the caller's `.catch(() => undefined)` in server.ts is redundant belt-and-suspenders — fine to leave but worth a comment noting it's intentional double-safety.
  • src/selfhost/redis-cache.ts:32: the `ttlSeconds = 300` default duplicates the previous inline magic number without a named constant explaining the 5-minute choice (matches GitHub's webhook retry window, per the module comment) — consider hoisting to a constant for discoverability.
  • Adding the `backend="redis"` label changes the metric's label set from unlabeled to labeled; confirm any existing Grafana panel or alert on `gittensory_webhook_dedup_total` (unlabeled) is updated to match, since mixing labeled/unlabeled samples for the same metric name is invalid in Prometheus.
  • Consider adding a short unit test asserting the seeded zero-value series `gittensory_webhook_dedup_total{backend="redis"} 0` appears at boot (server.ts's seeding loop change) so the first-scrape guarantee has explicit coverage.
  • webhookDeliveryCacheKey is a small pure helper — fine as-is, but if a future in-memory backend needs the same dedup+metric pattern, extracting a backend-agnostic wrapper now would avoid duplicating this logic later.
  • Touches a guarded path — held for manual review — A maintainer must review and merge this change.
Signal Result Evidence
Code review ✅ No blockers 1 reviewer
Linked issue ✅ Linked #2075
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 ❌ 5/25 Preflight is holding this PR: the review lane is unavailable, so it is not ready for automated review.
Contributor workload ✅ 10/10 Author activity: 1054 registered-repo PR(s), 728 merged, 41 issue(s).
Contributor context ✅ Confirmed Gittensor contributor jony376; Gittensor profile; 1054 PR(s), 41 issue(s).
Gate result ⚠️ Not blocking Advisory; not blocking this PR.
Review context
  • Author: jony376
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository registration is not available in the local Gittensory cache.
  • Public profile languages: TypeScript, Python, JavaScript, Rust, MDX, Clojure, Cuda, Dart
  • Official Gittensor activity: 1054 PR(s), 41 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Await review-lane availability.
  • Refresh registry data or choose a registered active repo.
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 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.09%. Comparing base (eb8cb4f) to head (a1807f6).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3544   +/-   ##
=======================================
  Coverage   93.09%   93.09%           
=======================================
  Files         301      301           
  Lines       31450    31462   +12     
  Branches    11483    11484    +1     
=======================================
+ Hits        29279    29291   +12     
  Misses       1517     1517           
  Partials      654      654           
Files with missing lines Coverage Δ
src/selfhost/redis-cache.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JSONbored
JSONbored merged commit d432c8b into JSONbored:main Jul 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor:flagged Contributor flagged for review by trust analysis. 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.

feat(metrics): emit a webhook-dedup hit counter from the Redis delivery cache

2 participants