MCPcopy Index your code
hub / github.com/coder/coder / runSubAgentInContainer

Method runSubAgentInContainer

agent/agentcontainers/api.go:2143–2171  ·  view source on GitHub ↗

runSubAgentInContainer runs the subagent process inside a dev container. The api.asyncWg must be incremented before calling this function, and it will be decremented when the subagent process completes or if an error occurs.

(ctx context.Context, logger slog.Logger, dc codersdk.WorkspaceAgentDevcontainer, proc subAgentProcess, agentPath string)

Source from the content-addressed store, hash-verified

2141// function, and it will be decremented when the subagent process
2142// completes or if an error occurs.
2143func (api *API) runSubAgentInContainer(ctx context.Context, logger slog.Logger, dc codersdk.WorkspaceAgentDevcontainer, proc subAgentProcess, agentPath string) {
2144 container := dc.Container // Must not be nil.
2145 logger = logger.With(
2146 slog.F("agent_id", proc.agent.ID),
2147 )
2148
2149 defer func() {
2150 proc.stop()
2151 logger.Debug(ctx, "agent process cleanup complete")
2152 api.asyncWg.Done()
2153 }()
2154
2155 logger.Info(ctx, "starting subagent in devcontainer")
2156
2157 env := []string{
2158 "CODER_AGENT_URL=" + api.subAgentURL,
2159 "CODER_AGENT_TOKEN=" + proc.agent.AuthToken.String(),
2160 }
2161 env = append(env, api.subAgentEnv...)
2162 err := api.dccli.Exec(proc.ctx, dc.WorkspaceFolder, dc.ConfigPath, agentPath, []string{"agent"},
2163 WithExecContainerID(container.ID),
2164 WithRemoteEnv(env...),
2165 )
2166 if err != nil && !errors.Is(err, context.Canceled) {
2167 logger.Error(ctx, "subagent process failed", slog.Error(err))
2168 } else {
2169 logger.Info(ctx, "subagent process finished")
2170 }
2171}
2172
2173func (api *API) Close() error {
2174 api.mu.Lock()

Calls 9

WithExecContainerIDFunction · 0.85
WithRemoteEnvFunction · 0.85
stopMethod · 0.65
ExecMethod · 0.65
DoneMethod · 0.45
InfoMethod · 0.45
StringMethod · 0.45
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected