Repository navigation
feat: detect the coding agent when the plugin agent is unknown - #167
Open
arorashivam96 wants to merge 1 commit into
Open
arorashivam96 wants to merge 1 commit into
arorashivam96 wants to merge 1 commit into
Conversation
auth.py now fills a missing, unknown or unrecognized DATAVERSE_PLUGIN_AGENT from the environment markers coding agents set on the processes they start (AI_AGENT, CLAUDECODE, CODEX_THREAD_ID, GEMINI_CLI, COPILOT_CLI, ANTIGRAVITY_AGENT, CURSOR_AGENT), following the GitHub CLI's detection order. An agent named in .env is never overridden, any /<surface> suffix is kept, and only allowlisted agents are reported. Applies to get_client, get_plugin_headers and get_cli_context. Bumps the plugin to 1.19.0.
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.
Summary
When
.envhas no usable agent,scripts/auth.pynow reports the coding agent that actually started the process instead ofagent=unknown. This is the plugin-side half of PowerPlatform-DataverseClient-Python#209. It also covers the raw-HTTP path (get_plugin_headers), which never goes through the SDK.Why
agent=unknownis the second-largest series in plugin traffic: 1,769,098 requests from 404 users between Oct 29 and Nov 4. The fallback comes from this helper. Since v1.14.1,_current_agent()maps a missing or unrecognizedDATAVERSE_PLUGIN_AGENTtounknown.Telemetry shows the agent is often known to the same caller on a different path:
unknownrequests come from users whose MCP or CLI traffic in the same window names a standard agent. The agent was running, but its name never reached the Python process.unknownarrives throughget_plugin_headers(raw urllib), so an SDK-only fix cannot reach it.What changes
_current_agent()keeps its current behaviour when.envnames an allowed agent. Detection runs only when the agent is missing,unknown, or not on the allowlist. It then checks the environment variables coding agents set on the processes they start, in the GitHub CLI's order (internal/agents/detect.go):AI_AGENT(cross-vendor; checked first)claude->claude-code,github_copilot_vscode_agent->copilot,gemini->gemini-cliCODEX_THREAD_ID/CODEX_SANDBOX/CODEX_CIcodexGEMINI_CLIgemini-cliCOPILOT_CLIcopilotANTIGRAVITY_AGENTantigravity-cliCLAUDECODE/CLAUDE_CODEclaude-codeCURSOR_AGENT, orCURSOR_EXTENSION_HOST_ROLE=agent-execcursorThe rules are deliberately narrow:
.envis never overridden./<surface>suffix is kept, sounknown/jetbrainsbecomescodex/jetbrainsunder Codex._ALLOWED_AGENTSare reported, so the context schema stays closed. AnAI_AGENTvalue outside the map, or Amp (AGENT=amp), staysunknown.CURSOR_TRACE_IDis ignored, because it is set in every Cursor terminal, including commands a person types by hand.The change applies to
get_client,get_plugin_headersandget_cli_context. Plugin version: 1.18.0 -> 1.19.0 in all manifests, including the two Gemini manifests.Testing
python -m pytest .github/evals/test_auth.py: 80 passed (9 new cases inAgentDetectionForUnknown), with and without an agent marker in the shell.python .github/evals/static_checks.py: passed.python .github/evals/version_bump_check.py: passed (minor).Live run against a Dataverse environment (
aurorabapenv39ef7.crm10.dynamics.com), using this branch'sauth.pyand the SDK from #209. Each User-Agent is the header actually sent, captured from the request; every call returned 200:get_plugin_headers(urllib).envagent,CLAUDECODE=1Python-urllib (app=dataverse-skills/0.0.0-livetest;skill=dv-query;agent=claude-code)get_plugin_headers(urllib).envagent, no markersPython-urllib (...;agent=unknown)get_client(SDK).envunknown/jetbrains,CODEX_THREAD_IDDataverseSvcPythonClient:0.1.0b10 (...;agent=codex/jetbrains)get_client(SDK).envcursor,CLAUDECODE=1DataverseSvcPythonClient:0.1.0b10 (...;agent=cursor)The fix does not depend on #209. The helper sets the agent before the context reaches the SDK, so it works with any SDK version the plugin already supports.