Skip to content

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

Merged
rahulpsq merged 3 commits into
mainfrom
fix/observability-stale-session-id-on-reload
Jul 21, 2026
Merged

fix(wdio-browserstack-service): refresh framework session id on reloadSession#54
rahulpsq merged 3 commits 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

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 — 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.

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.

Related Jira task/s

Release (mandatory for every PR — required for the ready-for-review label)

Version bump: (required — tick exactly one)

  • minor (backwards-compatible feature)
  • patch (bug fix or other small change)

Release notes type: (optional)

  • New Feature
  • Bug Fix
  • Other Improvement

Release notes (customer-facing): (optional but encouraged)

  • Fixed Test Observability reporting tests against the wrong session (stale video, status, and accessibility data) after browser.reloadSession() in WebdriverIO.

Release notes (internal): (required — engineer-facing; what actually changed / why)

  • onReload() now refreshes KEY_FRAMEWORK_SESSION_ID on the tracked automation-framework instance with the new session id (CLI-running path only), so sendTestSessionEvent reports the post-reload session instead of the worker's first session. The full CREATE event is deliberately not re-fired to avoid re-running CREATE observers (O11y sync, accessibility patching, Percy) twice per worker.
  • Added unit tests for both the CLI-running and CLI-not-running reload paths.

Checklist

  • Ready to review
  • Has it been tested locally?

PR Validations

Run Tests: Comment RUN_TESTS to trigger sanity tests.

🤖 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
@github-actions

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not reviewed the current head commit yet — run the SDK PR Review Agent.

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.

@github-actions

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not reviewed the current head commit yet — run the SDK PR Review Agent.

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.

@github-actions

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not reviewed the current head commit yet — run the SDK PR Review Agent.

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.

@rahulpsq
rahulpsq merged commit 0518f49 into main Jul 21, 2026
10 of 11 checks passed
@github-actions github-actions Bot mentioned this pull request Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants