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

Skip to content

Commit 3714fec

Browse files
chore: simplify things a little
1 parent 738b755 commit 3714fec

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

agent/agent.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,9 +1108,6 @@ func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context,
11081108
if a.devcontainers {
11091109
a.logger.Info(ctx, "devcontainers are not supported on sub agents, disabling feature")
11101110
a.devcontainers = false
1111-
if err := a.containerAPI.Close(); err != nil {
1112-
a.logger.Error(ctx, "disable container API", slog.Error(err))
1113-
}
11141111
}
11151112
}
11161113
a.client.RewriteDERPMap(manifest.DERPMap)

agent/agentcontainers/api.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ const (
5151
type API struct {
5252
ctx context.Context
5353
cancel context.CancelFunc
54-
initialized chan struct{}
5554
watcherDone chan struct{}
5655
updaterDone chan struct{}
5756
initialUpdateDone chan struct{} // Closed after first update in updaterLoop.
@@ -266,7 +265,6 @@ func NewAPI(logger slog.Logger, options ...Option) *API {
266265
api := &API{
267266
ctx: ctx,
268267
cancel: cancel,
269-
initialized: make(chan struct{}),
270268
watcherDone: make(chan struct{}),
271269
updaterDone: make(chan struct{}),
272270
initialUpdateDone: make(chan struct{}),
@@ -317,24 +315,19 @@ func NewAPI(logger slog.Logger, options ...Option) *API {
317315
api.subAgentClient.Store(&c)
318316
}
319317

320-
go func() {
321-
select {
322-
case <-api.ctx.Done():
323-
break
324-
case <-api.initialized:
325-
go api.watcherLoop()
326-
go api.updaterLoop()
327-
}
328-
}()
329-
330318
return api
331319
}
332320

321+
// Init applies a final set of options to the API and then
322+
// begins the watcherLoop and updaterLoop. This function
323+
// must only be called once.
333324
func (api *API) Init(opts ...Option) {
334325
for _, opt := range opts {
335326
opt(api)
336327
}
337-
close(api.initialized)
328+
329+
go api.watcherLoop()
330+
go api.updaterLoop()
338331
}
339332

340333
func (api *API) watcherLoop() {
@@ -1605,8 +1598,6 @@ func (api *API) Close() error {
16051598
api.logger.Debug(api.ctx, "closing API")
16061599
api.closed = true
16071600

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

0 commit comments

Comments
 (0)