on main help sign in
chore: cancel requests when user closes
fc8ec7fKujtim Hoxha
internal/app/app.go+1
@@ -163,4 +163,5 @@ func (app *App) Shutdown() {
163 }
163 }
164 cancel()
164 cancel()
165 }
165 }
166+ app.CoderAgent.CancelAll()
166}
167}
internal/llm/agent/agent.go+8
@@ -50,6 +50,7 @@ type Service interface {
50 Model() models.Model
50 Model() models.Model
51 Run(ctx context.Context, sessionID string, content string, attachments ...message.Attachment) (<-chan AgentEvent, error)
51 Run(ctx context.Context, sessionID string, content string, attachments ...message.Attachment) (<-chan AgentEvent, error)
52 Cancel(sessionID string)
52 Cancel(sessionID string)
53+ CancelAll()
53 IsSessionBusy(sessionID string) bool
54 IsSessionBusy(sessionID string) bool
54 IsBusy() bool
55 IsBusy() bool
55 Update(agentName config.AgentName, modelID models.ModelID) (models.Model, error)
56 Update(agentName config.AgentName, modelID models.ModelID) (models.Model, error)
@@ -698,6 +699,13 @@ func (a *agent) Summarize(ctx context.Context, sessionID string) error {
698 return nil
699 return nil
699}
700}
700
701
702+func (a *agent) CancelAll() {
703+ a.activeRequests.Range(func(key, value any) bool {
704+ a.Cancel(key.(string)) // key is sessionID
705+ return true
706+ })
707+}
708+
701func createAgentProvider(agentName config.AgentName) (provider.Provider, error) {
709func createAgentProvider(agentName config.AgentName) (provider.Provider, error) {
702 cfg := config.Get()
710 cfg := config.Get()
703 agentConfig, ok := cfg.Agents[agentName]
711 agentConfig, ok := cfg.Agents[agentName]