Skip to content

fix: track SDK language in v4 metadata - #2467

Merged
shrey150 merged 2 commits into
v4-spikefrom
shrey/stg-2714-track-sdk-language
Jul 28, 2026
Merged

fix: track SDK language in v4 metadata#2467
shrey150 merged 2 commits into
v4-spikefrom
shrey/stg-2714-track-sdk-language

Conversation

@shrey150

@shrey150 shrey150 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • tag Browserbase sessions created by the TypeScript SDK with authoritative stagehand and stagehand_sdk_language user metadata
  • preserve caller-provided session metadata while preventing attribution fields from being spoofed
  • send the Python SDK name and installed package version through the existing runtime.configure.clientInfo metadata field
  • add patch changesets for the TypeScript and Python SDKs

Why

Stagehand v3 identifies its SDK language with the x-language request header. V4 no longer routes SDK work through the hosted Stagehand API, so Browserbase session metadata is the durable, queryable equivalent for cloud sessions. The existing cross-language clientInfo handshake remains the right metadata path for runtime connections.

v4-spike currently creates Browserbase sessions from the TypeScript SDK. Python session creation is not implemented on this branch yet, while the in-flight Go SDK already sends its language and version through clientInfo. Future Python and Go Browserbase session creators should stamp stagehand_sdk_language with their respective language values.

E2E Test Matrix

Command / flow Observed output Confidence / sufficiency
Local TypeScript build → create a real Browserbase session with spoofed attribution → retrieve the session through the Browserbase API Retrieved stagehand: "true", stagehand_sdk_language: "typescript", and preserved the custom suite field Proves the exact code under review writes durable Browserbase session metadata and keeps Stagehand attribution authoritative
vitest run --root . packages/sdk-ts/tests 134 passed, 1 skipped Covers the TypeScript SDK, including session creation, packaging, and metadata merge behavior
uv run --locked pytest 196 passed Covers the full Python SDK, including the serialized runtime.configure.client_info payload
Build the local Python wheel → uv run --isolated --no-project --with dist/*.whl python scripts/smoke.py Installed wheel completed stagehand.init and stagehand.close against the built extension Proves the published Python artifact can complete the real runtime handshake with the new metadata
Workspace formatting, linting, protocol/evals type checking, Python formatting/linting/type checking, and changeset checks All commands exited successfully; workspace lint reported pre-existing warnings only Supporting static validation across every changed package

Linear

STG-2714


Summary by cubic

Track SDK language in v4 metadata to meet Linear STG-2714. TypeScript sessions now set authoritative Browserbase user metadata, and Python sends SDK name and version via client_info during runtime configuration.

  • New Features
    • TypeScript SDK: stamp Browserbase sessions with stagehand: "true" and stagehand_sdk_language: "typescript", merging other userMetadata and preventing spoofing using centralized SDK identity.
    • Python SDK: send client_info with name: "stagehand-sdk-python" and installed package version in runtime.configure.

Written for commit f9ff170. Summary will update on new commits.

Review in cubic

@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f9ff170

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@browserbasehq/stagehand Patch
@browserbasehq/stagehand-python Patch
@browserbasehq/stagehand-evals Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant TSClient as TypeScript SDK Client
    participant TSBrowserbase as Browserbase Session Client
    participant BrowserbaseAPI as Browserbase API
    participant PythonClient as Python SDK Client
    participant PythonRPC as RPC Client
    participant StagehandExt as Stagehand Extension

    Note over TSClient,StagehandExt: TypeScript SDK: Session Creation with Metadata

    TSClient->>TSBrowserbase: createSession({ userMetadata, ...params })
    TSBrowserbase->>TSBrowserbase: Merge userMetadata with authoritative STAGEHAND_SESSION_METADATA
    Note over TSBrowserbase: stagehand: "true", stagehand_sdk_language: "typescript"
    alt Caller provides spoofed stagehand keys
        Note over TSBrowserbase: Caller keys are overridden by authoritative metadata
    end
    TSBrowserbase->>BrowserbaseAPI: createSession({ userMetadata, extensionId, ...params })
    BrowserbaseAPI-->>TSBrowserbase: Session with cdpUrl, sessionId
    TSBrowserbase-->>TSClient: Session connection details

    Note over PythonClient,StagehandExt: Python SDK: Runtime Configuration with Client Info

    PythonClient->>PythonRPC: connect_rpc_client(cdp, ...)
    PythonRPC->>PythonRPC: Construct _STAGEHAND_SDK_CLIENT_INFO
    Note over PythonRPC: name: "stagehand-sdk-python", version: from importlib.metadata
    PythonRPC->>StagehandExt: runtime.configure({ client_info, cdp_url, log_level, telemetry })
    Note over PythonRPC,StagehandExt: client_info sent as ImplementationInfo payload
    StagehandExt-->>PythonRPC: Configuration acknowledged
    PythonRPC-->>PythonClient: Connected RPC client

    Note over TSClient,StagehandExt: Future: Go SDK would follow same pattern for session metadata
Loading

Re-trigger cubic

@shrey150
shrey150 merged commit c384b95 into v4-spike Jul 28, 2026
11 checks passed
shrey150 added a commit that referenced this pull request Jul 28, 2026
## Summary

- tag Browserbase sessions created by the Go SDK with authoritative
`stagehand` and `stagehand_sdk_language` user metadata, mirroring the
TypeScript SDK
- preserve caller-provided session metadata while preventing the
attribution fields from being spoofed
- add a unit test that captures the outgoing session-create request and
asserts spoofed attribution keys are overridden, plus update the
existing typed-request round-trip test

## Why

Stagehand v3 identifies its SDK language with the `x-language` request
header. V4 no longer routes SDK work through the hosted Stagehand API,
so Browserbase session metadata is the durable, queryable equivalent for
cloud sessions. #2467 added this for the TypeScript and Python SDKs. The
Go SDK has since landed on `v4-spike`, so this PR completes the
follow-up for Go.

## E2E Test Matrix

| Command / flow | Observed output | Confidence / sufficiency |
| --- | --- | --- |
| Build the current server extension, then run the Go generator check
and embedded-extension check | Both freshness checks passed after
rebasing onto the current `v4-spike`. | Confirms the PR no longer
inherits the generated-model or embedded-extension drift that previously
failed CI. |
| Go CI path: gofmt, vet, example compilation, package tests with local
Chrome, generator tests, and build | All commands passed; the Stagehand
package and extension packages passed their test suites. | Covers the
complete Go CI path against the rebased branch. |
| `go test -race -run
'TestStagehandSessionMetadata|TestBrowserbaseSessionClientCreateUsesTypedEndpoint'
.` | Passed under the race detector. | Directly exercises authoritative
attribution, caller-map immutability, and the typed Browserbase request
path. |
| `BROWSERBASE_SMOKE=1 go test -run TestStagehandBrowserbaseIntegration`
→ create a real Browserbase session through the Go SDK → retrieve it
through the Browserbase API | Retrieved
`{"stagehand":"true","stagehand_sdk_language":"go","suite":"stagehand-v4-go-public-smoke"}`;
the session was released. | Proves the exact Go attribution behavior is
durable and queryable on a live Browserbase session. |

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants