Skip to content

Add AI-slop detection with metrics and UI#72

Open
vtvz wants to merge 3 commits intomasterfrom
ai-slop-metrics
Open

Add AI-slop detection with metrics and UI#72
vtvz wants to merge 3 commits intomasterfrom
ai-slop-metrics

Conversation

@vtvz
Copy link
Owner

@vtvz vtvz commented Mar 16, 2026

Track AI slop detection results per provider (Spotify AI Blocker, Soul Over AI, SHLabs, Human Made) with database counters, metrics collection for both InfluxDB and Prometheus, and display in user and global statistics views.

Track AI slop detection results per provider (Spotify AI Blocker,
Soul Over AI, SHLabs, Human Made) with database counters, metrics
collection for both InfluxDB and Prometheus, and display in user
and global statistics views.
@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

📝 Walkthrough

Walkthrough

Adds AI-slop detection: four new per-provider counters, DB schema and ORM fields, service builder support, Prometheus and Influx collectors, queue integration to increment counters, and Telegram UI + locale strings to surface totals and breakdowns.

Changes

Cohort / File(s) Summary
Database & ORM
migrations/20260308152848_add_ai_slop_detection_counters.sql, src/entity/user.rs
Adds four bigint columns to user and corresponding Model fields, Column enum variants, and ColumnType mappings.
Service Layer
src/services/user.rs
Changes checked_lyrics to accept Option<&lyrics::Provider>; adds ai_slop builder to UserStatsIncreaseQueryBuilder; extends UserStats with four ai_slop fields; get_stats now returns coalesced ai_slop metrics.
Queue Processing
src/queue/track_check.rs
Uses provider as reference when calling checked_lyrics; calls increase_stats_query(...).ai_slop(provider.as_ref()).exec(...) during AI-slop processing.
Metrics Collection
src/metrics/prometheus.rs, src/metrics/prometheus_collector.rs, src/metrics/influx_collector.rs
Adds ai_slop_detection IntGaugeVec in Prometheus, introduces AISlopDetectionStats for InfluxDB, and populates both collectors with the four ai_slop metrics from get_stats.
Telegram UI & Localization
src/telegram/actions/admin_users/details.rs, src/telegram/actions/global_stats.rs, src/telegram/actions/stats.rs, locales/actions.yml
Adds "AI Slop Detection" display to user details, global stats, and stats actions; computes totals and percentages; appends English and Russian locale strings.

Sequence Diagram

