Skip to content

feat(run-context): record run context from the launcher and worker processes [v9] - #397

Open
harshit-browserstack wants to merge 5 commits into
v9from
feat/run-context-autocapture
Open

harshit-browserstack wants to merge 5 commits into
v9from
feat/run-context-autocapture

Conversation

@harshit-browserstack

@harshit-browserstack harshit-browserstack commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

What is this about?

Target: v9 (WebdriverIO 9). Ports to main (WebdriverIO 10) and v8 follow separately.

This is the service half of the run-context record: non-sensitive facts about how a WebdriverIO run is set up, so BrowserStack support can reproduce a customer's setup without asking. The service records only facts that exist inside the launcher and worker processes; everything visible from outside them (host, project files, node_modules on disk) is recorded by the paired BrowserStack CLI change. Each side works without the other.

What it records (CLI flow only: mocha and cucumber, not multiremote):

  • the Node version, in the existing StartBinSessionRequest.language_version field (sent today as an empty string)
  • launcher process line: Node version; execArgv / NODE_OPTIONS flag names from an allowlist (anything else is only counted); TS runner; debugger attached yes/no; versions of webdriverio, @wdio/cli, @wdio/local-runner, the framework adapter and the service, each with the anchor it was resolved from (found_at)
  • launcher workers line: framework; maxInstances, per-capability wdio:maxInstances, maxInstancesPerCapability and the capability count, before and after the server config is applied (override: server_config | none); specFileRetries; mocha retries / cucumber retry
  • worker process lines: per-process facts only (flags, TS runner, debugger), for the first 10 workers of each capability (cid <capability>-<n>, n < 10; a spec-file retry keeps its cid), so log volume does not grow with the number of spec files

Where it goes. Strictly additive: no new sends, RPCs, event names or proto fields.

  • [run-context] {json} debug lines in logs/bstack-wdio-service.log (file only, never the console or the WDIO logger), archived by the existing log upload
  • a runContext property on the existing SDKTestSuccessful event, launcher only; the exit-path resend rebuilds the same event and carries it too

Guarantees:

  • only allowlisted typed values (versions, flag names, enums, counts); at most 2048 bytes per line and per property, with lists halved and then the record truncated if ever exceeded
  • never paths, flag values, env values, hostnames, URLs, capability contents or error text
  • every exported function catches its own errors and changes no return value; when capture is on, a failure writes a typed [run-context] skipped at=<site> reason=<code> line (no message text)
  • off unless all three hold: the CLI's resolved config carries disableAutoCaptureLogs and it is falsy; the service option disableAutoCaptureLogs is not set; BROWSERSTACK_DISABLE_AUTO_CAPTURE_LOGS is not true (the CLI never sees that env var, so the service checks it itself)
  • fails closed when the resolved config is missing; one record per process
  • no network and no subprocesses; file reads happen in the launcher only (bounded node_modules walks, at most 4 package.json reads of up to 64 KB, 250 ms budget)

Reviewer notes:

  • The constants live in one RUN_CONTEXT entry at the end of src/constants.ts; only STATE_KEY, built from SCHEMA_VERSION, stays in the module.
  • @wdio/cli appends --import <tsx> to NODE_OPTIONS itself, so --import and ts_runner: tsx show on every run; customer-set flags are the ones beyond it.
  • WDIO merges its defaults before onPrepare, so an unset maxInstances reads WDIO's default 100 (source wdio_config) and cannot be told apart from an explicit 100.
  • The CLI-layer modules log through cli/cliLogger.js (same file) rather than bstackLogger / util.ts, so the gRPC client keeps its light import graph.
  • Per-process dedupe keeps its state in a Symbol.for(...) slot on process, so a second copy of the module in the same process shares it.
  • The existing Sending SDK event with data debug line prints the whole SDKTestSuccessful body, so it now includes runContext.
  • With a CLI whose resolved config lacks disableAutoCaptureLogs, every service-side record stays off; language_version is still sent and older CLIs ignore it.

Related Jira task/s

