Repository navigation
Drop the SDK agent token from User-Agent under DATABRICKS_NOT_AN_AGENT - #8143
Conversation
…ICKS_NOT_AN_AGENT The SDK adds an agent/<name> token to User-Agent from its process-wide agent detection, which does not read DATABRICKS_NOT_AN_AGENT. The SDK has no per-client option for this, and its header is set after request visitors run, so the CLI's workspace and account clients wrap their HTTP transport and remove the token when the variable is set. Without the variable the clients are unchanged. Co-authored-by: Isaac <no-reply@databricks.com>
Regression test report ✅Commit: Selected 1 changed tests (limit=20, 0 not selected) 1 tests: regression=1 unreleased=0 coverage=0 failing=0
TestAccept/cmd/aitools/not-an-agent: branch ✅ | main (e6f3460) ❌ | latest (v1.28.0) ❌main (e6f3460): latest (v1.28.0): |
✅ Integration test reportCommit: 34e0c26
Top 6 slowest tests (at least 2 minutes):
|
The acceptance golden for cmd/aitools/not-an-agent recorded a cicd/github token on GitHub Actions runners, so strip cicd/ segments from its User-Agent the way other acceptance tests do. The two new header tests opened a loopback server, which the Windows runners refuse to listen on. The libs/agent test now answers the SDK's requests from an in-process transport, and the bundle/config test, which needs the real Workspace.Client transport, is skipped on Windows. Co-authored-by: Isaac <no-reply@databricks.com>
The macOS runner recorded os/darwin where the golden had os/linux, so normalize the OS token the way the other User-Agent goldens do. Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
Automated review at e792723. Each finding was verified against the code.
Not ready yet: 1 blocking issue(s), tagged [blocking].
This PR wraps the HTTP transport of the root workspace and account clients and the bundle workspace client so that, with DATABRICKS_NOT_AN_AGENT set, the SDK's agent/<name> token is stripped from User-Agent. The filter does what it says on the paths it is installed on, and it leaves the config alone when the variable is unset. One gap is in scope for the paths the PR targets: when the interactive profile picker runs, the root client is rebuilt without the wrapper. The other comments are about tests and doc comments.
Comments outside the changed lines
- [nit]
acceptance/cmd/aitools/not-an-agent/script:44: Both newcurrent-user meruns (lines 44 and 46) send stdout to/dev/null. testing.md says to route that output toLOG.<name>, so it still shows undergo test -vwhen something goes wrong. Can these be> LOG.me_not_an_agentand> LOG.me_agent?
| cfg.Credentials = auth.CredentialsWithoutRefresh() | ||
| } | ||
| liteswap.Apply(ctx, cfg) | ||
| agent.ApplyNotAnAgentHeader(ctx, cfg) |
There was a problem hiding this comment.
[blocking] The wrapper only goes on this initial cfg. When the default config doesn't resolve and the user picks a profile, workspaceClientOrPrompt builds a fresh databricks.NewWorkspaceClient(&databricks.Config{Profile: profile}) at line 361, and that client is the one the command uses. accountClientOrPrompt does the same at line 178 for MustAccountClient (line 243). So DATABRICKS_NOT_AN_AGENT=1 CLAUDECODE=1 databricks current-user me in a TTY with no host or profile still sends agent/claude-code once a profile is picked. Can you call agent.ApplyNotAnAgentHeader(ctx, ...) on the picked-profile config in both prompt helpers, ideally from one small shared helper?
There was a problem hiding this comment.
Fixed in 7446ce7. Both prompt helpers now build the picked profile's config through one helper, profileConfig, which applies the not-an-agent header setting, so a profile picked at a prompt gets the same behaviour as the caller's config. TestProfileConfigNotAnAgentHeader covers the variable set and unset cases. The prompt path itself cannot run in a test, so that test stands in for it.
| // refuse to listen here (WSAEPROVIDERFAILEDINIT). The header logic is platform-independent and is | ||
| // covered without a listener in libs/agent. | ||
| if runtime.GOOS == "windows" { | ||
| t.Skip("needs a loopback listener, which the Windows test runners refuse") |
There was a problem hiding this comment.
[nice to have] TestWorkspaceClientNotAnAgentDropsAgentHeader skips on Windows, so nothing checks there that Workspace.Client installs the wrapper. AGENTS.md asks for tests that also run on Windows. Could this test check the client's resulting Config.HTTPTransport instead (for example, that it is no longer the bare httptransport.HealthChecked(...) value when the variable is set)? That way it needs no loopback listener.
There was a problem hiding this comment.
Changed in 7446ce7. The test no longer starts a loopback server and no longer skips on Windows. It checks the client's Config.HTTPTransport: it is the health-checked transport when the variable is unset, and a different, wrapping transport when it is set. The header itself is checked in libs/agent without a listener.
| // noAgentHeaderTransport drops the agent token from User-Agent and passes the request on to base. | ||
| type noAgentHeaderTransport struct { | ||
| // base is the transport cfg had. When it is nil, the SDK uses its shared default, which | ||
| // httptransport.HealthChecked mirrors. It is read from cfg on each request, so the insecure |
There was a problem hiding this comment.
[nit] "It is read from cfg on each request" reads as if base is re-read, but base is captured once in ApplyNotAnAgentHeader. Only cfg.InsecureSkipVerify is read per request, and only when base is nil. Also, HealthChecked doesn't just mirror the SDK default; it adds HTTP/2 pings. Maybe: "When base is nil, requests go to httptransport.HealthChecked, chosen per request from cfg.InsecureSkipVerify so a skip_verify resolved from the profile applies; it stands in for the SDK's unexported default."
There was a problem hiding this comment.
Taken as suggested in 7446ce7. The comment now says requests go to httptransport.HealthChecked, chosen per request from cfg.InsecureSkipVerify, and that it stands in for the SDK's unexported default.
| // Provider returns the agent name that useragent.AgentProvider reports, or "" when no agent is detected or | ||
| // NotAnAgent holds. The CLI's own readers of the calling agent (output, telemetry, the User-Agent) go through it. | ||
| // The SDK's agent request header still reads useragent.AgentProvider directly, so NotAnAgent does not reach it. | ||
| // The SDK adds its agent token from useragent.AgentProvider directly; ApplyNotAnAgentHeader removes it from the |
There was a problem hiding this comment.
[nit] "removes it from the CLI's clients" claims more than the change does. Sites that build their own SDK config, such as auth login and aitools mcp, still send the token. Can this name where it applies (the MustWorkspaceClient/MustAccountClient clients and the bundle workspace client), so the next reader knows the gap is there?
There was a problem hiding this comment.
Taken in 7446ce7. The comment now names where the token is dropped: the MustWorkspaceClient, MustAccountClient and bundle workspace clients, including a profile picked at a prompt. It also says that other places which build their own SDK config, such as auth login and aitools mcp, still send the token. Those remaining sites are handled in the follow-up pull request #8144.
…-agent-makes-the-cli-ac' into skills/noagentsdk-the-sdk-agent-header-follows-databricks
The picked profile builds its own SDK config, so the User-Agent wrapper set on the caller's config did not reach it. Both prompt helpers now build the picked profile's config through one helper that applies the same setting. The bundle workspace client test checks the client's transport instead of running a loopback server, so it runs on Windows too. The header itself is still checked in libs/agent. Comments now say where the agent token is dropped and where it is still sent. Co-authored-by: Isaac <no-reply@databricks.com>
…-agent-makes-the-cli-ac' into skills/noagentsdk-the-sdk-agent-header-follows-databricks Co-authored-by: Isaac <no-reply@databricks.com>
denik
left a comment
There was a problem hiding this comment.
🤖 Automated review of 5feabf3 by Opus and Astra (two independent passes); each finding verified against the code. Only this PR's own diff against its base was reviewed (stacked on #8126).
Verdict: no blocking issues. The wrapper strips agent/ tokens on the root and bundle clients and leaves the config alone with the variable unset. The PR merges cleanly with current main and the base tip, and the changed unit and acceptance tests pass on that merge. Two small things:
- Nit (comment)
libs/agent/agent_notice.go:22-25: the merge in 5feabf3 took the base's version of this file, which undid theProviderdoc comment update from 7446ce7 (made for review-oss-bot's thread on this line). Head says again "The SDK's agent request header still reads useragent.AgentProvider directly, so NotAnAgent does not reach it", and this PR makes that false for the root and bundle clients. Re-applying the 7446ce7 wording fixes it. - Nit (test)
cmd/root/auth_test.go:56: the "variable unset" subtest reads the process environment, soDATABRICKS_NOT_AN_AGENT=1 go test ./cmd/root -run TestProfileConfigNotAnAgentHeaderfails atassert.Nil(t, cfg.HTTPTransport). The siblingTestApplyNotAnAgentHeaderUnsetLeavesConfiginlibs/agent/agent_header_test.gocallstestutil.SetAgentEnvfirst. Doing the same here, ort.Setenv("DATABRICKS_NOT_AN_AGENT", ""), makes the test independent of the environment.
Still open from the earlier review: review-oss-bot's point to send the two current-user me outputs in acceptance/cmd/aitools/not-an-agent/script (lines 44 and 46) to LOG.* instead of /dev/null, as .agents/rules/testing.md asks.
rclarey
left a comment
There was a problem hiding this comment.
experimental/ssh/internal/client/client.go:721: [nit] "Decisions to review" lists the apps logs effect but not this one. databricks ssh connect/server/agent-shim build &http.Client{Transport: client.Config.HTTPTransport} from the root client. With the variable unset, that transport is nil and those requests use http.DefaultTransport. With it set, they go through the wrapper to httptransport.HealthChecked, which turns on HTTP/2 pings and now also applies skip_verify. It's probably harmless, and it also drops the agent token there, but could you add it to the list so an eval comparison doesn't blame a network difference on the nudges? (Raised by the fresh Claude session and the devil's advocate.)
[nit] .agents/skills/pr-checklist/SKILL.md asks for a .nextchanges/ fragment for user-visible changes. No fragment in the tree mentions DATABRICKS_NOT_AN_AGENT, neither from this PR nor from #8126. If the variable is meant to be eval-only or internal, ignore this. Otherwise, one fragment for the stack (for example under cli/) saying the variable now also drops the agent/ User-Agent token would cover it. (Conventions reviewer only; it's a judgment call about whether the variable is user-facing.)
[non-blocking] libs/agent/agent_header.go:13: Should DATABRICKS_NOT_AN_AGENT also drop the SDK's meta-harness/<name> token? The SDK adds that token from useragent.MetaHarnessProvider() (SDK v0.204.0 config/api_client.go:90-99; today only OMNIGENT). withoutAgentToken only removes agent/ tokens. A baseline run under Omnigent with the variable set therefore still sends meta-harness/omnigent, and its requests still look agent-driven. If that's intended (a meta-harness "is not itself an agent"), a one-line comment would save the next reader the question. (Raised by Isaac Review and the devil's advocate.)
| // in libs/agent, which needs no loopback listener. | ||
| client, err = w.Client(envlib.Set(t.Context(), "DATABRICKS_NOT_AN_AGENT", "1")) | ||
| require.NoError(t, err) | ||
| assert.NotSame(t, httptransport.HealthChecked(false), client.Config.HTTPTransport) |
There was a problem hiding this comment.
[nit] assert.NotSame(HealthChecked(false), …) and assert.NotNil(cfg.HTTPTransport) pass for any transport, so they don't show that the wrapper is installed or that it keeps the health-checked base. For example, a change that put the wrapper over a different base in Workspace.Client would still pass. Could these go through a small round-trip instead? Send a request with User-Agent: … agent/x through client.Config.HTTPTransport with a recording base, or check the base via a test-only accessor in libs/agent. Then the tests check the behaviour, not just that something changed. (Raised by Isaac Review, the fresh Claude session and the conventions reviewer.)
There was a problem hiding this comment.
Taken in 34e0c26. The test now checks the behaviour through a small accessor, agent.WrappedTransport: with the variable unset the client's transport is not the wrapper, and with it set the transport is the wrapper over the same health-checked base (assert.Same against HealthChecked(false)). A wrapper over a different base would now fail. It needs no loopback listener, so it runs on Windows too.
Co-authored-by: Isaac <no-reply@databricks.com>
With
DATABRICKS_NOT_AN_AGENTset, the CLI's workspace and account clients no longer send anagent/<name>token in the User-Agent header. The SDK added that token from its own agent detection, which does not read the variable. With the variable unset nothing changes. This PR is stacked on #8126, so until that merges the diff againstmainalso shows its changes.Changes
agent.ApplyNotAnAgentHeaderwraps the client's HTTP transport and removesagent/tokens from User-Agent. It does nothing unlessNotAnAgentholds, so with the variable unset the config is not touched.cmd/rootapplies it inMustWorkspaceClientandMustAccountClient, and to a profile picked at a prompt throughprofileConfig, which builds that profile's config with the same setting. The bundle workspace client applies it after setting its health-checked transport.Why
The SDK (v0.204.0) has no per-client option for this. Its header visitor reads
useragent.AgentProvider(), a process-wide value cached on first use, and it sets User-Agent after the request visitors have run. AConfig.Headershook therefore cannot change it. The transport is the only hook that sees the final header. An SDK change would also work, but this route needs no new SDK release.Decisions to review
key/valuetokens, which the SDK builds and its tests pin.httptransport.HealthChecked, because the SDK's default is unexported. This happens only with the variable set. The health-check ping settings differ, anddatabricks apps logstakes its plain-dialer path for a transport that is not an*http.Transport.auth loginandaitools mcp, still send the token with the variable set. The follow-up Apply the not-an-agent header guard to the remaining CLI SDK clients #8144 covers them.Tests
TestWithoutAgentTokencovers the token filter.TestNoAgentHeaderTransportDropsAgentAndKeepsRequestchecks the wrapper and that the caller's request is not modified.TestNotAnAgentHeaderOnSDKRequestssends real SDK requests through an in-process transport, with and without the variable.TestWorkspaceClientNotAnAgentWrapsTransportchecks that the bundle workspace client's transport is wrapped only when the variable is set. It needs no listener, so it also runs on Windows.TestProfileConfigNotAnAgentHeadercovers the config for a picked profile.acceptance/cmd/aitools/not-an-agentrecords thecurrent-user merequest (itscicd/token is stripped, so CI runners match local runs): noagent/token with the variable set, andagent/claude-codewithout it.go testpasses for./libs/agent/...,./cmd/root/...,./cmd/quickstart/...,./cmd/auth/...,./cmd/feedback/...,./bundle/config/...,./bundle/phases/...and./bundle/deploy/...after merging the parent branch tip../task fmt-q lint-qis clean.TestAccept/cmd/aitools,TestAccept/cmd/quickstart,TestAccept/cmd/feedback,TestAccept/cmd/auth,TestAccept/bundle/deployment/bindandTestAccept/bundle/resources/dashboardspass.Not tested:
databrickscommands against a real workspace, and the other SDK construction sites listed above.This pull request and its description were written by Isaac.