Skip to content

feat: report DriverInitFailure when a worker cannot create its session (v10) - #403

Open
kamal-kaur04 wants to merge 13 commits into
mainfrom
feat/driver-init-failure-event-v10
Open

kamal-kaur04 wants to merge 13 commits into
mainfrom
feat/driver-init-failure-event-v10

Conversation

@kamal-kaur04

@kamal-kaur04 kamal-kaur04 commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

What is this about?

Reports a DriverInitFailure SDK event when a worker cannot create its WebDriver session (newSession error or client-side timeout). Until now the service emitted no driver-init failure telemetry at all, unlike the other BrowserStack SDKs.

  • When session creation fails, the WDIO runner calls the service's after hook without before; the service detects that and sends one event per failed worker. Same path for the CLI/binary flow and the direct flow.
  • The event carries the real newSession error. WebdriverIO hands that error only to reporters (on runner:end, after after), so the service registers a small reporter of its own that writes no output. after() hands the failure off and returns; the reporter sends from onRunnerEnd, holding reporter sync until the send settles, with the send deadline derived from reporterSyncTimeout (min(10 s, max(1 s, reporterSyncTimeout − 500 ms))). If the reporter is not loaded or the runner provides no error text, the previous hostname/timeout message is sent instead, and exactly one event is sent per failed worker either way.
  • The error text is cut at when running " (webdriver appends the failed request there, including capabilities that carry the user's credentials), then credential-scrubbed and byte-capped.
  • Payload matches the other SDKs' DriverInitFailure shape, including testhub_uuid.
  • The sdk_events intake answers HTTP 503 to near-simultaneous posts from parallel workers; the event is resent on 429/503 only (max 4 attempts, jittered), so a delivered event is never duplicated.
  • created_day for DriverInitFailure and SDKFeaturePerformance is now sent as YYYY-MM-DDTHH:MM:SS.ffffff UTC. The previous en-GB string (DD/MM/YYYYT…) was parsed month-first downstream, so events sent on days 1–12 of a month were filed under the wrong date.

Related Jira task/s

N/A

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)

  • Improved diagnostics when a test session fails to start.
  • Fixed SDK telemetry events (SDKFeaturePerformance, DriverInitFailure) being recorded with day and month swapped on days 1–12 of the month.

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

  • Emit DriverInitFailure (sdk_events) once per worker whose session creation failed, detected as after without before; resend on 429/503 only.
  • Send created_day in ISO UTC for DriverInitFailure and SDKFeaturePerformance (en-GB string was parsed MM/DD downstream).
  • Bound the DriverInitFailure send in the worker after hook to a 10 s total deadline (each attempt capped by the time remaining; previously up to ~29 s); created_day formatting shared from src/instrumentation/createdDay.ts.
  • Send the real newSession error (from runner:end via a no-output service reporter) instead of a synthetic hostname/timeout message; cut webdriver's request details before scrubbing; deadline bounded by reporterSyncTimeout; synthetic fallback when no reporter/error.

Checklist

  • Ready to review
  • Has it been tested locally?

Tested end to end against BrowserStack on CLI flow (mocha) and direct flow (jasmine): a forced client-side newSession timeout on 2 workers sends 0 events before the change and exactly 2 after (one per failed worker), each delivered and stored with the correct date; healthy runs send none. Unit tests, build and lint pass.

PR Validations

Run Tests: Comment RUN_TESTS to trigger sanity tests.

🤖 Generated with Claude Code

kamal-kaur04 and others added 5 commits December 1, 2026 15:15
When the WebDriver new-session request fails or hits connectionRetryTimeout,
the WDIO runner calls the service's `after` hook without ever calling
`before`. Detect that in the worker (same path for the CLI and direct flows,
since only the client sees the outcome) and send one `DriverInitFailure`
sdk_events record to EDS, keyed by the TestHub build uuid, with the same
payload shape as the Node SDK. The send is bounded, resent only when EDS
sheds it with 429/503, and never throws into the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto (fallback from Default branch)
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited), Workspace UI (inherited); Enforced overrides: Organization
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: 4f66f419-aa26-47b5-8677-6264e0cebb43

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@kamal-kaur04

kamal-kaur04 commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

🔴 Blocking findings — fix required

Severity File · Symbol Finding
🟠 Warning packages/browserstack-service/src/driverInitFailureReporter.ts · DriverInitFailureReporter.onRunnerEnd Driver-init failure send rejection is swallowed with no log

Full reasoning, evidence and suggested fixes are in the SDK PR Review Agent's report from your local run.

Change map (generated deterministically from the diff)

graph LR
  subgraph nwdio_service["wdio-service"]
    npackages_browserstack_service_tests_instrumentation_funnelInstrumentation_test_ts["funnelInstrumentation.test.ts<br/>~435 lines"]
    npackages_browserstack_service_src_instrumentation_funnelInstrumentation_ts["funnelInstrumentation.ts<br/>~198 lines"]
    npackages_browserstack_service_src_service_ts["⚠ service.ts<br/>~131 lines"]
    npackages_browserstack_service_tests_service_test_ts["⚠ service.test.ts<br/>~131 lines"]
    npackages_browserstack_service_src_driverInitFailureReporter_ts["driverInitFailureReporter.ts<br/>~85 lines"]
    npackages_browserstack_service_tests_driverInitFailureReporter_test_ts["driverInitFailureReporter.test.ts<br/>~85 lines"]
    npackages_browserstack_service_src_instrumentation_performance_performance_tester_ts["performance-tester.ts<br/>~21 lines"]
    npackages_browserstack_service_tests_performance_tester_test_ts["performance-tester.test.ts<br/>~21 lines"]
    npackages_browserstack_service_src_constants_ts["constants.ts<br/>~11 lines"]
    n_changeset_pr_403_md["pr-403.md<br/>~6 lines"]
    npackages_browserstack_service_src_instrumentation_createdDay_ts["createdDay.ts<br/>~3 lines"]
  end
Loading

↻ This verdict comment is the review anchor — it's updated in place on each run (the gate posts its status separately).

— SDK PR Review Agent

@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

E2E evidence (v10) — events received

Real BrowserStack builds of a WDIO sample with the service built from this branch; newSession forced to fail client-side (connectionRetryTimeout: 1500). Right-hand columns are the DriverInitFailure / SDKFeaturePerformance events that landed in BrowserStack's SDK events store for each build.

Case Commit Build id Failed workers Expected DriverInitFailure rows Rows received created_day driverType / framework errorMessage (prefix)
CLI flow (mocha), 2 workers failing — BEFORE main 2izvailwf37pmrwhc5gj8kabdhlbety2buxx7k7x 2 2 0 (no event existed) — — —
Direct flow (jasmine), 2 workers failing — BEFORE main cfktrkcrwbuxdkgfc1wvhkq8tdcqeuu2rephhfke 2 2 0 — — —
Single-worker failing, before the 503 resend (×3) first commit, pre-resend vtbzfwxx5vevoimrqxxbgu6ypgdd33e2kccg22dj · tkuocthn95hlgeghfvt94jjohdalk514rvu1uvyk · qkufdvfadszsxq7dp6lc0vawyodarbqplajvfkne 2 each 2 each 1 each (2nd post got 503, not resent) 2026-01-12 ✗ webdriverio —
CLI flow (mocha), 2 workers failing — first commit first commit bxewhjg6jtceywbcodqopy0sgwxslo635t0ya8ti 2 2 2 2026-01-12 ✗ (day-first date) webdriverio / WebdriverIO-mocha [DriverInitError] WebdriverIO session could not be created (hostname=…, connectionRetryTimeout=…)
Direct flow (jasmine), 2 workers failing — first commit first commit 64xeohfqfppikurqeqalcf2vzwiwcvk63u3sspqn 2 2 2 2026-01-12 ✗ webdriverio / WebdriverIO-jasmine [DriverInitError] WebdriverIO session could not be created (hostname=…, connectionRetryTimeout=…)
CLI flow (mocha), 2 workers failing — date fix date fix gifusoqheennlcsahb2abrhqgc2i4h7b030tae7e 2 2 2 2026-12-01 10:39:49 webdriverio / WebdriverIO-mocha [DriverInitError] WebdriverIO session could not be created (hostname=…, connectionRetryTimeout=…)
Direct flow (jasmine), 2 workers failing — date fix date fix zstqammcpndlpjwtbuapat0okbwyjqhz1pt3wo2l 2 2 2 2026-12-01 10:40:06 webdriverio / WebdriverIO-jasmine [DriverInitError] WebdriverIO session could not be created (hostname=…, connectionRetryTimeout=…)
Healthy date fix 63ik7f1n3ace0km9yunw9ngubhmlcaa5pis7tnbh 0 0 0 — — —
SDKFeaturePerformance date — healthy run perf date fix xrjxbwxiooi0nmfaidhwge6hrsafy0udnxjrhnbz 0 1 perf row 1 perf row 2026-12-01 13:36:35 — —

After the date fix every event lands on the correct date (the first-commit rows show the day-first DD/MM string being read month-first). One event per failed worker, testhub_uuid = the build, none on the healthy run. Events are resent only on HTTP 429/503; in every failing run one of the two near-simultaneous posts got a 503 and was delivered on retry.

🤖 Generated with Claude Code

kamal-kaur04 and others added 3 commits December 2, 2026 16:31
…_day formatter

The awaited send in the worker after hook could hold teardown for about
29s (4 attempts x 5s timeout plus backoff). All attempts now share a 10s
deadline: each attempt's timeout is capped at the time remaining, a
backoff that would overrun it is skipped, and sending stops once it is
spent. Resends stay limited to 429/503 and at most 4 attempts.

formatCreatedDay moves to its own module so performance-tester can use
it without an import cycle through funnelInstrumentation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

E2E evidence — follow-up on 205e276 (review fixes: 10 s send deadline, shared created_day formatter)

Case Build (testhub_uuid) Failed workers Expected DriverInitFailure rows Rows received created_day SDKFeaturePerformance
CLI flow (mocha), 2 workers failing rrclwmpnhvilccfc8vtuebq80yllqd050ob8hwi2 2 2 2 (one 503 → 200 on resend) 2026-12-02 11:02:26 1 row, 2026-12-02 11:02:33
Healthy 1f1pyf4irrw9vcryczk67dmmymnovrdn9uwhxakp 0 0 0 — 1 row, 2026-12-02 11:03:16

Worst case now bounded: 10.05 s against a local endpoint that always answers 503 or hangs (previously ~29 s). One row per failed worker, none on the healthy run, resend on 429/503 only.

🤖 Generated with Claude Code

…runcation within the byte cap

Truncation now backs off to the last whole code point so the message stays
valid UTF-8 and never exceeds 8000 bytes. URL userinfo and the access key and
username values are masked before the message is logged or sent, and a failed
send logs only the error message. The uploadEventsData test restores
fsPromises.access.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

Review findings addressed in fb28adc

Finding Resolution
performance-tester.test.ts overwrote fsPromises.access without restoring it Original saved and restored in the existing afterEach (vi.spyOn can't be used here: the file's node:fs/promises mock has no access key).
8000-byte cap: a cut inside a multi-byte character decoded to U+FFFD and could exceed the cap truncateToBytes backs off to the last complete code point — result is always ≤ the cap and valid UTF-8. 7 new cases with 3- and 4-byte characters at shifted offsets (5 fail on the previous code).
errorMessage sent and debug-logged without redaction Scrubbed before it is logged or sent: URL userinfo → ***@, access key and username values → ***; the send catch logs only error.message. Tests cover the request body, the logger, an unchanged normal message, and a thrown error. (The message is built from hostname and retry settings only, so this is defence in depth.)
The report relies on WDIO calling after() without before() when session creation fails — "not demonstrated" Demonstrated end to end, no change: with newSession forced to fail client-side, the unpatched service sent 0 events and this branch sends exactly one per failed worker, in both the CLI flow (mocha) and the direct flow (jasmine), on v10, v9 and v8 — see the E2E evidence comments on this PR and on #403 (unpatched baseline). A healthy run, where before() does run, sends none.

