Skip to content

feat(agent/agentcontainers): allow auto start for discovered containers #19040

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 3 commits into from
Jul 28, 2025

Conversation

DanielleMaywood
Copy link
Contributor

@@ -143,7 +143,8 @@ func WithCommandEnv(ce CommandEnv) Option {
strings.HasPrefix(s, "CODER_WORKSPACE_AGENT_URL=") ||
strings.HasPrefix(s, "CODER_AGENT_TOKEN=") ||
strings.HasPrefix(s, "CODER_AGENT_AUTH=") ||
strings.HasPrefix(s, "CODER_AGENT_DEVCONTAINERS_ENABLE=")
strings.HasPrefix(s, "CODER_AGENT_DEVCONTAINERS_ENABLE=") ||
strings.HasPrefix(s, "CODER_AGENT_DEVCONTAINERS_PROJECT_DISCOVERY_ENABLE=")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed this in a previous PR #19016

@DanielleMaywood DanielleMaywood force-pushed the danielle/autostart-discovered-workspaces branch from ee6b803 to df5255b Compare July 28, 2025 09:26
api.knownDevcontainers[workspaceFolder] = dc
api.broadcastUpdatesLocked()
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'll now broadcast updates as we find the dev containers. This makes it feel a little quicker when there is a lot of files being searched through.

@DanielleMaywood DanielleMaywood marked this pull request as ready for review July 28, 2025 09:47
@DanielleMaywood
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Jul 28, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jul 28, 2025

📝 Walkthrough

Walkthrough

The changes introduce support for automatically starting devcontainers during project discovery if their configuration specifies AutoStart: true. This includes updating the devcontainer status, launching asynchronous container creation, filtering a specific environment variable, enhancing logging context, and adding comprehensive tests to verify the new auto-start behavior.

Changes

Cohort / File(s) Change Summary
AutoStart field addition
agent/agentcontainers/devcontainercli.go
Added AutoStart boolean field to the CoderCustomization struct for JSON serialization.
Devcontainer discovery & auto-start logic
agent/agentcontainers/api.go
Enhanced project discovery to read the AutoStart flag from devcontainer config, set initial status, and asynchronously start containers when required. Improved logger context and filtered an additional environment variable.
Auto-start behavior tests
agent/agentcontainers/api_test.go
Added new subtests to TestDevcontainerDiscovery to verify auto-start logic, including multiple scenarios with different AutoStart flag settings and corresponding expectations for container startup.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API
    participant DevcontainerCLI

    User->>API: Triggers project discovery
    API->>DevcontainerCLI: ReadConfig(devcontainer.json)
    DevcontainerCLI-->>API: Returns config (with AutoStart flag)
    API->>API: If AutoStart == true, set status to "Starting"
    API->>API: Broadcast devcontainer update
    API->>DevcontainerCLI: (async) CreateDevcontainer(workspace, configPath)
    DevcontainerCLI-->>API: (container started)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Scan repositories for non-started devcontainers (devcontainer.json) and prompt in the UI to start them (#711)
Support a customization to auto start devcontainers via .customizations.coder.autostart = true (#711)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Suggested reviewers

  • mafredri
  • mtojek

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch danielle/autostart-discovered-workspaces

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
agent/agentcontainers/api.go (2)

146-147: LGTM!

Correctly filters out the project discovery environment variable to prevent configuration conflicts between parent and child agents.


553-553: Broadcasting updates during discovery improves UX.

This allows the UI to show devcontainers as they're discovered rather than waiting for the entire discovery process to complete.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 398e80f and 02e606e.

📒 Files selected for processing (3)
  • agent/agentcontainers/api.go (2 hunks)
  • agent/agentcontainers/api_test.go (1 hunks)
  • agent/agentcontainers/devcontainercli.go (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
agent/agentcontainers/api_test.go (5)

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.064Z
Learning: Applies to **/*_test.go : All tests must use t.Parallel() to run concurrently, which improves test suite performance and helps identify race conditions.

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.064Z
Learning: Applies to **/*_test.go : All tests should run in parallel using t.Parallel() to ensure efficient testing and expose potential race conditions.

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T00:33:07.777Z
Learning: Applies to **/*_test.go : Use unique identifiers (e.g., fmt.Sprintf("test-client-%s-%d", t.Name(), time.Now().UnixNano())) and never use hardcoded names in concurrent tests to prevent race conditions.

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T00:33:07.155Z
Learning: Applies to **/*_test.go : Use unique identifiers (e.g., fmt.Sprintf("test-client-%s-%d", t.Name(), time.Now().UnixNano())) and never use hardcoded names in concurrent tests to prevent race conditions.

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-28T00:33:10.063Z
Learning: Applies to **/*_test.go : Use unique identifiers (e.g., fmt.Sprintf("test-client-%s-%d", t.Name(), time.Now().UnixNano())) and never use hardcoded names in concurrent tests to prevent race conditions.

🔇 Additional comments (3)
agent/agentcontainers/devcontainercli.go (1)

94-94: LGTM!

The AutoStart field is correctly added to the CoderCustomization struct with appropriate JSON serialization tags.

agent/agentcontainers/api.go (1)

528-528: Good addition of workspace folder context to logger.

This improves traceability during project discovery.

agent/agentcontainers/api_test.go (1)

3572-3816: LGTM! Well-implemented test for auto-start functionality.

This new test comprehensively validates the auto-start behavior described in the PR objectives. The implementation follows established patterns and best practices:

  • Properly uses t.Parallel() as required by the coding guidelines
  • Covers multiple scenarios: single enabled/disabled, mixed configurations, and multiple enabled devcontainers
  • Uses proper mock expectations with gomock.InOrder() to verify that Up() is called only for devcontainers with AutoStart: true
  • Follows the existing test structure and cleanup patterns
  • Uses appropriate test utilities and context handling

The test effectively validates that discovered devcontainers with the AutoStart flag set will trigger container creation via Up(), while those without it will not, which aligns perfectly with the PR's goal of implementing auto-start for discovered containers.

@DanielleMaywood DanielleMaywood assigned mtojek and unassigned mtojek Jul 28, 2025
@DanielleMaywood DanielleMaywood requested a review from mtojek July 28, 2025 10:50
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

LGTM!

go func() {
defer api.asyncWg.Done()

_ = api.CreateDevcontainer(dc.WorkspaceFolder, dc.ConfigPath)
Copy link
Member

Choose a reason for hiding this comment

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

nit: I suppose it returns an error, should we log it somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CreateDevcontainer already does a reasonable amount of logging. I don't think the error returned has any additional information to what is already logged.

@@ -3568,4 +3568,250 @@ func TestDevcontainerDiscovery(t *testing.T) {
// This is implicitly handled by `testutil.Logger` failing when it
// detects an error has been logged.
})

t.Run("AutoStart", func(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Nice tests!

@DanielleMaywood DanielleMaywood merged commit 66cf90c into main Jul 28, 2025
31 checks passed
@DanielleMaywood DanielleMaywood deleted the danielle/autostart-discovered-workspaces branch July 28, 2025 11:30
@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 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.

Devcontainers: Scan repositories for non-started devcontainers (devcontainer.json) and prompt in the UI to start them
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy