Commit aa6bdc5
authored
Honor AI_AGENT and pass raw values through (#815)
## Why
The Java 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.md `AGENT=<name>`
standard. Vercel's `@vercel/detect-agent` library uses a parallel
`AI_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 setting
`AI_AGENT=claude-code_2-1-141_agent` ends up as `agent/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.
This mirrors the Go SDK change in databricks/databricks-sdk-go#1683.
## Changes
Two behavior changes in
`src/main/java/com/databricks/sdk/core/UserAgent.java`:
1. **`AI_AGENT` fallback.** Add `AI_AGENT=<name>` as a secondary
fallback after `AGENT=<name>`. `AGENT` wins when both are set to
non-empty values; empty is treated as unset for both. Explicit product
matchers (e.g. `CLAUDECODE`) still always win over both.
2. **Raw passthrough instead of `"unknown"`.** Drop the known-product
lookup in the fallback. The value is piped through the existing
`sanitize()` helper (disallowed chars become `-`, satisfying the
User-Agent allowlist `[0-9A-Za-z_.+-]`) and capped at 64 chars to keep
the header bounded. Known products like `cursor` or `claude-code` pass
through unchanged because they already satisfy the allowlist. Note that
the Java allowlist does not include `/`, so a value like `cursor/1.2.3`
sanitizes to `cursor-1.2.3`.
Same change is landing in `databricks-sdk-py` as a sibling PR.
## Test plan
- [x] `mvn -pl databricks-sdk-java test -Dtest=UserAgentTest` passes (48
tests)
- [x] `mvn spotless:apply` clean
- [x] `AI_AGENT=<known product>` returns the product name
- [x] `AI_AGENT=<unrecognized>` returns the raw sanitized value (no
longer `"unknown"`)
- [x] `AGENT` wins over `AI_AGENT` when both are non-empty
- [x] Empty `AGENT` falls through to `AI_AGENT`
- [x] Disallowed chars in `AGENT` / `AI_AGENT` are sanitized to `-`
- [x] Values longer than 64 chars are truncated
- [x] Explicit matcher (e.g. `CLAUDECODE`) still wins over both
fallbacks1 parent b27860a commit aa6bdc5
3 files changed
Lines changed: 154 additions & 20 deletions
File tree
- databricks-sdk-java/src
- main/java/com/databricks/sdk/core
- test/java/com/databricks/sdk/core
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
Lines changed: 30 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
253 | | - | |
| 252 | + | |
| 253 | + | |
254 | 254 | | |
255 | 255 | | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
256 | 264 | | |
257 | | - | |
| 265 | + | |
| 266 | + | |
258 | 267 | | |
259 | 268 | | |
260 | 269 | | |
| |||
294 | 303 | | |
295 | 304 | | |
296 | 305 | | |
297 | | - | |
298 | | - | |
299 | | - | |
| 306 | + | |
| 307 | + | |
300 | 308 | | |
301 | 309 | | |
302 | 310 | | |
| |||
317 | 325 | | |
318 | 326 | | |
319 | 327 | | |
320 | | - | |
| 328 | + | |
321 | 329 | | |
322 | 330 | | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
327 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
328 | 343 | | |
329 | 344 | | |
330 | 345 | | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
335 | 349 | | |
336 | | - | |
| 350 | + | |
337 | 351 | | |
338 | 352 | | |
339 | 353 | | |
| |||
Lines changed: 123 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
309 | 309 | | |
310 | 310 | | |
311 | 311 | | |
312 | | - | |
| 312 | + | |
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
366 | 368 | | |
367 | 369 | | |
368 | 370 | | |
369 | 371 | | |
370 | 372 | | |
371 | 373 | | |
372 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
373 | 426 | | |
374 | 427 | | |
375 | 428 | | |
376 | 429 | | |
377 | | - | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
378 | 496 | | |
379 | 497 | | |
380 | 498 | | |
381 | 499 | | |
| 500 | + | |
382 | 501 | | |
383 | 502 | | |
384 | 503 | | |
| |||
0 commit comments