Conversation
johnmtll
force-pushed
the
NODE-7666/environment-variables-in-the-handshake-metadata
branch
4 times, most recently
from
September 14, 2026 21:46
50be426 to
cb1f4c9
Compare
| }); | ||
| }); | ||
|
|
||
| // Ref: https://github.com/aclark4life/specifications/blob/feaec8d0ca332a80f457f75c6ef1600267e61d64/source/mongodb-handshake/tests/README.md#test-3-test-that-agent-metadata-is-properly-captured |
Contributor
There was a problem hiding this comment.
The new spec and unit tests need to clean up the env vars before starting, so the developer's local variables do not impact the tests.
| const agentEnv = getAgentEnv(); | ||
|
|
||
| const fullEnv = new Map<string, unknown>(); | ||
| if (containerMetadata.size > 0) fullEnv.set('container', containerMetadata); |
Contributor
There was a problem hiding this comment.
With this insertion order, container data is dropped before faas. Current (main) implementation tries to re-add container after faas gets booted, so this is a change in behavior.
| * Resolves `env.agent` from the environment, or an empty string when no agent variable is | ||
| * populated. Returns the value of the first populated variable in `AGENT_ENV_VARIABLES`. | ||
| */ | ||
| export function getAgentEnv(): string { |
Contributor
There was a problem hiding this comment.
This function should be added to test/mongodb_bundled.ts (alphabetically next to getFAASEnv) for the bundled tests to succeed.
johnmtll
added a commit
that referenced
this pull request
Sep 16, 2026
johnmtll
added a commit
that referenced
this pull request
Sep 16, 2026
johnmtll
added a commit
that referenced
this pull request
Sep 16, 2026
johnmtll
force-pushed
the
NODE-7666/environment-variables-in-the-handshake-metadata
branch
from
September 17, 2026 19:27
612b981 to
b9f4582
Compare
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.
Description
Summary of Changes
Adds an AI agent identifier,
env.agent, to the client metadata handshake, and refactors how theenvsub-document is built and truncated.env.agentenv.agentis populated using first-match, order-bound logic over the agent-related environment variables defined in the spec. Depending on which variable matches, the value is either a generic marker (AI_AGENT/AGENT) or the variable's literal value.Per the spec, "a variable is considered populated if it is present in the environment with a non-empty value." We treat any value that is empty after
trim()as unpopulated and skip it. Populated values are used as-is (e.g.' claude'is kept verbatim).envconstruction and truncationThe spec's truncation order is:
Previously,
envwas built by progressively appending members to the live metadata document, and the spec was partially-satisfied somewhat incidentally:env.namehappened to be the last FaaS member added, so it was deleted last — butenv.containeriss appended after that, making it theoretically possible to end up with anenvcontaining onlycontainer.envis now constructed as a standalone document, truncated independently. This prepare us for a future spec alignment effort tracked in https://jira.mongodb.org/browse/NODE-7851Refer to: mongodb/specifications#1967 for the incoming changes.
Notes for Reviewers
What is the motivation for this change?
For bug fixes
Current (incorrect) behavior:
Expected behavior:
How to reproduce:
Affected versions:
Release Highlight
Release notes highlight
Double check the following
npm run check:lint)type(NODE-xxxx)[!]: descriptionfeat(NODE-1234)!: rewriting everything in coffeescript