Skip to content

Commit 8402237

Browse files
committed
fix(agent): fix script filtering for devcontainers
This was broken in #18630.
1 parent f0251df commit 8402237

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

agent/agent.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,15 +1158,13 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11581158
}
11591159
}
11601160

1161-
var (
1162-
scripts = manifest.Scripts
1163-
scriptRunnerOpts []agentscripts.InitOption
1164-
devcontainerScripts map[uuid.UUID]codersdk.WorkspaceAgentScript
1165-
)
1161+
scripts := manifest.Scripts
11661162
if a.containerAPI != nil {
1167-
scripts, devcontainerScripts = agentcontainers.ExtractDevcontainerScripts(manifest.Devcontainers, scripts)
1163+
// Since devcontainer are enabled, remove devcontainer scripts
1164+
// from the main scripts list to avoid showing an error.
1165+
scripts, _ = agentcontainers.ExtractDevcontainerScripts(manifest.Devcontainers, manifest.Scripts)
11681166
}
1169-
err = a.scriptRunner.Init(scripts, aAPI.ScriptCompleted, scriptRunnerOpts...)
1167+
err = a.scriptRunner.Init(scripts, aAPI.ScriptCompleted)
11701168
if err != nil {
11711169
return xerrors.Errorf("init script runner: %w", err)
11721170
}
@@ -1187,10 +1185,11 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11871185
if a.containerAPI != nil {
11881186
a.containerAPI.Init(
11891187
agentcontainers.WithManifestInfo(manifest.OwnerName, manifest.WorkspaceName, manifest.AgentName),
1190-
agentcontainers.WithDevcontainers(manifest.Devcontainers, scripts),
1188+
agentcontainers.WithDevcontainers(manifest.Devcontainers, manifest.Scripts),
11911189
agentcontainers.WithSubAgentClient(agentcontainers.NewSubAgentClientFromAPI(a.logger, aAPI)),
11921190
)
11931191

1192+
_, devcontainerScripts := agentcontainers.ExtractDevcontainerScripts(manifest.Devcontainers, manifest.Scripts)
11941193
for _, dc := range manifest.Devcontainers {
11951194
cErr := a.createDevcontainer(ctx, aAPI, dc, devcontainerScripts[dc.ID])
11961195
err = errors.Join(err, cErr)

agent/agentcontainers/api.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -935,12 +935,7 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
935935
return xerrors.Errorf("devcontainer not found")
936936
}
937937

938-
api.asyncWg.Add(1)
939-
defer api.asyncWg.Done()
940-
api.mu.Unlock()
941-
942938
var (
943-
err error
944939
ctx = api.ctx
945940
logger = api.logger.With(
946941
slog.F("devcontainer_id", dc.ID),
@@ -950,19 +945,23 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
950945
)
951946
)
952947

953-
if dc.ConfigPath != configPath {
954-
logger.Warn(ctx, "devcontainer config path mismatch",
955-
slog.F("config_path_param", configPath),
956-
)
957-
}
958-
959948
// Send logs via agent logging facilities.
960949
logSourceID := api.devcontainerLogSourceIDs[dc.WorkspaceFolder]
961950
if logSourceID == uuid.Nil {
962-
// Fallback to the external log source ID if not found.
951+
api.logger.Debug(api.ctx, "devcontainer log source ID not found, falling back to external log source ID")
963952
logSourceID = agentsdk.ExternalLogSourceID
964953
}
965954

955+
api.asyncWg.Add(1)
956+
defer api.asyncWg.Done()
957+
api.mu.Unlock()
958+
959+
if dc.ConfigPath != configPath {
960+
logger.Warn(ctx, "devcontainer config path mismatch",
961+
slog.F("config_path_param", configPath),
962+
)
963+
}
964+
966965
scriptLogger := api.scriptLogger(logSourceID)
967966
defer func() {
968967
flushCtx, cancel := context.WithTimeout(api.ctx, 5*time.Second)
@@ -981,7 +980,7 @@ func (api *API) CreateDevcontainer(workspaceFolder, configPath string, opts ...D
981980
upOptions := []DevcontainerCLIUpOptions{WithUpOutput(infoW, errW)}
982981
upOptions = append(upOptions, opts...)
983982

984-
_, err = api.dccli.Up(ctx, dc.WorkspaceFolder, configPath, upOptions...)
983+
_, err := api.dccli.Up(ctx, dc.WorkspaceFolder, configPath, upOptions...)
985984
if err != nil {
986985
// No need to log if the API is closing (context canceled), as this
987986
// is expected behavior when the API is shutting down.

0 commit comments

Comments
 (0)
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