vxcontrol/pentagi · warning

ErrTasksInvalidRequest

ErrTasksInvalidRequest

Error message

group field not found

What it means

GetFlowTasks supports grouped task listings. The `group` query parameter is checked against tasksSQLMappers; if it is set but not found in that map, the handler returns ErrTasksInvalidRequest before running the grouped query.

Source

Thrown at backend/pkg/server/services/tasks.go:108

		}
	} else if slices.Contains(privs, "tasks.view") {
		scope = func(db *gorm.DB) *gorm.DB {
			return db.
				Joins("INNER JOIN flows f ON f.id = tasks.flow_id").
				Where("f.id = ? AND f.user_id = ?", flowID, uid)
		}
	} else {
		logger.FromContext(c).Errorf("error filtering user role permissions: permission not found")
		response.Error(c, response.ErrNotPermitted, nil)
		return
	}

	query.Init("tasks", tasksSQLMappers)

	if query.Group != "" {
		if _, ok := tasksSQLMappers[query.Group]; !ok {
			logger.FromContext(c).Errorf("error finding tasks grouped: group field not found")
			response.Error(c, response.ErrTasksInvalidRequest, errors.New("group field not found"))
			return
		}

		var respGrouped tasksGrouped
		if respGrouped.Total, err = query.QueryGrouped(s.db, &respGrouped.Grouped, scope); err != nil {
			logger.FromContext(c).WithError(err).Errorf("error finding tasks grouped")
			response.Error(c, response.ErrInternal, err)
			return
		}

		response.Success(c, http.StatusOK, respGrouped)
		return
	}

	if resp.Total, err = query.Query(s.db, &resp.Tasks, scope); err != nil {
		logger.FromContext(c).WithError(err).Errorf("error finding tasks")
		response.Error(c, response.ErrInternal, err)
		return

View on GitHub (pinned to ea665308ba)

Solutions

  1. Use a group field present in tasksSQLMappers in backend/pkg/server/services/tasks.go.
  2. Drop the group parameter for the default listing.
  3. Update clients to the current groupable fields after schema/mapper changes.
  4. Add the field to tasksSQLMappers if server-side grouping by it is required.

Example fix

// before
GET /api/v1/flows/5/tasks?group=priority
// after
GET /api/v1/flows/5/tasks?group=status
Defensive patterns

Strategy: validation

Validate before calling

const TASKS_GROUP_FIELDS = ['status', 'created_at']; // keys of tasksSQLMappers
if (group && !TASKS_GROUP_FIELDS.includes(group)) {
  throw new Error(`invalid group field for tasks: ${group}`);
}

Type guard

function isValidTaskGroup(g) {
  return typeof g === 'string' && TASKS_GROUP_FIELDS.includes(g);
}

Try / catch

try {
  return await api.getFlowTasks(flowId, { group });
} catch (e) {
  if (e.code === 'ErrTasksInvalidRequest' && e.message === 'group field not found') {
    return await api.getFlowTasks(flowId, {});
  }
  throw e;
}

Prevention

When it happens

Trigger: GET /flows/{flow_id}/tasks?group=<field> where <field> is not a key of tasksSQLMappers (unknown/renamed/unmapped column).

Common situations: Flow overview dashboards grouping tasks by fields like priority or result that are not mapped; clients reusing group values from subtasks/termlogs endpoints whose mappers differ; frontend/backend drift after a mapper cleanup.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/d13033eaa7b0db88. Report an issue: GitHub.