fix(wdio-browserstack-service): refresh framework session id on reloadSession#54
Merged
Merged
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
pri-gadhiya
approved these changes
Jul 21, 2026
Contributor
|
🔴 SDK PR Review gate is red. Pending:
It turns green once the latest SDK PR Review Agent run reports GTG on the current head commit. A native reviewer approval is separately required by branch protection before merge. |
Contributor
|
🔴 SDK PR Review gate is red. Pending:
It turns green once the latest SDK PR Review Agent run reports GTG on the current head commit. A native reviewer approval is separately required by branch protection before merge. |
Contributor
|
🔴 SDK PR Review gate is red. Pending:
It turns green once the latest SDK PR Review Agent run reports GTG on the current head commit. A native reviewer approval is separately required by branch protection before merge. |
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.
What is this about?
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.
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.Related Jira task/s
Release (mandatory for every PR — required for the
ready-for-reviewlabel)Version bump: (required — tick exactly one)
Release notes type: (optional)
Release notes (customer-facing): (optional but encouraged)
browser.reloadSession()in WebdriverIO.Release notes (internal): (required — engineer-facing; what actually changed / why)
onReload()now refreshesKEY_FRAMEWORK_SESSION_IDon the tracked automation-framework instance with the new session id (CLI-running path only), sosendTestSessionEventreports the post-reload session instead of the worker's first session. The fullCREATEevent is deliberately not re-fired to avoid re-running CREATE observers (O11y sync, accessibility patching, Percy) twice per worker.Checklist
PR Validations
Run Tests: Comment RUN_TESTS to trigger sanity tests.
🤖 Generated with Claude Code