Skip to content

feat(review): add cache hit/miss telemetry to grounding and review-memory (#4448) - #4658

Merged
JSONbored merged 2 commits into
mainfrom
feat/ai-cache-telemetry-4448-grounding-review-memory
Jul 10, 2026
Merged

feat(review): add cache hit/miss telemetry to grounding and review-memory (#4448)#4658
JSONbored merged 2 commits into
mainfrom
feat/ai-cache-telemetry-4448-grounding-review-memory

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Summary

Scope

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally — 100% branch coverage on the new telemetry code in both files (confirmed via a scoped coverage run; the only reported gaps in these two files are pre-existing functions outside this diff, exercised by other test files not included in that scoped run)
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate — 0 vulnerabilities
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries — hit invariant, miss invariant, and a "swallows a failing audit-event write" fail-safe test per capability, mirroring fix(review): repo-culture-profile cache works correctly but has zero hit/miss telemetry #4509's exact test structure

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests. — N/A, no auth/session surface touched.
  • API/OpenAPI/MCP behavior is updated and tested where needed. — N/A, no public API surface changed in this slice (audit events are internal telemetry, not a public response).
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks. — N/A, backend-only change.
  • Visible UI changes include a UI Evidence section. — N/A, backend-only change, no visible UI.
  • Public docs/changelogs are updated where needed. — N/A, internal telemetry only, nothing public-facing yet.

Notes

  • The remaining three uninstrumented capabilities (enrichment, impact-map, reputation) don't have an existing cache mechanism to instrument, unlike these two — they need their own investigation into what a meaningful "reuse signal" looks like for each, deferred to follow-up PRs. The aggregate reuse-rate computation, daily rollup, public API extension, and homepage trend chart are also deferred.

@superagent-security

Copy link
Copy Markdown
Contributor

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

@JSONbored JSONbored linked an issue Jul 10, 2026 that may be closed by this pull request
6 tasks
@JSONbored JSONbored self-assigned this Jul 10, 2026
@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 10, 2026
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.12%. Comparing base (450e314) to head (01184aa).
⚠️ Report is 4 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4658   +/-   ##
=======================================
  Coverage   94.12%   94.12%           
=======================================
  Files         434      434           
  Lines       38496    38510   +14     
  Branches    14038    14038           
=======================================
+ Hits        36233    36247   +14     
  Misses       1604     1604           
  Partials      659      659           
Files with missing lines Coverage Δ
src/review/grounding-wire.ts 96.73% <100.00%> (+0.26%) ⬆️
src/review/review-memory-wire.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.

@loopover-orb

loopover-orb Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Caution

🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥🟥

🛑 Gittensory review result - fixes required

Review updated: 2026-07-10 10:11:30 UTC

4 files · 1 AI reviewer · 2 blockers · readiness 93/100 · CI failing · unstable

🛑 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 adds cache hit/miss telemetry (incr() counter + recordAuditEvent) to two existing caches — the grounding file-content D1 cache in grounding-wire.ts and the in-isolate review-suppression TTL cache in review-memory-wire.ts — mirroring the established repo_culture_profile (#4509) pattern exactly. Both call sites correctly place the miss branch on the fallthrough path and wrap recordAuditEvent in .catch(() => undefined) so a failed audit write never breaks the cached-value return, which is verified by dedicated 'swallows a failing audit-event write' tests in both test files. Test coverage is thorough: hit, miss, TTL-expiry-as-miss, and audit-write-failure scenarios are all exercised with concrete assertions on both the rendered metrics text and the audit_events table.

Nits — 5 non-blocking
  • grounding-wire.ts:145-153 and review-memory-wire.ts:47-55 now `await recordAuditEvent(...)` on every cache HIT before returning, adding a D1 write to a path that previously had zero I/O (review-memory) or only the cache-lookup read (grounding) — since `getFileContent` is called once per changed file, consider firing the audit write without awaiting it (fire-and-forget) to avoid serializing D1 latency into the grounding fetch loop.
  • The `detail` strings duplicate what `eventType` already encodes (e.g. 'reused a cached grounding file blob instead of re-fetching from GitHub' vs `github_app.grounding_cache_hit`) — consistent with existing repo_culture_profile events, so not asking for a change, just noting the redundancy is inherited rather than new.
  • grounding-wiring.test.ts's cache-hit test relies on two separate `makeGithubFileFetcher` calls sharing the same underlying D1-backed cache — worth a one-line comment (like review-memory-store.test.ts already has) clarifying the cache is keyed by (repo, path, ref) at the D1 layer, not per-fetcher-instance, so a reader doesn't assume the second fetcher instance is coincidentally warm.
  • Consider whether recordAuditEvent on every cache hit is worth the write volume long-term (grounding fetches can be dozens of files per PR); if audit-event volume becomes a concern, sampling or batching could be a follow-up.
  • The `/* v8 ignore next */` block in grounding-wire.ts is unrelated to this diff and can be ignored for this review.

Why this is blocked

  • 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.

CI checks failing

  • codecov/patch — 93.75% of diff hit (target 99.00%)
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, 330 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 48 PR(s), 330 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), 330 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

…mory (#4448)

Two of the six AI-touching capabilities #4448 identified as having zero
reuse-rate signal: grounding's per-file GitHub Contents cache
(getCachedGroundingFileContent) and review-memory's in-isolate
suppression-list TTL cache (getCachedReviewSuppressions, #4508). Both
already correctly avoid redundant work -- they just had no telemetry
proving it, mirroring the exact gap #4509 closed for repo-culture-profile.

Instruments both with the SAME incr()+recordAuditEvent hit/miss pair
convention already established for repo_culture_profile / ai_review /
ai_slop / linked_issue_satisfaction / miner_detection, so a future
aggregate reuse-rate computation (#4448's remaining deliverable) can read
a consistent event shape across every instrumented capability.

Part of epic #4445's #4448. The remaining three uninstrumented
capabilities (enrichment, impact-map, reputation -- none of which have an
existing cache mechanism to instrument, unlike these two), the aggregate
reuse-rate computation, the daily rollup, the public API extension, and
the homepage trend chart are deferred to follow-up PRs.
…/review-memory (#4448)

codecov/patch flagged 93.75% on the prior commit -- both new hit/miss
telemetry sites wrap recordAuditEvent in .catch(() => undefined), but only
the cache-HIT side's failure path had a test; the cache-MISS side's catch
callback was never actually invoked by any test, so it never executed.
Adds the missing miss-side "swallows a failing audit-event write" test to
both files, mirroring the existing hit-side test exactly.
@JSONbored
JSONbored force-pushed the feat/ai-cache-telemetry-4448-grounding-review-memory branch from 9eb4b85 to 01184aa Compare July 10, 2026 10:24
@JSONbored
JSONbored merged commit 978cba4 into main Jul 10, 2026
7 checks passed
@JSONbored
JSONbored deleted the feat/ai-cache-telemetry-4448-grounding-review-memory branch July 10, 2026 10:30
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.

feat(stats): AI-feature cache/reuse-efficiency rate, tracked over time, public

1 participant