diff options
Diffstat (limited to 'internal/api/server.go')
| -rw-r--r-- | internal/api/server.go | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/internal/api/server.go b/internal/api/server.go index 59d59eb..65b0181 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -397,14 +397,15 @@ func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) { func (s *Server) handleCreateTask(w http.ResponseWriter, r *http.Request) { var input struct { - Name string `json:"name"` - Description string `json:"description"` - Agent task.AgentConfig `json:"agent"` - Claude task.AgentConfig `json:"claude"` // legacy alias - Timeout string `json:"timeout"` - Priority string `json:"priority"` - Tags []string `json:"tags"` - ParentTaskID string `json:"parent_task_id"` + Name string `json:"name"` + Description string `json:"description"` + ElaborationInput string `json:"elaboration_input"` + Agent task.AgentConfig `json:"agent"` + Claude task.AgentConfig `json:"claude"` // legacy alias + Timeout string `json:"timeout"` + Priority string `json:"priority"` + Tags []string `json:"tags"` + ParentTaskID string `json:"parent_task_id"` } if err := json.NewDecoder(r.Body).Decode(&input); err != nil { writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid JSON: " + err.Error()}) @@ -418,10 +419,11 @@ func (s *Server) handleCreateTask(w http.ResponseWriter, r *http.Request) { now := time.Now().UTC() t := &task.Task{ - ID: uuid.New().String(), - Name: input.Name, - Description: input.Description, - Agent: input.Agent, + ID: uuid.New().String(), + Name: input.Name, + Description: input.Description, + ElaborationInput: input.ElaborationInput, + Agent: input.Agent, Priority: task.Priority(input.Priority), Tags: input.Tags, DependsOn: []string{}, @@ -515,8 +517,16 @@ func (s *Server) handleGetTask(w http.ResponseWriter, r *http.Request) { } func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) { id := r.PathValue("id") - agent := r.URL.Query().Get("agent") + agentParam := r.URL.Query().Get("agent") // Use a different name to avoid confusion + // 1. Retrieve the original task to preserve agent config if not "auto". + originalTask, err := s.store.GetTask(id) + if err != nil { + writeJSON(w, http.StatusNotFound, map[string]string{"error": "task not found"}) + return + } + + // 2. Reset the task for retry, which clears the agent config. t, err := s.store.ResetTaskForRetry(id) if err != nil { if strings.Contains(err.Error(), "not found") { @@ -531,9 +541,27 @@ func (s *Server) handleRunTask(w http.ResponseWriter, r *http.Request) { return } - if agent != "" && agent != "auto" { - t.Agent.Type = agent + // 3. Restore original agent type and model if not explicitly overridden by query parameter. + // Only restore if original task had a specific agent type set and query parameter is not overriding it. + if originalTask.Agent.Type != "" && agentParam == "" { + t.Agent.Type = originalTask.Agent.Type + t.Agent.Model = originalTask.Agent.Model + } + + // 4. Handle agent query parameter override. + if agentParam != "" && agentParam != "auto" { + t.Agent.Type = agentParam + } + + // 5. Update task agent in DB if it has changed from the reset (only if originalTask.Agent.Type was explicitly set, or agentParam was set). + if originalTask.Agent.Type != t.Agent.Type || originalTask.Agent.Model != t.Agent.Model { + if err := s.store.UpdateTaskAgent(t.ID, t.Agent); err != nil { + s.logger.Error("failed to update task agent config", "error", err, "taskID", t.ID) + writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()}) + return + } } + // The task `t` now has the correct agent configuration. if err := s.pool.Submit(context.Background(), t); err != nil { writeJSON(w, http.StatusServiceUnavailable, map[string]string{"error": fmt.Sprintf("executor pool: %v", err)}) |