N/A (tracked internally)

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)

  • The service now records non-sensitive details about how your tests are run (Node version, WebdriverIO package versions, worker and retry settings, whether a debugger is attached) in its debug log and in the usage data it already sends to BrowserStack at the start and end of a run, to help BrowserStack support reproduce issues faster. Credentials, paths, URLs and environment values are never recorded; set disableAutoCaptureLogs: true in the service options to turn it off.

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

  • Add the WebdriverIO run-context record (CLI flow only): language_version on StartBinSession, [run-context] lines in bstack-wdio-service.log (launcher process and workers lines, plus per-process lines for the first 10 workers of each capability), and runContext on SDKTestSuccessful. Allowlisted typed values only; honours disableAutoCaptureLogs (CLI config, service option and env).

Checklist

  • Ready to review
  • Has it been tested locally?

Unit tests:

  • existing suite: 1505 passing (58 files) on this branch and 1505 on its base (v9); the failing set is identical to the base (empty)
  • eslint and tsc --noEmit clean
  • moving the constants: every old and new value compared mechanically (all identical, rest of the module byte-identical), and an 11-scenario behavioural check (gate open and closed, opt-outs, sampled and unsampled workers, held records, the skipped line) gave byte-identical output before and after; that check ran locally and is not part of this diff

Live acceptance: the same code before the constants move passed earlier live acceptance on WebdriverIO 9 + mocha (5 runs, including a released-service control against the same CLI build).

Live build (this head, WebdriverIO 9 + mocha, Chrome latest / Windows 11, CLI flow, run under env -i with planted decoy secrets):

Pending: build links and [run-context] lines will be added after the live run.

PR Validations

Run Tests: Comment RUN_TESTS to trigger sanity tests.

🤖 Generated with Claude Code

harshit-browserstack and others added 4 commits November 30, 2026 13:08
Write typed `[run-context]` debug lines to the service log from the
launcher and from each worker that connects to the CLI: Node version,
allowlisted preload and inspector flag names from execArgv and
NODE_OPTIONS, inspector state, and name@version of the WebdriverIO
packages resolvable from the running entry script. The launcher also
records maxInstances, per-capability instances, spec-file retries and
framework retries, before and after the server config is applied.

The launcher facts ride on SDKTestSuccessful as `runContext`, and
StartBinSessionRequest.language_version carries process.version.
Nothing is written or sent when disableAutoCaptureLogs is set, or when
the CLI config does not carry the key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WDIO starts one worker per spec file per capability, so one line per
worker grew with suite size. Worker lines now carry only per-process
facts (flag names, TypeScript loader, inspector state); package
versions stay on the launcher line. Only the first ten workers of each
capability, by the spec index in their worker id, write a line.

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

coderabbitai Bot commented Nov 30, 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: 5705d487-1c24-4e7d-ba37-edd50869ac89

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

@harshit-browserstack

harshit-browserstack commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator Author

⚠️ Needs human review

File Status Reason
.changeset/pr-397.md ✅ All Clear Re-judged this round; no blocking findings
packages/browserstack-service/src/cli/grpcClient.ts ⚠️ Needs Human Review Not re-judged this round; unchanged since the last reviewed commit
packages/browserstack-service/src/cli/index.ts ⚠️ Needs Human Review Not re-judged this round; unchanged since the last reviewed commit
packages/browserstack-service/src/cli/runContext.ts ⚠️ Needs Human Review Not re-judged this round; unchanged since the last reviewed commit
packages/browserstack-service/src/constants.ts ⚠️ Needs Human Review Not re-judged this round; unchanged since the last reviewed commit
packages/browserstack-service/src/instrumentation/funnelInstrumentation.ts ⚠️ Needs Human Review Not re-judged this round; unchanged since the last reviewed commit
packages/browserstack-service/src/launcher.ts ⚠️ Needs Human Review Not re-judged this round; unchanged since the last reviewed commit

Process integrity

