Skip to content

Deduplicate identical key/value pairs in user agent builder#1718

Open
Divyansh-db wants to merge 1 commit into
mainfrom
useragent-dedup-identical-pairs
Open

Deduplicate identical key/value pairs in user agent builder#1718
Divyansh-db wants to merge 1 commit into
mainfrom
useragent-dedup-identical-pairs

Conversation

@Divyansh-db

Copy link
Copy Markdown
Contributor

Summary

useragent.data.With() appended every key/value pair unconditionally and never deduplicated. When the same user-agent dimension is injected repeatedly onto a reused or long-lived context.Context — for example a caller that threads a single context across many operations — the per-context user-agent data accumulates duplicate entries, so FromContext produces a User-Agent string that grows without bound (e.g. ... sdk/x sdk/x resource/y resource/y ...). Sufficiently large headers can be rejected or truncated downstream.

Note that With's doc comment claimed it "always uses the latest value for a given alphanumeric key", but the implementation always appended, and existing tests rely on multiple distinct values per key being preserved (e.g. multiple partners). This change keeps that behavior and only removes exact duplicates.

Change

data.With() now skips appending a key/value pair when an identical pair is already present. Distinct values for the same key are still preserved, so no existing behavior or tests change. The doc comment is updated to describe the actual behavior.

Testing

  • go test ./useragent/ — all pass, including TestMultiplePartners and TestFromContext_Custom.
  • Added TestInContext_DeduplicatesIdenticalPairs: 100 repeated identical injections collapse to one entry each; distinct values still preserved.
  • go vet ./useragent/ and gofmt clean.

🤖 Generated with Claude Code.

`useragent.data.With()` appended every key/value pair unconditionally and never deduplicated. When the same user-agent dimension is injected repeatedly onto a reused or long-lived context (a caller that threads one context across many operations), the per-context user-agent data accumulated duplicate entries and `FromContext` produced a User-Agent string that grew without bound.

Skip appending a pair when an identical key/value is already present. Distinct values for the same key are still preserved, so existing multi-value behavior (e.g. multiple partners) is unchanged.
@github-actions

Copy link
Copy Markdown

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/sdk-go

Inputs:

  • PR number: 1718
  • Commit SHA: f743f5bb933f82cf33ef7716ec35607401ccca46

Checks will be approved automatically on success.

@Divyansh-db Divyansh-db deployed to test-trigger-is June 12, 2026 08:19 — with GitHub Actions Active
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