Repository navigation
feat: report DriverInitFailure when a worker cannot create its session (v9) - #404
kamal-kaur04 wants to merge 13 commits into
Conversation
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>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
✅ Good to go
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_404_md["pr-404.md<br/>~6 lines"]
npackages_browserstack_service_src_instrumentation_createdDay_ts["createdDay.ts<br/>~3 lines"]
end
↻ 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 |
E2E evidence (v9) — events receivedReal BrowserStack builds of a WDIO sample with the service built from this branch; newSession forced to fail client-side (
The unpatched baseline (0 events from failing workers) and the pre-resend 503 control were run on the v10 line — see #403. After the date fix every event lands on the correct date (the first-commit rows show the day-first 🤖 Generated with Claude Code |
…_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>
E2E evidence — follow-up on
|
| Case | Build (testhub_uuid) |
Failed workers | Expected DriverInitFailure rows |
Rows received | created_day | SDKFeaturePerformance |
|---|---|---|---|---|---|---|
| CLI flow (mocha), 2 workers failing | kcagktxy4ms3janjdazyi0vilsdzbr2imgpzlnap |
2 | 2 | 2 (one 503 → 200 on resend) | 2026-12-02 11:06:01 | 1 row, 2026-12-02 11:06:09 |
| Healthy | ppp39octt00iroewr7uhgrjtwmxfbvnhalr9hkf4 |
0 | 0 | 0 | — | 1 row, 2026-12-02 11:06:37 |
Worst case now bounded: ~10 s (same change as v10) 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>
Review findings addressed in
|
| 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 596ab7a (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 | fmqnowtfwdarcpchku57d7kp0jsgvylrndjjow4l |
2 | 2 | 2 (one 503 → 200 on resend) | 2026-12-02 14:28:49 | [DriverInitError] WebdriverIO session could not be created (hostname=hub-euw.browserstack.com, …) — unmasked, as expected |
| Healthy | pz7p5ydpmgfe0bywb4qmgfztn6odxszihqomze8t |
0 | 0 | 0 | — | — |
🤖 Generated with Claude Code
… 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>
Review findings addressed in
|
| 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 2935a7a (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 | vtjzwpmwns3odiuvhk2xplvgx4bnkqzfecpkwv8p |
2 | 2 | 2 | 2026-12-02 15:59:29 | [DriverInitError] WebdriverIO session could not be created (hostname=…) — unmasked, as expected |
| Healthy | bzwuhfuzhhe1pke46zdxvxsio32aoop1kzmgjqwe |
0 | 0 | 0 | — | — |
🤖 Generated with Claude Code
|
RUN_TESTS |
|
🔴 SDK PR Review gate is red. Pending:
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. |
|
[SDK Wdio Test] TRA build state: passed | Stability 100% — verdict: success. Passed: 58, Failed: 0, Aggregate: 58. TRA: https://observability.browserstack.com/builds/vxqkkpdhm8gg1upidr4ljgrchpxhmnbe6gpuysrf |
|
🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: 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. |
|
🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: 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. |
1 similar comment
|
🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: 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>
|
🔴 SDK PR Review gate is red. Pending:
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. |
Real newSession error — implemented in
|
| Case | Build id | Expected | Received | errorMessage received |
|---|---|---|---|---|
| mocha (CLI flow), failing | qzpig06f5evvi7le7kjbogpzynd7vwrkfeq1imoa |
2 | 2 | [DriverInitError] WebDriverError: Request timed out! Consider increasing the "connectionRetryTimeout" option. |
| jasmine (direct flow), failing | qzn11npcp8c9bcjqz8drtgczwzvdontddnpqksgq |
2 | 2 | same |
| mocha, failing, observability off | 4bcy6znbhnzulqckc3asptocpqlamuyny2jbjoux |
2 | 2 | same |
| healthy | cyf0q22iyoopahffxg6ljxr1nyigmrgarw84jnzy |
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
|
🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: 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. |
|
🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: 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. |
|
RUN_TESTS |
|
[SDK Wdio Test] TRA build state: passed | Stability 100% — verdict: success. Passed: 58, Failed: 0, Aggregate: 58. TRA: https://observability.browserstack.com/builds/7xakgi9brkua11lbpmmgurcyvyccovcxqxkdhmad |
|
🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: 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. |
1 similar comment
|
🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: 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. |
What is this about?
Reports a
DriverInitFailureSDK 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.afterhook withoutbefore; the service detects that and sends one event per failed worker. Same path for the CLI/binary flow and the direct flow.runner:end, afterafter), so the service registers a small reporter of its own that writes no output.after()hands the failure off and returns; the reporter sends fromonRunnerEnd, holding reporter sync until the send settles, with the send deadline derived fromreporterSyncTimeout(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.when running "(webdriver appends the failed request there, including capabilities that carry the user's credentials), then credential-scrubbed and byte-capped.DriverInitFailureshape, includingtesthub_uuid.created_dayforDriverInitFailureandSDKFeaturePerformanceis now sent asYYYY-MM-DDTHH:MM:SS.ffffff UTC. The previousen-GBstring (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-reviewlabel)Version bump: (required — tick exactly one)
Release notes type: (optional)
Release notes (customer-facing): (optional but encouraged)
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)
DriverInitFailure(sdk_events) once per worker whose session creation failed, detected asafterwithoutbefore; resend on 429/503 only.created_dayin ISO UTC forDriverInitFailureandSDKFeaturePerformance(en-GB string was parsed MM/DD downstream).DriverInitFailuresend in the workerafterhook to a 10 s total deadline (each attempt capped by the time remaining; previously up to ~29 s);created_dayformatting shared fromsrc/instrumentation/createdDay.ts.runner:endvia a no-output service reporter) instead of a synthetic hostname/timeout message; cut webdriver's request details before scrubbing; deadline bounded byreporterSyncTimeout; synthetic fallback when no reporter/error.Checklist
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