summaryrefslogtreecommitdiff
path: root/internal/api/server.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-03-09 07:11:57 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-03-10 09:29:02 +0000
commit0676f0f2e6d1ba371806ca4b808a4993027d86ea (patch)
treec8d6776d1b4f1b82e3ba2b392272f359fb0ca499 /internal/api/server.go
parenta62a19bbf774289e2018e50454aa719c1a2a9070 (diff)
fix: ensure tasks are re-classified on manual restart
Updated handleRunTask to use ResetTaskForRetry, which clears the agent type and model. This ensures that manually restarted tasks are always re-classified, allowing the system to switch to a different agent if the previous one is rate-limited. Also improved Claude quota-exhaustion detection.
Diffstat (limited to 'internal/api/server.go')
-rw-r--r--internal/api/server.go23
1 files changed, 9 insertions, 14 deletions
diff --git a/internal/api/server.go b/internal/api/server.go
index a6e708a..944e450 100644
--- a/internal/api/server.go
+++ b/internal/api/server.go
@@ -459,24 +459,19 @@ func (s *Server) handleGetTask(w http.ResponseWriter, r *http.Request) {
func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
- t, err := s.store.GetTask(id)
+ t, err := s.store.ResetTaskForRetry(id)
if err != nil {
- writeJSON(w, http.StatusNotFound, map[string]string{"error": "task not found"})
- return
- }
-
- if !task.ValidTransition(t.State, task.StateQueued) {
- writeJSON(w, http.StatusConflict, map[string]string{
- "error": fmt.Sprintf("task cannot be queued from state %s", t.State),
- })
- return
- }
-
- if err := s.store.UpdateTaskState(id, task.StateQueued); err != nil {
+ if strings.Contains(err.Error(), "not found") {
+ writeJSON(w, http.StatusNotFound, map[string]string{"error": "task not found"})
+ return
+ }
+ if strings.Contains(err.Error(), "invalid state transition") {
+ writeJSON(w, http.StatusConflict, map[string]string{"error": err.Error()})
+ return
+ }
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
return
}
- t.State = task.StateQueued
if err := s.pool.Submit(context.Background(), t); err != nil {
writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": fmt.Sprintf("executor pool: %v", err)})