Skip to content

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

Merged
merged 5 commits into from
Jul 8, 2025

Conversation

DanielleMaywood
Copy link
Contributor

It appears we accidentally broke this logic in a previous PR. This should now correctly disable the agent api as we'd expect.

…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
Copy link
Contributor Author

@DanielleMaywood DanielleMaywood Jul 7, 2025

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.

Comment on lines +339 to +348
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...)
Copy link
Contributor Author

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.

@DanielleMaywood DanielleMaywood requested a review from Copilot July 7, 2025 21:57
Copy link
Contributor

@Copilot Copilot AI left a 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 check devcontainers 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 the devcontainers flag guard to avoid unnecessary resource allocation when the feature is disabled.
	a.containerAPI = agentcontainers.NewAPI(a.logger.Named("containers"), containerAPIOpts...)

Comment on lines +2457 to +2458
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.")
Copy link
Contributor Author

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.

@DanielleMaywood DanielleMaywood marked this pull request as ready for review July 7, 2025 22:05
@DanielleMaywood DanielleMaywood requested a review from mafredri July 8, 2025 09:08
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid! 👍🏻

@DanielleMaywood DanielleMaywood merged commit 0118e75 into main Jul 8, 2025
34 checks passed
@DanielleMaywood DanielleMaywood deleted the danielle/stop-devcontainer-in-devcontainer branch July 8, 2025 10:05
@github-actions github-actions bot locked and limited conversation to collaborators Jul 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants