Add AI agent detection to user-agent string#701
Conversation
Detect known AI coding agents (Claude Code, Cursor, Cline, Codex, Gemini CLI, OpenCode, Antigravity) via environment variables and append agent/<name> to the user-agent header. Uses the same double-checked locking pattern as CI/CD detection. Returns empty when zero or multiple agents are detected (ambiguity guard). Co-authored-by: Isaac
Move cleanupAgentEnv() to an @AfterEach tearDown method so test isolation is failure-safe. Previously, if an assertion failed before the manual cleanup call, static state would leak between tests. Co-authored-by: Isaac
simonfaltum
left a comment
There was a problem hiding this comment.
Review (automated, 2 agents)
Verdict: Approved
0 Critical | 0 Major | 2 Gap | 2 Nit | 1 Suggestion
See inline comments for details.
databricks-sdk-java/src/main/java/com/databricks/sdk/core/UserAgent.java
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/UserAgent.java
Outdated
Show resolved
Hide resolved
databricks-sdk-java/src/main/java/com/databricks/sdk/core/UserAgent.java
Show resolved
Hide resolved
|
[Gap (Nit)] Existing cicd tests now depend on The PR removes manual Suggestion: Add |
|
[Gap (Nit)] Missing test that cicd and agent coexist in user-agent string The PR adds agent detection alongside CI/CD detection, but no test asserts both segments are present together. Suggestion: Add a test with one CI/CD env var and one agent env var set, then assert both |
Replace AbstractMap.SimpleEntry with AgentDef inner class to match the CicdProvider/EnvVar style. Add early exit in lookupAgentProvider when count > 1. Remove redundant null check for agentProvider() return value to match cicdProvider() pattern. Co-authored-by: Isaac
We have data from direct testing in Copilot CLI confirming it sets COPILOT_CLI=1 in its environment. Add it to the canonical agent list. Co-authored-by: Isaac
|
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. |
Summary
agent/<name>to the HTTP user-agent headerANTIGRAVITY_AGENT), Claude Code (CLAUDECODE), Cline (CLINE_ACTIVE), Codex (CODEX_CI), Copilot CLI (COPILOT_CLI), Cursor (CURSOR_AGENT), Gemini CLI (GEMINI_CLI), OpenCode (OPENCODE)The
COPILOT_CLIenv var was confirmed by direct testing in Copilot CLI.Test plan
agent/segmentagent/segmentagent/segmentmvn spotless:applypassesmvn -Dtest=UserAgentTest testpassesThis pull request was AI-assisted by Isaac.