Skip to content

feat: [SDK-5377] enqueue policy for session requests (2/4) - #1572

Merged
fadi-george merged 1 commit into
fadi/sdk-5377from
fadi/sdk-5377-enqueue
Nov 13, 2026
Merged

fadi-george merged 1 commit into
fadi/sdk-5377from
fadi/sdk-5377-enqueue

Conversation

@fadi-george

@fadi-george fadi-george commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description

1 Line Summary

Queues session create/update records with ordering, coalescing, an end replacing updates, and a cap.

Details

  • Every request gets its own idempotency key, stored and reused on retries.
  • All queue reads and writes run under a Web Lock (navigator.locks.request), so an enqueue never interleaves with the sender applying a result. Web Locks ship in Chrome 69, Firefox 96 and Safari 15.4; Safari web push needs 16+. Older Chrome/Firefox with VAPID push lack it, so the SDK-5381 wiring should only use the sessions API when navigator.locks exists. Tests use a small per-name fake (__test__/support/helpers/locks.ts) since jsdom has none.
  • Each new update replaces the session's queued updates and keeps the highest duration, so durations coalesce and an end replaces unsent updates with one rule. The replacement is a new record with a new key since its body changed (duration is absolute, so a duplicate is harmless).
  • An end replaces unsent updates; updates or ends after an end are dropped.
  • Cap of 100 requests (matches Android/iOS): oldest dropped and logged; a dropped create takes its session's updates.
  • Requests older than 30 days can be dropped (used by the sender).
  • No in-flight tracking: the sender re-reads a request after sending it (3/4), so a request replaced or dropped while on the wire is simply not retried.

Nothing enqueues yet; wiring is SDK-5381.

Stack

Built on #1569 (SDK-5373 sessions API client).

  1. feat: [SDK-5377] add SessionRequests IndexedDB store (1/4) #1571 SessionRequests IndexedDB store
  2. feat: [SDK-5377] enqueue policy for session requests (2/4) #1572 (this PR) enqueue policy
  3. feat: [SDK-5377] send queued session requests with retry (3/4) #1573 send with retry
  4. feat: [SDK-5377] drain session requests on worker start and online (4/4) #1574 drain on worker start and online

Systems Affected

  • WebSDK
  • Backend
  • Dashboard

Validation

Tests

Info

queue.test.ts: order and keys, coalescing with a new key, end replacing updates, drops after an end, per-session isolation, cap, cap with create, age limit.

vp check clean (only existing warnings), full vp run test passes, each PR in the stack passes on its own. Not tested in a browser: nothing enqueues session requests until the lifecycle wiring (SDK-5381).

Checklist

  • All the automated tests pass or I explained why that is not possible
  • I have personally tested this on my machine or explained why that is not possible
  • I have included test coverage for these changes or explained why they are not needed

Programming Checklist
Interfaces:

  • Don't use default export
  • New interfaces are in model files

Functions:

  • Don't use default export
  • All function signatures have return types
  • Helpers should not access any data but rather be given the data to operate on.

Typescript:

  • No Typescript warnings
  • Avoid silencing null/undefined warnings with the exclamation point

Other:

  • Iteration: refrain from using elem of array syntax. Prefer forEach or use map. Uses for...of where IndexedDB writes must run in sequence.
  • Avoid using global OneSignal accessor for context if possible.

Screenshots

Info

No UI changes.

Checklist

  • I have included screenshots/recordings of the intended results or explained why they are not needed

Related Tickets

SDK-5377


🤖 Generated with Claude Code

@nan-li nan-li left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes:

  • queue.ts:89 When an end replaces queued updates, it's built from the new request only. If the sender already stamped one of those updates with serverSessionId (the create succeeded and the update is waiting out the 5s delay), the end loses it and pickNext drops the end. Carrying the server fields over from the replaced update fixes it, and so does looking the ID up at send time as suggested on #1573.
  • queue.ts:76 "Only one unsent duration-only update can exist" stops being true once an in-flight update gets a retry. Then there are two, and the next update coalesces into the older one. The backend never lowers a duration, so the only cost is one extra request. Either fix the comment or coalesce into the newest update.

@fadi-george
fadi-george force-pushed the fadi/sdk-5377-enqueue branch from 1b8e85a to 122b829 Compare November 12, 2026 23:05
@fadi-george

Copy link
Copy Markdown
Contributor Author

Thanks, both fixed.

  • End losing the server ID: the server session ID now lives in a SessionRequestStates store (added in feat: [SDK-5377] add SessionRequests IndexedDB store (1/4) #1571) and is looked up at send time, so requests no longer carry it and an end can't lose it.
  • Two unsent updates: a new update now coalesces into the newest one at the highest duration and removes the older ones. Dropped the wrong comment and added a test.

@fadi-george
fadi-george force-pushed the fadi/sdk-5377-enqueue branch 2 times, most recently from 39d7c3e to 834ada5 Compare November 12, 2026 23:11
@fadi-george
fadi-george requested a review from nan-li November 12, 2026 23:22
@fadi-george
fadi-george force-pushed the fadi/sdk-5377-enqueue branch 2 times, most recently from 6867f66 to 242a317 Compare November 12, 2026 23:38

@nan-li nan-li left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@fadi-george
fadi-george force-pushed the fadi/sdk-5377-enqueue branch 2 times, most recently from 3c6da2b to aa79ae2 Compare November 12, 2026 23:57
Queues sessions API create/update records in SessionRequests with an
idempotency key per request. Duration-only updates coalesce to the highest
duration, an end replaces unsent updates, updates after an end are dropped,
and the queue is capped at 100 (a dropped create takes its updates). Requests
older than 30 days can be dropped. The request in flight is never touched.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fadi-george
fadi-george force-pushed the fadi/sdk-5377-enqueue branch from aa79ae2 to 8b261c2 Compare November 13, 2026 02:18
@fadi-george
fadi-george merged commit e46dca2 into new-session-events Nov 13, 2026
1 check failed
@fadi-george
fadi-george deleted the fadi/sdk-5377-enqueue branch November 13, 2026 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants