Skip to content

fix(review): repo-culture-profile cache works correctly but has zero hit/miss telemetry #4509

Description

@JSONbored

Part of #4496. P12 — low severity, observability-only (no functional defect).

Context

Unlike enrichment/grounding/impact-map, repo-culture-profile is NOT exposed to per-invocation recomputation — it has a genuine, correctly-functioning cache (signal_snapshots table, 6-hour TTL, plus a merged-PR-count drift invalidation, src/review/repo-culture-profile.ts:229-243) — but that cache's hit/miss branch is completely unlabeled: it emits no incr() counter and no audit event distinguishing a cache hit from a fresh D1 derive.

Compare to ai_review's cache sitting right beside it in the same prompt-assembly pipeline, which has full instrumentation: incr("gittensory_ai_review_cache_hit_total") (processors.ts:9840) plus a paired recordAuditEvent (github_app.ai_review_cache_hit), and the mirror incr("gittensory_ai_review_cache_miss_total") (processors.ts:9874) plus github_app.ai_review_cache_miss. readCachedCultureProfile (repo-culture-profile.ts:229-243) and extractRepoCultureProfile's hit/miss branches (lines 278-294) have neither.

This is the exact gap #4448 (part of tonight's earlier efficiency-tracking epic, #4445) already identified for 6 currently-uninstrumented AI capabilities — repo-culture-profile is one of them. Confirmed the underlying cache reads (listSignalSnapshots, src/db/repositories.ts:4742-4751) DO have a correct ORDER BY/LIMIT, so this is NOT the same "non-deterministic ordering defeats the cache" bug as the fixed linked_issue_satisfaction issue (#4481) — the cache itself works correctly; only the metrics/audit-event layer is absent.

Requirements

  • Add incr()/recordAuditEvent calls on both the readCachedCultureProfile hit path and the extractRepoCultureProfile miss/re-derive path, mirroring the ai_review cache's instrumentation exactly (event names, metadata shape).
  • This sub-issue's scope is narrower than feat(stats): AI-feature cache/reuse-efficiency rate, tracked over time, public #4448's full 6-capability rollout — it only covers repo-culture-profile. If feat(stats): AI-feature cache/reuse-efficiency rate, tracked over time, public #4448 is picked up first, coordinate to avoid duplicate work; otherwise this can ship independently as a small, self-contained instrumentation addition.
  • Invariant + regression tests (non-negotiable): a test asserting a cache hit fires exactly the hit counter/audit-event pair and NOT the miss pair; a test asserting a cache miss (TTL expired, or drift-invalidated) fires exactly the miss counter/audit-event pair and NOT the hit pair; a regression test for the drift-invalidation path specifically (a merged-PR-count change since the last snapshot), confirming it's correctly counted as a miss, not silently uninstrumented.

Deliverables

  • Hit/miss incr() counters added, matching the ai_review cache's naming convention
  • Hit/miss recordAuditEvent calls added, matching the ai_review cache's event shape
  • Invariant tests: hit fires only hit telemetry, miss fires only miss telemetry
  • Regression test: drift-invalidation path is correctly counted as a miss

Expected outcome

An operator dashboard can see repo-culture-profile's actual cache reuse rate, closing one of the six capability gaps #4448 already identified — no functional change, purely restoring parity with the sibling ai_review cache's observability.

References

Effort

XS

Metadata

Metadata

Assignees

Labels

gittensor:bugGittensor-scored bug fix — scores a 0.05x multiplier.maintainer-onlyOwner-only work — yields no Gittensor points.orbGittensory Orb related - maintainer self-hosting analytics.

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions