Skip to content

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

Merged
Divyansh-db merged 3 commits into
mainfrom
useragent-dedup-identical-pairs
Jun 24, 2026
Merged

Deduplicate identical key/value pairs in user agent builder#1718
Divyansh-db merged 3 commits 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.
Comment thread useragent/user_agent.go Outdated
@Divyansh-db Divyansh-db enabled auto-merge June 24, 2026 05:05
@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: 0279aff29e2ecea968731af458f2cc4a7d198d05

Checks will be approved automatically on success.

@Divyansh-db Divyansh-db added this pull request to the merge queue Jun 24, 2026
Merged via the queue into main with commit 3900b84 Jun 24, 2026
14 checks passed
@Divyansh-db Divyansh-db deleted the useragent-dedup-identical-pairs branch June 24, 2026 05:28
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