Skip to content

fix(review): ops-anomaly scanner's own SQL query is malformed (396 Sentry events, escalating) #4997

Description

@JSONbored

Summary

The ops-anomaly scanner's own SQL query is broken — 396 events, escalating (first seen 3 days ago, still firing this hour). This is the same src/review/ops-wire.ts pipeline referenced when discussing extending anomaly detection for other correctness bugs, so it's worth fixing before relying on it further.

Evidence (Sentry)

GITTENSORY-1Hops_anomaly_repo_error: Failed query: select json_extract("metadata_json", '$.pullNumber'), count(*) from "ai_usage_events" where ("ai_usage_events"."feature" = ? and "ai_usage_events"."created_at" >= ? and json_extract("ai_... (truncated in Sentry's title). First seen 2026-07-08, last seen 2026-07-11 (1 hour ago), substatus escalating. One captured event tags repo: vouchdev/vouchnot one of the three gated repos (gittensory/metagraphed/awesome-claude) — worth confirming whether that's a real registered repo, stale/test data, or a symptom of the same query bug producing a garbage repo label.

Root cause (Sentry Seer — plausible, verify the specific query)

Seer's summary: "Replace json_extract-based ai_usage_events query with an audit_events LIKE query, matching the working findHottestReviewTargetForRepo pattern." Find findHottestReviewTargetForRepo (or its sibling findHottestInconclusiveReviewTargetForRepo, both imported into src/review/ops-wire.ts) as the known-working reference pattern, and find the broken query (likely a different helper feeding computeOpsStats/runOpsAlerts) to bring in line with it.

Requirements

  1. Fix the malformed query so the ops-anomaly scan runs cleanly for every repo, every scan tick.
  2. Investigate the vouchdev/vouch repo tag — confirm whether it's a real tracked repo or a data artifact, and note the finding either way.
  3. Since this pipeline emits gittensory_ops_anomaly_total (a Prometheus counter with its own alert rule, GittensoryOpsAnomalyDetected) — confirm this SQL failure isn't ALSO silently suppressing real anomaly detections for whichever repos it fails on.

Deliverables

  • Fixed query, matching the working sibling pattern.
  • Regression test covering the previously-broken query shape.
  • A one-line note on the vouchdev/vouch finding.

Metadata

Metadata

Assignees

Labels

maintainer-onlyOwner-only work — yields no Gittensor points.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions