DRIVERS-3529 Add env.agent to handshake metadata for agentic client identification - #1967
aclark4life wants to merge 11 commits into
Conversation
f32a3df to
8c1e1f0
Compare
|
Assigned |
| | `KUBERNETES_SERVICE_HOST` | `1` | | ||
|
|
||
| ### Test 2: Test that the driver accepts an arbitrary auth mechanism | ||
| ### Test 2: Test that agent metadata is properly captured |
There was a problem hiding this comment.
I think this should be added as Test 3, to prevent drivers from having to change existing test code
|
|
||
| ##### Agent | ||
|
|
||
| Many AI coding assistants and agentic clients ("agents", e.g. Claude Code, Cursor, Gemini CLI) set an environment |
There was a problem hiding this comment.
The word wrapping here feels unnatural. I suggest either a soft-fixed length or sentence per line
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
source/mongodb-handshake/tests/README.md:135
- This table is intended to represent “no environment variables set”, but an all-empty row renders oddly and can be confusing (or trigger table-formatting checks). Consider replacing the table with a short sentence stating that no variables are set.
| Environment Variable | Value |
| -------------------- | ----- |
| | |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
source/mongodb-handshake/tests/README.md:88
- Subject–verb agreement: “a connection and hello command succeeds” should be plural (“…command succeed”).
Drivers that capture values for `client.env` should test that a connection and hello command succeeds in the presence of
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
source/mongodb-handshake/tests/README.md:129
- In Test 3 case 6, the table shows the
AI_AGENTvalue as""(two quote characters), which is not an empty string. This could cause implementers to set the variable to a non-empty value and accidentally treat it as populated, defeating the intent of the test case (empty value treated as unset). Consider leaving the table value cell blank (or otherwise unambiguously indicating an empty value) while keeping the bullet text as the normative requirement.
| Environment Variable | Value |
| -------------------- | ------------------- |
| `AI_AGENT` | `""` (empty string) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
source/mongodb-handshake/tests/README.md:143
- The new Agent prose test cases cover generic-vs-known precedence, but they don’t include a case asserting the precedence between the two generic variables themselves (
AI_AGENTmust win overAGENT, since it is earlier in the ordered table in the spec). Without this, a driver could accidentally flip the generic precedence and still pass these tests.
7. No agent variables. None of the environment variables in the `client.env.agent` table are set. `client.env.agent`
MUST be omitted.
8. Agent alongside FaaS. This test MUST verify that both the AWS Lambda metadata and `client.env.agent` (equal to
`claude-code`) are present in `client.env`.
| Environment Variable | Value |
| -------------------- | ------------------ |
| `AWS_EXECUTION_ENV` | `AWS_Lambda_java8` |
| `AWS_REGION` | `us-east-2` |
| `CLAUDECODE` | `1` |
…tion Address review feedback from PavelSafronov and johnmtll: - Evaluate known agent variables before the generic AI_AGENT, so a versioned AI_AGENT value cannot mask a known agent. - Adopt the environment variables and snake_case agent names that mongosh already uses, so drivers and the shell agree. - Drop the generic AGENT variable, which is common outside agents. - Specify normalization: trim, lowercase, map 1/true to ai_agent, and truncate to 64 characters. - Treat a whitespace-only value as unset. - Omit env.agent before env.name in the size-limit cascade.
feaec8d to
d5adec0
Compare
Entries 1 through 11 report a fixed name from the table, but a value derived from AI_AGENT is reported by the agent itself. Say so, so that the two value spaces of client.env.agent are distinguishable.
Truncate to the largest valid UTF-8 prefix of 64 bytes, never splitting a character or substituting U+FFFD. State why the cap exists. Scope the mongosh parity claim to the variable list and names, and record the three normalization divergences. Add prose tests for a boolean value with whitespace and for truncation on a character boundary.
| 3. Omit the `env` document entirely. | ||
| 4. Truncate `platform`. | ||
| 1. Omit fields from `env` except `env.name` and `env.agent`. | ||
| 2. Omit `env.agent`. |
There was a problem hiding this comment.
On an agent-only host (no FaaS, no container), steps 1+2 result in an empty env, and if this now fits, env: {} gets sent, which contradicts line 295
If no fields of
client.envwould be populated,client.envMUST be entirely omitted.
Suggest step 2 be changed to:
2. Omit `env.agent`; if `env` then has no remaining fields, omit `env` entirely.”
Summary
Adds
client.env.agentto the MongoDB Handshake metadata, so agent-mediated usage of MongoDB (Claude Code, Cursor, Gemini CLI, …) can be distinguished from direct human usage. See DRIVERS-3529.Detection matches what mongosh already ships, except for
AI_AGENTnormalization. mongosh alignment: MONGOSH-3696.Changes
env.agentto theclientdocument, with an ordered environment-variable table for detection.AI_AGENTlast, so a versioned value such asclaude-code_2-1-238_agentcannot mask a known agent. Normalize it: trim, lowercase, truncate to the largest valid UTF-8 prefix of 64 bytes, and map1/truetoai_agent.env.agentbeforeenv.namein the size-limit cascade.AI_AGENTnormalization divergences from mongosh, tracked by MONGOSH-3696.Notes
v1 targets Node and Python. Other language tickets are split from DRIVERS-3529 and blocked on this spec change. Implementations: PYTHON-5929, NODE-7666.
Please complete the following before merging: