FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

PYTHON-5929 Add coding agent env var to handshake metadata by aclark4life · Pull Request #3063 · mongodb/mongo-python-driver · GitHub

Repository navigation

PYTHON-5929 Add coding agent env var to handshake metadata - #3063

Draft
aclark4life wants to merge 19 commits into
mongodb:mainfrom
aclark4life:PYTHON-5929
Draft

aclark4life wants to merge 19 commits into
mongodb:mainfrom
aclark4life:PYTHON-5929

Conversation

aclark4life commented Sep 22, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor

PYTHON-5929

Changes in this PR

Implements the agent identification section of the handshake spec (DRIVERS-3529):

  • client.env.agent reports a detected coding agent in the handshake metadata. A fixed, spec-ordered list of known agent environment variables (CLAUDECODE, CURSOR_AGENT, CODEX_SANDBOX, and 8 more) each map to a fixed name, whatever the variable's value. The generic AI_AGENT variable is evaluated last: 1/true reports ai_agent; any other populated value is stripped, lowercased, and truncated to the largest valid UTF-8 prefix of 64 bytes. An empty or whitespace-only value means unset. No agent variable populated means env.agent is omitted.
  • Metadata truncation follows the spec order: keep env.name and env.agent, then omit env.agent (omitting env entirely if nothing remains), then the existing steps.

Test Plan

  • Added metadata tests covering every prose test in the spec's Test 3 (known agent, fixed name, precedence, generic variable, normalization, truncation, truncation on a character boundary, empty and whitespace-only values, unset).
  • Added a unit test for the truncation order: env.agent is omitted before env.name, and an env holding only agent is omitted entirely.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Copy link
Copy Markdown

There is an existing patch(es) for this commit SHA:

Please note that the status that is posted is not in the context of this PR but rather the (latest) existing patch and that may affect some tests that may depend on the particular PR. If your tests do not rely on any PR-specific values (like base or head branch name) then your tests will report the same status. If you would like a patch to run in the context of this PR and abort the other(s), comment 'evergreen retry'.

aclark4life changed the title Python 5929 PYTHON-5929 Add coding agent env var to handshake metadata Sep 22, 2026
aclark4life and others added 2 commits September 22, 2026 13:20
The spec changed after this branch was written:

- Evaluate AI_AGENT last, so a versioned value cannot mask a known agent.
- Adopt mongosh's variable list and snake_case agent names, and add
  CLAUDE_CODE_ENTRYPOINT, CLINE_ACTIVE, TRAE_AI_SHELL_ID, GOOSE_TERMINAL
  and GOOSE_AGENT.
- Drop the generic AGENT variable, which is common outside agents.
- Normalize AI_AGENT: trim, lowercase, map 1/true to ai_agent, and
  truncate to 64 characters.
- Treat a whitespace-only value as unset.

codecov Bot commented Sep 22, 2026 •
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

aclark4life and others added 9 commits September 23, 2026 15:45
test_metadata and test_container_metadata compare the full handshake
metadata dict. They fail when the test process itself runs under a
coding agent, because env.agent is then present.

Add a no_ambient_agent() helper that clears every var the handshake
reads, and use it in both tests. _test_handshake now reuses the helper
instead of clearing the vars inline.

This branch has not been deployed

No deployments
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL