Honor AI_AGENT and pass raw values through.#1683
Open
renaudhartert-db wants to merge 4 commits into
Open
Conversation
Adds the Vercel @vercel/detect-agent AI_AGENT=<name> env var as a secondary fallback after the agents.md AGENT=<name> standard. AGENT wins when both are non-empty; empty is treated as unset for both. Also changes the fallback behavior to pass the raw value through (sanitized via Sanitize() and capped at 64 chars) instead of coercing unrecognized names to the literal "unknown". Bucketing arbitrary tool names is an ETL concern, not the SDK's; the prior coercion buried useful telemetry such as versioned variants like "claude-code_2-1-141_agent" under agent/unknown.
Trim const comment for maxAgentFallbackLen and the agentEnvFallback function comment to remove duplicated rationale. Drop three test cases that exercise the same code path as a sibling case (AGENT=claude-code, AI_AGENT=claude-code, AI_AGENT-unrecognized-passthrough).
814947c to
035c7d1
Compare
|
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. |
simonfaltum
approved these changes
May 19, 2026
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.
Why
The Go SDK detects AI coding agents and surfaces them as
agent/<name>in the User-Agent. Today the generic fallback (when no proprietary env var fires) only honors the agents.mdAGENT=<name>standard. Vercel's@vercel/detect-agentlibrary uses a parallelAI_AGENT=<name>convention that tools in the Vercel ecosystem set instead; we currently miss those.Separately, the existing fallback coerces any unrecognized value to the literal string
"unknown". That buries useful signal: a tool settingAI_AGENT=claude-code_2-1-141_agentends up asagent/unknown, discarding the very signal (tool name plus version variant) we want to see. Bucketing arbitrary names is an ETL concern, not the SDK's.Changes
Two behavior changes in
useragent/agent.go:AI_AGENTfallback. AddAI_AGENT=<name>as a secondary fallback afterAGENT=<name>.AGENTwins when both are set to non-empty values; empty is treated as unset for both. Explicit product matchers (e.g.CLAUDECODE=1) still always win over both.Raw passthrough instead of
"unknown". Drop the known-product lookup in the fallback. The value is piped through the existingSanitize()helper (so disallowed chars become-and the User-Agent allowlist[0-9A-Za-z_.+-]+is satisfied) and capped at 64 chars to keep the header bounded. Known products likecursororclaude-codepass through unchanged because they already satisfy the allowlist.Same change should land in
databricks-sdk-pyanddatabricks-sdk-java; sibling PRs to follow.Test plan
go test ./useragent/...passesgofmt -l useragent/cleanAI_AGENT=<known product>returns the product nameAI_AGENT=<unrecognized>returns the raw sanitized value (no longer"unknown")AGENTwins overAI_AGENTwhen both are non-emptyAGENTfalls through toAI_AGENTAGENT/AI_AGENTare sanitized to-CLAUDECODE=1) still wins over both fallbacks