The review gate could NOT certify this run — the verdict is held at ⚠️ pending regardless of findings:

  • G3 — u002: no full read receipt for card:cards/_shared.md
  • G3 — u002: no full read receipt for card:cards/wdio-service.md
  • G3 — u002: no full read receipt for pack:default
  • G3 — u002: no full read receipt for pack:external
  • G3 — u002: no full read receipt for pack:grpc
  • G3 — u002: no full read receipt for pack:integration
  • G3 — u002: no full read receipt for pack:node
  • G3 — u002: no full read receipt for pack:observability
  • G3 — u002: no full read receipt for slice
  • G3 — u003: no full read receipt for card:cards/_shared.md
  • G3 — u003: no full read receipt for card:cards/wdio-service.md
  • G3 — u003: no full read receipt for pack:default
  • G3 — u003: no full read receipt for pack:external
  • G3 — u003: no full read receipt for pack:integration
  • G3 — u003: no full read receipt for pack:node
  • G3 — u003: no full read receipt for pack:observability
  • G3 — u003: no full read receipt for slice
  • G3 — u004: no full read receipt for card:cards/_shared.md
  • G3 — u004: no full read receipt for card:cards/wdio-service.md
  • G3 — u004: no full read receipt for pack:default
  • G3 — u004: no full read receipt for pack:external
  • G3 — u004: no full read receipt for pack:integration
  • G3 — u004: no full read receipt for pack:node
  • G3 — u004: no full read receipt for pack:observability
  • G3 — u004: no full read receipt for slice
  • G3 — u005: no full read receipt for card:cards/_shared.md
  • G3 — u005: no full read receipt for card:cards/wdio-service.md
  • G3 — u005: no full read receipt for pack:default
  • G3 — u005: no full read receipt for pack:external
  • G3 — u005: no full read receipt for pack:integration
  • G3 — u005: no full read receipt for pack:node
  • G3 — u005: no full read receipt for pack:observability
  • G3 — u005: no full read receipt for slice
  • G3 — u006: no full read receipt for card:cards/_shared.md
  • G3 — u006: no full read receipt for card:cards/wdio-service.md
  • G3 — u006: no full read receipt for pack:default
  • G3 — u006: no full read receipt for pack:external
  • G3 — u006: no full read receipt for pack:integration
  • G3 — u006: no full read receipt for pack:node
  • G3 — u006: no full read receipt for pack:observability
  • G3 — u006: no full read receipt for slice
  • G3 — u007: no full read receipt for card:cards/_shared.md
  • G3 — u007: no full read receipt for card:cards/wdio-service.md
  • G3 — u007: no full read receipt for pack:default
  • G3 — u007: no full read receipt for pack:external
  • G3 — u007: no full read receipt for pack:integration
  • G3 — u007: no full read receipt for pack:node
  • G3 — u007: no full read receipt for pack:observability
  • G3 — u007: no full read receipt for slice

Change map (generated deterministically from the diff)

graph LR
  subgraph nwdio_service["wdio-service"]
    npackages_browserstack_service_src_cli_runContext_ts["⚠ runContext.ts<br/>~433 lines"]
    npackages_browserstack_service_src_constants_ts["constants.ts<br/>~48 lines"]
    n_changeset_pr_397_md["pr-397.md<br/>~5 lines"]
    npackages_browserstack_service_src_cli_index_ts["index.ts<br/>~3 lines"]
    npackages_browserstack_service_src_launcher_ts["launcher.ts<br/>~3 lines"]
    npackages_browserstack_service_src_cli_grpcClient_ts["grpcClient.ts<br/>~2 lines"]
    npackages_browserstack_service_src_instrumentation_funnelInstrumentation_ts["funnelInstrumentation.ts<br/>~2 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

@harshit-browserstack

Copy link
Copy Markdown
Collaborator Author

RUN_TESTS

@minionhelperappqa

Copy link
Copy Markdown

[SDK Wdio Test] TRA build state: passed | Stability 100% — verdict: success. Passed: 58, Failed: 0, Aggregate: 58. TRA: https://observability.browserstack.com/builds/xwr9kdktiay6abgd4guddtbjzuqvbmbf6z4qf8hi

@github-actions

github-actions Bot commented Dec 1, 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: pending).

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.

1 participant