Skip to content

fix: track SDK language in Go Browserbase session metadata - #2477

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

fix: track SDK language in Go Browserbase session metadata#2477
shrey150 merged 2 commits into
v4-spikefrom
shrey/stg-2714-go-sdk-language

Conversation

@shrey150

@shrey150 shrey150 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 4b2b857

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

Comment thread packages/sdk-go/browserbase_session.go Outdated

@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 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.
Architecture diagram
sequenceDiagram
    participant GoSDK as BrowserbaseSessionClient
    participant Metadata as stagehandSessionMetadata
    participant BBAPI as Browserbase API

    Note over GoSDK,BBAPI: Session creation with Stagehand attribution

    GoSDK->>GoSDK: caller provides userMetadata<br/>(may contain spoofed "stagehand" keys)
    GoSDK->>Metadata: stagehandSessionMetadata(userMetadata)
    Metadata->>Metadata: clone userMetadata map
    Metadata->>Metadata: merge authoritative keys:<br/>"stagehand"="true",<br/>"stagehand_sdk_language"="go"
    Note over Metadata: Authoritative keys always win –<br/>any caller values for these keys are overridden
    Metadata-->>GoSDK: merged metadata
    GoSDK->>BBAPI: POST /sessions with merged userMetadata
    alt Authoritative keys preserved
        BBAPI-->>GoSDK: Session created with attribution
    else Spoofed caller keys present
        Note over GoSDK: Spoofed keys silently overwritten<br/>(no error)
    end
Loading

Re-trigger cubic

@shrey150
shrey150 requested a review from monadoid July 28, 2026 17:54
@shrey150
shrey150 force-pushed the shrey/stg-2714-go-sdk-language branch from 43c0bb6 to 692d09f Compare July 28, 2026 18:42
shrey150 and others added 2 commits July 28, 2026 11:45
Stamp every Browserbase session the Go SDK creates with authoritative
stagehand/stagehand_sdk_language user metadata, mirroring the TypeScript
SDK's session-metadata attribution. Attribution is applied after the
caller's userMetadata so it cannot be spoofed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Addresses review feedback from shrey150
@shrey150
shrey150 force-pushed the shrey/stg-2714-go-sdk-language branch from 692d09f to 4b2b857 Compare July 28, 2026 18:46
@shrey150
shrey150 merged commit 8882b68 into v4-spike Jul 28, 2026
14 checks passed
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