Skip to content

feat(audience): exponential backoff, 429/Retry-After, HTTP timeout, 4xx drop (SDK-291)#2873

Merged
nattb8 merged 2 commits into
mainfrom
feat/sdk-291-backoff-retry
May 20, 2026
Merged

feat(audience): exponential backoff, 429/Retry-After, HTTP timeout, 4xx drop (SDK-291)#2873
nattb8 merged 2 commits into
mainfrom
feat/sdk-291-backoff-retry

Conversation

@nattb8
Copy link
Copy Markdown
Contributor

@nattb8 nattb8 commented May 20, 2026

Fixes four gaps in @imtbl/audience-core vs Unity SDK:

  1. Exponential backoff - failed flushes back off on a 5s / 10s / 20s / 40s / 60s schedule instead of retrying every 5s forever
  2. 429 / Retry-After - rate-limited responses honour the Retry-After header; queue uses server-supplied delay and emits a new RATE_LIMITED error code
  3. HTTP timeout - 30s AbortController timeout on every fetch; hung connections surface as NETWORK_ERROR instead of wedging the queue
  4. 4xx drop - non-429 4xx responses are treated as terminal (batch dropped, VALIDATION_REJECTED emitted) instead of retrying forever

Note

Medium Risk
Changes message flushing and transport behavior (timeouts, retry windows, and terminal vs retryable HTTP statuses), which can affect event delivery timing and drop conditions if misclassified. Covered by new unit tests, but it alters core queue/transport control flow.

Overview
Adds queue-level exponential backoff to MessageQueue.flush() so repeated send failures suppress further flush attempts until a growing delay window elapses, and resets the backoff after a successful or terminally-rejected batch.

Extends the transport/SDK error surface to handle HTTP 429 rate limits: TransportResult can now include retryAfterMs, httpSend parses Retry-After, and a new AudienceErrorCode RATE_LIMITED is emitted while keeping the batch queued and delaying retries.

Introduces a 30s fetch timeout via AbortController (surfacing as status: 0 network errors) and treats non-429 4xx during flush as terminal by mapping them to VALIDATION_REJECTED and dropping the batch. Unit tests were added/updated to cover backoff escalation, Retry-After, timeout behavior, and 4xx drop semantics.

Reviewed by Cursor Bugbot for commit a75a24c. Bugbot is set up for automated code reviews on this repo. Configure here.

nattb8 and others added 2 commits May 20, 2026 15:52
…xx drop (SDK-291)

- Exponential backoff in MessageQueue: 5s → 10s → 20s → 40s → 60s cap
- 429 handling: parse Retry-After header, override backoff with server delay, emit RATE_LIMITED
- 30s AbortController timeout on fetch; timeouts surface as NETWORK_ERROR
- 4xx (non-429) treated as terminal: drop batch, emit VALIDATION_REJECTED

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@nattb8 nattb8 requested a review from a team as a code owner May 20, 2026 03:58
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 20, 2026

View your CI Pipeline Execution ↗ for commit a75a24c

Command Status Duration Result
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 9s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-20 03:59:04 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 20, 2026

View your CI Pipeline Execution ↗ for commit a75a24c

Command Status Duration Result
nx affected -t build,lint,test ✅ Succeeded 20s View ↗
nx run-many -p @imtbl/sdk,@imtbl/checkout-widge... ✅ Succeeded 9s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-20 03:59:13 UTC

@github-actions
Copy link
Copy Markdown

✅ Pixel Bundle Size — @imtbl/pixel

Metric Size Delta vs main
Gzipped 6350 bytes (6.20 KB) +478 bytes
Raw (minified) 17450 bytes +1594 bytes

Budget: 10.00 KB gzipped (warn at 8.00 KB)

@github-actions
Copy link
Copy Markdown

✅ Audience Bundle Size — @imtbl/audience

Metric Size Delta vs main (fc8b5e3)
Gzipped 18704 bytes (18.26 KB) +472 bytes
Raw (minified) 54675 bytes +1628 bytes

Budget: 24.00 KB gzipped (warn at 20.00 KB)

@nattb8 nattb8 added this pull request to the merge queue May 20, 2026
Merged via the queue into main with commit 8a128ef May 20, 2026
14 checks passed
@nattb8 nattb8 deleted the feat/sdk-291-backoff-retry branch May 20, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants