fix: Spotify 429 backoff + workflow-native chunk retries (memoized actor fetch, durable mapping)
What
The 570-album re-snapshot (chat#1794 item 2) exposed the gap: all 6 actor chunks succeeded (~$1.71 spent, 570 albums scraped), but only 2 chunks' identifier mappings landed (420 of ~4,000 expected measurements). Root cause: ~85 Spotify /v1/tracks batch lookups in 2.5 minutes → 429s → getTracks had no retry → mapUnmappedAlbumTracks degraded to mapped-only capture for 4 chunks (by design, silently).
Fix: per-batch Retry-After backoff in getTracks, up to 3 retries; non-429 failures still fail fast. Tests: retry-then-succeed, exhaust-then-error, non-429 no-retry (RED→GREEN).
Recovery plan
After merge: one re-snapshot heals everything — already-mapped tracks skip Spotify entirely (no lookups), so the retry only has to cover the remaining ~3,500 resolutions, now with backoff. Verification = identifier/measurement coverage counts on the PR.
Diagnostic trail on chat#1794. Apify-side spend is not wasted — the scrape data was fine; only the mapping degraded.
🤖 Generated with Claude Code
Summary by cubic
Adds 429 backoff to Spotify getTracks and splits snapshot capture into fetch and map+write steps with durable retries and memoized actor results. Also dedupes songs by ISRC before upsert to keep multi-album chunks from failing and prevent partial captures.
-
Bug Fixes
- Per-batch 429 backoff using
Retry-After, up to 3 retries; throwsSpotifyRateLimitErroron exhaustion; non-429 errors fail fast. - Deduplicate songs by ISRC across albums before
upsertSongsto avoid in-batch ON CONFLICT updates on the same row; maintains bootstrap coverage for reissues. - Tests cover retry success, retry exhaustion, non-429 handling, and ISRC dedupe.
- Per-batch 429 backoff using
-
Refactors
- Split chunk capture into
fetchChunkStep(actor call, result memoized) andmapAndWriteChunkStep(mapping + write). - Escalate sustained Spotify rate limiting to a workflow
RetryableError(retryAfter 30s);mapUnmappedAlbumTracksrethrowsSpotifyRateLimitError.
- Split chunk capture into
Summary by CodeRabbit
-
New Features
- Added automatic retry logic for Spotify API rate limits with intelligent backoff using the service's
Retry-Afterheader.
- Added automatic retry logic for Spotify API rate limits with intelligent backoff using the service's
-
Refactor
- Restructured snapshot capture workflow into modular steps for improved durability and error handling.
- Enhanced rate limit error escalation with durable retry behavior across workflow execution.