{"record":{"id":"62197141d166979d","repo":"vxcontrol/pentagi","slug":"failed-to-get-task-d-subtasks-w","errorCode":null,"errorMessage":"failed to get task %d subtasks: %w","messagePattern":"failed to get task (.+?) subtasks: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/pkg/controller/subtasks.go","lineNumber":100,"sourceCode":"\tfor _, info := range plan {\n\t\t_, err := stc.taskCtx.DB.CreateSubtask(ctx, database.CreateSubtaskParams{\n\t\t\tStatus:      database.SubtaskStatusCreated,\n\t\t\tTaskID:      stc.taskCtx.TaskID,\n\t\t\tTitle:       info.Title,\n\t\t\tDescription: info.Description,\n\t\t})\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create subtask for task %d: %w\", stc.taskCtx.TaskID, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (stc *subtaskController) RefineSubtasks(ctx context.Context) error {\n\tsubtasks, err := stc.taskCtx.DB.GetTaskSubtasks(ctx, stc.taskCtx.TaskID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get task %d subtasks: %w\", stc.taskCtx.TaskID, err)\n\t}\n\n\tplan, err := stc.taskCtx.Provider.RefineSubtasks(ctx, stc.taskCtx.TaskID)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to refine subtasks for task %d: %w\", stc.taskCtx.TaskID, err)\n\t}\n\n\tif len(plan) == 0 {\n\t\treturn nil // no subtasks refined\n\t}\n\n\tsubtaskIDs := make([]int64, 0, len(subtasks))\n\tfor _, subtask := range subtasks {\n\t\tif subtask.Status == database.SubtaskStatusCreated {\n\t\t\tsubtaskIDs = append(subtaskIDs, subtask.ID)\n\t\t}\n\t}\n","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/vxcontrol/pentagi/blob/ea665308baaff015b226f308438a68d929d0f29b/backend/pkg/controller/subtasks.go#L82-L118","documentation":"RefineSubtasks first reloads the task's subtasks from the database via GetTaskSubtasks before asking the LLM provider for a refined plan. This error wraps any failure of that read, binding the task ID to the underlying store error. It is a pre-condition failure: refinement never starts because the current subtask state could not be loaded.","triggerScenarios":"Calling RefineSubtasks when the database connection is down, the subtasks table is missing/corrupted, the query context is cancelled (e.g. client disconnect or timeout), or GetTaskSubtasks returns a row-scan error.","commonSituations":"Postgres restarted mid-flow; context deadline exceeded because the flow context was cancelled while the agent was running; migration drift after upgrading so SQLC query no longer matches schema.","solutions":["Check backend logs for the wrapped cause (%w) — usually a pq/GORM connection error","Verify PostgreSQL is reachable and the DB pool is not exhausted","Confirm migrations ran (goose up) so the subtasks table matches SQLC queries","Retry RefineSubtasks once the DB connection is restored; the operation is safe to re-run"],"exampleFix":"// before\nsubtasks, err := stc.taskCtx.DB.GetTaskSubtasks(ctx, stc.taskCtx.TaskID)\nif err != nil {\n    return fmt.Errorf(\"failed to get task %d subtasks: %w\", stc.taskCtx.TaskID, err)\n}\n// after\nctx, cancel := context.WithTimeout(ctx, 10*time.Second)\ndefer cancel()\nsubtasks, err := stc.taskCtx.DB.GetTaskSubtasks(ctx, stc.taskCtx.TaskID)\nif err != nil {\n    return fmt.Errorf(\"failed to get task %d subtasks: %w\", stc.taskCtx.TaskID, err)\n}","handlingStrategy":"retry","validationCode":"if stc.taskCtx.TaskID <= 0 { return fmt.Errorf(\"invalid task id\") }\nif err := db.PingContext(ctx); err != nil { return fmt.Errorf(\"db unavailable: %w\", err) }","typeGuard":null,"tryCatchPattern":"subtasks, err := stc.taskCtx.DB.GetTaskSubtasks(ctx, taskID)\nif err != nil {\n    if errors.Is(err, context.Canceled) { return err }\n    return fmt.Errorf(\"failed to get task %d subtasks: %w\", taskID, err)\n}","preventionTips":["Run goose migrations on deploy so SQLC queries match schema","Monitor DB connection pool saturation","Always pass a live, non-cancelled context to DB calls"],"tags":["database","subtasks","controller"],"backgroundTag":"database-query-failed","analyzedSha":"ea665308baaff015b226f308438a68d929d0f29b","analyzedAt":"2026-09-01T14:16:31.421Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}