sequenceDiagram
    participant Queue as Track Queue
    participant Service as UserService
    participant DB as Database
    participant Metrics as Metrics Collector
    participant Prometheus as Prometheus
    participant InfluxDB as InfluxDB

    Queue->>Service: increase_stats_query(user_id).ai_slop(provider)
    Service->>DB: UPDATE user SET ai_slop_* = ai_slop_* + 1
    DB-->>Service: OK

    Metrics->>Service: get_stats(user_id)
    Service->>DB: SELECT coalesce(ai_slop_*, 0)...
    DB-->>Service: UserStats (includes ai_slop_*)
    Service-->>Metrics: ai_slop values

    Metrics->>Prometheus: set ai_slop_detection_total[label=provider]
    Metrics->>InfluxDB: write measurement "ai_slop_detection"
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 35.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description accurately describes the changes: tracking AI slop detection per provider with database counters and metrics collection.
Title check ✅ Passed The title accurately summarizes the main changes: adding AI-slop detection functionality with corresponding metrics collection and UI updates across multiple components.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ai-slop-metrics
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Repository owner deleted a comment from coderabbitai bot Mar 16, 2026
@vtvz vtvz changed the title Add AI slop detection statistics tracking @coderabbitai Mar 16, 2026
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/metrics/prometheus.rs`:
- Around line 115-121: The context message for the ai_slop_detection metric
registration is a copy-paste leftover referencing "lyrics_source"; update the
context string used after register_int_gauge_vec_with_registry for
ai_slop_detection to mention "ai_slop_detection" (or a matching descriptive
message) so the .context("Failed to register ...") call correctly identifies the
ai_slop_detection metric when reporting errors.

In `@src/queue/track_check.rs`:
- Around line 279-282: The UserService::increase_stats_query call inside
check_ai_slop currently awaits .exec(...) and propagates errors, causing
check_ai_slop to return early; change it to a best-effort fire-and-forget (or
swallow/log errors) so failures don't abort the rest of check_ai_slop's
skip/notify logic. Specifically, wrap the await in a non-fallible path: spawn a
background task or .await and catch/map_err to log the error via your logger (or
ignore) instead of using the ? operator, leaving check_ai_slop to continue
execution even if UserService::increase_stats_query(...).exec(app.db()).await
fails.

In `@src/services/user.rs`:
- Around line 74-84: The ai_slop builder method currently buckets solely by
provider, which misclassifies cases where AISlopDetectionResult.prediction and
provider must be considered together; change the signature of ai_slop (in
src/services/user.rs) to accept the prediction (or the whole
AISlopDetectionResult) and map buckets from the tuple (prediction, provider)
instead of provider alone, e.g. treat (HumanMade, Some(_)) and (HumanMade, None)
as HumanMade bucket, treat (AIMade, Some(SpotifyAIBlocker)) as
AISlopSpotifyAIBlocker, handle the fail-open path (provider: None, prediction:
HumanMade) as HumanMade, and update the col selection logic that currently uses
UserColumn::AISlopSpotifyAIBlocker / AISlopSoulOverAI / AISlopSHLabs /
AISlopHumanMade accordingly so Expr::col(col).add(1) increments the correct
bucket.

In `@src/telegram/actions/admin_users/details.rs`:
- Around line 121-124: The ai_slop_total calculation incorrectly includes
stats.ai_slop_human_made (and the same inclusion in the later block around the
second occurrence), which makes the "AI Slop Detection" total include non-AI
results; change the ai_slop_total expression to sum only the provider buckets
(stats.ai_slop_spotify_ai_blocker + stats.ai_slop_soul_over_ai +
stats.ai_slop_shlabs) and remove stats.ai_slop_human_made from both occurrences,
or alternatively rename the variable/label to something like checks_total if you
intend to keep human_made included.

In `@src/telegram/actions/global_stats.rs`:
- Around line 53-59: The ai_slop ratio computations can divide by zero when
ai_slop_total == 0; update the logic in src/telegram/actions/global_stats.rs
around the ai_slop_* variables to check ai_slop_total before dividing (use
ai_slop_total > 0) and compute the four ratios
(ai_slop_spotify_ai_blocker_ratio, ai_slop_soul_over_ai_ratio,
ai_slop_shlabs_ratio, ai_slop_human_made_ratio) only when the total is nonzero,
otherwise set them to 0.0 (or an explicit safe value) so no NaN appears in the
Telegram output; reference the ai_slop_total, ai_slop_spotify_ai_blocker_ratio,
ai_slop_soul_over_ai_ratio, ai_slop_shlabs_ratio, and ai_slop_human_made_ratio
symbols when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9db1abbe-546d-4fb3-b6ae-9e42c9620d0e

📥 Commits

Reviewing files that changed from the base of the PR and between 27c59a7 and bb9c983.

📒 Files selected for processing (11)
  • locales/actions.yml
  • migrations/20260308152848_add_ai_slop_detection_counters.sql
  • src/entity/user.rs
  • src/metrics/influx_collector.rs
  • src/metrics/prometheus.rs
  • src/metrics/prometheus_collector.rs
  • src/queue/track_check.rs
  • src/services/user.rs
  • src/telegram/actions/admin_users/details.rs
  • src/telegram/actions/global_stats.rs
  • src/telegram/actions/stats.rs

@coderabbitai coderabbitai bot changed the title @coderabbitai Add AI-slop detection with metrics and UI Mar 16, 2026
@vtvz vtvz deployed to production March 16, 2026 18:30 — with GitHub Actions Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant