-
Notifications
You must be signed in to change notification settings - Fork 924
fix(agent/agentcontainers): ensure agent name env var is correct #18457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Previously, `CODER_WORKSPACE_AGENT_NAME` would always be passed as the dev container name. This is invalid for the following scenarios: - The dev container is specified in terraform - The dev container has a name customization This change now runs `ReadConfig` twice. The first read is to extract a name (if present), from the `devcontainer.json`. The second read will then use the name we have stored for the dev container (so this could be either the customization, terraform resource name, or container name).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures the agent’s custom name from devcontainer.json
is correctly applied to the CODER_WORKSPACE_AGENT_NAME
environment variable by reading the config twice and updated tests to verify both reads.
- Changed
readConfigErrC
channel capacity and added assertions for the first “empty” read. - Added a new subtest (
CreateReadsConfigTwice
) to cover custom-name override. - Updated
api.go
to runReadConfig
once to extract the name and again to pass the proper env var.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
agent/agentcontainers/api_test.go | Increase readConfigErrC capacity; assert empty vs. populated envs on two reads; new custom-name subtest |
agent/agentcontainers/api.go | Call ReadConfig twice: first to pick up Coder.Name , second to inject it into the env |
Comments suppressed due to low confidence (4)
agent/agentcontainers/api.go:1172
- [nitpick] If
subAgentConfig.Name
is empty (no customization), this injects an emptyCODER_WORKSPACE_AGENT_NAME
; consider defaulting explicitly to the container’s name (dc.Name
) to avoid passing a blank value.
fmt.Sprintf("CODER_WORKSPACE_AGENT_NAME=%s", subAgentConfig.Name),
agent/agentcontainers/api_test.go:1896
- There is no test covering the branch where the customization name is invalid; add a case that supplies an invalid
Coder.Name
and asserts that the warning path is triggered.
t.Run("CreateReadsConfigTwice", func(t *testing.T) {
agent/agentcontainers/api_test.go:1264
- [nitpick] The variable name
fakeDCCLI
differs fromfDCCLI
used in the new subtest; consider unifying the naming for clarity and consistency across tests.
fakeDCCLI = &fakeDevcontainerCLI{
agent/agentcontainers/api.go:1163
- The local variable
logger
is undefined here; useapi.logger.Warn
to correctly reference the API’s logger instance.
logger.Warn(ctx, "invalid agent name in devcontainer customization, ignoring", slog.F("name", name))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit about log message but otherwise all good 👍🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimization looks good 💪🏻
Previously,
CODER_WORKSPACE_AGENT_NAME
would always be passed as the dev container name.This is invalid for the following scenarios:
This change now runs
ReadConfig
twice. The first read is to extract a name (if present), from thedevcontainer.json
. The second read will then use the name we have stored for the dev container (so this could be either the customization, terraform resource name, or container name).