- Notifications
You must be signed in to change notification settings - Fork948
fix(agent): disable dev container integration inside sub agents#18781
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
…gentIt appears we accidentally broke this logic in a previous PR. Thisshould now correctly disable the agent api as we'd expect.
@@ -2441,7 +2441,8 @@ func TestAgent_DevcontainersDisabledForSubAgent(t *testing.T) { | |||
// Setup the agent with devcontainers enabled initially. | |||
//nolint:dogsled | |||
conn, _, _, _, _ := setupAgent(t, manifest, 0, func(*agenttest.Client, *agent.Options) { | |||
conn, _, _, _, _ := setupAgent(t, manifest, 0, func(_ *agenttest.Client, o *agent.Options) { | |||
o.Devcontainers = true |
DanielleMaywoodJul 7, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
It appears the test allowed the regression to occur as it had Dev Containersdisabled by default. This means it didn't properly test the flow we'd expect.
containerAPIOpts := []agentcontainers.Option{ | ||
agentcontainers.WithExecer(a.execer), | ||
agentcontainers.WithCommandEnv(a.sshServer.CommandEnv), | ||
agentcontainers.WithScriptLogger(func(logSourceID uuid.UUID) agentcontainers.ScriptLogger { | ||
return a.logSender.GetScriptLogger(logSourceID) | ||
}), | ||
} | ||
containerAPIOpts = append(containerAPIOpts, a.containerAPIOptions...) | ||
a.containerAPI = agentcontainers.NewAPI(a.logger.Named("containers"), containerAPIOpts...) |
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.
We're going to create the API by default. This is fine as we onlyInit
and thenStart
at a later stage. This allows us to assumecontainerAPI
will always be anon-nil
value.
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 restores correct behavior for the dev container API by disabling it when running inside a sub-agent and adjusting the user-facing error messages accordingly.
- Update the
/api/v0/containers
handler to checkdevcontainers
flag first, then explicitly forbid calls from sub-agents. - Adjust test to enable
Devcontainers
in options and assert on the new error text. - Remove conditional guard around
containerAPI
instantiation/closure to align API setup with the new flag-based routing.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
agent/api.go | Revised routing logic for/api/v0/containers based on flags and manifest parent. |
agent/agent_test.go | EnabledDevcontainers option in setup and updated expected error messages. |
agent/agent.go | Removedif a.devcontainers guard socontainerAPI is always created and closed. |
Comments suppressed due to low confidence (1)
agent/agent.go:348
- Since
containerAPI
is now instantiated unconditionally, consider wrapping its creation in thedevcontainers
flag guard to avoid unnecessary resource allocation when the feature is disabled.
a.containerAPI = agentcontainers.NewAPI(a.logger.Named("containers"), containerAPIOpts...)
Uh oh!
There was an error while loading.Please reload this page.
require.Contains(t, err.Error(), "Dev Containerfeature notsupported.") | ||
require.Contains(t, err.Error(), "Dev Container integration inside other Dev Containers is explicitly not supported.") |
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.
Reminder to runCODER_TEST_USE_DOCKER=1 go test ./coderd ./agent ./agent/agentcontainers
if you want to verify the "integration" tests.
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.
Looks solid! 👍🏻
0118e75
intomainUh oh!
There was an error while loading.Please reload this page.
It appears we accidentally broke this logic in a previous PR. This should now correctly disable the agent api as we'd expect.