E2E on fb28adc (real BrowserStack builds; rows received in BrowserStack's SDK events store):

Case Build id Failed workers Expected Received created_day errorMessage sent
CLI flow (mocha), 2 workers failing pfpnpa9uqlg9ckkk97mkhdazbe8eeip3dm1t4ve5 2 2 2 (one 503 → 200 on resend) 2026-12-02 14:25:30 [DriverInitError] WebdriverIO session could not be created (hostname=hub-euw.browserstack.com, …) — unmasked, as expected
Healthy wqqwyau9wnhy0t52drw2y6wolx2mh6ywq3cp5pdp 0 0 0 — —

🤖 Generated with Claude Code

@kamal-kaur04
kamal-kaur04 marked this pull request as ready for review December 2, 2026 15:41
@kamal-kaur04
kamal-kaur04 requested a review from a team as a code owner December 2, 2026 15:41
… coverage

Cap the message before scrubbing and anchor the userinfo pass on the
scheme delimiter so a long input cannot stall the failure path. Also mask
Basic/Bearer values, key-style parameters, the base64 and URL-encoded
credential forms, and match the username only as a whole token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

Review findings addressed in 6f7e32f

Finding Resolution
URL-userinfo scrub regex quadratic on long unbroken strings, run on the uncapped message Pattern is now anchored on the delimiter (/:\/\/[^\s/?#@]+@/g → ://***@), and the message is capped at 32000 bytes on a whole character before scrubbing, then capped at 8000 bytes after. All passes are linear. 100 KB adversarial input: 1730 ms → 1.9 ms (run with no ://); 7869 ms → 0.8 ms (run ending in ://x). A 100 KB timing test is added.
Scrub covered only userinfo + literal values; short usernames over-redacted New passes: Basic / Bearer values (8+ chars), access_key / accessKey / key / token / password values (after = or a JSON ":"), the literal base64 of userName:accessKey, and the URL-encoded key. The username is now masked only as a whole token of 4+ characters, so a short username no longer alters hostnames. A test per pattern.

Unit tests, build and lint pass.

E2E on 6f7e32f (real BrowserStack builds; events received in BrowserStack's SDK events store):

Case Build id Failed workers Expected Received created_day errorMessage sent
CLI flow (mocha), 2 workers failing jeexh1rbnitlp81jvozznhyc9pggcow98tvbkadr 2 2 2 2026-12-02 15:56:34 [DriverInitError] WebdriverIO session could not be created (hostname=…) — unmasked, as expected
Healthy mkufodgbuvv9coroaxyhcs0wtarn9schstnikcrc 0 0 0 — —

🤖 Generated with Claude Code

@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

RUN_TESTS

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: success).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can merge.

@minionhelperappqa

Copy link
Copy Markdown

[SDK Wdio Test] TRA build state: failed | Stability 83% — verdict: failure. Passed: 48, Failed: 10, Aggregate: 58. TRA: https://observability.browserstack.com/builds/o23pwxtusdgfrnzyjahzs8ogaademtzswdsvxcd6

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: success).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can merge.

wdio exposes the session creation error only on runner:end, after the
service's after() hook, so a small always-on reporter now sends the
event from onRunnerEnd and holds the reporter sync until it settles.
The request webdriver appends to the error, whose capabilities carry
the credentials, is cut before the existing scrub. The send deadline
follows reporterSyncTimeout. When the reporter is absent or the runner
error is empty, the previous synthetic message is sent instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge.

@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

Real newSession error — implemented in b510279

DriverInitFailure now carries the error WebdriverIO actually hit, instead of a synthetic hostname/timeout message. WebdriverIO passes that error only to reporters (on runner:end, after the after hook), so the service registers a small reporter that writes no output; after() hands the failure off and returns, and the reporter sends from onRunnerEnd, holding reporter sync until the send settles. The text is cut at when running " (where webdriver appends the request, including capabilities that hold the user's credentials), then scrubbed and byte-capped. If no reporter or no error text is available, the previous message is sent instead.

Full suite 1605 tests passing; 34 new tests (reporter, credential cut, fallback, single send, deadline from reporterSyncTimeout, healthy run, user reporters untouched); tsc and ESLint clean.

E2E (real BrowserStack builds, 2 workers, connectionRetryTimeout: 1500; events received in BrowserStack's SDK events store):

Case Build id Expected Received errorMessage received
mocha (CLI flow), failing xunckjdqfbmcfjnj9pz5fo5jikvwfsikhawqsd4e 2 2 [DriverInitError] WebDriverError: Request timed out! Consider increasing the "connectionRetryTimeout" option.
jasmine (direct flow), failing 2uq6hnllvltn47defc2umzlpivyjq846it3cmbdd 2 2 same
mocha, failing, observability off tcwmcbfdikovdhkk21ufdnv0tv6lkyqxeyfxy7xi 2 2 same
healthy wgzfwhvn5a4jjuat2yblmgv14qpcemjz8jyujiv6 0 0 —

No received message contains the hub URL, the capabilities, the username or the access key. after() now returns within ~10–40 ms (it previously waited 1–5 s on the send); workers exit 1–3 s after runner:end, inside the reporter sync budget. On the failure path WebdriverIO logs its own "Wait for 1 reporter to synchronize" while the send is in flight.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: failure).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can merge.

@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

RUN_TESTS

@minionhelperappqa

Copy link
Copy Markdown

[SDK Wdio Test] TRA build state: failed | Stability 83% — verdict: failure. Passed: 48, Failed: 10, Aggregate: 58. TRA: https://observability.browserstack.com/builds/fuqigqcrv89gyvliwuepdfvp7avbgpaenqaakt5d

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: failure).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can merge.

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