| 214 | } |
| 215 | |
| 216 | func (rt *AgentTaskRuntime) Shutdown() { |
| 217 | rt.mu.Lock() |
| 218 | type taskRef struct { |
| 219 | id string |
| 220 | scope string |
| 221 | } |
| 222 | refs := make([]taskRef, 0, len(rt.records)) |
| 223 | for id, record := range rt.records { |
| 224 | if _, terminal := terminalTaskStatuses[record.Status]; terminal { |
| 225 | continue |
| 226 | } |
| 227 | refs = append(refs, taskRef{id: id, scope: record.ParentScopeID}) |
| 228 | } |
| 229 | rt.mu.Unlock() |
| 230 | for _, ref := range refs { |
| 231 | rt.StopTask(ref.id, ref.scope) |
| 232 | } |
| 233 | rt.mu.Lock() |
| 234 | rt.cancelAllRecordCleanupLocked() |
| 235 | rt.cancelAllIdleTTLLocked() |
| 236 | rt.mu.Unlock() |
| 237 | } |
| 238 | |
| 239 | func (rt *AgentTaskRuntime) ListTasks(scopeID string) []AgentTaskRecord { |
| 240 | rt.mu.Lock() |