Commit d761f2d6 authored by Aryan Noshirvnai's avatar Aryan Noshirvnai

Discovery: confidence meter + source label, updated Roadmap for backend direction

Confidence meter (small bar + %) and source label render on each Discovery
history row when the identification source produced a real score. Roadmap
updated to reflect today's backend decisions: Discovery app-wide library
matching and confidence field marked done, Telegram fully-automatic scanning
marked as an intentional non-goal rather than deferred, reverse proxy and
media-storage-optimization tracked with their confirmed direction, and the
Postgres/PostGIS migration added as a tracked item (previously discussed but
never written down).
Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019i3NAUkLkHNbsPg5vKfzF9
parent d68d0fb5
Pipeline #1139 failed with stage
in 14 minutes and 57 seconds
......@@ -7,6 +7,11 @@ export interface DiscoveredSong {
artist: string
genre: string | null
coverart: string | null
/** 0-100, null when the identification source doesn't produce a real score (Shazam gets a
* fixed high value since a hit is already a fingerprint match, not a guess; Gemini stays
* null - see music_identification.py). */
confidence: number | null
source: string | null
detected_at: string
liked: boolean | null
/** Set when this match's title+artist already exists in the caller's own library - lets the
......@@ -37,7 +42,12 @@ export async function listen(file: File) {
body,
})
return res.json() as Promise<
| { status: 'success'; detected: Record<string, unknown>; discovery_id: number }
| {
status: 'success'
detected: { title: string; artist: string; confidence: number | null; source: string | null } & Record<string, unknown>
discovery_id: number
library_song_id: number | null
}
| { status: 'error'; message: string }
>
}
......@@ -15,6 +15,8 @@ const SONG = {
artist: 'Test Artist',
genre: 'Pop',
coverart: null,
confidence: null,
source: null,
detected_at: '2026-01-01T00:00:00Z',
liked: null,
library_song_id: null,
......@@ -90,7 +92,7 @@ describe('Discovery', () => {
it('requests noise suppression and auto gain, not echo cancellation, when starting to listen', async () => {
const { getUserMedia } = mockMicSupport()
vi.spyOn(discoveryApi, 'listen').mockResolvedValue({ status: 'success', detected: {}, discovery_id: 1 })
vi.spyOn(discoveryApi, 'listen').mockResolvedValue({ status: 'success', detected: { title: '', artist: '', confidence: null, source: null }, discovery_id: 1, library_song_id: null })
renderDiscovery()
const button = await screen.findByLabelText(/Listen for what/)
......@@ -116,8 +118,9 @@ describe('Discovery', () => {
mockMicSupport()
const listenSpy = vi.spyOn(discoveryApi, 'listen').mockResolvedValue({
status: 'success',
detected: { title: 'Found Song', artist: 'Found Artist' },
detected: { title: 'Found Song', artist: 'Found Artist', confidence: null, source: null },
discovery_id: 42,
library_song_id: null,
})
renderDiscovery()
......@@ -157,7 +160,7 @@ describe('Discovery', () => {
it('releases the microphone once recording stops', async () => {
const { stopTrack } = mockMicSupport()
vi.spyOn(discoveryApi, 'listen').mockResolvedValue({ status: 'success', detected: {}, discovery_id: 1 })
vi.spyOn(discoveryApi, 'listen').mockResolvedValue({ status: 'success', detected: { title: '', artist: '', confidence: null, source: null }, discovery_id: 1, library_song_id: null })
renderDiscovery()
const button = await screen.findByLabelText(/Listen for what/)
......@@ -225,4 +228,24 @@ describe('Discovery', () => {
})
expect(await within(row).findByRole('button', { name: 'Pause' })).toBeInTheDocument()
})
it('shows a confidence meter and source label when the match has a score', async () => {
const scored = { ...SONG, confidence: 87.5, source: 'AcoustID' }
vi.spyOn(discoveryApi, 'getDiscoveryHistory').mockResolvedValue({ status: 'success', history: [scored] })
renderDiscovery()
await screen.findByText('Test Song')
expect(screen.getByText('88%')).toBeInTheDocument()
expect(screen.getByText('· AcoustID')).toBeInTheDocument()
})
it('shows no confidence meter when the source has no score', async () => {
vi.spyOn(discoveryApi, 'getDiscoveryHistory').mockResolvedValue({ status: 'success', history: [SONG] })
renderDiscovery()
await screen.findByText('Test Song')
expect(screen.queryByText(/%/)).not.toBeInTheDocument()
})
})
......@@ -214,6 +214,18 @@ export function Discovery() {
<div className="min-w-0 flex-1">
<p className="truncate font-medium text-on-surface">{song.title}</p>
<p className="truncate text-sm text-on-surface-variant">{song.artist}</p>
{song.confidence !== null && (
<div className="mt-1 flex items-center gap-1.5">
<div className="h-1 w-12 shrink-0 overflow-hidden rounded-full bg-surface-container-high">
<div
className="h-full rounded-full bg-primary"
style={{ width: `${Math.min(100, Math.max(0, song.confidence))}%` }}
/>
</div>
<span className="shrink-0 text-[10px] tabular-nums text-outline">{Math.round(song.confidence)}%</span>
{song.source && <span className="truncate text-[10px] text-outline">· {song.source}</span>}
</div>
)}
</div>
{song.library_song_id !== null && (
<button
......
......@@ -41,7 +41,7 @@ describe('Roadmap', () => {
expect(screen.getByText('Channels: vibe sets, stories, showcase screens')).toBeInTheDocument()
expect(screen.getByText('Delete buttons for library songs, playlists, and playlist tracks')).toBeInTheDocument()
// A "needs design" idea split into its own backend half and frontend half.
expect(screen.getByText('Discovery → Library: source a real playable file for a match with no existing library song')).toBeInTheDocument()
expect(screen.getByText('Migrate off SQLite to PostgreSQL + PostGIS')).toBeInTheDocument()
expect(screen.getByText('Wire a "save to library" action for liked Discovery matches')).toBeInTheDocument()
expect(screen.getAllByText('Ready to start').length).toBeGreaterThan(0)
expect(screen.getAllByText('Needs design').length).toBeGreaterThan(0)
......
......@@ -93,6 +93,7 @@ const BACKEND_DONE: DoneGroup[] = [
'Auth-scoped end to end - job status and library-song sourcing both scoped to the owner (was an IDOR)',
'Library-sourced only now, not raw uploads - skips a fresh identify_audio() call and feeds the already-known title/artist/genre into the planning prompt instead',
'Finished remix is library-only, not directly downloadable (2026-08-23) - also closed a real access-control gap: the old download_url pointed at the unauthenticated /downloads static mount with no ownership check at all',
'Rate limited: 5 jobs/user/hour (2026-08-28) - the one genuinely expensive endpoint (real Gemini spend + minutes of CPU-bound Demucs per call) that had no throttling at all; reuses RemixJob.created_at as its own counter rather than a separate table, since an accepted request always leaves exactly one row',
],
},
{
......@@ -101,6 +102,8 @@ const BACKEND_DONE: DoneGroup[] = [
'Identify (Shazam + AcoustID), 24h history, swipe (like/dismiss)',
'Rate limited: 20 identify calls per user per 10 minutes',
'History links a match to the caller\'s own library by title+artist when one already exists (computed live on read, not stored) - makes it playable instead of just informational',
'App-wide library matching (2026-08-28): if a hit doesn\'t match the caller\'s own library but matches *any* user\'s (including a super admin\'s deliberately-seeded uploads), a new LibrarySong row is created for the caller at detection time - reusing the existing file_path rather than duplicating the audio on disk. The library is a collective pool built entirely from real uploads (never anything auto-downloaded from an external source), so this stays clear of the copyright question raised earlier.',
'Real confidence field (2026-08-28): AcoustID\'s native score is now a queryable 0-100 float instead of embedded in a string; Shazam gets a fixed high value (a returned match is already a fingerprint hit, not a fuzzy guess); Gemini stays null (no comparable signal). Surfaced as a small meter + source label on each history row.',
],
},
{
......@@ -111,30 +114,26 @@ const BACKEND_DONE: DoneGroup[] = [
'Guardrails: 50 messages/scan, 5 scans/user/day, no two concurrent scans of the same chat, 1.5s pace between songs',
'Per-song outcome tracking (saved/skipped_duplicate/failed), not just one pass/fail for the whole job',
'30-second preview stream endpoint for a not-yet-saved chat music file (2026-08-23) - ffmpeg -t caps read/encode at the cutoff so cost doesn\'t scale with the source file\'s real length, reuses the same token-in-query-param stream auth as every other direct <audio> endpoint',
'On-demand scanning (not "always watching") is the deliberate final design, not a stepping stone (confirmed 2026-08-28) - the point of the Telegram scanner is a growth hook: pull someone\'s music into Stax so they stop needing Telegram for it, not run a permanent background sync. See the Backend TODO note on why automatic scanning was dropped rather than deferred.',
],
},
]
const BACKEND_TODO: WorkItem[] = [
{
item: 'Discovery → Library: source a real playable file for a match with no existing library song',
item: 'Migrate off SQLite to PostgreSQL + PostGIS',
status: 'needs-design',
note: 'A Discovery hit is playable now if it happens to match something already in the caller\'s library by title+artist (shipped 2026-08-22) - this item is specifically the remaining case: no match exists yet. DiscoveredSong has no audio file at all - ambient ID fingerprints a mic snippet then discards it. Needs a real answer for where a playable file would come from before there\'s anything to save for a genuinely new find.',
note: 'The prod path (deploy.sh, docker-compose.yml) still defaults to SQLite even now. Real risk under concurrent load: SQLite\'s single-writer lock, no real backup/replication story, and the two nearby-query endpoints (soundmarks, live-location) do a full-table-scan haversine in Python instead of a real spatial index - PostGIS fixes that directly with a geography column + GIST index. Open decision: self-hosted Postgres on the existing box (disk is already at 76%, so it can\'t just share that headroom) vs. a managed service. Sequence as two passes: engine/driver swap + data migration first, PostGIS/nearby-query rewrite as a separate follow-up.',
},
{
item: 'Give Discovery candidates a real, queryable confidence field',
item: 'Optimize on-disk media storage',
status: 'needs-design',
note: 'AcoustID candidates carry a score, but it\'s embedded in a source string ("AcoustID (72%)"), not a queryable field - and Shazam candidates carry no score at all. Needs a schema decision, not just a passthrough.',
},
{
item: 'Telegram chat scanning: fully automatic (no user-triggered scan)',
status: 'needs-design',
note: 'On-demand bulk scanning of one approved chat now works end to end (shipped 2026-08-19). This item is specifically "notice a new song without being asked" - needs either a persistent per-user Telegram connection or a scheduled poller across every approved chat for every user, neither of which the current single-process/no-scheduler setup supports. Deliberately deferred, not blocked - worth building once on-demand scanning proves out the feature.',
note: 'Confirmed direction (2026-08-28): media stays on our own server, not object storage - this is about using that disk more efficiently, not migrating off it. One piece already lands for free as of the Discovery app-wide-library change: a "given" song reuses the original uploader\'s file_path instead of duplicating bytes. Still open: cleanup of orphaned temp/remix files, whether multiple users tagging the exact same audio should dedupe by fingerprint the same way, and disk-usage monitoring so this box doesn\'t quietly fill up again.',
},
{
item: 'Proxy-aware IP detection for the rate limiters',
status: 'blocked',
note: 'Blocked on this box sitting behind a real load balancer/reverse proxy - request.client.host is correct for the current direct-to-IP setup.',
note: 'Confirmed direction (2026-08-28): will be tackled as part of standing up a real reverse proxy in front of prod - request.client.host is correct for the current direct-to-IP setup and would need to become X-Forwarded-For-aware once nginx/Caddy sits in front.',
},
]
......
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