Skip to content

feat: name the client product in the provider User-Agent - #382

Merged
liuedcson merged 1 commit into
mainfrom
feat/user-agent-client-token
Dec 2, 2026
Merged

liuedcson merged 1 commit into
mainfrom
feat/user-agent-client-token

Conversation

@liuedcson

Copy link
Copy Markdown
Collaborator

Why

User-Agent on model requests identified only the runtime:

stepcode (darwin 25.1.0; arm64)

A provider-side log could therefore not tell a stale desktop build from a current CLI, nor which release sent a request. The product name and version existed only in x-step-client / x-step-client-version, so anything that reads just the User-Agent saw a single anonymous client.

What

Append the client identity as an RFC 9110 product/version token after the runtime token:

stepcode (darwin 25.1.0; arm64) stepcode-cli/1.4.2
  • getPiUserAgent(client?) renders the value; the no-argument form is unchanged.
  • createModels({ userAgent }) sets the identity once for every request the collection dispatches (session turns, compaction, and any other completeSimple() caller). A per-request userAgent overrides it.
  • ProviderRequestOptions.userAgent reaches all three adapters (anthropic-messages, openai-completions, openai-responses) and survives buildBaseOptions(), so streamSimple keeps it.
  • Each half must be an RFC 9110 product token (ASCII tchar, ≤64 chars). An invalid half drops the client token and leaves the runtime token untouched, rather than emitting a malformed header.
  • The coding product resolves the pair in one place — resolveStepClientIdentity(): STEP_CLIENT (default stepcode-cli) plus STEPCODE_VERSION. x-step-client / x-step-client-version now read the same helper, so the header pair and the User-Agent cannot drift.
  • ModelRuntime seeds it from that helper and allows a host override via CreateModelRuntimeOptions.userAgent.

Hosts that set STEP_CLIENT (stepcode-desktop, stepcode-web, an embedding host) get their own product token without further changes.

Validation

  • pnpm run check — the type check, layer/boundary/entry-freeze/public-boundary guards, and check:browser-smoke pass. biome check --error-on-warnings passes on every touched path; note that current main already fails it on packages/coding-agent/test/step-subagent-events.test.ts:1218 (lint/style/useTemplate), which this PR does not touch.
  • pnpm exec vitest --run test/user-agent.test.ts test/fetch-option.test.ts test/telemetry-options.test.ts test/models-runtime.test.ts (providers) — 48 passed.
  • pnpm exec vitest --run test/step-client-identity.test.ts test/sdk-openrouter-attribution.test.ts test/step-trace-headers.test.ts test/step-environment.test.ts test/step-extension.test.ts (coding-agent) — 59 passed.

test/user-agent.test.ts asserts the header actually sent on the wire by each adapter through a capturing fetch, plus the collection → request → provider precedence. sdk-openrouter-attribution.test.ts now also asserts the session runtime hands the resolved identity to the provider.

Docs

packages/providers/README.md (client identity section), packages/coding-agent/docs/step-integration.md, and the STEP_CLIENT row in environment-variables.md.

The model request User-Agent identified only the runtime (`stepcode (darwin
25.1.0; arm64)`), so a provider-side log could not tell which product or
release sent a request. Append the client as an RFC 9110 `product/version`
token after the runtime token:

    stepcode (darwin 25.1.0; arm64) stepcode-cli/1.4.2

`getPiUserAgent(client?)` renders the value; `createModels({ userAgent })` and
per-request `userAgent` carry the identity to every adapter, and an invalid
half drops the client token instead of corrupting the runtime token. The
coding product resolves the pair from `STEP_CLIENT` and the build version in
one place, so `x-step-client` / `x-step-client-version` and the User-Agent
cannot drift apart.
@liuedcson
liuedcson merged commit c5c90ce into main Dec 2, 2026
2 checks passed
@liuedcson
liuedcson deleted the feat/user-agent-client-token branch December 2, 2026 06:07
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.

1 participant