Deduplicate identical key/value pairs in user agent builder#1718
Open
Divyansh-db wants to merge 1 commit into
Open
Deduplicate identical key/value pairs in user agent builder#1718Divyansh-db wants to merge 1 commit into
Divyansh-db wants to merge 1 commit into
Conversation
`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.
|
If integration tests don't run automatically, an authorized user can run them manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-livedcontext.Context— for example a caller that threads a single context across many operations — the per-context user-agent data accumulates duplicate entries, soFromContextproduces aUser-Agentstring 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, includingTestMultiplePartnersandTestFromContext_Custom.TestInContext_DeduplicatesIdenticalPairs: 100 repeated identical injections collapse to one entry each; distinct values still preserved.go vet ./useragent/andgofmtclean.🤖 Generated with Claude Code.