• Aryan Noshirvani's avatar
    Wire the remix engine into the social graph · 383b5162
    Aryan Noshirvani authored
    Completed remixes were only ever written to the RemixJob row and the
    downloads/ folder - invisible to /library, /social, and therefore to
    "remix trees" entirely. A remix created through /remix had zero
    connection to the rest of the app's social model.
    
    - /remix now accepts library_song_ids (comma-separated LibrarySong
      IDs) as an alternative/addition to uploaded files. Using a library
      song as a source is what makes tree linkage possible - a source
      with no existing library entry has nothing to link back to. Also
      accepts an optional user_id for attribution.
    - On completion, the engine now registers the output as a real
      LibrarySong (streamable, searchable, playlist-able, same as any
      other library entry) and creates a Post referencing it, so finished
      remixes actually show up in the social feed.
    - parent_post_id links to the first library-sourced input's most
      recent existing Post, if any - the schema only supports one parent
      per post (a tree, not a DAG), so with multiple library-sourced
      inputs only the first is represented as the "parent."
    - RemixJob gained result_song_id/result_post_id columns, surfaced in
      the GET /remix/{id} response once done. Added a lightweight
      automatic migration in database.py (create_all only creates missing
      tables, never ALTERs existing ones for new columns - this bit dev's
      own already-running database the moment these columns were added).
    
    Also fixed two real bugs hit while testing this end-to-end against the
    live Gemini API (not caught by mocked tests, since they're about the
    actual shape of model output):
    - gain_db came back as a per-stem dict ({"drums": -6.0, "other": 0.0})
      instead of the single float the schema asks for, when a role listed
      multiple stems - added _coerce_gain_db to average/sanitize whatever
      comes back rather than assuming schema compliance is guaranteed even
      with response_mime_type=application/json.
    - Gemini occasionally returns syntactically invalid JSON outright (a
      missing comma mid-response) - added a 3-attempt retry around
      generation+parsing, the standard mitigation for this class of
      transient flakiness.
    
    Verified end-to-end against the real API: submitted a remix using two
    pre-existing library songs (one with an existing social Post), and
    confirmed GET /social/posts/{id}/tree shows the finished remix as a
    real child post with the correct caption and parent linkage.
    Co-Authored-By: 's avatarClaude Sonnet 5 <noreply@anthropic.com>
    Claude-Session: https://claude.ai/code/session_01BCxXmJVvDFJVHTUi4QgNzi
    383b5162
database.py 7.21 KB