fix(wdio-browserstack-service): refresh framework session id on reloadSession#54
Open
osho-20 wants to merge 1 commit into
Open
fix(wdio-browserstack-service): refresh framework session id on reloadSession#54osho-20 wants to merge 1 commit into
osho-20 wants to merge 1 commit into
Conversation
osho-20
force-pushed
the
fix/observability-stale-session-id-on-reload
branch
from
July 16, 2026 16:12
8332420 to
3ee0fb1
Compare
Bhargavi-BS
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 — inonDriverCreated(fired from theAutomationFrameworkState.CREATEPOST hook duringbefore()), which writesKEY_FRAMEWORK_SESSION_IDon 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, everysendTestSessionEventafter 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 to5a61b8ae…and later3f5154a0…, yet all three tests in the spec were reported againstdee4a053…; the post-reload session ids never appeared in anyCBTSessionCreatedevent.Fix
onReload()now updatesKEY_FRAMEWORK_SESSION_IDon the tracked instance with the new session id when the BrowserStack CLI is running. This deliberately does not re-fire the fullCREATEevent, 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 mutatesbrowser.sessionIdin 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
Checklist
Backport Request
v9and doesn't need to be back-ported#XXXXXFurther comments
Alternatives considered: re-firing
trackEvent(AutomationFrameworkState.CREATE, HookState.POST, …)fromonReloadwould 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