Commit 91450d45 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Disable AI identification fallback - too unreliable to keep in the live upload path

Per explicit instruction: Gemini's last-resort identification and
genre-backfill calls are now gated behind a new AI_IDENTIFICATION_ENABLED
flag, off by default. Shazam/AcoustID remain the only identification
sources - a song neither can match now comes back unidentified
immediately instead of waiting out an unreliable AI call first.
parent db4acbbe
Pipeline #1287 canceled with stage
...@@ -9,7 +9,7 @@ from pydantic import BaseModel ...@@ -9,7 +9,7 @@ from pydantic import BaseModel
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
import src.telegram_worker.telegram_sync as telegram_sync import src.telegram_worker.telegram_sync as telegram_sync
from src.core.config import logger from src.core.config import AI_IDENTIFICATION_ENABLED, logger
from src.core.database import IdentifiedTrack, LibrarySong, User, get_db from src.core.database import IdentifiedTrack, LibrarySong, User, get_db
from src.core.security import get_current_user from src.core.security import get_current_user
from src.services import storage from src.services import storage
...@@ -108,9 +108,11 @@ async def _identify_tag_and_store( ...@@ -108,9 +108,11 @@ async def _identify_tag_and_store(
candidates = await identify_audio(raw_file_path) candidates = await identify_audio(raw_file_path)
candidate = candidates[0] if candidates else None candidate = candidates[0] if candidates else None
if not candidate: if not candidate and AI_IDENTIFICATION_ENABLED:
gemini_result = await identify_with_gemini(raw_file_path, language_preference) gemini_result = await identify_with_gemini(raw_file_path, language_preference)
candidate = gemini_result if gemini_result else {} candidate = gemini_result if gemini_result else {}
elif not candidate:
candidate = {}
# Always attempted, not gated on "candidate already has plain lyrics" - Shazam and # Always attempted, not gated on "candidate already has plain lyrics" - Shazam and
# Gemini can both independently return a plain lyrics snippet as part of # Gemini can both independently return a plain lyrics snippet as part of
...@@ -135,7 +137,7 @@ async def _identify_tag_and_store( ...@@ -135,7 +137,7 @@ async def _identify_tag_and_store(
# starving the fallback path that's actually needed for songs nothing else can match. # starving the fallback path that's actually needed for songs nothing else can match.
source = candidate.get("source") source = candidate.get("source")
genre_missing = not candidate.get("genre") or candidate.get("genre") == "Unknown Genre" genre_missing = not candidate.get("genre") or candidate.get("genre") == "Unknown Genre"
if genre_missing and source not in ("Shazam", "AcoustID"): if genre_missing and source not in ("Shazam", "AcoustID") and AI_IDENTIFICATION_ENABLED:
title, artist = candidate.get("title", ""), candidate.get("artist", "") title, artist = candidate.get("title", ""), candidate.get("artist", "")
if title and artist and title != "Unknown" and artist != "Unknown": if title and artist and title != "Unknown" and artist != "Unknown":
try: try:
......
...@@ -19,6 +19,15 @@ DOCS_PASSWORD = os.getenv("DOCS_PASSWORD") ...@@ -19,6 +19,15 @@ DOCS_PASSWORD = os.getenv("DOCS_PASSWORD")
# (stax_webapp/src/config/flags.ts), which already hides the nav entry/route. # (stax_webapp/src/config/flags.ts), which already hides the nav entry/route.
REMIX_ENABLED = os.getenv("REMIX_ENABLED", "false").lower() == "true" REMIX_ENABLED = os.getenv("REMIX_ENABLED", "false").lower() == "true"
# Gate for every Gemini call in the music identification pipeline (the last-resort
# full-identification fallback in identify_with_gemini, and the inline genre-backfill call in
# music.py's _identify_tag_and_store) - turned off 2026-11-23 at the user's explicit request
# after repeated unreliability (Google's gemini-3.7-flash returning 503 "high demand", the SDK
# silently retrying until timeout). Off by default: Shazam/AcoustID are the only identification
# sources while this is false - a song neither can match just comes back unidentified, fast,
# instead of waiting out a flaky AI call first.
AI_IDENTIFICATION_ENABLED = os.getenv("AI_IDENTIFICATION_ENABLED", "false").lower() == "true"
# Origins allowed to call this API from a browser (the stax_webapp frontend, dev and prod). # Origins allowed to call this API from a browser (the stax_webapp frontend, dev and prod).
# Comma-separated in the env var. Auth here is a Bearer token in localStorage, never a # Comma-separated in the env var. Auth here is a Bearer token in localStorage, never a
# cookie, so allowing these origins doesn't need allow_credentials. # cookie, so allowing these origins doesn't need allow_credentials.
......
...@@ -346,3 +346,25 @@ def test_music_upload_same_fingerprint_different_users_both_get_their_own_song(c ...@@ -346,3 +346,25 @@ def test_music_upload_same_fingerprint_different_users_both_get_their_own_song(c
assert len(songs_b) == 1 assert len(songs_b) == 1
songs_a = db_session.query(LibrarySong).filter(LibrarySong.user_id == user_a.id).all() songs_a = db_session.query(LibrarySong).filter(LibrarySong.user_id == user_a.id).all()
assert len(songs_a) == 1 assert len(songs_a) == 1
def test_music_upload_skips_gemini_fallback_when_ai_identification_disabled(client, db_session, auth_as, mocker):
"""AI_IDENTIFICATION_ENABLED defaults to false (turned off 2026-11-23 after Gemini's
repeated unreliability) - a song neither Shazam nor AcoustID can match should come back
unidentified rather than falling through to identify_with_gemini."""
headers, _ = auth_as()
mocker.patch("src.api.routers.music.compute_fingerprint", return_value=None)
mocker.patch("src.api.routers.music.identify_audio", return_value=[])
identify_with_gemini = mocker.patch("src.api.routers.music.identify_with_gemini")
mocker.patch("src.api.routers.music.tag_and_convert_audio", return_value="/tmp/tagged.mp3")
mocker.patch("src.api.routers.music.storage.store_final", return_value=("/tmp/does-not-need-to-exist.mp3", "/downloads/1/x.mp3"))
mocker.patch("src.api.routers.music.fetch_lyrics", return_value={"lyrics": None, "synced_lyrics": None})
response = client.post(
"/music/upload",
headers=headers,
files={"file": ("test.mp3", b"fake mp3 bytes", "audio/mpeg")},
)
assert response.status_code == 200
assert response.json()["metadata"]["title"] == "Unknown"
identify_with_gemini.assert_not_called()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment