Skip to content

fix(wdio-browserstack-service): refresh framework session id on reloadSession#54

Open
osho-20 wants to merge 1 commit into
mainfrom
fix/observability-stale-session-id-on-reload
Open

fix(wdio-browserstack-service): refresh framework session id on reloadSession#54
osho-20 wants to merge 1 commit into
mainfrom
fix/observability-stale-session-id-on-reload

Conversation

@osho-20

@osho-20 osho-20 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Proposed changes

When a WDIO worker calls browser.reloadSession(), BrowserStack creates a new remote session (new session id, new video recording). However, the session id used by the BrowserStack SDK/CLI integration for test-to-session mapping is cached only once per worker — in onDriverCreated (fired from the AutomationFrameworkState.CREATE POST hook during before()), which writes KEY_FRAMEWORK_SESSION_ID on the tracked automation-framework instance.

onReload() updated the old session's status via the REST API and logged the new session id, but never refreshed that cached state. As a result, every sendTestSessionEvent after a reload kept reporting the worker's first session id, so Test Observability bound all subsequent tests to the wrong session — showing the wrong (duplicate) video, and misattributing session status and accessibility data.

Observed in a real App Automate build: a worker created session dee4a053…, reloaded to 5a61b8ae… and later 3f5154a0…, yet all three tests in the spec were reported against dee4a053…; the post-reload session ids never appeared in any CBTSessionCreated event.

Fix

onReload() now updates KEY_FRAMEWORK_SESSION_ID on the tracked instance with the new session id when the BrowserStack CLI is running. This deliberately does not re-fire the full CREATE event, since the other CREATE observers (observability sync, accessibility command patching, Percy) must not run twice per worker. The driver reference itself stays valid because WebdriverIO mutates browser.sessionId in place on reload; only the cached state key went stale.

Added unit tests covering both the CLI-running and CLI-not-running reload paths.

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

Alternatives considered: re-firing trackEvent(AutomationFrameworkState.CREATE, HookState.POST, …) from onReload would also refresh capabilities and driver state, but it re-runs all registered CREATE observers and risks double-patching browser commands (accessibility) and duplicate O11y sync, so the targeted state update was chosen instead.

Reviewers: @webdriverio/project-committers

🤖 Generated with Claude Code

@osho-20
osho-20 requested a review from a team as a code owner July 16, 2026 16:11
@osho-20
osho-20 requested review from anish353 and kamal-kaur04 July 16, 2026 16:11
@osho-20
osho-20 force-pushed the fix/observability-stale-session-id-on-reload branch from 8332420 to 3ee0fb1 Compare July 16, 2026 16:12
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