Skip to content

Harden LLM response handling; fix mixtape management bugs #339

Description

@joestump

Part of #320. Governing: ADR-0008, ADR-0017, SPEC vibes-ai-mixtape-engine, SPEC similar-artists-discovery. All review CONFIRMED.

Requirements

  • Process-killing panic: callOpenAI returns resp.Choices[0].Message.Content with no length guard, and all three calling handlers spawn GenerateMixtape in bare goroutines with no recover() — an empty-choices 200 response (content filter, proxy passthrough) crashes the server (internal/vibes/generator.go:650; enhancer.go:513 already has the guard). Add the guard AND recover() in the spawned goroutines (publish a mixtape-error event on panic)
  • Nil artist edge panic: getListeningHistory dereferences t.Edges.Artist.Name without the nil check Album gets; Track's artist edge is not Required in the schema (internal/vibes/enhancer.go:385,391)
  • Dead cover-art prompting: EnrichAlbum sets data.HasCoverArt=true after the prompt template has already executed, so the {{.HasCoverArt}} branches in album.tmpl never fire — cover-art commentary/dominant colors silently always empty (internal/enrichers/openai/openai.go:583-607)
  • Similar-artists data loss: storeSimilarArtists deletes all existing rows before inserting, no transaction — an LLM response whose artists match nothing wipes prior data and returns nil (internal/services/similar_artists.go:358-414). Validate matches first, write in a transaction
  • DeleteDJ 500s forever: deleting a DJ that owns mixtapes hits the NOT NULL FK (OnDelete: NoAction, _fk=1) → constraint error → 500; DJ undeletable from the UI (internal/handlers/vibes.go:228). Cascade or block-with-message
  • Invalid schedule form value → ent enum validation error → 500; validate and return 400 with a usable message (vibes.go:354,447)

Acceptance Criteria

  • Empty-choices LLM response yields a user-visible mixtape-error event, process alive
  • Enhancement over a listen with an artist-less track completes
  • Regenerated album enrichment includes cover-art commentary when images exist
  • DJ with mixtapes is deletable (or cleanly refused), never 500

Branch

feature/339-llm-hardening-mixtape-fixes

PR Convention

PR title references the story; body ends with Closes #339, references the parent epic and governing artifacts above.

🤖 Posted on behalf of @joestump by Claude.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendGo backend codebugSomething isn't workingqueuedIssue is queued for workstoryStory issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions