Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 738b755

Browse files
chore: only enable when devcontainers are enabled
1 parent 32ac48a commit 738b755

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

agent/agent.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,18 @@ func (a *agent) init() {
336336
// will not report anywhere.
337337
a.scriptRunner.RegisterMetrics(a.prometheusRegistry)
338338

339-
containerAPIOpts := []agentcontainers.Option{
340-
agentcontainers.WithExecer(a.execer),
341-
agentcontainers.WithCommandEnv(a.sshServer.CommandEnv),
342-
agentcontainers.WithScriptLogger(func(logSourceID uuid.UUID) agentcontainers.ScriptLogger {
343-
return a.logSender.GetScriptLogger(logSourceID)
344-
}),
345-
}
346-
containerAPIOpts = append(containerAPIOpts, a.containerAPIOptions...)
339+
if a.devcontainers {
340+
containerAPIOpts := []agentcontainers.Option{
341+
agentcontainers.WithExecer(a.execer),
342+
agentcontainers.WithCommandEnv(a.sshServer.CommandEnv),
343+
agentcontainers.WithScriptLogger(func(logSourceID uuid.UUID) agentcontainers.ScriptLogger {
344+
return a.logSender.GetScriptLogger(logSourceID)
345+
}),
346+
}
347+
containerAPIOpts = append(containerAPIOpts, a.containerAPIOptions...)
347348

348-
a.containerAPI = agentcontainers.NewAPI(a.logger.Named("containers"), containerAPIOpts...)
349+
a.containerAPI = agentcontainers.NewAPI(a.logger.Named("containers"), containerAPIOpts...)
350+
}
349351

350352
a.reconnectingPTYServer = reconnectingpty.NewServer(
351353
a.logger.Named("reconnecting-pty"),
@@ -1106,6 +1108,9 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11061108
if a.devcontainers {
11071109
a.logger.Info(ctx, "devcontainers are not supported on sub agents, disabling feature")
11081110
a.devcontainers = false
1111+
if err := a.containerAPI.Close(); err != nil {
1112+
a.logger.Error(ctx, "disable container API", slog.Error(err))
1113+
}
11091114
}
11101115
}
11111116
a.client.RewriteDERPMap(manifest.DERPMap)
@@ -1310,8 +1315,10 @@ func (a *agent) createOrUpdateNetwork(manifestOK, networkOK *checkpoint) func(co
13101315
network.SetBlockEndpoints(manifest.DisableDirectConnections)
13111316

13121317
// Update the subagent client if the container API is available.
1313-
client := agentcontainers.NewSubAgentClientFromAPI(a.logger, aAPI)
1314-
a.containerAPI.UpdateSubAgentClient(client)
1318+
if a.containerAPI != nil {
1319+
client := agentcontainers.NewSubAgentClientFromAPI(a.logger, aAPI)
1320+
a.containerAPI.UpdateSubAgentClient(client)
1321+
}
13151322
}
13161323
return nil
13171324
}
@@ -1912,8 +1919,10 @@ func (a *agent) Close() error {
19121919
a.logger.Error(a.hardCtx, "script runner close", slog.Error(err))
19131920
}
19141921

1915-
if err := a.containerAPI.Close(); err != nil {
1916-
a.logger.Error(a.hardCtx, "container API close", slog.Error(err))
1922+
if a.containerAPI != nil {
1923+
if err := a.containerAPI.Close(); err != nil {
1924+
a.logger.Error(a.hardCtx, "container API close", slog.Error(err))
1925+
}
19171926
}
19181927

19191928
// Wait for the graceful shutdown to complete, but don't wait forever so

agent/agentcontainers/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,8 @@ func (api *API) Close() error {
16051605
api.logger.Debug(api.ctx, "closing API")
16061606
api.closed = true
16071607

1608+
close(api.initialized)
1609+
16081610
// Stop all running subagent processes and clean up.
16091611
subAgentIDs := make([]uuid.UUID, 0, len(api.injectedSubAgentProcs))
16101612
for workspaceFolder, proc := range api.injectedSubAgentProcs {

0 commit comments

Comments
 (0)