fix: reserve-then-publish to prevent upload/Jetstream race (#1072)
* fix: reserve-then-publish to prevent upload/Jetstream race
Upload path now generates rkey upfront, reserves the DB row as "pending",
then publishes to PDS via putRecord. Jetstream ingest reconciles pending
rows instead of racing to create duplicates. Only the winner of the
pending→published transition runs post-creation hooks.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* fix: CAS-guard cleanup on ambiguous PDS failure, defer album creation
- Only delete pending row + media if row is still pending (CAS delete).
On ambiguous failures (timeout after PDS committed), Jetstream may
have already finalized the row — don't destroy a published track.
- Defer get_or_create_album to after PDS success to avoid orphan albums
when the publish step fails.
- Add db_session.expire_all() in tests before re-querying rows that
ingest_track_create committed in its own session.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
authored by