Skip to content

Fix adobe-edge web: "Session ID is not available" race on media events - #460

Merged
tvanlaerhoven merged 15 commits into
mainfrom
bugfix/adobe-edge-session-start-race
Aug 17, 2026
Merged

tvanlaerhoven merged 15 commits into
mainfrom
bugfix/adobe-edge-session-start-race

Conversation

@tvanlaerhoven

@tvanlaerhoven tvanlaerhoven commented Aug 13, 2026

Copy link
Copy Markdown
Member

Summary

On web, AdobeEdgeHandler treated trackSessionStart() as fire-and-forget: it flipped _sessionInProgress = true immediately, so any media event fired before the edge network returned a sessionId was rejected by alloy with
Failed to trigger media event: media.bitrateChange. Session ID is not available for playerId: <uuid>.

The session is now only considered active once the start is confirmed, events are queued until then, and failed starts are retried:

startSession(mediaLength, attempt, sessionMetadata?) {
  const generation = ++this._sessionGeneration;   // invalidates in-flight starts on reset/sourcechange
  this._sessionStarting = true;
  Promise.resolve(tracker.trackSessionStart(...))
    .then((result) => {
      if (generation !== this._sessionGeneration) { /* orphan: complete if needed, then end */ return; }
      if (result?.sessionId) { this._sessionInProgress = true; flush(this._eventQueue); }
      else                   { this.retryStartSession(generation, mediaLength, attempt, customMetadata); }
    })
    .catch(() => this.retryStartSession(...));     // no more unhandled rejections
}

Other behaviour worth calling out:

  • maybeStartSession() is retried once the media tracker promise resolves, so a loadedmetadata that arrives before the tracker is ready no longer silently skips the session start.
  • Retries: 3 attempts with 1s/2s backoff. After giving up, _sessionStartAbandoned is set and events are dropped (not queued) until a sourcechange/stopAndStartNewSession starts a fresh session.
  • The custom metadata from updateMetadata() is snapshotted for the first attempt and reused by every retry, so a retried session start still reports the customer's metadata instead of an empty object. Metadata set after the snapshot is kept for the next session.
  • If playback ends while a start is still in flight, _completeOnConfirm remembers it so the late-confirmed session is completed (sessionComplete) before it is ended, instead of losing the completion.
  • The pending-event queue is capped at MAX_EVENT_QUEUE_SIZE = 500 (oldest dropped first), so a start that never resolves cannot grow the queue without bound.

Testing

In adobe-edge: npm test (18 tests, new sessionStart.test.ts covers queue/flush, retry + recovery, rejection, tracker-not-ready race, metadata on retries, late completion, queue cap and orphan close), npm run typescript, npm run build.

Link to Devin session: https://dolby.devinenterprise.com/sessions/37fdbe28150a45588efc33754efcdd32
Requested by: @tvanlaerhoven


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8b556cb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@theoplayer/react-native-analytics-adobe-edge Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

devin-ai-integration[bot]

This comment was marked as resolved.

@tvanlaerhoven
tvanlaerhoven force-pushed the bugfix/adobe-edge-session-start-race branch from 008cf72 to cbcc31c Compare August 13, 2026 21:11
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

tvanlaerhoven and others added 11 commits August 13, 2026 17:27
The web handler marked the media session as started immediately after
calling trackSessionStart(), without awaiting the returned promise. If
the edge network response contained no session ID (e.g. transient edge
failure), every subsequent media event rejected with "Session ID is not
available for playerId" for the remainder of the session, surfacing as
unhandled promise rejections.

- Only mark the session in progress after trackSessionStart() resolves
  with a sessionId; queue events in the meantime.
- Retry failed session starts with exponential backoff (3 attempts).
- Catch tracker promise rejections and log them in debug mode.
- Close sessions that get confirmed after a sourcechange already ended
  them.
- Also start the session when loadedmetadata fired before the
  getMediaAnalyticsTracker promise resolved, which previously dropped
  the whole session silently.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
The changelog is generated from changesets at release time
(changeset:version); the previous commit edited CHANGELOG.md directly.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…onfirmed sessions

Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
@tvanlaerhoven
tvanlaerhoven force-pushed the bugfix/adobe-edge-session-start-race branch from cbb14a6 to 9ff1ccc Compare August 14, 2026 00:27
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration Bot and others added 2 commits August 17, 2026 05:26
A session whose start is confirmed after it was superseded by a new source is now
completed and ended on its own tracker, so it is no longer left open on the edge
network.

Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
devin-ai-integration[bot]

This comment was marked as resolved.

…atched

Alloy builds a media event's payload from the tracker state in a microtask after the
event was triggered, so destroying the tracker right after trackComplete/trackSessionEnd
would drop the beacon.

Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>
devin-ai-integration[bot]

This comment was marked as resolved.

…n per session

- A synchronous failure of getInstance/trackSessionStart no longer leaves the handler
  stuck in 'starting'; it is retried like an async failure.
- The pending completion is tied to the session generation, so a session that was
  superseded by a source change is not reported as completed.

Co-Authored-By: tom.vanlaerhoven <tom.vanlaerhoven@dolby.com>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 2 new potential issues.

Open in Devin Review

Comment thread adobe-edge/src/internal/web/AdobeEdgeHandler.ts
Comment thread adobe-edge/src/internal/web/AdobeEdgeHandler.ts
@tvanlaerhoven
tvanlaerhoven merged commit 60352ed into main Aug 17, 2026
6 checks passed
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.

1 participant