-
Notifications
You must be signed in to change notification settings - Fork 928
fix(agent): fix script filtering for devcontainers #18635
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
mafredri
merged 1 commit into
main
from
mafredri/fix-agent-fix-devcontainer-script-filtering
Jun 27, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,15 +79,14 @@ type API struct { | |
containersErr error // Error from the last list operation. | ||
devcontainerNames map[string]bool // By devcontainer name. | ||
knownDevcontainers map[string]codersdk.WorkspaceAgentDevcontainer // By workspace folder. | ||
devcontainerLogSourceIDs map[string]uuid.UUID // By workspace folder. | ||
configFileModifiedTimes map[string]time.Time // By config file path. | ||
recreateSuccessTimes map[string]time.Time // By workspace folder. | ||
recreateErrorTimes map[string]time.Time // By workspace folder. | ||
injectedSubAgentProcs map[string]subAgentProcess // By workspace folder. | ||
usingWorkspaceFolderName map[string]bool // By workspace folder. | ||
ignoredDevcontainers map[string]bool // By workspace folder. Tracks three states (true, false and not checked). | ||
asyncWg sync.WaitGroup | ||
|
||
devcontainerLogSourceIDs map[string]uuid.UUID // By workspace folder. | ||
} | ||
|
||
type subAgentProcess struct { | ||
|
@@ -935,12 +934,7 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D | |
return xerrors.Errorf("devcontainer not found") | ||
} | ||
|
||
api.asyncWg.Add(1) | ||
defer api.asyncWg.Done() | ||
api.mu.Unlock() | ||
|
||
var ( | ||
err error | ||
ctx = api.ctx | ||
logger = api.logger.With( | ||
slog.F("devcontainer_id", dc.ID), | ||
|
@@ -950,19 +944,23 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D | |
) | ||
) | ||
|
||
if dc.ConfigPath != configPath { | ||
logger.Warn(ctx, "devcontainer config path mismatch", | ||
slog.F("config_path_param", configPath), | ||
) | ||
} | ||
|
||
// Send logs via agent logging facilities. | ||
logSourceID := api.devcontainerLogSourceIDs[dc.WorkspaceFolder] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review: We were accessing this outside the mutex so I moved it just in case due to change in how we |
||
if logSourceID == uuid.Nil { | ||
// Fallback to the external log source ID if not found. | ||
api.logger.Debug(api.ctx, "devcontainer log source ID not found, falling back to external log source ID") | ||
logSourceID = agentsdk.ExternalLogSourceID | ||
} | ||
|
||
api.asyncWg.Add(1) | ||
defer api.asyncWg.Done() | ||
api.mu.Unlock() | ||
|
||
if dc.ConfigPath != configPath { | ||
logger.Warn(ctx, "devcontainer config path mismatch", | ||
slog.F("config_path_param", configPath), | ||
) | ||
} | ||
|
||
scriptLogger := api.scriptLogger(logSourceID) | ||
defer func() { | ||
flushCtx, cancel := context.WithTimeout(api.ctx, 5*time.Second) | ||
|
@@ -981,7 +979,7 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D | |
upOptions := []DevcontainerCLIUpOptions{WithUpOutput(infoW, errW)} | ||
upOptions = append(upOptions, opts...) | ||
|
||
_, err = api.dccli.Up(ctx, dc.WorkspaceFolder, configPath, upOptions...) | ||
_, err := api.dccli.Up(ctx, dc.WorkspaceFolder, configPath, upOptions...) | ||
if err != nil { | ||
// No need to log if the API is closing (context canceled), as this | ||
// is expected behavior when the API is shutting down. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there any reason to call this function twice?
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.
Mainly I wanted to reduce variable scope to avoid similar issues as introduced in the previous PR. And make it clear that scripts from earlier shouldn't be used here. It's a lightweight call but I can revert it if you prefer.
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.
I have no issue with the duplication just wanted to ensure I knew the reason why, all good!