Repository navigation
feat: accept any safe OperationContext value and detect the coding agent for agent=unknown - #209
Merged
arorashivam96 merged 5 commits intoNov 6, 2026
Conversation
OperationContext now accepts an optional IDE-surface suffix on the agent value, written as agent/<host> (e.g. codex/jetbrains), drawn from a new closed host allowlist (jetbrains, vscode, cli). The agent value is split on '/': the base is validated against the agent allowlist and the optional suffix against the host allowlist; unknown bases and unknown suffixes are still rejected. Enables plugin/tool attribution to record the IDE surface while preserving the closed key/value allowlist model. Bumped 1.0.1 -> 1.1.0.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new changelog release lacks an accurate comparison reference and leaves the Unreleased link stale.
1 open finding
What changed in this PR
Adds optional allowlisted host suffixes to OperationContext agent values.
Changes:
- Validates agent bases and optional host suffixes separately.
- Adds validation tests.
- Bumps version to 1.1.0 and updates the changelog.
| File | Description |
|---|---|
src/PowerPlatform/Dataverse/core/config.py |
Adds host-suffix validation. |
tests/unit/test_operation_context.py |
Tests accepted and rejected suffixes. |
pyproject.toml |
Bumps package version. |
CHANGELOG.md |
Documents the feature release. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Drop the closed skill/agent/host value allowlists. New agents and skills are added constantly, so enumerating values forces an SDK release for every addition and the enums had already drifted. The validator now enforces the key allowlist (app/skill/agent), the safe-character pattern (still excludes spaces/control chars/PII), and the app <name>/<version> format. Any safe-charset agent/skill value is accepted, including an agent/<surface> suffix like codex/jetbrains. Unknown keys and unsafe characters are still rejected.
…on-context-agent-host-suffix # Conflicts: # CHANGELOG.md # src/PowerPlatform/Dataverse/core/config.py
arorashivam96
enabled auto-merge (squash)
October 16, 2026 23:36
…ding CONTRIBUTING.md: maintainers update CHANGELOG.md and the version in the release PR (see #207), so this PR should not bump to 1.2.0 or add a dated entry. Also corrects the ValueError docstring (values are no longer rejected, only unknown keys and a malformed app value), a code comment that implied the charset filter detects PII, and a test docstring that referenced the removed plugin allowlist.
When an OperationContext says agent=unknown, the outbound User-Agent reports the agent detected from process markers (AI_AGENT, CLAUDECODE, CODEX_THREAD_ID, GEMINI_CLI, ...), following the GitHub CLI's detection order. Clients without an operation context never read the environment, and an explicit agent is never overridden.
Vikas Rathee (vrathee-msft)
approved these changes
Nov 6, 2026
arorashivam96
deleted the
u/shivamarora/operation-context-agent-host-suffix
branch
November 6, 2026 22:28
arorashivam96
added a commit
that referenced
this pull request
Nov 21, 2026
Prepares the **v1.2.0** release. - Adds the `## [1.2.0]` CHANGELOG section for the user-facing changes from #209: - `OperationContext` accepts any safe `skill` and `agent` value, including new agents such as `gemini-cli` and `antigravity-cli` and `agent/<surface>` values such as `codex/jetbrains`. In 1.1.0 these raised `ValueError`. - When the operation context says `agent=unknown`, the client fills in the coding agent detected from the environment. Clients without an operation context are unaffected. - Bumps `pyproject.toml` from `1.1.0` to `1.2.0`. The changes are backward compatible and add behaviour, so this is a MINOR release under SemVer. - Fixes the `[Unreleased]` compare link, which still pointed at `v1.0.1...HEAD`, and adds the `[1.2.0]` link. The post-release bump after 1.1.0 was never made, so `main` still builds as `1.1.0` even though it contains #209. This release removes that ambiguity. **Why now:** the Dataverse plugin ([microsoft/Dataverse-skills#167](microsoft/Dataverse-skills#167)) sends `gemini-cli` and `antigravity-cli` as the agent. With 1.1.0 those values are rejected on the SDK path, so that traffic is still recorded as `unknown`. Once 1.2.0 is on PyPI the plugin can require it. **Validation** - `pytest tests/unit`: 2502 passed. - `black --check src tests`: clean. - `python -m build` produces `powerplatform_dataverse_client-1.2.0` (sdist and wheel), and the wheel includes `core/_agent_detection.py`. - Live check against a Dataverse org with the same code built from `main`: an SDK request made inside Antigravity, or with Gemini CLI's environment marker set, is recorded as `antigravity-cli` / `gemini-cli` instead of `unknown`. After merge: run the `PowerPlatform-DataverseClient-Python-Official` pipeline to publish to PyPI, tag `v1.2.0`, create the GitHub release, then bump `main` to `1.2.1`.
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.


What
Two changes to how
OperationContextattribution reaches theUser-Agentheader:Accept any safe
agent/skillvalue. Values are no longer checked against closed allowlists. The validator still enforces:app,skill,agent(unknown keys rejected)-,_,.,/(rejects spaces, control characters, and email-shaped text because@is not allowed)<name>/<version>format guardFill
agent=unknownfrom the coding agent that started the process. When the caller's context saysagent=unknown(optionallyunknown/<surface>), the client looks for the environment markers coding agents set on the processes they launch and sends the detected agent instead. The marker list and precedence follow the GitHub CLI (internal/agents/detect.go) and@vercel/detect-agent:AI_AGENT=<name>(cross-vendor convention, checked first; e.g. VS Code Copilot setsgithub_copilot_vscode_agent)copilot,claude-code, ...); other safe values passed throughAGENT=ampampCODEX_THREAD_ID,CODEX_SANDBOX,CODEX_CIcodexGEMINI_CLIgemini-cliCOPILOT_CLIcopilotANTIGRAVITY_AGENTantigravity-cliCLAUDECODE,CLAUDE_CODEclaude-codeCURSOR_AGENT,CURSOR_EXTENSION_HOST_ROLE=agent-execcursorCURSOR_TRACE_IDis deliberately not used: it is present in every Cursor terminal, including commands a person runs by hand.No effect on non-agent use of the SDK
Detection only runs when the caller supplied an
OperationContextand that context saysagent=unknown. In every other case theUser-Agentis byte-for-byte what it was:DataverseSvcPythonClient:<ver>. Covered by tests that setCLAUDECODEandAI_AGENTand assert the header is unchanged (sync and async).agent=copilot): sent as given, never overridden.agentkey: anagentkey is never added.agent=unknownis sent as given.OperationContextobject is not modified; only the outbound header is filled in.Why
Loosening. New agents and skills are added constantly, and the lists had already drifted from the Dataverse plugin (
_ALLOWED_AGENTSwas missinggemini-cli/antigravity-cli, so a plugin script passing those names gets aValueError). Accepting any safe value also lets anagent/<surface>suffix such ascodex/jetbrainsthrough.Detection. About 30% of Dataverse plugin requests carry
agent=unknown. The plugin decides the agent once, at setup, by asking the model to writeDATAVERSE_PLUGIN_AGENTinto.env, and many scripts never see that value. Production telemetry (Oct 22 - Nov 4, 2026) shows 12% ofunknownrequests come from a person whose agent was active and correctly named on MCP or CLI in the same hour, i.e. the Python process was started by the agent but could not name it. Process markers fix exactly that case, deterministically, without relying on.env. Unattended jobs (service accounts, no agent running) stayunknown, which is correct.Privacy note: the character filter is structural, not a PII detector; callers must pass fixed attribution literals. Detected values come from agent-set environment variables, are lower-cased, limited to
[a-z0-9_.-]{1,40}, and otherwise ignored.Change
core/config.py:OperationContext.__post_init__drops_ALLOWED_SKILLS/_ALLOWED_AGENTSand their per-value checks; docstring describes theagent=unknownfill.core/_agent_detection.py(new, private):_detect_agent()and_fill_unknown_agent().data/_odata_base.py: the outbound context is_fill_unknown_agent(ctx.user_agent_context); both the sync and async clients read it.Backward compatible: every string that was valid before is still valid. Only previously rejected shapes now pass, and the header changes only for
agent=unknowninside a detected agent process.Tests
tests/unit/test_agent_detection.py(new): each marker,AI_AGENTprecedence and aliases, unsafeAI_AGENTfalls back,CURSOR_TRACE_IDalone is not an agent,ampoverCLAUDECODE, surface suffix kept, explicit agent never overridden, noagentkey never added, result is a validOperationContext, header unchanged without a context, caller's object not modified.tests/unit/aio/data/test_async_odata_internal.py: async client fillsagent=unknownand leaves a context-less client unchanged.tests/unit/test_operation_context.py: accept tests for any safeskill/agentvalue (incl.codex/jetbrains); structural rejection tests kept.tests/unit: 2502 passed.Live run against a Dataverse environment (
aurorabapenv39ef7.crm10.dynamics.com) with this branch's SDK. Each User-Agent is the header actually sent, captured from the request; every call returned 200:AI_AGENT=github_copilot_vscode_agent...;agent=unknownDataverseSvcPythonClient:0.1.0b10 (app=pr209-livetest/162819;skill=sdk;agent=copilot)...;agent=unknown... (...;agent=unknown)CLAUDECODE=1DataverseSvcPythonClient:0.1.0b10(unchanged)CODEX_THREAD_ID=t1...;agent=unknown/jetbrains... (...;agent=codex/jetbrains)CLAUDECODE=1...;agent=cursor... (...;agent=cursor)...;agent=windsurf... (...;agent=windsurf)(raisedValueErrorbefore)The plugin-side change that fills the same gap for scripts using the plugin's
auth.py(including its raw-HTTP path) is microsoft/Dataverse-skills#167.Version / CHANGELOG
No version bump or CHANGELOG edit in this PR, per CONTRIBUTING.md. Suggested entries for the next release: