Skip to content

feat: report DriverInitFailure when a worker cannot create its session (v8) - #405

Closed
kamal-kaur04 wants to merge 12 commits into
v8from
feat/driver-init-failure-event-v8
Closed

kamal-kaur04 wants to merge 12 commits into
v8from
feat/driver-init-failure-event-v8

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

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 4 commits December 1, 2026 15:26
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: a10179d4-b5b9-4140-801f-bd713c8b5f04

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

✅ Good to go

File Confidence
.changeset/pr-405.md ✅ All Clear
packages/browserstack-service/src/constants.ts ✅ All Clear
packages/browserstack-service/src/instrumentation/createdDay.ts ✅ All Clear
packages/browserstack-service/src/instrumentation/funnelInstrumentation.ts ✅ All Clear
packages/browserstack-service/src/instrumentation/performance/performance-tester.ts ✅ All Clear
packages/browserstack-service/src/service.ts ✅ All Clear
packages/browserstack-service/tests/instrumentation/funnelInstrumentation.test.ts ✅ All Clear
packages/browserstack-service/tests/performance-tester.test.ts ✅ All Clear
packages/browserstack-service/tests/service.test.ts ✅ All Clear

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/>~340 lines"]
    npackages_browserstack_service_src_instrumentation_funnelInstrumentation_ts["funnelInstrumentation.ts<br/>~166 lines"]
    npackages_browserstack_service_src_service_ts["service.ts<br/>~51 lines"]
    npackages_browserstack_service_tests_service_test_ts["service.test.ts<br/>~51 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/>~8 lines"]
    n_changeset_pr_405_md["pr-405.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 (v8) — 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 — first commit first commit 3mcpn3kggw984d4eu8m25ouridw1wmuliweo6bwe 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 qqzihzywpuzardp5i8iw0amsqfpfn8hfbtknplg8 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 trn3lycz8kzcxcgfqxdkj8ncfh6kwb6ieymd0rhk 2 2 2 2026-12-01 10:43:28 webdriverio / WebdriverIO-mocha [DriverInitError] WebdriverIO session could not be created (hostname=…, connectionRetryTimeout=…)
Direct flow (jasmine), 2 workers failing — date fix date fix f0wnnuu2luxsec90goxpx6sqmuxbdxmibl4welxg 2 2 2 2026-12-01 10:43:44 webdriverio / WebdriverIO-jasmine [DriverInitError] WebdriverIO session could not be created (hostname=…, connectionRetryTimeout=…)
Healthy date fix nrx92m4kgpp3ehondibok50fyylr9r5r7fnnf92s 0 0 0 — — —
SDKFeaturePerformance date — healthy run perf date fix 7jyd1vzrpey5cmyiulzxqyibvyemla3vfqvnphkz 0 1 perf row 1 perf row 2026-12-01 13:39:43 — —

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 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 2 commits December 2, 2026 16:39
…_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>
@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

E2E evidence — follow-up on 7c6b940 (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 fftgxeqpn691rdyi1et2d7yr6fwvbj9vnc1n5hbp 2 2 2 (one 503 → 200 on resend) 2026-12-02 11:10:45 1 row, 2026-12-02 11:10:54
Healthy du8hjy8i1iztosi0donaeglwjwak9xxhj9fo5kob 0 0 0 — 1 row, 2026-12-02 11:11:21

Worst case now bounded: 10.02 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 8cedd8d

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 8cedd8d (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 yqpwg1wp19fydukra1bqtsaeappxlvbsyrfnfevq 2 2 2 (one 503 → 200 on resend) 2026-12-02 14:32:05 [DriverInitError] WebdriverIO session could not be created (hostname=hub-euw.browserstack.com, …) — unmasked, as expected
Healthy ycvsiymp1shnenjincr5aefgwzojxewwaegcj0jc 0 0 0 — —

🤖 Generated with Claude Code

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

github-actions Bot commented Dec 2, 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.

1 similar comment
@github-actions

github-actions Bot commented Dec 2, 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 2, 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.

1 similar comment
@github-actions

github-actions Bot commented Dec 2, 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 2, 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.

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

github-actions Bot commented Dec 2, 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.

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

@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

Review findings addressed in adc879c

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 adc879c (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 gckyaan2l3t49u0b5qrjh9v61c3k0a8rux1yqf5i 2 2 2 2026-12-02 16:04:50 [DriverInitError] WebdriverIO session could not be created (hostname=…) — unmasked, as expected
Healthy zfmdgi7zt9smj7mcbwsnvuhkpt1efkp1hxhyzmzu 0 0 0 — —

🤖 Generated with Claude Code

@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: 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

Review findings addressed

1. testhub_uuid / sdkRunId taken straight from BROWSERSTACK_TESTHUB_UUID — fixed in 20adccd.

Both launcher paths (util.ts and cli/index.ts) set TestOpsConfig.buildHashedId and BROWSERSTACK_TESTHUB_UUID to the same value at the same moment. This event is sent from the worker, which inherits the env var, while the TestOpsConfig singleton is populated in the launcher process, so in a worker it is usually unset. That is why the env var was used, and the E2E runs on this PR show every row keyed to the correct build.

The guard is still warranted: if the build id were ever missing, process.env.X = undefined stores the literal string "undefined", which would have been sent as an identity. The payload now uses a resolver that:

  • prefers TestOpsConfig.getInstance().buildHashedId when this process owns one
  • falls back to the inherited BROWSERSTACK_TESTHUB_UUID
  • rejects '', 'null' and 'undefined' (→ null)

Five new tests cover the owned id, the worker fallback, and each placeholder value. Full suite passes (46 files / 1205 tests); tsc clean. The same change is applied on the v10 and v9 lines.

2. New EDS endpoint and payload shape — no change needed; verified.

/send_sdk_events with the sdk_events envelope (testhub_uuid, created_day, event_name, user_data, host_info, event_json) is not new to this service: PerformanceTester.uploadEventsData already posts SDKFeaturePerformance events to ${APIUtils.EDS_URL}/send_sdk_events with the same envelope. Ingestion of this exact DriverInitFailure payload, including the YYYY-MM-DDTHH:MM:SS.ffffff UTC created_day format, is confirmed by real builds whose events were received and stored with the correct build id and date. See the E2E evidence comments on this PR (each table lists the build ids, expected and received counts, and created_day).

🤖 Generated with Claude Code

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

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

1 similar comment
@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.

@kamal-kaur04

Copy link
Copy Markdown
Collaborator Author

Closing: the driver-init failure reporting will ship on the v9 and v10 lines only (#404, #403). The v8 line is not being updated with this change.

🤖 Generated with Claude Code

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.

2 participants