-
Notifications
You must be signed in to change notification settings - Fork 936
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(agent): disable dev container integration inside sub agents #18781
Conversation
…gent It appears we accidentally broke this logic in a previous PR. This should 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 |
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 Containers disabled 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 only Init
and then Start
at a later stage. This allows us to assume containerAPI
will always be a non-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 | Enabled Devcontainers option in setup and updated expected error messages. |
agent/agent.go | Removed if a.devcontainers guard so containerAPI 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...)
require.Contains(t, err.Error(), "Dev Container feature not supported.") | ||
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 run CODER_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! 👍🏻
It appears we accidentally broke this logic in a previous PR. This should now correctly disable the agent api as we'd expect.