Skip to content

Commit a2ea56c

Browse files
authored
Detect VS Code agent via VSCODE_AGENT, remove COPILOT_MODEL heuristic (#810)
## Why [VS Code 1.121](https://code.visualstudio.com/updates/v1_121) introduced the `VSCODE_AGENT` environment variable, set for any agent-initiated terminal command (Copilot Chat agent mode and other agent extensions). This is the official signal for VS Code agent usage. The previous heuristic detected `COPILOT_MODEL` and reported `copilot-vscode`, but `COPILOT_MODEL` is actually set by Copilot CLI users who bring their own key, not specifically by VS Code. This produced false positives and required a BYOK collapse workaround (drop `copilot-vscode` whenever `COPILOT_CLI` was also set). Over the last 13 weeks, the heuristic identified 3 users / 52 events; `copilot-cli` saw 539 users / 175k events. The signal was effectively dead. ## Changes - Add `VSCODE_AGENT` to `listKnownAgents()`, reported as `agent/vscode-agent`. - Remove the `COPILOT_MODEL` to `copilot-vscode` mapping. - Remove the BYOK collapse logic. `VSCODE_AGENT` can legitimately stack with `COPILOT_CLI` (e.g. running Copilot CLI from a VS Code agent terminal), so the multi-agent path covers it without special handling. ## Tests - [x] Updated `UserAgentTest.java`: new `testAgentProviderVscodeAgent` and stacking test. - [x] `mvn test -Dtest=UserAgentTest` passes (40 tests, 0 failures). - [x] `make fmt` clean. This PR mirrors parallel changes in [databricks-sdk-go](databricks/databricks-sdk-go#1697), [databricks-sdk-py](databricks/databricks-sdk-py#1444), and [sdk-js](databricks/sdk-js#152). NO_CHANGELOG=true
1 parent 311d530 commit a2ea56c

2 files changed

Lines changed: 10 additions & 32 deletions

File tree

databricks-sdk-java/src/main/java/com/databricks/sdk/core/UserAgent.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ private static List<KnownAgent> listKnownAgents() {
267267
new KnownAgent("CLINE_ACTIVE", "cline"), // https://github.com/cline/cline (v3.24.0+)
268268
new KnownAgent("CODEX_CI", "codex"), // https://github.com/openai/codex
269269
new KnownAgent("COPILOT_CLI", "copilot-cli"), // https://github.com/features/copilot
270-
// VS Code Copilot terminal; best-effort heuristic, not officially identified.
271-
new KnownAgent("COPILOT_MODEL", "copilot-vscode"),
272270
new KnownAgent("CURSOR_AGENT", "cursor"), // Closed source
273271
new KnownAgent("GEMINI_CLI", "gemini-cli"), // https://google-gemini.github.io/gemini-cli
274272
new KnownAgent(
@@ -277,6 +275,9 @@ private static List<KnownAgent> listKnownAgents() {
277275
new KnownAgent("KIRO", "kiro"), // https://kiro.dev/ (Amazon)
278276
new KnownAgent("OPENCLAW_SHELL", "openclaw"), // https://github.com/anthropics/openclaw
279277
new KnownAgent("OPENCODE", "opencode"), // https://github.com/opencode-ai/opencode
278+
// Set by VS Code 1.121+ for agent-initiated terminal commands
279+
// (https://code.visualstudio.com/updates/v1_121).
280+
new KnownAgent("VSCODE_AGENT", "vscode-agent"),
280281
new KnownAgent("WINDSURF_AGENT", "windsurf")); // https://codeium.com/windsurf (Codeium)
281282
}
282283

@@ -310,13 +311,6 @@ private static String lookupAgentProvider(Environment env) {
310311
}
311312
}
312313

313-
// Known BYOK false positive: Copilot CLI users often set COPILOT_MODEL
314-
// alongside COPILOT_CLI. Treat that pair as a single copilot-cli signal
315-
// rather than a stacked multi-agent setup.
316-
if (matches.contains("copilot-cli") && matches.contains("copilot-vscode")) {
317-
matches.removeIf(m -> m.equals("copilot-vscode"));
318-
}
319-
320314
if (matches.size() == 1) {
321315
return matches.get(0);
322316
}

databricks-sdk-java/src/test/java/com/databricks/sdk/core/UserAgentTest.java

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,14 @@ public void testAgentProviderAugment() {
241241
}
242242

243243
@Test
244-
public void testAgentProviderCopilotVscode() {
244+
public void testAgentProviderVscodeAgent() {
245245
setupAgentEnv(
246246
new HashMap<String, String>() {
247247
{
248-
put("COPILOT_MODEL", "gpt-4");
248+
put("VSCODE_AGENT", "1");
249249
}
250250
});
251-
Assertions.assertTrue(UserAgent.asString().contains("agent/copilot-vscode"));
251+
Assertions.assertTrue(UserAgent.asString().contains("agent/vscode-agent"));
252252
}
253253

254254
@Test
@@ -415,30 +415,14 @@ public void testAgentProviderExplicitEnvWinsOverKnownAgentEnv() {
415415
}
416416

417417
@Test
418-
public void testAgentProviderCopilotCliAndCopilotVscodeCollapseToCopilotCli() {
419-
// Copilot CLI users (BYOK mode) often set COPILOT_MODEL alongside
420-
// COPILOT_CLI. Treat the pair as a single copilot-cli signal rather
421-
// than a stacked multi-agent setup.
418+
public void testAgentProviderVscodeAgentAndCopilotCliReportsMultiple() {
419+
// VSCODE_AGENT can legitimately stack with other agents (e.g. running
420+
// Copilot CLI from a VS Code agent terminal).
422421
setupAgentEnv(
423422
new HashMap<String, String>() {
424423
{
424+
put("VSCODE_AGENT", "1");
425425
put("COPILOT_CLI", "1");
426-
put("COPILOT_MODEL", "gpt-4");
427-
}
428-
});
429-
Assertions.assertTrue(UserAgent.asString().contains("agent/copilot-cli"));
430-
}
431-
432-
@Test
433-
public void testAgentProviderCopilotByokCollapseStillMultiple() {
434-
// The Copilot BYOK collapse only drops the copilot-vscode match. If
435-
// another agent is also present, the result is still "multiple".
436-
setupAgentEnv(
437-
new HashMap<String, String>() {
438-
{
439-
put("COPILOT_CLI", "1");
440-
put("COPILOT_MODEL", "gpt-4");
441-
put("CLAUDECODE", "1");
442426
}
443427
});
444428
Assertions.assertTrue(UserAgent.asString().contains("agent/multiple"));

0 commit comments

Comments
 (0)